0

The problem : I have two products A and B in cart. Two of them are shipped from different locations and thus i need to calculate shipping for these two products separately (with the source Zip as different). Which is the best way to do this?

I was thinking while the shipping is calculated remove one of the products and let magento calculate the shipping for product A. Then after the the shipping is calculated using and observer we send another request to fedex with the product B and the different Zip code as source. I am not sure but i believe this is possible by observing the events sales_quote_address_collect_totals_before and sales_quote_address_collect_totals_after . I am having trouble getting quote details in here , that's another story.

Or

Maybe split the order as in Split order into seperate orders and calculate shipping seperately with ups and fedex and different origin addresses
I understand this but unable to start somewhere on coding level.

Or is their even another easier simpler solution that doesn't include a paid plugin.

Only requirement calculate shipping for products shipped from two different locations.Also i am using onepagecheckout.

1

So here's how i tackled this problem .This is not a great flexible solution , but it suited my client requirements . What i basically did was sent one additional request to the shipping API for the product shipped from the second location . For this i first observed sales_quote_collect_totals_before observer to set the weight of the products shipped from second location as zero in the cart (shouldn't do this if all products are shipped from second location as if weight is 0 shipping API will return error) . After this i set the weight of the products shipped from first location as zero and applied the weight of the items shipped from second location then changed the zip code and send an additional request to the API using the code

 $store->setConfig('shipping/origin/postcode' , $zipcode);
 $shipping      = Mage::getModel('shipping/shipping');      
    $result         = $shipping->collectRatesByAddress($address)->getResult();
    $newrates       = array();
    $newrateCodes   = array();
    $shippingRates  = $result->getAllRates();
    foreach ($shippingRates as $rate) {
        if ($rate instanceof Mage_Shipping_Model_Rate_Result_Error) {
            $errors[$rate->getCarrierTitle()] = 1;
        } else {
            $k = $rate->getCarrierTitle().' - '.$rate->getMethodTitle();
            $k = $rate->getCarrier() . '_' . $rate->getMethod();

            if ($address->getFreeShipping()) {
                $price = 0;
            } else {
                $price = $rate->getPrice();
            }

            if ($price) {
                $price = Mage::helper('tax')->getShippingPrice($price, false, $address);
            }

            $newrates[$k] = $price ;
            $newrateCodes[$k] = $rate->getCarrier() . '_' . $rate->getMethod();
        }
    }

But i couldn't get any working code to modify the rate by adding this rate using an observer .

So i stored these rates in a session and modified the phtml file where it shows the rate to add these rates and i used the this plugin to set whichever shipping method selected cost as a fee and show it separately.

  • thanks fior adding your solution, it indeed is not what is what i would want but maybe i can use it to start an improvement – Tobias Hagenbeek Nov 28 '15 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.