27
Ivan Chepurnyi Hidden Secrets of Magento Promotion Rules

Hidden Secrets of Magento Price Rules

Embed Size (px)

DESCRIPTION

Meet Magento Poland Presenetation

Citation preview

Page 1: Hidden Secrets of Magento Price Rules

Ivan Chepurnyi

Hidden Secrets of Magento Promotion Rules

Page 2: Hidden Secrets of Magento Price 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

Page 3: Hidden Secrets of Magento Price Rules

Short Overview

• Price Calculation Basics• Catalog Rule vs Shopping Cart Rule• The Base of Promo Rules• How To Customize

Page 4: Hidden Secrets of Magento Price Rules

General Magento Price Types

Final Price• Based on Qty &

Customer Group • Calculated

Dynamically• Used in:

– Shopping Cart– Product View

Minimal Price• Based on Customer

Group• Calculated by

Indexer• Used in:

– Product List

Page 5: Hidden Secrets of Magento Price Rules

Minimal Price

It is just minimal variation of final price

Page 6: Hidden Secrets of Magento Price Rules

HOW IS CALCULATED FINAL PRICE?

Page 7: Hidden Secrets of Magento Price Rules

Final Price

Option Price 1

Minimal Base Price

Option Price 2

Option Price N

Page 8: Hidden Secrets of Magento Price Rules

Minimal Base Price

• Product Price• Tier Price• Group Price (CE1.7)• Special Price• Catalog Rule Price

Magento takes minimal value from the following calculated price variations.

Page 9: Hidden Secrets of Magento Price Rules

Option Price

• Configurable Product Options (If Product is Configurable)

• Custom Options

Page 10: Hidden Secrets of Magento Price Rules

PRICE RULESAnd finally

Page 11: Hidden Secrets of Magento 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

Page 12: Hidden Secrets of Magento Price Rules

Price Rule Types

Catalog Price Rules• Pre-applied• Affect Final Product

Price• Conditions only for

Product Attributes

Shopping Cart Price Rules• Applied on the fly• Affect Shopping Cart

Totals• Various Set of

Conditions– Product Sub-select– Address Match– Advanced Customer

Targeting

Page 13: Hidden Secrets of Magento Price Rules

Use Cases

Catalog Price Rules• Season Sale

Discount• Customer Group

Discount• Discount on Product

Attribute Match

Shopping Cart Price Rule• Buy X Get Y Free

Discount• Free Shipping on

Particular Items• Special Discount for

Loyal Customers (in conjunction with Customer Segment)

Page 14: Hidden Secrets of Magento Price Rules

MAGE_RULE MODULEAnd finally some code

Page 15: Hidden Secrets of Magento Price Rules

Mage_Rule Module

Rule ModelMage_Rule_Model_Rule

ConditionMage_Rule_Model_Condition_Abstract

ActionMage_Rule_Model_Action_Abstract

Page 16: Hidden Secrets of Magento Price Rules

Rule Model

Contains such information• Conditions set• Actions set• Takes care about matched object

Page 17: Hidden Secrets of Magento Price Rules

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

Page 18: Hidden Secrets of Magento Price Rules

Action Model

• Supposed to be flexible list of actions that should be performed

• Currently is not used in the system

Page 19: Hidden Secrets of Magento Price Rules

Specific Implementations

Magento Community Edition• Mage_CatalogRule• Mage_SalesRule

Magento Enterprise Edition• Enterprise_TargetRule• Enterprise_CustomerSegment

Page 20: Hidden Secrets of Magento Price Rules

CUSTOMIZATIONDoing Simple

Page 21: Hidden Secrets of Magento Price Rules

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

Page 22: Hidden Secrets of Magento Price Rules

Properties Initialization

protected function _initProperties() { $this->_properties = array( ‘attribute_' => array( 'label' => ‘Some Field Name’, 'type' => 'select', 'data_path' => ’data/path’, 'options' => array() ) );}

Page 23: Hidden Secrets of Magento Price Rules

Property Types

Types:• string• numeric• date• select• multiselect

Page 24: Hidden Secrets of Magento Price Rules

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());

Page 25: Hidden Secrets of Magento Price Rules

Thank You!

Page 26: Hidden Secrets of Magento Price Rules

Test Driven Development Training Course in Berlin, 09-10 Jan

http://bit.ly/QeOmia

Page 27: Hidden Secrets of Magento Price Rules

Questions?Twitter: @IvanChepurnyi

Email: [email protected]

Blog: ecomdev.org