如果满足条件,则删除运输选项 [英] Remove Shipping Option if Condition is Met
本文介绍了如果满足条件,则删除运输选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果要满足某些条件,我想从运输方式中删除标准运输选项productmatrix_Standard
.我相信我需要重写以下内容:
I would like to remove the standard shipping option productmatrix_Standard
from the shipping methods if a certain condition is met. I believe I need to override the following:
/**
* 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
选项?
How can I remove existing shipping methods from this collection, or empty it and re-build it manually, skipping the productmatrix_Standard
option?
推荐答案
我最后得到了
<?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;
}
这篇关于如果满足条件,则删除运输选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文