0

productmatrix_Standard如果满足特定条件,我想从运输方式中删除标准运输选项。我相信我需要覆盖以下内容:

/**
 * One page checkout status
 *
 * @category   Mage
 * @category   Mage
 * @package    Mage_Checkout
 * @author      Magento Core Team <core@magentocommerce.com>
 */
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选项?

4

2 回答 2

2

您应该改写function collectRates()运输模型中的“”。
例如在里面 /app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php/app/code/Mage/Usa/Model/Shipping/Carrier/Ups.php

有关地址和购物车的所有详细信息当时collectRates()都在每个运营商上运行。这使得过滤特定费率或更改其names/price.

于 2013-02-11T18:08:57.177 回答
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;
    }
于 2013-02-11T18:25:11.620 回答