Convert magento admin quote into a multi address order -
Convert magento admin quote into a multi address order -
say have quote admin create order products entered, how go writing code add together multiple shipping addresses , assign item address.
ive got code working, based loosely off frontend multiship model. problem i'm having adding multiple address , assigning items quote. if have standard quote, how can add together multiple addresses?
i've tried :
$address = mage::getmodel('customer/address')->load($addressid); $quote->addshippingaddress($address);
which seems hold 1 address
the whole function:
public function createmultiorders() { // print_r($_post); $items = $_post['item']; $itemsbyaddress = array(); $billinginfo = array(); $session = mage::getsingleton('adminhtml/session_quote'); $quote = $session->getquote(); //first reorganizing info provided javascript array based on address id's foreach ($items $key => $item) { $addid = $item['addressid']; $itemid = $key; $qty = $item['qty']; $itemsbyaddress[$addid][] = array('itemid' => $itemid, 'qty' => $qty); } // print_r($itemsbyaddress); //now have array of items, seperated addressid goto, can create order each address foreach ($itemsbyaddress $addressid => $items) { $address = mage::getmodel('customer/address')->load($addressid); $quote->addshippingaddress($address); echo"<br/>address id $addressid, items are: <br/>"; foreach ($items $item) { // $address->additem($_item); ///add items order // echo"id before $item<br/>"; $itemid = explode('-_', $item['itemid']); $itemid = $itemid[0]; $qty = $item['qty']; echo "itemid $itemid, qty " . $qty . " <br/><br/><br/><br/>"; } } //print_r(get_class_methods($quote)); $shippingaddresses = $quote->getallshippingaddresses(); seek { foreach ($shippingaddresses $address) { $order = $this->_prepareorder($address); $orders[] = $order; mage::dispatchevent( 'checkout_type_multishipping_create_orders_single', array('order' => $order, 'address' => $address) ); } foreach ($orders $order) { $order->place(); $order->save(); if ($order->getcansendnewemailflag()) { $order->sendneworderemail(); } $orderids[$order->getid()] = $order->getincrementid(); } mage::getsingleton('core/session')->setorderids($orderids); mage::getsingleton('checkout/session')->setlastquoteid($quote->getid()); $quote->setisactive(false)->save(); mage::dispatchevent('checkout_submit_all_after', array('orders' => $orders, 'quote' => $quote)); homecoming $this; } grab (exception $e) { mage::dispatchevent('checkout_multishipping_refund_all', array('orders' => $orders)); throw $e; }
ok solved issue , able write script turn ordinary admin order multi address order. 1 of mistakes messed me entire time way loaded admin quote:
i loading session this
$session = mage::getsingleton('adminhtml/session_quote');
and should
$session = mage::getmodel('adminhtml/session_quote');
now, far assigning each of quote items address, final code looks like:
$address = mage::getmodel('customer/address')->load($addressid); echo"<br/>address id $addressid<br/>"; echo"quote address not set, adding shipping address <br/>"; $quoteaddress = mage::getmodel('sales/quote_address')->importcustomeraddress($address); $quote->addshippingaddress($quoteaddress); $quoteaddressitem = $quoteaddress->getitembyquoteitemid($quoteitem->getid()); if ($quoteaddressitem) { echo"increasing item quantitiy quote address<br/>"; // $quoteaddressitem->setqty((int) ($quoteaddressitem->getqty() + $qty)); } else { echo"setting client id quote item<br/>"; $quoteitem->setcustomeraddressid($quoteaddress->getcustomeraddressid()); echo"adding item quote address<br/>"; $quoteaddress->additem($quoteitem)->setquote($quote); echo"adding item quote collection<br/>"; if (!$quoteaddress->getitemscollection()->getitembyid($quoteitem->getid())) { $quoteaddress->getitemscollection()->additem($quoteitem)->save(); } $quoteaddress->setcollectshippingrates(true); $quoteaddress->collectshippingrates(); $quoteaddress->save(); $quoteitem->save(); $quote->save();
}
magento
Comments
Post a Comment