/** * Get url for reorder action * * @param \Magento\Sales\Model\Order $order * @return string */ public function getReorderUrl($order) { if (!$this->httpContext->getValue(Context::CONTEXT_AUTH)) { return $this->getUrl('sales/guest/reorder', ['order_id' => $order->getId()]); } return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]); }
/** * @dataProvider canVoidDataProvider * @param bool $canVoid */ public function testCanVoid($canVoid) { $this->_orderMock->expects($this->once())->method('getPayment')->will($this->returnValue($this->_paymentMock)); $this->_paymentMock->expects($this->once())->method('canVoid', '__wakeup')->with($this->equalTo($this->_model))->will($this->returnValue($canVoid)); $this->_model->setState(\Magento\Sales\Model\Order\Invoice::STATE_PAID); $this->assertEquals($canVoid, $this->_model->canVoid()); }
/** * @param Order $order * @param string $status * @param string $state * @return void */ protected function setOrderStateAndStatus(Order $order, $status, $state) { if (!$status) { $status = $order->getConfig()->getStateDefaultStatus($state); } $order->setState($state)->setStatus($status); }
/** * Retrieve tracking url with params * * @param string $key * @param \Magento\Sales\Model\Order|\Magento\Sales\Model\Order\Shipment|\Magento\Sales\Model\Order\Shipment\Track $model * @param string $method Optional - method of a model to get id * @return string */ protected function _getTrackingUrl($key, $model, $method = 'getId') { $urlPart = "{$key}:{$model->{$method}()}:{$model->getProtectCode()}"; $params = ['_direct' => 'shipping/tracking/popup', '_query' => ['hash' => $this->urlEncoder->encode($urlPart)]]; $storeModel = $this->_storeManager->getStore($model->getStoreId()); return $storeModel->getUrl('', $params); }
/** * Process addresses saving * * @param Order $order * @return $this * @throws \Exception */ public function process(Order $order) { if (null !== $order->getAddresses()) { /** @var \Magento\Sales\Model\Order\Address $address */ foreach ($order->getAddresses() as $address) { $address->setParentId($order->getId()); $address->setOrder($order); $address->save(); } $billingAddress = $order->getBillingAddress(); $attributesForSave = []; if ($billingAddress && $order->getBillingAddressId() != $billingAddress->getId()) { $order->setBillingAddressId($billingAddress->getId()); $attributesForSave[] = 'billing_address_id'; } $shippingAddress = $order->getShippingAddress(); if ($shippingAddress && $order->getShippigAddressId() != $shippingAddress->getId()) { $order->setShippingAddressId($shippingAddress->getId()); $attributesForSave[] = 'shipping_address_id'; } if (!empty($attributesForSave)) { $this->attribute->saveAttribute($order, $attributesForSave); } } return $this; }
/** * Send email to customer * * @param Order $order * @param bool $notify * @param string $comment * @return bool */ public function send(Order $order, $notify = true, $comment = '') { $transport = ['order' => $order, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order)]; $this->eventManager->dispatch('email_order_comment_set_template_vars_before', ['sender' => $this, 'transport' => $transport]); $this->templateContainer->setTemplateVars($transport); return $this->checkAndSend($order, $notify); }
public function testSaveDownloadableOrderItem() { $itemId = 100; $itemMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->getMock(); $itemMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($this->orderMock); $itemMock->expects($this->any())->method('getId')->willReturn($itemId); $itemMock->expects($this->any())->method('getProductType')->willReturn(DownloadableProductType::TYPE_DOWNLOADABLE); $this->orderMock->expects($this->once())->method('getStoreId')->willReturn(10500); $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $product->expects($this->once())->method('getTypeId')->willReturn(DownloadableProductType::TYPE_DOWNLOADABLE); $productType = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Product\\Type')->disableOriginalConstructor()->getMock(); $product->expects($this->once())->method('getTypeInstance')->willReturn($productType); $product->expects($this->once())->method('setStoreId')->with(10500)->willReturnSelf(); $product->expects($this->once())->method('load')->willReturnSelf(); $this->productFactory->expects($this->once())->method('create')->willReturn($product); $linkItem = $this->createLinkItem(12, 12, true, 'pending'); $this->itemFactory->expects($this->once())->method('create')->willReturn($linkItem); $productType->expects($this->once())->method('getLinks')->willReturn([123 => $linkItem]); $itemMock->expects($this->once())->method('getProductOptionByCode')->willReturn([123]); $itemMock->expects($this->once())->method('getProduct')->willReturn(null); $purchasedLink = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Link\\Purchased')->disableOriginalConstructor()->setMethods(['load', 'setLinkSectionTitle', 'save'])->getMock(); $purchasedLink->expects($this->once())->method('load')->with($itemId, 'order_item_id')->willReturnSelf(); $purchasedLink->expects($this->once())->method('setLinkSectionTitle')->willReturnSelf(); $purchasedLink->expects($this->once())->method('save')->willReturnSelf(); $this->purchasedFactory->expects($this->any())->method('create')->willReturn($purchasedLink); $event = new \Magento\Framework\DataObject(['item' => $itemMock]); $observer = new \Magento\Framework\Event\Observer(['event' => $event]); $this->saveDownloadableOrderItemObserver->execute($observer); }
public function testSave() { $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->once())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->once())->method('getGroup')->willReturn($this->storeGroupMock); $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->adapterMock); $this->adapterMock->expects($this->any())->method('quoteInto'); $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([])); $this->adapterMock->expects($this->any())->method('update'); $this->adapterMock->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); }
private function setupOrder($orderData) { //Set up order mock foreach ($orderData['data_fields'] as $key => $value) { $this->order->setData($key, $value); } }
public function testGetAllItems() { $items = [new \Magento\Framework\Object(['parent_item' => 'parent item 1', 'name' => 'name 1', 'qty_ordered' => 1, 'base_price' => 0.1]), new \Magento\Framework\Object(['parent_item' => 'parent item 2', 'name' => 'name 2', 'qty_ordered' => 2, 'base_price' => 1.2]), new \Magento\Framework\Object(['parent_item' => 'parent item 3', 'name' => 'name 3', 'qty_ordered' => 3, 'base_price' => 2.3])]; $expected = [new \Magento\Framework\Object(['parent_item' => 'parent item 1', 'name' => 'name 1', 'qty' => 1, 'price' => 0.1, 'original_item' => $items[0]]), new \Magento\Framework\Object(['parent_item' => 'parent item 2', 'name' => 'name 2', 'qty' => 2, 'price' => 1.2, 'original_item' => $items[1]]), new \Magento\Framework\Object(['parent_item' => 'parent item 3', 'name' => 'name 3', 'qty' => 3, 'price' => 2.3, 'original_item' => $items[2]])]; $this->_orderMock->expects($this->once())->method('getAllItems')->will($this->returnValue($items)); $this->assertEquals($expected, $this->_model->getAllItems()); }
public function testSendEmailWhenRedirectUrlExists() { $this->paymentMock->expects($this->once())->method('getOrderPlaceRedirectUrl')->willReturn(false); $this->orderMock->expects($this->once())->method('getCanSendNewEmailFlag'); $this->orderSenderMock->expects($this->never())->method('send'); $this->loggerMock->expects($this->never())->method('critical'); $this->model->execute($this->observerMock); }
public function testGetOrder() { $orderId = 100000041; $this->model->setOrderId($orderId); $entityName = 'invoice'; $this->orderMock->expects($this->atLeastOnce())->method('setHistoryEntityName')->with($entityName)->will($this->returnSelf()); $this->assertEquals($this->orderMock, $this->model->getOrder()); }
/** * @param array $orderItemAppliedTaxes * @param array $expectedResults * @return void * @dataProvider getOrderTaxDetailsDataProvider */ public function testGetOrderTaxDetails($orderItemAppliedTaxes, $expectedResults) { $orderId = 1; $this->order->expects($this->once())->method('load')->with($orderId)->will($this->returnValue(true)); $this->orderItemTaxResource->expects($this->once())->method('getTaxItemsByOrderId')->with($orderId)->will($this->returnValue($orderItemAppliedTaxes)); $orderTaxDetails = $this->ordertTaxService->getOrderTaxDetails($orderId); $this->assertEquals($expectedResults, $orderTaxDetails->__toArray()); }
/** * {@inheritdoc} */ public function canView(\Magento\Sales\Model\Order $order) { $currentOrder = $this->registry->registry('current_order'); if ($order->getId() && $order->getId() === $currentOrder->getId()) { return true; } return false; }
/** * {@inheritdoc} */ public function canView(\Magento\Sales\Model\Order $order) { $customerId = $this->customerSession->getCustomerId(); $availableStatuses = $this->orderConfig->getVisibleOnFrontStatuses(); if ($order->getId() && $order->getCustomerId() && $order->getCustomerId() == $customerId && in_array($order->getStatus(), $availableStatuses, true)) { return true; } return false; }
/** * test _beforeSaveMethod via save() */ public function testSave() { $this->validatorMock->expects($this->once())->method('validate')->with($this->equalTo($this->addressMock))->will($this->returnValue([])); $this->addressMock->expects($this->any())->method('hasDataChanges')->will($this->returnValue(true)); $this->addressMock->expects($this->exactly(2))->method('getOrder')->will($this->returnValue($this->orderMock)); $this->orderMock->expects($this->once())->method('getId')->willReturn(1); $this->addressMock->expects($this->exactly(2))->method('getOrderId')->will($this->returnValue(2)); $this->gridPoolMock->expects($this->once())->method('refreshByOrderId')->with($this->equalTo(2))->will($this->returnSelf()); $this->addressResource->save($this->addressMock); }
/** * Perform order state and status assertions depending on currency code * * @param \Magento\Sales\Model\Order $order * @param string $currencyCode */ protected function _assertOrder($order, $currencyCode) { if ($currencyCode == 'USD') { $this->assertEquals('complete', $order->getState()); $this->assertEquals('complete', $order->getStatus()); } else { $this->assertEquals('payment_review', $order->getState()); $this->assertEquals('fraud', $order->getStatus()); } }
/** * @param \Magento\Sales\Model\Order $order * @return bool */ public function canReorder(\Magento\Sales\Model\Order $order) { if (!$this->isAllowed($order->getStore())) { return false; } if ($this->_customerSession->isLoggedIn()) { return $order->canReorder(); } else { return true; } }
protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->authorizationMock = $this->getMock('\\Magento\\Framework\\Authorization', [], [], '', false); $this->coreRegistryMock = $this->getMock('Magento\\Framework\\Registry', [], [], '', false); $this->orderMock = $this->getMock('\\Magento\\Sales\\Model\\Order', [], [], '', false); $this->paymentMock = $this->getMock('\\Magento\\Sales\\Model\\Order\\Payment', [], [], '', false); $this->coreRegistryMock->expects($this->any())->method('registry')->with('current_order')->willReturn($this->orderMock); $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock); $this->transactionsTab = $this->objectManager->getObject('Magento\\Sales\\Block\\Adminhtml\\Order\\View\\Tab\\Transactions', ['authorization' => $this->authorizationMock, 'registry' => $this->coreRegistryMock]); }
/** * Send email about new order. * Process mail exception * * @param Order $order * @return bool */ public function send(Order $order) { try { $order->sendNewOrderEmail(); } catch (\Magento\Framework\Mail\Exception $exception) { $this->logger->logException($exception); $this->messageManager->addWarning(__('You did not email your customer. Please check your email settings.')); return false; } return true; }
/** * Saves new order transaction incrementing "try". * * @param \Magento\Sales\Model\Order $order * @param string $payuplOrderId * @param string $payuplExternalOrderId * @param string $status */ public function addNewOrderTransaction(\Magento\Sales\Model\Order $order, $payuplOrderId, $payuplExternalOrderId, $status) { $orderId = $order->getId(); $payment = $order->getPayment(); $payment->setTransactionId($payuplOrderId); $payment->setTransactionAdditionalInfo(\Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS, ['order_id' => $payuplExternalOrderId, 'try' => $this->transactionResource->getLastTryByOrderId($orderId) + 1, 'status' => $status]); $payment->setIsTransactionClosed(0); $transaction = $payment->addTransaction('order'); $transaction->save(); $payment->save(); }
/** * @magentoDataFixture Magento/Paypal/_files/quote_payment_standard.php * @magentoConfigFixture current_store payment/paypal_standard/active 1 * @magentoConfigFixture current_store paypal/general/business_account merchant_2012050718_biz@example.com */ public function testCancelAction() { $quote = $this->_objectManager->create('Magento\\Sales\\Model\\Quote'); $quote->load('test01', 'reserved_order_id'); $this->_session->setQuoteId($quote->getId()); $this->_session->setPaypalStandardQuoteId($quote->getId())->setLastRealOrderId('100000002'); $this->dispatch('paypal/standard/cancel'); $this->_order->load('100000002', 'increment_id'); $this->assertEquals('canceled', $this->_order->getState()); $this->assertEquals($this->_session->getQuote()->getGrandTotal(), $quote->getGrandTotal()); $this->assertEquals($this->_session->getQuote()->getItemsCount(), $quote->getItemsCount()); }
/** * @param Order $order * @return void */ protected function prepareTemplate(Order $order) { $this->templateContainer->setTemplateOptions($this->getTemplateOptions()); if ($order->getCustomerIsGuest()) { $templateId = $this->identityContainer->getGuestTemplateId(); $customerName = $order->getBillingAddress()->getName(); } else { $templateId = $this->identityContainer->getTemplateId(); $customerName = $order->getCustomerName(); } $this->identityContainer->setCustomerName($customerName); $this->identityContainer->setCustomerEmail($order->getCustomerEmail()); $this->templateContainer->setTemplateId($templateId); }
/** * Retrieve sales address (order or quote) on which tax calculation must be based * * @param \Magento\Sales\Model\Order $order * @param \Magento\Store\Model\Store|string|int|null $store * @return \Magento\Sales\Model\Order\Address|null */ protected function _getVatRequiredSalesAddress($order, $store = null) { $configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType($store); $requiredAddress = null; switch ($configAddressType) { case \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING: $requiredAddress = $order->getShippingAddress(); break; default: $requiredAddress = $order->getBillingAddress(); break; } return $requiredAddress; }
/** * test check order - set state processing */ public function testCheckSetStateProcessing() { $this->orderMock->expects($this->once())->method('getId')->will($this->returnValue(1)); $this->orderMock->expects($this->once())->method('isCanceled')->will($this->returnValue(false)); $this->orderMock->expects($this->once())->method('canUnhold')->will($this->returnValue(false)); $this->orderMock->expects($this->once())->method('canInvoice')->will($this->returnValue(false)); $this->orderMock->expects($this->once())->method('canShip')->will($this->returnValue(true)); $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue(Order::STATE_NEW)); $this->orderMock->expects($this->once())->method('getIsInProcess')->will($this->returnValue(true)); $this->orderMock->expects($this->once())->method('setState')->with(Order::STATE_PROCESSING)->will($this->returnSelf()); $this->assertEquals($this->state, $this->state->check($this->orderMock)); }
private function initOrderMock($orderId, $state) { $this->orderFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->orderMock)); $this->orderMock->expects($this->once())->method('loadByIncrementId')->with($orderId)->will($this->returnSelf()); $this->orderMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($orderId)); $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue($state)); }
/** * Prepare order creditmemo based on order items and requested params * * @param array $data * @return \Magento\Sales\Model\Order\Creditmemo */ public function prepareCreditmemo($data = []) { $totalQty = 0; $creditmemo = $this->_convertor->toCreditmemo($this->_order); $qtys = isset($data['qtys']) ? $data['qtys'] : []; foreach ($this->_order->getAllItems() as $orderItem) { if (!$this->_canRefundItem($orderItem, $qtys)) { continue; } $item = $this->_convertor->itemToCreditmemoItem($orderItem); if ($orderItem->isDummy()) { $qty = 1; $orderItem->setLockedDoShip(true); } else { if (isset($qtys[$orderItem->getId()])) { $qty = (double) $qtys[$orderItem->getId()]; } elseif (!count($qtys)) { $qty = $orderItem->getQtyToRefund(); } else { continue; } } $totalQty += $qty; $item->setQty($qty); $creditmemo->addItem($item); } $creditmemo->setTotalQty($totalQty); $this->_initCreditmemoData($creditmemo, $data); $creditmemo->collectTotals(); return $creditmemo; }
/** * Retrieve the order the invoice for created for * * @return \Magento\Sales\Model\Order */ public function getOrder() { if (!$this->_order instanceof \Magento\Sales\Model\Order) { $this->_order = $this->_orderFactory->create()->load($this->getOrderId()); } return $this->_order->setHistoryEntityName($this->entityType); }
/** * Retrieve the order the shipment for created for * * @return \Magento\Sales\Model\Order */ public function getOrder() { if (!$this->_order instanceof \Magento\Sales\Model\Order) { $this->_order = $this->orderRepository->get($this->getOrderId()); } return $this->_order->setHistoryEntityName($this->entityType); }
/** * @covers \Magento\Sales\Controller\Adminhtml\Order\View::executeInternal */ public function testExecute() { $id = 111; $titlePart = '#111'; $this->initOrder(); $this->initOrderSuccess($id); $this->prepareRedirect(); $this->initAction(); $this->resultPageMock->expects($this->atLeastOnce()) ->method('getConfig') ->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->atLeastOnce()) ->method('getTitle') ->willReturn($this->pageTitleMock); $this->orderMock->expects($this->atLeastOnce()) ->method('getIncrementId') ->willReturn($id); $this->pageTitleMock->expects($this->exactly(2)) ->method('prepend') ->withConsecutive( ['Orders'], [$titlePart] ) ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Backend\Model\View\Result\Page', $this->viewAction->executeInternal() ); }