Пример #1
0
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', ['getCustomerNoteNotify'], [], '', false);
     $this->sessionQuoteMock = $this->getMock('\\Magento\\Backend\\Model\\Session\\Quote', [], [], '', false);
     $this->sessionQuoteMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
     $this->totals = $this->objectManager->getObject('\\Magento\\Sales\\Block\\Adminhtml\\Order\\Create\\Totals', ['sessionQuote' => $this->sessionQuoteMock]);
 }
Пример #2
0
 /**
  * @return array
  */
 public function getOneClickCards()
 {
     $customerId = $this->_sessionQuote->getCustomerId();
     $storeId = $this->_sessionQuote->getStoreId();
     $grandTotal = $this->_sessionQuote->getQuote()->getGrandTotal();
     // For backend only allow recurring payments
     $recurringType = \Adyen\Payment\Model\RecurringType::RECURRING;
     $cards = $this->_adyenHelper->getOneClickPaymentMethods($customerId, $storeId, $grandTotal, $recurringType);
     return $cards;
 }
Пример #3
0
 /**
  * Init
  */
 protected function setUp()
 {
     $this->helperManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->sessionQuoteMock = $this->getMockBuilder('Magento\\Backend\\Model\\Session\\Quote')->disableOriginalConstructor()->getMock();
     $this->quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['setTotalsCollectedFlag', 'collectTotals', 'getTotals', 'isVirtual', 'getBillingAddress', 'getShippingAddress'])->getMock();
     $this->shippingAddressMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->getMock();
     $this->billingAddressMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->getMock();
     $this->quoteMock->expects($this->any())->method('getBillingAddress')->willreturn($this->billingAddressMock);
     $this->quoteMock->expects($this->any())->method('getShippingAddress')->willreturn($this->shippingAddressMock);
     $this->sessionQuoteMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
     $this->totals = $this->helperManager->getObject('Magento\\Sales\\Block\\Adminhtml\\Order\\Create\\Totals', ['sessionQuote' => $this->sessionQuoteMock]);
 }
Пример #4
0
 /**
  * @param bool $noDiscount
  * @param string $couponCode
  * @param string $errorMessage
  * @param string $actualCouponCode
  * @dataProvider isApplyDiscountDataProvider
  */
 public function testExecute($noDiscount, $couponCode, $errorMessage, $actualCouponCode)
 {
     $quote = $this->getMock('Magento\\Quote\\Model\\Quote', ['getCouponCode', 'isVirtual', 'getAllItems'], [], '', false);
     $create = $this->getMock('Magento\\Sales\\Model\\AdminOrder\\Create', [], [], '', false);
     $paramReturnMap = [['customer_id', null, null], ['store_id', null, null], ['currency_id', null, null]];
     $this->request->expects($this->atLeastOnce())->method('getParam')->willReturnMap($paramReturnMap);
     $objectManagerParamMap = [['Magento\\Sales\\Model\\AdminOrder\\Create', $create], ['Magento\\Backend\\Model\\Session\\Quote', $this->session]];
     $this->objectManager->expects($this->atLeastOnce())->method('get')->willReturnMap($objectManagerParamMap);
     $this->eventManager->expects($this->any())->method('dispatch');
     $data = ['coupon' => ['code' => $couponCode]];
     $postReturnMap = [['order', $data], ['reset_shipping', false], ['collect_shipping_rates', false], ['sidebar', false], ['add_product', false], ['', false], ['update_items', false], ['remove_item', 1], ['from', 2], ['move_item', 1], ['to', 2], ['qty', 3], ['payment', false], [null, 'request'], ['payment', false], ['giftmessage', false], ['add_products', false], ['update_items', false]];
     $this->request->expects($this->atLeastOnce())->method('getPost')->willReturnMap($postReturnMap);
     $create->expects($this->once())->method('importPostData')->willReturnSelf();
     $create->expects($this->once())->method('initRuleData')->willReturnSelf();
     $create->expects($this->any())->method('getQuote')->willReturn($quote);
     $address = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
     $create->expects($this->once())->method('getBillingAddress')->willReturn($address);
     $quote->expects($this->any())->method('isVirtual')->willReturn(true);
     $this->request->expects($this->once())->method('has')->with('item')->willReturn(false);
     $create->expects($this->once())->method('saveQuote')->willReturnSelf();
     $this->session->expects($this->any())->method('getQuote')->willReturn($quote);
     $item = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], '', false, true, true, ['getNoDiscount']);
     $quote->expects($this->any())->method('getAllItems')->willReturn([$item]);
     $item->expects($this->any())->method('getNoDiscount')->willReturn($noDiscount);
     if (!$noDiscount) {
         $quote->expects($this->once())->method('getCouponCode')->willReturn($actualCouponCode);
     }
     $errorMessageManager = __($errorMessage, $couponCode);
     $this->escaper->expects($this->once())->method('escapeHtml')->with($couponCode)->willReturn($couponCode);
     $this->messageManager->expects($this->once())->method('addError')->with($errorMessageManager)->willReturnSelf();
     $this->resultForward->expects($this->once())->method('forward')->with('index')->willReturnSelf();
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->processData->execute());
 }
