Hidden Secrets of Magento Price Rules

Post on 09-May-2015

18.776 views 1 download

description

Meet Magento Poland Presenetation

Transcript of Hidden Secrets of Magento Price Rules

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• 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

Minimal Price

It is just minimal variation of final price

HOW IS CALCULATED FINAL PRICE?

Final Price

Option Price 1

Minimal Base Price

Option Price 2

Option Price N

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.

Option Price

• Configurable Product Options (If Product is Configurable)

• Custom Options

PRICE RULESAnd finally

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• 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

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)

MAGE_RULE MODULEAnd finally some code

Mage_Rule Module

Rule ModelMage_Rule_Model_Rule

ConditionMage_Rule_Model_Condition_Abstract

ActionMage_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

CUSTOMIZATIONDoing Simple

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