2

I have installed simple multi-warehouse extension.its only manage inventory.

Now i created two warehouses A & B.and Product-X quantities in A-10 & in B-15.

Now if i ordered Product-X with 25 quantities its reducing quantity from both A & B.

Now My requirement is I need to send two requests to carrier.

1st request: origin-A to customer shipping address quanity-10

2nd request:origin-B to customer shipping address quantity-15.

Now I want to display both requests in front end.and customer should select two shipping methods to complete the order.

any idea ? how to start this requirement.i'm thinking i need to repeat request in

 Mage_Sales_Model_Quote_Address requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null)

Update

Mage_Sales_Model_Quote_Address

public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null)
    {
         $titems=$this->getAllItems();

        if(!$item)
        {
            $warehouses=array();
           foreach($titems as $titem)
           {

                $kitem=clone $titem;

                $stockCollection = Mage::getModel('exinent_warehouse/stock')
                    ->getCollection()            
                    ->addFieldToSelect(array('location_id', 'qty'))                    
                    ->addFieldToFilter(
                        'qty',
                        array(
                            'gt' => '0'
                        )
                    )
                    ->addFieldToFilter('product_id', $kitem->getProductId());       


            foreach($stockCollection as $res)
             {
                if($kitem->getQty()>=$res->getQty())
                {
                   $citem=clone $kitem;
                   $citem->setQty($res->getQty());//->save();              
                   $warehouses[$res->getLocationId()][]= $citem;
                   $loc[]=$res->getLocationId();

                   $kitem->setQty($kitem->getQty()-$res->getQty());//->save();

                }

             }
           }
        }

        $i=0;
       foreach($warehouses as $warehouse)
       {

        /** @var $request Mage_Shipping_Model_Rate_Request */
        $request = Mage::getModel('shipping/rate_request');
        $request->setAllItems($item ? array($item) : $warehouse);
        $warehouseinfo=Mage::getModel('exinent_warehouse/location')->load($loc[$i]);

        $request->setOrigCountry($warehouseinfo->getData('country_id'));
        $request->setOrigPostcode($warehouseinfo->getData('zipcode'));

        $request->setDestCountryId($this->getCountryId());
        $request->setDestRegionId($this->getRegionId());
        $request->setDestRegionCode($this->getRegionCode());
        /**
         * need to call getStreet with -1
         * to get data in string instead of array
         */
        $request->setDestStreet($this->getStreet(self::DEFAULT_DEST_STREET));
        $request->setDestCity($this->getCity());
        $request->setDestPostcode($this->getPostcode());
        $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal());
        $packageValueWithDiscount = $item
            ? $item->getBaseRowTotal() - $item->getBaseDiscountAmount()
            : $this->getBaseSubtotalWithDiscount();
        $request->setPackageValueWithDiscount($packageValueWithDiscount);
        $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight());
        $request->setPackageQty($item ? $item->getQty() : $this->getItemQty());

        /**
         * Need for shipping methods that use insurance based on price of physical products
         */
        $packagePhysicalValue = $item
            ? $item->getBaseRowTotal()
            : $this->getBaseSubtotal() - $this->getBaseVirtualAmount();
        $request->setPackagePhysicalValue($packagePhysicalValue);

        $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight());

        /**
         * Store and website identifiers need specify from quote
         */
        /*$request->setStoreId(Mage::app()->getStore()->getId());
        $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());*/

        $request->setStoreId($this->getQuote()->getStore()->getId());
        $request->setWebsiteId($this->getQuote()->getStore()->getWebsiteId());
        $request->setFreeShipping($this->getFreeShipping());
        /**
         * Currencies need to convert in free shipping
         */
        $request->setBaseCurrency($this->getQuote()->getStore()->getBaseCurrency());
        $request->setPackageCurrency($this->getQuote()->getStore()->getCurrentCurrency());
        $request->setLimitCarrier($this->getLimitCarrier());

        $request->setBaseSubtotalInclTax($this->getBaseSubtotalInclTax() + $this->getBaseExtraTaxAmount());

        $result = Mage::getModel('shipping/shipping')->collectRates($request)->getResult();

        $found = false;
        if ($result) {
            $shippingRates = $result->getAllRates();

            foreach ($shippingRates as $shippingRate) {
                $rate = Mage::getModel('sales/quote_address_rate')
                    ->importShippingRate($shippingRate,$loc[$i]);
                if (!$item) {
                    $this->addShippingRate($rate);
                }

                if ($this->getShippingMethod() == $rate->getCode()) {
                    if ($item) {
                        $item->setBaseShippingAmount($rate->getPrice());
                    } else {
                        /**
                         * possible bug: this should be setBaseShippingAmount(),
                         * see Mage_Sales_Model_Quote_Address_Total_Shipping::collect()
                         * where this value is set again from the current specified rate price
                         * (looks like a workaround for this bug)
                         */
                        $this->setShippingAmount($rate->getPrice());
                    }

                    $found = true;
                }
            }
        }
        $i++;
        }

        return $found;
    }

