将费用从一种运输方式转移到另一种方式

时间:2012-08-01 16:25:53

标签: magento magento-1.4

我有一个棘手的运输问题,我正在尝试解决。我有一个自定义扩展程序,可以计算所有国内运费的表格费率。但对于国际而言,一种产品(A类)是35美元/产品运费,其余产品(B类和C类)由UPS和USPS计算。如果客户购买两种类型的产品,我唯一能够弄清楚如何正确计算运费的方法是为A类创建一个表格费率,然后将其作为手续费传递给UPS / USPS。我可以使用变量/方法进行此过程吗?我还没找到一个。

根据要求,这是我的功能:

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{

    // Cut out code where it adds up the categories and the number of items in each category

    $rates = $this->getRates($request, $_categories);
    if (!empty($rates))
    {   
        $rateTypes = array();
        foreach($rates as $rate)
        {
            $rateTypes[] = $rate['method_name'];
        }
        $rateTypes = array_unique($rateTypes);


        $i=0;
        // Create array to pass along to UPS/USPS, if needed
        $tempCategories = $_categories;

        foreach($rateTypes as $rateType)
        {   
            $groupPrice = 0;

            foreach($_categories as $category=>$catQty)
            {
                $rateExists = false;
                $standardRate = 0;
                foreach($rates as $rate)
                {   
                    $rateCats = explode(',',$rate['category_list']);
                    if(in_array($category,$rateCats) && $rate['method_name'] == $rateType )
                    {   
                        $rateExists = true;
                        if($rate['condition_type'] == 'I'){
                            $ratePrice = $rate['price']  * $catQty;

                        }
                        else if ($rate['condition_type'] == 'O') {
                            $ratePrice = $rate['price'];
                        }
                        unset($tempCategories[$category]);

                    }
                    else if(in_array($category,$rateCats) && $rate['method_name'] == "Standard" && $rateType != "Standard")
                    {
                        if($rate['condition_type'] == 'I'){
                            $standardRate += $rate['price']  * $catQty;

                        }
                        else if ($rate['condition_type'] == 'O') {
                            $standardRate += $rate['price'];
                        }
                        unset($tempCategories[$category]);
                    }

                }

                if($rateExists == false)
                {
                    $groupPrice += $standardRate;                   
                }
                else
                    $groupPrice += $ratePrice;

            }
            if(count($tempCategories) > 0)
            {
                // Figure out how to pass the $groupPrice to other shipping methods here
            }
            else {

                $method = Mage::getModel('shipping/rate_result_method');
                $method->setCarrier('shippingcodes');
                $method->setCarrierTitle($this->getConfigData('title'));
                $method->setMethod('shippingcodes_'.$rateType);
                $method->setMethodTitle($rateType);
                $method->setPrice($groupPrice);
                $result->append($method);
            }
        }


    }
    else
        return false;
    return $result;
}

0 个答案:

没有答案