在购物车上应用了错误的运费

时间:2014-10-24 15:50:30

标签: php magento

当我向购物车添加一些产品时,我有一个问题,我总是得到错误的运费。我之前想过,我得到错误运费的原因是因为购物车中奖金产品的重量,因此奖金产品的价格为0.据我所知,Magento将在购物车中找到所有产品的总和

所以要排除我写下以下内容的价格:

//If we have no weight, try to calculate this
            $weight = 0;
            if ($quote->getShippingAddress()->getWeight() == null ||
                $quote->getShippingAddress()->getWeight() == 0 ||
                $quote->getShippingAddress()->getWeight() == ''){

//this is where I do a check for bonus product. because a bonus product might have either aweight of 0 or 0 price

                foreach ($quote->getAllItems() as $item){
                    $itemWeight = $item->getWeight();
                    if ($itemWeight != null && $item->getPrice() > 0){
                        $weight += $itemWeight;
                    }
                }
            }else{
                $weight = $quote->getShippingAddress()->getWeight();
            }

但我仍然得到购物车总额中包含的奖励产品的重量,而奇怪的部分是当我按下购物车中的更新按钮时,我得到了正确的运费。

1 个答案:

答案 0 :(得分:1)

foreach ($quote->getAllItems() as $item){

    if($item->isBonusItem(){
        continue;
    }

    $itemWeight = $item->getWeight();
    if ($itemWeight != null && $item->getPrice() > 0){
       $weight += $itemWeight;
    }
   else{
       $weight = $quote->getShippingAddress()->getWeight();
       }

你必须编写函数isBonusItem(),它将返回一个标志值。