Ivan Chepurnyi

Hidden Secrets of Magento
     Promotion Rules
About Me
•   Devoted to Magento Platform since 2007
•   Ex Magento Core Team member
•   5+ Years of Magento Development Experience
•   Co-Founder & Technical Director at EcomDev
•   Providing Training Courses for Magento
    Developers
Short Overview
•   Price Calculation Basics
•   Catalog Rule vs Shopping Cart Rule
•   The Base of Promo Rules
•   How To Customize
General Magento Price Types
Final Price         Minimal Price
• Based on Qty &    • Based on Customer
  Customer Group      Group
• Calculated        • Calculated by
  Dynamically         Indexer
• Used in:          • Used in:
  – Shopping Cart     – Product List
  – Product View
Minimal Price


It is just minimal variation of
           final price
HOW IS CALCULATED FINAL
         PRICE?
Final Price

                Option Price 1

Minimal         Option Price 2
Base Price             …
                Option Price N
Minimal Base Price
•   Product Price         Magento takes
•   Tier Price            minimal value
•   Group Price (CE1.7)   from the following
•   Special Price         calculated price
•   Catalog Rule Price    variations.
Option Price
• Configurable Product Options
  (If Product is Configurable)

• Custom Options
And finally
PRICE RULES
Price Rules
• Easy way to set up discounts for a group
  of products

• Conditional Discounts Based on
  – Product Attributes
  – Customer Group
  – Shopping Cart Content
Price Rule Types
Catalog Price Rules      Shopping Cart Price Rules
• Pre-applied            • Applied on the fly
• Affect Final Product   • Affect Shopping Cart
  Price                    Totals
• Conditions only for    • Various Set of
  Product Attributes       Conditions
                           – Product Sub-select
                           – Address Match
                           – Advanced Customer
                             Targeting
Use Cases
Catalog Price Rules     Shopping Cart Price Rule
• Season Sale           • Buy X Get Y Free
  Discount                Discount
• Customer Group        • Free Shipping on
  Discount                Particular Items
• Discount on Product   • Special Discount for
  Attribute Match         Loyal Customers (in
                          conjunction with
                          Customer Segment)
And finally some code
MAGE_RULE MODULE
Mage_Rule Module

                        Condition
                        Mage_Rule_Model_Condition_Abstract



Rule Model
Mage_Rule_Model_Rule



                       Action
                       Mage_Rule_Model_Action_Abstract
Rule Model
Contains such information
• Conditions set
• Actions set
• Takes care about matched object
Condition Model
• Conditions can be complex or simple
• Matched against some Varien_Object
  (Product, Address, Customer, etc)
• All condition models extended from
 Mage_Rule_Model_Condition_Abstract
Action Model
• Supposed to be flexible list of actions that
  should be performed
• Currently is not used in the system
Specific Implementations
Magento Community Edition
• Mage_CatalogRule
• Mage_SalesRule

Magento Enterprise Edition
• Enterprise_TargetRule
• Enterprise_CustomerSegment
Doing Simple

CUSTOMIZATION
Create Custom Condition
1. Extend from this class in gist:
   https://gist.github.com/4136339

2. Implement _getLabel() method

3. Implement _initProperties() method

4. Add your condition to combine condition model for
   existing rule
Properties Initialization
protected function _initProperties()
{
    $this->_properties = array(
          ‘attribute_' => array(
               'label' => ‘Some Field Name’,
               'type' => 'select',
               'data_path' => ’data/path’,
               'options' => array()
          )
     );
}
Property Types
Types:
• string
• numeric
• date
• select
• multiselect
Adding To Combine Cond
For Sales Rules
• Add observer to salesrule_rule_condition_combine

• Add an array item to additional event property:

  $observer->getEvent()->setAdditional(
     Mage::getModel(‘yourcondition/model’)->getNewChildSelectOptions()
  );
Thank You!
Test Driven Development
Training Course in
Berlin, 09-10 Jan

http://bit.ly/QeOmia
Questions?
Twitter:
@IvanChepurnyi