Пример #5
0
 /**
  * @param array $orderData
  * @return void
  */
 public function createOrder($orderData)
 {
     $this->setPhraseRenderer();
     if (!empty($orderData)) {
         $orderCreateModel = $this->processQuote($orderData);
         if (!empty($orderData['payment'])) {
             $orderCreateModel->setPaymentData($orderData['payment']);
             $orderCreateModel->getQuote()->getPayment()->addData($orderData['payment']);
         }
         $customer = $this->customerRepository->get($orderData['order']['account']['email'], $this->storeManager->getWebsite()->getId());
         $orderCreateModel->getQuote()->setCustomer($customer);
         $orderCreateModel->getSession()->setCustomerId($customer->getId());
         $order = $orderCreateModel->importPostData($orderData['order'])->createOrder();
         $orderItem = $this->getOrderItemForTransaction($order);
         $this->invoiceOrder($orderItem);
         $this->shipOrder($orderItem);
         if ($orderData['refund'] === "yes") {
             $this->refundOrder($orderItem);
         }
         $registryItems = ['rule_data', 'currently_saved_addresses', 'current_invoice', 'current_shipment'];
         $this->unsetRegistryData($registryItems);
         $this->currentSession->unsQuoteId();
         $this->currentSession->unsStoreId();
         $this->currentSession->unsCustomerId();
     }
 }
 public function testGetMerchantId()
 {
     $this->sessionQuote->expects($this->once())->method('getStoreId')->willReturn(1);
     $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(1);
     $result = $this->model->getMerchantId();
     $this->assertEquals(1, $result);
 }
Пример #7
0
 /**
  * Get cancel url
  *
  * @return string
  */
 public function getCancelUrl()
 {
     if ($this->_sessionQuote->getOrder()->getId()) {
         $url = $this->getUrl('sales/order/view', array('order_id' => $this->_sessionQuote->getOrder()->getId()));
     } else {
         $url = $this->getUrl('sales/*/cancel');
     }
     return $url;
 }
Пример #8
0
 /**
  * Cancel active partial authorizations
  *
  * @return void
  */
 public function execute()
 {
     $result['success'] = false;
     try {
         $paymentMethod = $this->_objectManager->get('Magento\\Payment\\Helper\\Data')->getMethodInstance(\Magento\Authorizenet\Model\Authorizenet::METHOD_CODE);
         if ($paymentMethod) {
             $paymentMethod->setStore($this->_sessionQuote->getQuote()->getStoreId());
             $paymentMethod->cancelPartialAuthorization($this->_sessionQuote->getQuote()->getPayment());
         }
         $result['success'] = true;
         $result['update_html'] = $this->_objectManager->get('Magento\\Authorizenet\\Helper\\Data')->getPaymentMethodsHtml($this->_view);
     } catch (\Magento\Framework\Model\Exception $e) {
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         $result['error_message'] = $e->getMessage();
     } catch (\Exception $e) {
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         $result['error_message'] = __('Something went wrong canceling the transactions.');
     }
     $this->_sessionQuote->getQuote()->getPayment()->save();
     $this->getResponse()->representJson($this->_objectManager->get('Magento\\Core\\Helper\\Data')->jsonEncode($result));
 }
