0

I am trying to achieve a very different scenario for my few items.

What I need

Have product with 3 prices (org price, sale price, and higher sale price) with sale price expiry date.

How it should work

When sale price expires then it should fall back to higher sale price.

Example

Let's say product has price of $100 and sale price is $60 and expiry date is tomorrow.

When sale expires tomorrow, by default magento rule it will fall back to rrp but I want it to fall back to another user defined sale price (i.e. higher sale price: $70). I can create a new price attribute to have new price field for each item.

Is this possible?

1 Answer 1

0

Right, looks like I have to answer it myself. After few days of struggle I came to use observer to achieve this.

So decided to run a daily cron to check if there are any special price to date for any product within my category and then do the business logic.

Cron runs everyday at the midnight.

My observer.php

public function scheduledChangePrice()
    {
        $category_id = 132;
        $products = Mage::getModel('catalog/category')->load($category_id)
                    ->getProductCollection()
                    ->addAttributeToSelect('*') // add all attributes - optional
                    ->addAttributeToFilter('status', 1) // enabled
                    ->addAttributeToFilter('visibility', 4) //visibility in catalog,search
                    //->setOrder('price', 'ASC')
                     ; //sets the order by price
        $i = 0;
        //$product = Mage::getModel('catalog/product')->load(3338);//(3389);
        foreach($products as $product){
            $i++;
            if($product->getSpecialToDate() && ($product->getSpecialToDate() . ' 11:59:59 PM') <= $this->getCurrentDateTime()){
                $product
                        ->setSpecialPrice($product->getSpecialPrice() + 5) //add $5 to special price so it falls to higher sale price
                        ->setSpecialToDate(null) //remove special to date so that cron doesn't run again
                        ->save();
            }
        }
    }

public function getCurrentDateTime($_storeId = null, $_format = 'm/d/y H:i:s') {
        if (is_null($_storeId)) {
            $_storeId = Mage::app()->getStore()->getId();
        }
        $storeDatetime = new DateTime();
        $storeDatetime->setTimezone(new DateTimeZone(Mage::getStoreConfig('general/locale/timezone', $_storeId)));  

        return $storeDatetime->format($_format);
    }

Hope this will help someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.