本文整理汇总了PHP中Varien_Event_Observer::getRule方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Event_Observer::getRule方法的具体用法?PHP Varien_Event_Observer::getRule怎么用?PHP Varien_Event_Observer::getRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Event_Observer
的用法示例。
在下文中一共展示了Varien_Event_Observer::getRule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: salesruleProcess
/**
* Calculate discounts by sales rules
* @param Varien_Event_Observer $observer
*/
public function salesruleProcess($observer)
{
$quote = $observer->getQuote();
$address = $observer->getAddress();
$rule = $observer->getRule();
$discounts = @unserialize($quote->getAuctaneapiDiscounts());
if (!self::$_counter) {
$discounts = array();
$address->setBaseShippingDiscountAmount(0);
self::$_counter++;
}
if (!isset(self::$_shippingAmountProcessed[$rule->getId()]) && $address->getShippingAmount()) {
$shippingAmount = $address->getShippingAmountForDiscount();
if ($shippingAmount !== null) {
$baseShippingAmount = $address->getBaseShippingAmountForDiscount();
} else {
$baseShippingAmount = $address->getBaseShippingAmount();
}
//check for discount applied on shipping amount or not
if (!$rule['apply_to_shipping']) {
$baseShippingAmount = 0;
}
$baseDiscountAmount = 0;
$rulePercent = min(100, $rule->getDiscountAmount());
switch ($rule->getSimpleAction()) {
case Mage_SalesRule_Model_Rule::TO_PERCENT_ACTION:
$rulePercent = max(0, 100 - $rule->getDiscountAmount());
case Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION:
$baseDiscountAmount = ($baseShippingAmount - $address->getBaseShippingDiscountAmount()) * $rulePercent / 100;
break;
case Mage_SalesRule_Model_Rule::TO_FIXED_ACTION:
$baseDiscountAmount = $baseShippingAmount - $rule->getDiscountAmount();
break;
case Mage_SalesRule_Model_Rule::BY_FIXED_ACTION:
$baseDiscountAmount = $rule->getDiscountAmount();
break;
case Mage_SalesRule_Model_Rule::CART_FIXED_ACTION:
self::$_cartRules = $address->getCartFixedRules();
if (!isset(self::$_cartRules[$rule->getId()])) {
self::$_cartRules[$rule->getId()] = $rule->getDiscountAmount();
}
if (self::$_cartRules[$rule->getId()] > 0) {
$baseDiscountAmount = min($baseShippingAmount - $address->getBaseShippingDiscountAmount(), self::$_cartRules[$rule->getId()]);
self::$_cartRules[$rule->getId()] -= $baseDiscountAmount;
}
break;
}
$ruleDiscount = 0;
$left = $baseShippingAmount - ($address->getBaseShippingDiscountAmount() + $baseDiscountAmount);
if ($left >= 0) {
$ruleDiscount = $baseDiscountAmount;
}
$discounts[$rule->getId() . '-' . $observer->getItem()->getId() . '-' . uniqid()] = $observer->getResult()->getBaseDiscountAmount() + $ruleDiscount;
$address->setBaseShippingDiscountAmount(min($address->getBaseShippingDiscountAmount() + $baseDiscountAmount, $baseShippingAmount));
self::$_shippingAmountProcessed[$rule->getId()] = true;
} else {
$discounts[$rule->getId() . '-' . $observer->getItem()->getId() . '-' . uniqid()] = $observer->getResult()->getBaseDiscountAmount();
}
$quote->setAuctaneapiDiscounts(@serialize($discounts));
}
示例2: detachUnsupportedSalesRule
/**
* Checks whether Sales Rule can be used in Email Remainder Rules and if it cant -
* detaches it from Email Remainder Rules
*
* @param Varien_Event_Observer $observer
*/
public function detachUnsupportedSalesRule($observer)
{
$rule = $observer->getRule();
$couponType = $rule->getCouponType();
$autoGeneration = $rule->getUseAutoGeneration();
if ($couponType == Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC && !empty($autoGeneration)) {
$model = Mage::getModel('enterprise_reminder/rule');
$ruleId = $rule->getId();
$model->detachSalesRule($ruleId);
}
}