Пример #9
0
 public function testExecuteSuccess()
 {
     $params = ['success' => 1, 'controller_action_name' => 'action', 'x_invoice_num' => 1];
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($params);
     $this->helperMock->expects($this->once())->method('getSuccessOrderUrl')->willReturn('redirect_parent_url');
     $this->directpostSessionMock->expects($this->once())->method('unsetData')->with('quote_id');
     $this->orderMock->expects($this->once())->method('getId')->willReturn(null);
     $this->sessionQuoteMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($this->orderMock);
     $this->adminOrderCreateMock->expects($this->atLeastOnce())->method('getSession')->willReturn($this->sessionQuoteMock);
     $this->coreRegistryMock->expects($this->once())->method('register')->with(Iframe::REGISTRY_KEY);
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Result\\Layout', $this->controller->execute());
 }
 /**
  * @covers \Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider::getTokensComponents
  */
 public function testGetTokensComponentsEmptyComponentProvider()
 {
     $storeId = 1;
     $customerId = 2;
     $code = 'vault_payment';
     $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
     $this->initStoreMock();
     $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true);
     $this->vaultPayment->expects(static::once())->method('getProviderCode')->with($storeId)->willReturn($code);
     $this->paymentTokenRepository->expects(static::never())->method('getList');
     $configProvider = new TokensConfigProvider($this->session, $this->paymentTokenRepository, $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, $this->vaultPayment, $this->dateTimeFactory);
     static::assertEmpty($configProvider->getTokensComponents());
 }
 /**
  * @covers \Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider::getTokensComponents
  */
 public function testGetTokensComponentsEmptyComponentProvider()
 {
     $storeId = 1;
     $customerId = 2;
     $vaultPaymentCode = 'vault_payment';
     $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
     $this->initStoreMock();
     $this->paymentDataHelper->expects(static::once())->method('getMethodInstance')->with($vaultPaymentCode)->willReturn($this->vaultPayment);
     $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(false);
     $this->paymentTokenRepository->expects(static::never())->method('getList');
     $configProvider = new TokensConfigProvider($this->session, $this->paymentTokenRepository, $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, $this->dateTimeFactory);
     $this->objectManager->setBackwardCompatibleProperty($configProvider, 'paymentDataHelper', $this->paymentDataHelper);
     static::assertEmpty($configProvider->getTokensComponents($vaultPaymentCode));
 }
Пример #12
0
 public function testUpdateQuoteItemsWithConfiguredOption()
 {
     $qty = 100000000;
     $items = [1 => ['qty' => 10, 'configured' => true, 'action' => false]];
     $itemMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', [], [], '', false);
     $itemMock->expects($this->once())->method('getQty')->will($this->returnValue($qty));
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $quoteMock->expects($this->once())->method('updateItem')->will($this->returnValue($itemMock));
     $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
     $expectedInfo = $items[1];
     $expectedInfo['qty'] = $qty;
     $this->itemUpdater->expects($this->once())->method('update')->with($this->equalTo($itemMock), $this->equalTo($expectedInfo));
     $this->adminOrderCreate->setRecollect(false);
     $this->adminOrderCreate->updateQuoteItems($items);
 }
Пример #13
0
 /**
  * Retrieve availables credit card types
  *
  * @return array
  */
 public function getCcAvailableTypes()
 {
     if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
         $country = $this->sessionQuote->getQuote()->getBillingAddress()->getCountryId();
     } else {
         $country = $this->checkoutSession->getQuote()->getBillingAddress()->getCountryId();
     }
     $applicableTypes = $this->config->getApplicableCardTypes($country);
     $types = $this->_paymentConfig->getCcTypes();
     foreach (array_keys($types) as $code) {
         if (!in_array($code, $applicableTypes)) {
             unset($types[$code]);
         }
     }
     return $types;
 }
