绑定事件添加新的rule规则,比如根据客户属性判断优惠规则:

<salesrule_rule_condition_combine>
    <observers>
        <add_condition_to_sales_rule>
            <class>Ets_Showlevel_Model_Observer</class>
            <method>addConditionToSalesRule</method>
        </add_condition_to_sales_rule>
    </observers>
</salesrule_rule_condition_combine>

public function addConditionToSalesRule($observer){
    $additional = $observer->getAdditional();
    $conditions = (array) $additional->getConditions();

    $customer = Mage::getModel('customer/customer');
    $customer_attributes = array();
    foreach($customer->getAttributes() as $attribute){
        if($attribute->getBackendModel() == "" && $attribute->getFrontendLabel() != ""){
            $customer_attributes[] = array('value'=>'Ets_Showlevel_Model_Condition_Customerattribute_Params|'.                       attribute->getAttributeCode(), 'label'=> $attribute->getFrontendLabel());
        }
    }
    $conditions = array_merge_recursive($conditions, array(
        array('label'=>Mage::helper('rewardpoints')->__('User Attributes'), 'value'=>$customer_attributes),
    ));

    $additional->setConditions($conditions);
    $observer->setAdditional($additional);
    return $observer;
}

results matching ""

    No results matching ""