Php 使用可配置产品的每个产品的运费

Php 使用可配置产品的每个产品的运费,php,magento,Php,Magento,我在MagentoCE1.8上使用免费的、开源的、每个产品扩展的统一运费。基本上,它只是创建了一种新的运输方法,您可以在产品级别控制该方法的价格 我的问题是,我正在使用可配置产品和子简单产品。我正在尝试设置子简单产品的运费,例如,特定选项的运费为$5,如果我将该选项添加到购物车,运费将正确显示为$5,但如果我添加数量为3,运费仍显示为$5,而不是$15 你知道如何正确计算购物车中子产品的运费吗 它使用此表达式计算运费,其中shipCost是产品上的自定义属性,您可以在其中输入运费: $shipp

我在MagentoCE1.8上使用免费的、开源的、每个产品扩展的统一运费。基本上,它只是创建了一种新的运输方法,您可以在产品级别控制该方法的价格

我的问题是,我正在使用可配置产品和子简单产品。我正在尝试设置子简单产品的运费,例如,特定选项的运费为$5,如果我将该选项添加到购物车,运费将正确显示为$5,但如果我添加数量为3,运费仍显示为$5,而不是$15

你知道如何正确计算购物车中子产品的运费吗

它使用此表达式计算运费,其中shipCost是产品上的自定义属性,您可以在其中输入运费:

$shippingPrice += $item->getQty() * $shipCost;
我认为问题就在这里:

if($product->getTypeId()=='configurable' || $product->getTypeId()=='bundle') {
    continue;
  }
以下是完整的代码:

class Magebuzz_Flatrateperproduct_Model_Carrier_Flatrateperproduct
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface {       
protected $_code = 'flatrateperproduct';
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {           
    if (!$this->getConfigFlag('active')) {
        return false;
    }
        $shippingPrice =0;
        if ($request->getAllItems()) {
            foreach ($request->getAllItems() as $item) {
                $product = Mage::getModel('catalog/product')->load($item->getProductId());
      if($product->getTypeId()=='configurable' || $product->getTypeId()=='bundle') {
        continue;
      }
                $shipCost= $product->getShipCost();                         
                if($shipCost==null || $shipCost==0){
                $shippingPrice += $item->getQty() * $this->getConfigData('price');                       
                }
                    else{
                                $shippingPrice += $item->getQty() * $shipCost;  
                    }
            }
        }                   
            $result = Mage::getModel('shipping/rate_result');           
            if ($shippingPrice !== false) {
                $method = Mage::getModel('shipping/rate_result_method');
                $method->setCarrier('flatrateperproduct');
                $method->setCarrierTitle($this->getConfigData('title'));
                $method->setMethod('flatrateperproduct');
                $method->setMethodTitle($this->getConfigData('name'));  
                $method->setPrice($shippingPrice);
                $method->setCost($shippingPrice);
                $result->append($method);
                       }
            return $result;
}
public function getAllowedMethods()
   {
        return array('flatrateperproduct'=>$this->getConfigData('name'));
   }
}

请勾选此项,您可以通过此代码获得可配置的产品数量:

if($product->getTypeId()=='configurable' || $product->getTypeId()=='bundle') 
          {           
              foreach ($item->getChildren() as $child) 
                {
                 $quentity = $item->getQty() * $child->getQty();
                }

          }
        else
        {
                $quentity = $item->getQty();
        }