当前位置: 首页>>代码示例>>PHP>>正文


PHP Varien_Event_Observer::getAdjustments方法代码示例

本文整理汇总了PHP中Varien_Event_Observer::getAdjustments方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Event_Observer::getAdjustments方法的具体用法?PHP Varien_Event_Observer::getAdjustments怎么用?PHP Varien_Event_Observer::getAdjustments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Varien_Event_Observer的用法示例。


在下文中一共展示了Varien_Event_Observer::getAdjustments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: calculateAdjustment

 public function calculateAdjustment(Varien_Event_Observer $observer)
 {
     $store = $observer->getStore();
     $request = $observer->getRequest();
     $allItems = $observer->getAllItems();
     $adjustments = $observer->getAdjustments();
     if (!$request->getFreeShipping()) {
         $itemAdjustments = $adjustments->getItems();
         $defaultAdjustment = Mage::helper('Lokey_PerItemShipping')->getDefaultAdjustment($store);
         foreach ($allItems as $item) {
             // Skip child items in main loop
             if ($item->getParentItem()) {
                 continue;
             }
             $qty = (double) ($item->getFreeShipping() === true ? 0 : $item->getQty() - $item->getFreeShipping());
             // Skip free shipping items
             if ($qty <= 0.0) {
                 continue;
             }
             $product = Mage::getModel('catalog/product')->setStoreId($store->getId())->load($item->getProductId());
             $adjustment = Mage::helper('Lokey_PerItemShipping')->getAdjustmentAmount($product, $defaultAdjustment);
             // Skip virtual products
             if ($product->getTypeInstance()->isVirtual()) {
                 continue;
             }
             if ($item->getHasChildren()) {
                 foreach ($item->getChildren() as $childItem) {
                     $childQty = (double) ($childItem->getFreeShipping() === true ? 0 : $childItem->getQty() - $childItem->getFreeShipping());
                     // Skip free shipping items
                     if ($childQty <= 0.0) {
                         continue;
                     }
                     $childProduct = Mage::getModel('catalog/product')->setStoreId($store->getId())->load($childItem->getProductId());
                     $childAdjustment = Mage::helper('Lokey_PerItemShipping')->getAdjustmentAmount($childProduct, $defaultAdjustment);
                     // Skip virtual products
                     if ($childProduct->getTypeInstance()->isVirtual()) {
                         continue;
                     }
                     if (Mage::helper('Lokey_PerItemShipping')->getUseQty($childProduct)) {
                         $adjustment += $childAdjustment * $childQty;
                     } else {
                         $adjustment += $childAdjustment;
                     }
                 }
             }
             if (!isset($itemAdjustments[$item->getId()])) {
                 $itemAdjustments[$item->getId()] = 0.0;
             }
             if (Mage::helper('Lokey_PerItemShipping')->getUseQty($product)) {
                 $itemAdjustments[$item->getId()] += $adjustment * $qty;
             } else {
                 $itemAdjustments[$item->getId()] += $adjustment;
             }
         }
         $adjustments->setItems($itemAdjustments);
     }
     return $this;
 }
开发者ID:xxorax,项目名称:Lokey_PerItemShipping,代码行数:58,代码来源:Observer.php

示例2: calculateAdjustment

 public function calculateAdjustment(Varien_Event_Observer $observer)
 {
     $store = $observer->getStore();
     $request = $observer->getRequest();
     $allItems = $observer->getAllItems();
     $adjustments = $observer->getAdjustments();
     $groupAdjustments = array();
     $itemAdjustments = $adjustments->getItems();
     foreach ($allItems as $item) {
         $qty = $item->getQty();
         if ($item->getParentItem()) {
             $qty *= $item->getParentItem()->getQty();
         }
         $qty -= $item->getFreeShipping();
         $qty = max($qty, 0);
         if ($request->getFreeShipping() || $qty === 0) {
             continue;
         }
         $product = Mage::getModel('catalog/product')->setStoreId($store->getId())->load($item->getProductId());
         $group = Mage::helper('Lokey_PerGroupShipping/Data')->getAdjustmentGroupByProduct($product);
         if (!$product->getTypeInstance()->isVirtual() && $group->getId()) {
             $adjustment = max(round($group->getAmount(), 2), 0.0);
             switch ($group->getType()) {
                 case Lokey_PerGroupShipping_Model_System_Config_Source_AdjustmentType::ORDER:
                     $groupAdjustments[$group->getId()] = $adjustment;
                     break;
                 case Lokey_PerGroupShipping_Model_System_Config_Source_AdjustmentType::LINE:
                     if (!isset($itemAdjustments[$item->getId()])) {
                         $itemAdjustments[$item->getId()] = 0.0;
                     }
                     $itemAdjustments[$item->getId()] += $adjustment;
                     break;
                 case Lokey_PerGroupShipping_Model_System_Config_Source_AdjustmentType::UNIT:
                 default:
                     if (!isset($itemAdjustments[$item->getId()])) {
                         $itemAdjustments[$item->getId()] = 0.0;
                     }
                     $itemAdjustments[$item->getId()] += $adjustment * $qty;
                     break;
             }
         }
     }
     foreach ($groupAdjustments as $groupAdjustment) {
         $adjustments->setOrder($adjustments->getOrder() + $groupAdjustment);
     }
     $adjustments->setItems($itemAdjustments);
     return $this;
 }
开发者ID:xxorax,项目名称:Lokey_PerGroupShipping,代码行数:48,代码来源:Observer.php


注:本文中的Varien_Event_Observer::getAdjustments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。