Hi,
Thanks in advance..
As in my previous question i have set the discount code for the product on fly its working fine but i want to apply this rule for specific product only is this possible by changing previous code.
please help me...
Thanks, Jitendra
for your information the code is here....
function generateUniqueId($length = null)
{
$rndId = crypt(uniqid(rand(),1));
$rndId = strip_tags(stripslashes($rndId));
$rndId = str_replace(array(".", "$"),"",$rndId);
$rndId = strrev(str_replace("/","",$rndId));
if (!is_null($rndId)){
return strtoupper(substr($rndId, 0, $length));
}
return strtoupper($rndId);
}
/* create unique coupan code */
$productId = (int) $this->getRequest()->getParam('id');
$discountprice=$_POST['product']['discountprice'];
$model = Mage::getModel('salesrule/rule');
$couponCode=generateUniqueId(8);
$model->setName($couponCode);
$model->setDescription('Discount coupon for Surger.');
$model->setUsesPerCoupon(1);
$model->setUsesPerCustomer(1);
$model->setCustomerGroupIds('0,1');
$model->setIsActive(1);
// $model->setConditionsSerialized('a:6:{s:4:\"type\";s:32:\"salesrule/rule_condition_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
//$model->setActionsSerialized('a:6:{s:4:\"type\";s:40:\"salesrule/rule_condition_product_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
$model->setStopRulesProcessing(0);
$model->setIsAdvanced(1);
// $model->setProductIds($productId);
$model->setSortOrder('0');
$model->setSimpleAction('by_percent');
$model->setDiscountAmount($discountprice);
$model->setDiscountStep(0);
$model->setSimpleFreeShipping(0);
$model->setCouponType(2);
$model->setCouponCode($couponCode);
$model->setUsesPerCoupon(1);
$model->setTimesUsed(0);
$model->setIsRss(0);
$model->setWebsiteIds('1');
$model->save();