Home > Blog > Custom Shopping Cart Price Rule Condition


30 Aug 2017

Custom Shopping Cart Price Rule Condition

Posted By : Admin Blog, Magento, E-Commerce,

Magento offers a set of Shopping cart price rules, which will be helpful for the merchant for various promotions. However, there are difficult situations that merchant face to promote unique offers with given conditions & attributes. Hence merchant requires to have an additional condition for shopping cart price rule (Discount with or without coupon). Detailed Description: Magento is a leading open-source e-commerce platform written in PHP. Fully functional, user-friendly, customizable, secure, robust and feature-rich, Magento has strong evidence of success in the eCommerce market. Successful companies know that sales promotions are among the most effective methods of increasing sales and building customer satisfaction. A survey found that up to 50% of consumers make a purchase only with a promotion. Magento offers standard price rules for Catalog and Shopping cart. Many a time, the standard rules are not sufficient to create new promotional rules for a merchant offer. For anyone looking for Magento Development, we explain here the method to add a custom condition (discount applicable only for orders from mobile app) in Shopping cart price rules. Solution:

Step -1: Override the class Mage_SalesRule_Model_Rule_Condition_Address. (Copy the file Address.php from app/code/core/Mage/SalesRule/Model/Rule/Condition/ to app/code/local/Mage/SalesRule/Model/Rule/Condition/)

Step -2: Add the new condition (highlighted) in the $attributes array as given below $attributes = array( 'base_subtotal' => Mage::helper('salesrule')->__('Subtotal'), 'total_qty' => Mage::helper('salesrule')->__('Total Items Quantity'), 'weight' => Mage::helper('salesrule')->__('Total Weight'), 'payment_method' => Mage::helper('salesrule')->__('Payment Method'), 'shipping_method' => Mage::helper('salesrule')->__('Shipping Method'), 'postcode' => Mage::helper('salesrule')->__('Shipping Postcode'), 'region' => Mage::helper('salesrule')->__('Shipping Region'), 'region_id' => Mage::helper('salesrule')->__('Shipping State/Province'), 'country_id' => Mage::helper('salesrule')->__('Shipping Country'), 'only_for_app' => Mage::helper('salesrule')->__('Only for Mobile App'), /* Newly Added Condition */ ); Step -3: Now the condition will display in the shopping cart price rule, Admin -> Promotions -> Shopping Cart Price Rules -> Add New Rule -> Conditions -> Add New. Step -4: To validate this new condition while applying shopping cart price rules, add the below condition (you shall change condition according to your requirement) into validate function public function validate(Varien_Object $object) { : : if ($this->getAttribute() == 'only_for_app') /* checking new condition */ { /* Your custom logic to validate the condition */ if(Mage::getSingleton('core/session')->getMobile()) { return true; /* If validation success apply rule */ } } : : return parent::validate($object); } Step -5: After adding your logic invalidate function, create the shopping cart price rule with your own new condition and check it out from the front end.

Share this Article on

Tags: magento, add new condition in shopping cart, custom shopping cart price rule,

© 2007 - Synamen Thinklabs Pvt Ltd. All rights reserved Privacy Policy