Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magento- Adding a From and a To date for tier prices in admin module

I need to know how to add a data range (from and a to date) for tier prices in magento, which will make the prices only appear within the given date range.

I am new to magento, so any guidance will be great help.

thanks in advance.

like image 639
melaka Avatar asked Jan 23 '13 03:01

melaka


2 Answers

Since this is not possible by default within, magento what you could try is :

Create 2 fields in Admin -> Catalog -> Attribute for tierprice_to_date and tierprice_from_date and add it to price group in your Attribute Sets.

In /app/design/frontend/base/default/template/catalog/product/view.phtml

if(date between tierprice_from_date and tierprice_to_date){
    echo $this->getTierPriceHtml();
}

Then create a custom module with observer that check the price when items are added to cart using event 'sales_quote_add_item':

Create: app/code/local/MageIgniter/TierPriceDateRange/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MageIgniter_TierPriceDateRange>
            <version>1.0.1</version>
        </MageIgniter_TierPriceDateRange>
    </modules>

    <global>
        <models>
            <tierpricedaterange>
                <class>MageIgniter_TierPriceDateRange_Model</class>
            </tierpricedaterange>
        </models>
         <events>
            <sales_quote_add_item>
                <observers>
                    <tierpricedaterange_observer>
                        <type>singleton</type>
                        <class>tierpricedaterange/observer</class>
                        <method>updatePrice</method>
                    </tierpricedaterange_observer>
                </observers>
            </sales_quote_add_item>
        </events>
    </global>
</config>

Create: app/code/local/MageIgniter/TierPriceDateRange/Model/Observer.php

class MageIgniter_TierPriceDateRange_Model_Observer 
{
    public function updatePrice($observer) {
    if(date NOT between tierprice_from_date and tierprice_to_date){
       $cartItem = $observer->getEvent()->getQuoteItem();
       // check if a tier price was apply and change it back to the original price (none tier price)
       $product = Mage::getModule('catalog/product')->load($product->getId());

       if($cartItem->getPrice() == $product->getTierPrice($cartItem->getQty())){
            $new_price = $product->getPrice();
            $product->setOriginalCustomPrice($new_price);
            $product->save();
       }
    }
   return $this;
}

Create: app/etc/modules/MageIgniter_TierPriceDateRange.xml

  <?xml version="1.0"?>
    <config>
           <modules>
                  <MageIgniter_TierPriceDateRange>
                          <active>true</active>
                          <codePool>local</codePool>
                  </MageIgniter_TierPriceDateRange>
           </modules>
    </config>

Then clear cache, if any.

like image 117
Renon Stewart Avatar answered Nov 18 '22 01:11

Renon Stewart


This is not possible within the standard Magento configuration. You would have to build (or have it build for you) a custom module to make this possible.

See also http://www.magentocommerce.com/boards/viewthread/230679/

like image 2
jmmeijer Avatar answered Nov 18 '22 00:11

jmmeijer