Krt_Malta Krt_Malta - 6 months ago 60
PHP Question

Read promotion rule condition - Magento

I need to read the condition of a shopping cart price rule in magento programatically.

Mage_SalesRule_Model_Rule
has a method
getConditionsSerialized()
which does provide the conditions but in a cryptic manner to say the least such as the following:

a:7:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:5:{s:4:"type";s:32:"salesrule/rule_condition_address";s:9:"attribute";s:13:"base_subtotal";s:8:"operator";s:2:">=";s:5:"value";s:1:"1";s:18:"is_value_processed";b:0;}}}


Does anyone know how to read the condition in a more humane way plz? I'd like to be able to read certain attributes.

Thanks a bunch!

Krt_Malta

Answer

You can use php's unserialize function to convert this to a workable array.

Try this:

$conditions = unserialize($rule->getConditionsSerialized());
print_r($conditions);

I've blogged before about how these work, and while my post is about creating rules, it still explains a bit about how you might come to understand conditions.

Here's my post

Hope it helps!

Comments