Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magento - shipping to multiple addresses but keeping payment to one charge

I'm trying to find a way to allow an order to be split for multiple shipping addresses, but to keep the charge to the customer as a one time payment rather than having to charge for each shipment separately. Is there a way to do this? Currently, customers are getting charged multiple times, corresponding to their "multiple orders", as magento splits the orders up into many smaller ones. This is a problem from the credit card company side since they are getting suspicious of so many consecutive charges to the card. Any ideas?

like image 624
helefa Avatar asked Feb 28 '12 18:02

helefa


2 Answers

Well, I'm not going to be able to provide a full solution because to be honest, the solution would take quite a bit of time and testing but I'll give out comprehensive information that could you to the right direction instead.

Basically, upfront -- there isn't an option to do this in default Magento.

So instead, we are going to rewrite a certain model called Mage_Checkout_Model_Type_Multishipping. If you're into the proper way of rewriting a model, please read this post by Inchoo.

But if you're lazy and looking into a quick way of rewriting, then please copy the whole file app/code/core/Mage/Checkout/Model/Type/Multishipping.php to app/code/local/Mage/Checkout/Model/Type/Multishipping.php

Once you've finished either of the two above, you can move on to rewriting stuff we need into this class. Check out the function around line 498:

public function createOrders()
{
    $orderIds = array();
    $this->_validate();
    $shippingAddresses = $this->getQuote()->getAllShippingAddresses();
    $orders = array();

    if ($this->getQuote()->hasVirtualItems()) {
        $shippingAddresses[] = $this->getQuote()->getBillingAddress();
    }

    try {
        foreach ($shippingAddresses as $address) {
            $order = $this->_prepareOrder($address);

            $orders[] = $order;
        ....
        } 

    foreach ($orders as $order) {
            $order->place();
            $order->save();
       ...
    }

    ....

    Mage::dispatchEvent('checkout_submit_all_after', array('orders' => $orders, 'quote' => $this->getQuote()));

        return $this;
    } catch (Exception $e) {
        Mage::dispatchEvent('checkout_multishipping_refund_all', array('orders' => $orders));
        throw $e;
    }
 }

So we can clearly see here that it's trying to create an order for each address and then (the most important part), triggering the checkout_submit_all_after event which is monitored by the payment modules (order and quote information are passed to all of the available/active payment modules and the payment method set inside the quote will determine if a certain payment module receiving the dispatched event can process it or not).

With that in mind, you can have a couple of options now:

1.) if you can live with just one order, then try and rewrite the createOrders routine to just combine all items again into one order, ->place() it, then pass into dispatchEvent for good measure.

2.) if you need multiple orders, well -- this is where it becomes convoluted as there's a slim chance that you can do either of the following:

  • create a payment first then link it into the orders (almost impossible to do)
  • create the orders and another 'combined' order in which you will pass into the dispatchEvent. sounds filthy and/or wrong so don't bother maybe?

So yeah, you guys are pretty much asking for a lot here so the best I can do is to shed some light on where you can first do serious damage. I'd do it myself, but it's above my pay-grade here.

Some additional pointers:

  • Watch out for the session methods right after order creation, know where they lead too
  • Also be wary of all the dispatched events. They all have a purpose why they are there and where they are.

Good luck!

like image 129
Seth Malaki Avatar answered Sep 29 '22 12:09

Seth Malaki


Make sure this option is enabled:

enter image description here

If I'm not mistaken, when customer clicks one page checkout button, ship to multiple adresses option wouldn't be shown to him. But if he clicks on main checkout button it would.

like image 27
Dmytro Zavalkin Avatar answered Sep 29 '22 11:09

Dmytro Zavalkin