Php 如果满足条件,则删除装运选项
如果满足特定条件,我想从配送方法中删除标准配送选项Php 如果满足条件,则删除装运选项,php,magento,shipping,Php,Magento,Shipping,如果满足特定条件,我想从配送方法中删除标准配送选项productmatrix\u standard。我认为我需要覆盖以下内容: /** * One page checkout status * * @category Mage * @category Mage * @package Mage_Checkout * @author Magento Core Team <core@magentocommerce.com> */ class Mage_
productmatrix\u 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;
}
}
/**
*单页签出状态
*
*@category法师
*@category法师
*@package Mage_结帐
*@author Magento核心团队
*/
类Mage\u Checkout\u Block\u Onepage\u Shipping\u Method\u Available扩展了Mage\u Checkout\u Block\u Onepage\u Abstract
{
受保护的美元汇率;
受保护的$\u地址;
公共函数getShippingRates()
{
如果(空($this->\u费率)){
$this->getAddress()->collectShippingRates()->save();
$groups=$this->getAddress()->getGroupedAllShippingRates();
/*
如果(!空($groups)){
$ratesFilter=新变量过滤器对象网格();
$ratesFilter->addFilter(Mage::app()->getStore()->getPriceFilter(),'price');
foreach($code=>$groupItems的组){
$groups[$code]=$ratesFilter->filter($groupItems);
}
}
*/
返回$this->_rates=$groups;
}
返回$this->\u费率;
}
}
如何从该集合中删除现有的运送方法,或者清空它并手动重新构建它,跳过
productmatrix\u Standard
选项?您应该在运送模型中覆盖“函数collectRates()
”。e、 g.内部
/app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php
或
/app/code/Mage/Usa/Model/Shipping/Carrier/Ups.php
在每个运营商上运行
collectRates()
时,可以获得有关地址和购物车的所有详细信息。这使得筛选出特定的费率或更改其名称/价格非常理想。
您应该替代发货模型中的“函数collectRates()
”。e、 g.内部
/app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php
或
/app/code/Mage/Usa/Model/Shipping/Carrier/Ups.php
在每个运营商上运行collectRates()
时,可以获得有关地址和购物车的所有详细信息。这使得筛选出特定的费率或更改其名称/价格非常理想。
<?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;
}
我最终得到了
<?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;
}