Email:
ivan@ecomdev.org


Blog:
ecomdev.org

Hidden Secrets of Magento Price Rules

  • 1.
    Ivan Chepurnyi Hidden Secretsof Magento Promotion Rules
  • 2.
    About Me • Devoted to Magento Platform since 2007 • Ex Magento Core Team member • 5+ Years of Magento Development Experience • Co-Founder & Technical Director at EcomDev • Providing Training Courses for Magento Developers
  • 3.
    Short Overview • Price Calculation Basics • Catalog Rule vs Shopping Cart Rule • The Base of Promo Rules • How To Customize
  • 4.
    General Magento PriceTypes Final Price Minimal Price • Based on Qty & • Based on Customer Customer Group Group • Calculated • Calculated by Dynamically Indexer • Used in: • Used in: – Shopping Cart – Product List – Product View
  • 5.
    Minimal Price It isjust minimal variation of final price
  • 6.
    HOW IS CALCULATEDFINAL PRICE?
  • 7.
    Final Price Option Price 1 Minimal Option Price 2 Base Price … Option Price N
  • 8.
    Minimal Base Price • Product Price Magento takes • Tier Price minimal value • Group Price (CE1.7) from the following • Special Price calculated price • Catalog Rule Price variations.
  • 9.
    Option Price • ConfigurableProduct Options (If Product is Configurable) • Custom Options
  • 10.
  • 11.
    Price Rules • Easyway to set up discounts for a group of products • Conditional Discounts Based on – Product Attributes – Customer Group – Shopping Cart Content
  • 12.
    Price Rule Types CatalogPrice Rules Shopping Cart Price Rules • Pre-applied • Applied on the fly • Affect Final Product • Affect Shopping Cart Price Totals • Conditions only for • Various Set of Product Attributes Conditions – Product Sub-select – Address Match – Advanced Customer Targeting
  • 13.
    Use Cases Catalog PriceRules Shopping Cart Price Rule • Season Sale • Buy X Get Y Free Discount Discount • Customer Group • Free Shipping on Discount Particular Items • Discount on Product • Special Discount for Attribute Match Loyal Customers (in conjunction with Customer Segment)
  • 14.
    And finally somecode MAGE_RULE MODULE
  • 15.
    Mage_Rule Module Condition Mage_Rule_Model_Condition_Abstract Rule Model Mage_Rule_Model_Rule Action Mage_Rule_Model_Action_Abstract
  • 16.
    Rule Model Contains suchinformation • Conditions set • Actions set • Takes care about matched object
  • 17.
    Condition Model • Conditionscan be complex or simple • Matched against some Varien_Object (Product, Address, Customer, etc) • All condition models extended from Mage_Rule_Model_Condition_Abstract
  • 18.
    Action Model • Supposedto be flexible list of actions that should be performed • Currently is not used in the system
  • 19.
    Specific Implementations Magento CommunityEdition • Mage_CatalogRule • Mage_SalesRule Magento Enterprise Edition • Enterprise_TargetRule • Enterprise_CustomerSegment
  • 20.
  • 21.
    Create Custom Condition 1.Extend from this class in gist: https://gist.github.com/4136339 2. Implement _getLabel() method 3. Implement _initProperties() method 4. Add your condition to combine condition model for existing rule
  • 22.
    Properties Initialization protected function_initProperties() { $this->_properties = array( ‘attribute_' => array( 'label' => ‘Some Field Name’, 'type' => 'select', 'data_path' => ’data/path’, 'options' => array() ) ); }
  • 23.
    Property Types Types: • string •numeric • date • select • multiselect
  • 24.
    Adding To CombineCond For Sales Rules • Add observer to salesrule_rule_condition_combine • Add an array item to additional event property: $observer->getEvent()->setAdditional( Mage::getModel(‘yourcondition/model’)->getNewChildSelectOptions() );
  • 25.
  • 26.
    Test Driven Development TrainingCourse in Berlin, 09-10 Jan http://bit.ly/QeOmia
  • 27.