2013-02-11 59 views
0

如果滿足特定條件,我想從裝運方法中刪除標準裝運選項productmatrix_Standard。我相信我需要重寫如下:如果條件滿足,請刪除裝運選項

/** 
* One page checkout status 
* 
* @category Mage 
* @category Mage 
* @package Mage_Checkout 
* @author  Magento Core Team <[email protected]> 
*/ 
class Mage_Checkout_Block_Onepage_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Abstract 
{ 
    protected $_rates; 
    protected $_address; 

    public function getShippingRates() 
    { 

     if (empty($this->_rates)) { 
      $this->getAddress()->collectShippingRates()->save(); 

      $groups = $this->getAddress()->getGroupedAllShippingRates(); 
      /* 
      if (!empty($groups)) { 
       $ratesFilter = new Varien_Filter_Object_Grid(); 
       $ratesFilter->addFilter(Mage::app()->getStore()->getPriceFilter(), 'price'); 

       foreach ($groups as $code => $groupItems) { 
        $groups[$code] = $ratesFilter->filter($groupItems); 
       } 
      } 
      */ 

      return $this->_rates = $groups; 
     } 

     return $this->_rates; 
    } 
} 

如何從這個集合中刪除現有的運輸方法,或清空,然後手動重新構建它,跳過productmatrix_Standard選項?

回答

1

我結束了

<?php 

    public function getShippingRates() { 

     if (empty($this->_rates)) { 

      $this->getAddress()->collectShippingRates()->save(); 

      $groups = $this->getAddress()->getGroupedAllShippingRates(); 

      if ($this->someCondition()) { 

       $badMethods = array('productmatrix_Standard'); 

       // Loop through groups (productmatrix) 
       // pass by reference for unset later 
       foreach ($groups as $code => &$groupItems) { 

        // Lopp through methods (standards, 2day) 
        foreach($groupItems as $key => $item) { 

         // Check for bad shipping methods 
         if (in_array($item->getCode(), $badMethods)) { 

          // Remove the method from the shipping groups 
          unset($groupItems[$key]); 
         } 
        } 
       } 
      } 

      $this->_rates = $groups; 
     } 

     return $this->_rates; 
    } 
2

您應該在運輸模式中覆蓋「function collectRates()」。
例如裏面 /app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php/app/code/Mage/Usa/Model/Shipping/Carrier/Ups.php

所有的關於地址和車的細節都可以在時間collectRates()是每個載波上運行。這使得它非常過濾掉特定的利率,或改變其names/price.