in onepagecontroller

public function saveShippingMethodAction()
    {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {

            $warehouses=$this->getRequest()->getPost('warehouses', '');
        foreach($warehouses as $warehouse)
        {
            $data[]= $this->getRequest()->getPost('shipping_method'.$warehouse, '');


            }
            $result= $this->getOnepage()->saveShippingMethod($data);

            // $result will contain error data if shipping method is empty
            if (!$result) {
                Mage::dispatchEvent(
                    'checkout_controller_onepage_save_shipping_method',
                     array(
                          'request' => $this->getRequest(),
                          'quote'   => $this->getOnepage()->getQuote()));
                $this->getOnepage()->getQuote()->collectTotals();
                $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

                $result['goto_section'] = 'payment';
                $result['update_section'] = array(
                    'name' => 'payment-method',
                    'html' => $this->_getPaymentMethodsHtml()
                );
            }
            $this->getOnepage()->getQuote()->collectTotals()->save();
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }

in onepage.php

public function saveShippingMethod($shippingMethod)
    {
    if(is_array($shippingMethod))
    {

    if (empty($shippingMethod)) {
            return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
        }       
        for($i=0;$i<count($shippingMethod);$i++)
        {
        $rate = $this->getQuote()->getShippingAddress()->getShippingRateByCode($shippingMethod[$i]);
        if (!$rate) {
            return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
        }

        }

        $this->getQuote()->getShippingAddress()
            ->setShippingMethod(serialize($shippingMethod));

        $this->getCheckout()
            ->setStepData('shipping_method', 'complete', true)
            ->setStepData('payment', 'allow', true);

        return array();
    } else {
        if (empty($shippingMethod)) {
            return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
        }
        $rate = $this->getQuote()->getShippingAddress()->getShippingRateByCode($shippingMethod);
        if (!$rate) {
            return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
        }
        $this->getQuote()->getShippingAddress()
            ->setShippingMethod($shippingMethod)->setWarehouse($warehouse);

        $this->getCheckout()
            ->setStepData('shipping_method', 'complete', true)
            ->setStepData('payment', 'allow', true);

        return array();
        }
    }
  • This may be a better question for the developers of the module, as they are the ones that set this functionality up, and have the best access to the code. Apologies I can't answer your question. – Dan Hanly Feb 4 '15 at 22:40
  • Yes.we are trying to create extension only.but we dont know we are going in right track or not – sivakumar Feb 5 '15 at 7:15
2
+25

Now I want to display both requests in front end.and customer should select two shipping methods to complete the order.

I'm afraid this is not possible (not in a reasonable time frame at least).
Magento is designed to allow you to select one and only one shipping method.
But I have an idea.
Let's take them step by step.

First...making 2 requests.

I don't know how your carrier works or the API for that matter, but for all carriers, the price of the shipment is determined inside the collectRates method in the carrier model.
Most probably there is something in that method that makes a request to their API, sending data about the package and receiving a cost (or a set of costs).

You can modify the section that sends the request and send 2 of them instead and add up the prices you get as response. Yes add them up... see my idea for showing 2 methods.

Now...Selecting 2 shipping methods.
As I said, Magento is designed to work with selecting one shipping method.
How about combining the 2 shipping methods into 1.

Let's take the following scenario.
Your carrier gives you 2 prices for each request allowing the customer to choose one.
If you make 2 requests you will receive 2 * 2 = 4 prices.
You can make 4 shipping methods out of the 4 response you get.
Let's say you get this:

First request (15 items)

  • price 10, Description: "We deliver in 2 days"
  • price 20, Description: "We deliver in 1 days"

second request (10 items)

  • price 8, Description: "We deliver in 2 days"
  • price 16, Description: "We deliver in 1 days"

Combine these 4 prices into 4 shipping methods like this:

  • price 18 (10 + 8). Description "10 products: We deliver in 2 days, 15 products: We deliver in 2 days"
  • price 26 (10 + 16). Description "10 products: We deliver in 2 days, 15 products: We deliver in 1 day"
  • price 28 (20 + 8). Description "10 products: We deliver in 1 day, 15 products: We deliver in 2 days"
  • price 36 (20 + 16). Description "10 products: We deliver in 1 day, 15 products: We deliver in 1 day"

I hope I was clear in my description. Sorry if I chose the descriptions wrong and I hope you get the idea.

Unfortunately I don't have code for it. This is just how I would do it if faced with the same issue.

  • You're welcome, but the question is "Is it helpful at least a bit?" – Marius Feb 5 '15 at 14:06
  • helpful Marius.i will update my question where we are – sivakumar Feb 5 '15 at 14:07
  • sorry forgot to upvote Marius. – sivakumar Feb 6 '15 at 10:56

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.