/** * Retrieve address items collection * * @return Mage_Sales_Model_Resource_Order_Item_Collection */ public function getItemsCollection() { if (!$this->_items) { $this->_items = $this->_multishippingFactory->createItemCollectionForAddress($this); } return $this->_items; }
/** * Get the order address. If only an order address id is available, will * attempt to load the order address. * * @return Mage_Sales_Model_Order_Address */ public function getOrderAddress() { if (!$this->hasOrderAddress()) { $this->setOrderAddress($this->_multishippingFactory->loadAddressForItem($this)); } return $this->getData('order_address'); }
/** * When getting an order address for an item, if the item does not yet have * a loaded order address instance, load a new one and return it. */ public function testGetOrderAddressMemoized() { $addressId = 3; $this->_item->setOrderAddressId($addressId); $address = Mage::getModel('sales/order_address'); // Side-effect test: ensure that the factory, which will load new // address instances for the item, is only invoked one time, no matter // how many times getOrderAddress is invoked. $this->_multishippingFactory->expects($this->once())->method('loadAddressForItem')->with($this->identicalTo($this->_item))->will($this->returnValue($address)); // Invoke getOrderAddress multiple times, the factory should still only // be invoked one time. $this->_item->getOrderAddress(); $this->_item->getOrderAddress(); }
/** * When getting an items collection for the address, if an order item * does not yet exist for the address, a new item collection should be * created and returned. */ public function testGetItemsCollection() { $itemCollection = $this->getResourceModelMockBuilder('sales/order_item_collection')->disableOriginalConstructor()->getMock(); $address = Mage::getModel('sales/order_address', ['multishipping_factory' => $this->_multishippingFactory]); // Mock the factory such that, if given the address, factory will return // the expected item collection. Expect that no matter how many times this // method is called, a new collection will only be created once. $this->_multishippingFactory->expects($this->once())->method('createItemCollectionForAddress')->with($this->identicalTo($address))->will($this->returnValue($itemCollection)); $this->assertSame($itemCollection, $address->getItemsCollection()); // Re-call to ensure that the item collection is stored and not // recreated each time it is requested. Factory's `once` invocation // matcher will ensure the method is only called the one time to create // a new item collection. $this->assertSame($itemCollection, $address->getItemsCollection()); }
/** * Submit the quote. Quote submit process will create the order based on * quote data. * * @return Mage_Sales_Model_Order */ public function submitOrder() { $this->_prepareQuote(); $order = $this->_createOrder(); // Create the transaction to place the order. $transaction = $this->_multishippingFactory->createOrderSaveTransaction($this->_quote, $order, $this->_quote->getCustomerId() ? $this->_quote->getCustomer() : null); // Dispatch events for when the order has been instantiated but before // any attempt has been made to actually save the order. Allows for // additional modifications to the order to be made before attempting // to save and place the order. $this->_checkoutDispatcher->dispatchBeforeOrderSubmit($this->_quote, $order); try { // Saving the transaction should trigger the order to be created - // save quote and order objects (incl. addresses & items), place // payments, and dispatch one last event that may be able to block // the order from being created. $transaction->save(); $this->_inactivateQuote(); $this->_checkoutDispatcher->dispatchOrderSubmitSuccess($this->_quote, $order); } catch (Exception $e) { $this->_cleanupFailedOrder($order); // Dispatch events signaling that the order failed to be created. // Allows related modules to cleanup or roll back actions taken // while attempting to creating the order. $this->_checkoutDispatcher->dispatchOrderSubmitFailure($this->_quote, $order); // Re-throw the exception to be handled in a user-friendly way elsewhere. throw $e; } // Signal that the order create was a success and the order has been // placed and saved. $this->_checkoutDispatcher->dispatchAfterOrderSubmit($this->_quote, $order); $this->_order = $order; return $order; }
/** * Submit the order, returning the created order object if successful. * * @return Mage_Sales_Model_Order|null */ protected function _submitOrder() { $service = $this->_multishippingFactory->createQuoteService($this->getQuote(), true); // Using submitOrder instead of submitAll. submitAll is only necessary // when creating an order that may contain recurring profiles/nominal // items. As such orders can only be ordered separately, they should // never find their way into multishipping checkout. return $service->submitOrder(); }
/** * Stub out dependencies to get through a very basic completion of an order * submit. * * @return self */ protected function _stubForBasicOrderSubmitCompletion() { // Stubs to get through submit order. Assertions related to these stubs // will be covered in more targeted tests. $this->_customerSession->method('isLoggedIn')->will($this->returnValue(false)); $this->_multishippingFactory->method('createOrderSaveTransaction')->will($this->returnValue($this->_transaction)); $this->_order->method('addData')->will($this->returnSelf()); $this->_order->method('collectShipmentAmounts')->will($this->returnSelf()); $this->_order->method('getItemsCollection')->will($this->returnValue([])); $this->_order->method('setId')->will($this->returnSelf()); $this->_order->method('setPayment')->will($this->returnSelf()); $this->_order->method('setQuote')->will($this->returnSelf()); $this->_quote->method('getAllAddresses')->will($this->returnValue([])); $this->_quote->method('getCustomer')->will($this->returnValue($this->_customer)); $this->_quote->method('getPayment')->will($this->returnValue($this->_quotePayment)); $this->_quoteConvertor->method('paymentToOrderPayment')->will($this->returnValue($this->_orderPayment)); $this->_quoteConvertor->method('toOrder')->will($this->returnValue($this->_order)); return $this; }
/** * Submit the order, returning the created order object if successful. * * @return Mage_Sales_Model_Order|null */ protected function _submitOrder() { /** @var Mage_Sales_Model_Quote */ $quote = $this->getQuote(); Mage::dispatchEvent(static::MULTI_SHIPPING_ORDER_CREATE_EVENT, ['quote' => $quote]); $service = $this->_multishippingFactory->createQuoteService($quote, true); // Using submitOrder instead of submitAll. submitAll is only necessary // when creating an order that may contain recurring profiles/nominal // items. As such orders can only be ordered separately, they should // never find their way into multishipping checkout. return $service->submitOrder(); }
protected function setUp() { // Stub log context builder to prevent session hits while collecting // log context meta-data. $logContext = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']); $logContext->method('getMetaData')->will($this->returnValue([])); $this->_quote = $this->getModelMock('sales/quote', ['getId', 'save']); $this->_order = $this->getModelMock('sales/order', ['getCanSendNewEmailFlag', 'queueNewOrderEmail', 'getId', 'getIncrementId']); $this->_quoteService = $this->getModelMockBuilder('sales/service_quote')->disableOriginalConstructor()->setMethods(['submitOrder', 'setCheckoutDispatcher'])->getMock(); $this->_multishippingFactory = $this->getHelperMock('ebayenterprise_multishipping/factory', ['createQuoteService']); $this->_multishippingFactory->method('createQuoteService')->with($this->identicalTo($this->_quote), $this->isTrue())->will($this->returnValue($this->_quoteService)); $this->_checkoutSession = $this->getModelMockBuilder('checkout/session')->disableOriginalConstructor()->setMethods(['setLastQuoteId'])->getMock(); $this->_coreSession = $this->getModelMockBuilder('core/session')->disableOriginalConstructor()->setMethods(['setOrderIds'])->getMock(); // Create the multishipping checkout type model to test - mocked to // prevent the need for complex mocking for inherited behaviors. $builder = $this->getModelMockBuilder('checkout/type_multishipping')->setMethods(['_validate', '_init', 'getQuote'])->setConstructorArgs([['multishipping_factory' => $this->_multishippingFactory, 'log_context' => $logContext, 'core_session' => $this->_coreSession, 'checkout_session' => $this->_checkoutSession]]); $this->_multishippingCheckout = $builder->getMock(); $this->_multishippingCheckout->method('getQuote')->will($this->returnValue($this->_quote)); // Disable event dispatch to prevent event handling from causing // any unexpected side-effects during the test. Mage::app()->disableEvents(); }
/** * When loading an address for an virtual item without an order address id, * the default billing address of the order associated with the item * should be used. */ public function testLoadAddressForItemDefaultVirtualAddress() { $shippingAddress = $this->getModelMock('sales/order_address'); $billingAddress = $this->getModelMock('sales/order_address'); $order = $this->getModelMock('sales/order', ['getShippingAddress', 'getBillingAddress']); $order->method('getShippingAddress')->will($this->returnValue($shippingAddress)); $order->method('getBillingAddress')->will($this->returnValue($billingAddress)); $item = $this->getModelMock('sales/order_item', ['getOrderAddressId', 'getOrder', 'getIsVirtual']); $item->method('getOrderAddressId')->will($this->returnValue(null)); $item->method('getOrder')->will($this->returnValue($order)); $item->method('getIsVirtual')->will($this->returnValue(true)); $this->assertSame($billingAddress, $this->_multishippingFactory->loadAddressForItem($item)); }