Magento Tutorial Shopping Cart Rule Programatically

Shopping cart rule selain bisa dibuat melalui backend, bisa juga dibuat melalui kode
107  
       

Shopping cart rule selain bisa dibuat melalui backend, bisa juga dibuat melalui kode. Kode ini hanya bisa diaplikasikan didalam extension.

$rule = Mage::getModel('salesrule/rule');
$customerGroupIds = Mage::getModel('customer/group')->getCollection()->getAllIds();
$kodevoucher = "ONTHROUGH-USD-10K";
$rule->setName('PROMO USD 10K');
$rule->setDescription('onthrough.link promo USD 10K. Dapatkan harga spesial produk dengan nilai tukar USD 10RB.');
$rule->setFromDate("2016-02-01");
$rule->setToDate("2016-05-01");
$rule->setCouponCode($email);
$rule->setUsesPerCustomer(0);
$rule->setUsesPerCoupon(0);
$rule->setCustomerGroupIds($customerGroupIds);
$rule->setIsActive(1);
$rule->setConditionsSerialized('');
$rule->setActionsSerialized('');
$rule->setIsAdvanced(1);
$rule->setProductIds('');
$rule->setSortOrder(5);
$rule->setSimpleAction(Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION);
$rule->setDiscountAmount('29');
$rule->setDiscountQty(0);
$rule->setDiscountStep(0);
$rule->setApplyToShipping(0);
$rule->setStopRulesProcessing(1);
$rule->setIsRss(0);
$rule->setWebsiteIds(array(1));
$rule->setCouponType(Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC);
$rule->setStoreLabels(array('USD 10K'));
$productFoundCondition = Mage::getModel('salesrule/rule_condition_product_found')
				->setType('salesrule/rule_condition_product_found')
				->setValue(1) // 1 == FOUND
				->setAggregator('all');
			
$rule->getConditions()->addCondition($productFoundCondition);
$attributeSetCondition = Mage::getModel('salesrule/rule_condition_product')
					->setAggregator('all');  
$rule->getActions()->addCondition($attributeSetCondition);
$rule->save();

Demikian.

One Response to “Magento Tutorial Shopping Cart Rule Programatically”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>