0

One of My client has requirement to change product price daily
ie- he fill the product price for all month at once when month start
eg- day1:$10, day2:$15, day3:$12, day4:$11 and so on to last date
my idea is create 31 products attributes to fill price & run a cron job daily to set product price according to date like if date is 1st set price of attribute day1 & if date is 2nd set price of attribute day2 & so on
but I didn't have any idea about how to run cron job as per my requirement , can anyone guide me how to use cron job as per requirement or any other best idea to fulfil the above requirement

Thanks in advance for help

1
  • 1
    do you have specific rules for how the price will change or is ist just arbitrarily Commented Feb 20, 2016 at 19:29

1 Answer 1

1

Assuming that the prices are random and impossible to figure out a formula, you could either create 31 product attributes (ie today_price_1...31) for each day, create one attributes and enter the price for each day as a csv or create a csv upload that keep track of the product id/sku and each day price for all the item that need to be updated.

Assuming that there is a formula, then you will need to figure out if this formula should apply to the current day price or the original base product price. You may want to consider using/changing the "special price" so you can all way know what the base price is (assuming it always more)

Module

<config>
    <global>
        <models>
            <pricecron>
                <class>MagePal_PriceCron_Model</class>
            </pricecron>                            
        </models>
    </global>
    <crontab>
        <jobs>
            <pricecron>
                <schedule>
                    <cron_expr>0 0 * * *</cron_expr>
                </schedule>
                <run>
                    <model>pricecron/observer::setPrice</model>
                </run>
            </pricecron>
        </jobs>
    </crontab>
</config>

In app/code/local/Roomstory/Invoice/Model/Observer.php add the following:

<?php
class MagePal_PriceCron_Model_Observer {
    public function setPrice() {
        //to do - get today day index (assuming 1)
        $todayIndex = 1;

        Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
        //Assuming you are using product attributes
        $products = Mage::getModel('catalog/product')->getCollection();
        foreach($products as $product) {
            //get attribute base of today
            $todayPrice = $product->getData('today_price_' . $todayIndex);
            if($todayPrice > 0){
                //may want to think about using special price
                $product->getPrice($todayPrice);
                $product->save();
            }

        }
    }
}
2
  • thanks for help ,let me one thing where to put config code in app/code/local/Roomstory/config.xml right
    – Dinesh
    Commented Feb 21, 2016 at 9:04
  • is I need to create new module named Roomstory
    – Dinesh
    Commented Feb 21, 2016 at 9:11

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.