Question

I want to add discount to the product when that product exceeds more than 15 days from created date.

Generally i know how to add discount to the product, but i felt this is difficult to set the discount with that condition. It make me as so confused. I have found where to add that attribute in combo box.

\app\code\core\Mage\SalesRule\Model\Rule\Condition\address.php

I got created date of product by $product->getCreatedAt()

But i totally confused "how to do that action?". If anybody know, Please help me guys!

Was it helpful?

Solution 2

I have simply used shopping cart price rules by the following way.

first i had created product attribute named as days. Then I have set the value to that days textbox as programmatically as follows

require_once("app/Mage.php");

Mage::app(); 

$productCollection = Mage::getModel('catalog/product')->getCollection();

$date2=Date("Y-m-d");
foreach($productCollection as $_product) 
{
$product = Mage::getModel('catalog/product')->load($_product->getEntityId());

$date1=$product->getCreatedAt();

$diff = abs(strtotime($date2) - strtotime($date1));

 $years = floor($diff / (365*60*60*24));
 $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
 $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

 $product->setDays($days);

$product->save();
}

After that i have added that product attribute promo rules. Then i set the condition as if differerence between dates which are from product creation date to now is more than 15 days, to add discount to that particular product.

OTHER TIPS

Here i am givin you some brief idea to make customization in catalog rule to check if your product is old from created with 15 days and more.

Try to build your own module to manage this kind of catalog rule in your applicaion

you can take understand from this tutorial to manage catalog rule

specially just go throw last 4 slides to make your own rule to achieve your goal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top