Exemple #1
0
 public function testSave()
 {
     $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn(null);
     $this->orderItemMock->expects($this->once())->method('getChildrenItems')->willReturn([]);
     $this->orderItemMock->expects($this->once())->method('getQuoteParentItemId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('setTotalItemCount')->with(1);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->orderMock->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]);
     $this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true);
     $this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order');
     $this->orderMock->expects($this->exactly(2))->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->exactly(2))->method('getGroup')->willReturn($this->storeGroupMock);
     $this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock);
     $this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001');
     $this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']);
     $this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']);
     $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock);
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
     $this->connectionMock->expects($this->any())->method('quoteInto');
     $this->connectionMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->connectionMock->expects($this->any())->method('update');
     $this->connectionMock->expects($this->any())->method('lastInsertId');
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Framework\Model\AbstractModel $object)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'save');
     if (!$pluginInfo) {
         return parent::save($object);
     } else {
         return $this->___callPlugins('save', func_get_args(), $pluginInfo);
     }
 }
 /**
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testSaveOrder()
 {
     $addressData = ['region' => 'CA', 'postcode' => '11111', 'lastname' => 'lastname', 'firstname' => 'firstname', 'street' => 'street', 'city' => 'Los Angeles', 'email' => '*****@*****.**', 'telephone' => '11111111', 'country_id' => 'US'];
     $billingAddress = $this->objectManager->create('Magento\\Sales\\Model\\Order\\Address', ['data' => $addressData]);
     $billingAddress->setAddressType('billing');
     $shippingAddress = clone $billingAddress;
     $shippingAddress->setId(null)->setAddressType('shipping');
     $payment = $this->objectManager->create('Magento\\Sales\\Model\\Order\\Payment');
     $payment->setMethod('checkmo');
     /** @var \Magento\Sales\Model\Order\Item $orderItem */
     $orderItem = $this->objectManager->create('Magento\\Sales\\Model\\Order\\Item');
     $orderItem->setProductId(1)->setQtyOrdered(2)->setBasePrice(10)->setPrice(10)->setRowTotal(10);
     /** @var \Magento\Sales\Model\Order $order */
     $order = $this->objectManager->create('Magento\\Sales\\Model\\Order');
     $order->setIncrementId($this->orderIncrementId)->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING))->setSubtotal(100)->setBaseSubtotal(100)->setBaseGrandTotal(100)->setCustomerIsGuest(true)->setCustomerEmail('*****@*****.**')->setBillingAddress($billingAddress)->setShippingAddress($shippingAddress)->setStoreId($this->objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getId())->addItem($orderItem)->setPayment($payment);
     $this->resourceModel->save($order);
     $this->assertNotNull($order->getCreatedAt());
     $this->assertNotNull($order->getUpdatedAt());
 }