Пример #14
0
 /**
  * Run test getQuote method
  *
  * @return void
  * @dataProvider getQuoteDataProvider
  */
 public function testGetQuoteWithQuoteId($customerId, $quoteCustomerId, $expectedNumberOfInvokes)
 {
     $quoteId = 22;
     $storeId = 10;
     $this->quote->expects($this->any())->method('getQuoteId')->will($this->returnValue($quoteId));
     $this->quote->expects($this->any())->method('setQuoteId')->with($quoteId);
     $this->quote->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId));
     $this->quote->expects($this->any())->method('getCustomerId')->will($this->returnValue($customerId));
     $dataCustomerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerRepositoryMock->expects($this->{$expectedNumberOfInvokes}())->method('getById')->with($customerId)->willReturn($dataCustomerMock);
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['setStoreId', 'setCustomerGroupId', 'setIsActive', 'getId', 'assignCustomer', 'setIgnoreOldQty', 'setIsSuperMode', 'getCustomerId', '__wakeup'], [], '', false);
     $quoteMock->expects($this->once())->method('setStoreId')->with($storeId);
     $quoteMock->expects($this->{$expectedNumberOfInvokes}())->method('assignCustomer')->with($dataCustomerMock);
     $quoteMock->expects($this->once())->method('setIgnoreOldQty')->with(true);
     $quoteMock->expects($this->once())->method('setIsSuperMode')->with(true);
     $quoteMock->expects($this->once())->method('getCustomerId')->will($this->returnValue($quoteCustomerId));
     $this->quoteRepositoryMock->expects($this->once())->method('get')->with($quoteId)->willReturn($quoteMock);
     $this->assertEquals($quoteMock, $this->quote->getQuote());
 }
Пример #15
0
 /**
  * Initialize data for price rules
  *
  * @return $this
  */
 public function initRuleData()
 {
     $this->_coreRegistry->register('rule_data', new \Magento\Framework\DataObject(['store_id' => $this->_session->getStore()->getId(), 'website_id' => $this->_session->getStore()->getWebsiteId(), 'customer_group_id' => $this->getCustomerGroupId()]));
     return $this;
 }
Пример #16
0
 /**
  * Retrieve quote object
  *
  * @return \Magento\Quote\Model\Quote
  */
 protected function _getQuote()
 {
     return $this->_session->getQuote();
 }
Пример #17
0
 /**
  * Indicates that block can display gift message form
  *
  * @return bool
  */
 public function canDisplayGiftmessageForm()
 {
     $quote = $this->_sessionQuote->getQuote();
     return $this->_messageHelper->isMessagesAllowed('items', $quote, $quote->getStore());
 }
Пример #18
0
 /**
  * Create mock for session quote
  */
 private function initSessionQuoteMock()
 {
     $this->sessionQuote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->setMethods(['getQuote', 'getBillingAddress', 'getCountryId', '__wakeup'])->getMock();
     $this->sessionQuote->expects(static::any())->method('getQuote')->willReturnSelf();
     $this->sessionQuote->expects(static::any())->method('getBillingAddress')->willReturnSelf();
 }
Пример #19
0
 /**
  * Enter description here...
  *
  * @return \Magento\Sales\Model\Quote
  */
 public function getQuote()
 {
     return $this->_sessionQuote->getQuote();
 }
Пример #20
0
 /**
  * Returns merchant id
  *
  * @return string
  */
 public function getMerchantId()
 {
     return $this->scopeConfig->getValue(self::CONFIG_PATH_MERCHANT_ID, $this->sessionQuote->getStoreId());
 }
Пример #21
0
 /**
  * Get list of available card types of order billing address country
  * @return array
  */
 public function getCcAvailableTypes()
 {
     $configuredCardTypes = $this->getConfiguredCardTypes();
     $countryId = $this->sessionQuote->getQuote()->getBillingAddress()->getCountryId();
     return $this->filterCardTypesForCountry($configuredCardTypes, $countryId);
 }