コード例 #1
1
 /**
  * @covers \Magento\SalesRule\Model\Rule\Action\Discount\CartFixed::calculate
  */
 public function testCalculate()
 {
     $this->rule->setData(['id' => 1, 'discount_amount' => 10.0]);
     $this->address->expects($this->any())->method('getCartFixedRules')->will($this->returnValue([]));
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->priceCurrency->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0));
     $this->priceCurrency->expects($this->atLeastOnce())->method('round')->will($this->returnArgument(0));
     $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($store));
     /** validators data */
     $this->validator->expects($this->once())->method('getItemPrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemBasePrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemOriginalPrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemBaseOriginalPrice')->with($this->item)->will($this->returnValue(100));
     $this->address->expects($this->once())->method('setCartFixedRules')->with([1 => 0.0]);
     $this->model->calculate($this->rule, $this->item, 1);
     $this->assertEquals($this->data->getAmount(), 10);
     $this->assertEquals($this->data->getBaseAmount(), 10);
     $this->assertEquals($this->data->getOriginalAmount(), 10);
     $this->assertEquals($this->data->getBaseOriginalAmount(), 100);
 }
コード例 #2
0
 /**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool shippingPriceInclTax
  * @param array $expectedValue
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
 {
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $itemMock = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterface');
     $this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
     $this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
     $this->address->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $this->address->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($baseShippingAmount);
         } else {
             $this->address->expects($this->never())->method('getBaseShippingDiscountAmount');
             $this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($shippingAmount);
         }
     }
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $this->taxClassKeyBuilderMock->expects($this->any())->method('setType')->willReturnSelf();
     $this->taxClassKeyBuilderMock->expects($this->any())->method('setValue')->with($shippingTaxClass)->willReturnSelf();
     $this->quoteDetailsItemBuilderMock->expects($this->once())->method('create')->willReturn($itemMock);
     $this->assertEquals($itemMock, $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency));
 }
コード例 #3
0
 /**
  * Test getShippingRate method
  */
 public function testGetShippingRate()
 {
     $rate = $this->getMock('Magento\\Quote\\Model\\Quote\\Address\\Rate', ['__wakeup'], [], '', false);
     $this->shippingAddress->setShippingMethod(self::SHIPPING_METHOD);
     $this->shippingAddress->expects($this->once())->method('getShippingRateByCode')->with(self::SHIPPING_METHOD)->will($this->returnValue($rate));
     $this->assertEquals($rate, $this->model->getShippingRate());
 }
コード例 #4
0
 /**
  * Fetch customer balance
  *
  * @param \Magento\Quote\Model\Quote\Address $address
  * @return $this
  */
 public function fetchTotals(\Magento\Quote\Model\Quote\Address $address)
 {
     $custbalance = $address->getCustbalanceAmount();
     if ($custbalance != 0) {
         $address->addTotal(['code' => 'custbalance', 'title' => __('Store Credit'), 'value' => -$custbalance]);
     }
     return $this;
 }
コード例 #5
0
ファイル: Tax.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * Fetch totals
  *
  * @param \Magento\Quote\Model\Quote\Address $address
  * @return $this
  */
 public function fetchTotals(\Magento\Quote\Model\Quote\Address $address)
 {
     $amount = $address->getTaxAmount();
     if ($amount != 0) {
         $address->addTotal(['code' => 'tax', 'title' => __('Tax'), 'value' => $amount]);
     }
     return $this;
 }
 /**
  * @param \PHPUnit_Framework_MockObject_MockObject $quoteMock
  */
 private function disabledQuoteAddressValidationStep(\PHPUnit_Framework_MockObject_MockObject $quoteMock)
 {
     $billingAddressMock = $this->getBillingAddressMock($quoteMock);
     $billingAddressMock->expects(self::once())->method('setShouldIgnoreValidation')->with(true)->willReturnSelf();
     $this->shippingAddressMock->expects(self::once())->method('setShouldIgnoreValidation')->with(true)->willReturnSelf();
     $billingAddressMock->expects(self::at(1))->method('getEmail')->willReturn(self::TEST_EMAIL);
     $billingAddressMock->expects(self::never())->method('setSameAsBilling');
 }
コード例 #7
0
 public function testValidateMiniumumAmountNegative()
 {
     $storeId = 1;
     $scopeConfigValues = [['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true], ['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20], ['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true]];
     $this->quote->expects($this->once())->method('getStoreId')->willReturn($storeId);
     $this->quote->expects($this->once())->method('getIsVirtual')->willReturn(false);
     $this->address->setAddressType(Address::TYPE_SHIPPING);
     $this->scopeConfig->expects($this->once())->method('isSetFlag')->willReturnMap($scopeConfigValues);
     $this->assertTrue($this->address->validateMinimumAmount());
 }
コード例 #8
0
 /**
  * Check whether VAT ID validation is enabled
  *
  * @param \Magento\Quote\Model\Quote\Address $quoteAddress
  * @param \Magento\Store\Model\Store|int $store
  * @return bool
  */
 public function isEnabled(\Magento\Quote\Model\Quote\Address $quoteAddress, $store)
 {
     $configAddressType = $this->customerAddress->getTaxCalculationAddressType($store);
     // When VAT is based on billing address then Magento have to handle only billing addresses
     $additionalBillingAddressCondition = $configAddressType == \Magento\Customer\Model\Address\AbstractAddress::TYPE_BILLING ? $configAddressType != $quoteAddress->getAddressType() : false;
     // Handle only addresses that corresponds to VAT configuration
     if (!$this->customerAddress->isVatValidationEnabled($store) || $additionalBillingAddressCondition) {
         return false;
     }
     return true;
 }
コード例 #9
0
 /**
  * @param \Magento\Quote\Model\Quote\Address $address
  * @return bool
  */
 public function isCanApplyMsrp($address)
 {
     $canApplyMsrp = false;
     foreach ($address->getAllItems() as $item) {
         if (!$item->getParentItemId() && $this->msrpHelper->isShowBeforeOrderConfirm($item->getProductId()) && $this->msrpHelper->isMinimalPriceLessMsrp($item->getProductId())) {
             $canApplyMsrp = true;
             break;
         }
     }
     return $canApplyMsrp;
 }
コード例 #10
0
 /**
  * @param \Magento\Quote\Model\Quote\Address $address
  * @return $this
  */
 public function collect(\Magento\Quote\Model\Quote\Address $address)
 {
     $address->setCustbalanceAmount(0);
     $address->setBaseCustbalanceAmount(0);
     $address->setGrandTotal($address->getGrandTotal() - $address->getCustbalanceAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseCustbalanceAmount());
     return $this;
 }
コード例 #11
0
 /**
  * Fetch discount
  *
  * @param \Magento\Quote\Model\Quote\Address $address
  * @return $this
  */
 public function fetchTotals(\Magento\Quote\Model\Quote\Address $address)
 {
     $amount = $address->getDiscountAmount();
     if ($amount != 0) {
         $title = __('Discount');
         $couponCode = $address->getQuote()->getCouponCode();
         if (strlen($couponCode)) {
             $title .= sprintf(' (%s)', $couponCode);
         }
         $address->addTotal(['code' => 'discount', 'title' => $title, 'value' => -$amount]);
     }
     return $this;
 }
コード例 #12
0
ファイル: ShippingTest.php プロジェクト: nblair/magescotch
 public function testCollect()
 {
     $this->shippingAssignment->expects($this->exactly(3))->method('getShipping')->willReturn($this->shipping);
     $this->shipping->expects($this->exactly(2))->method('getAddress')->willReturn($this->address);
     $this->shipping->expects($this->once())->method('getMethod')->willReturn('flatrate');
     $this->shippingAssignment->expects($this->atLeastOnce())->method('getItems')->willReturn([$this->cartItem]);
     $this->freeShipping->expects($this->once())->method('isFreeShipping')->with($this->quote, [$this->cartItem])->willReturn(true);
     $this->address->expects($this->once())->method('setFreeShipping')->with(true);
     $this->total->expects($this->atLeastOnce())->method('setTotalAmount');
     $this->total->expects($this->atLeastOnce())->method('setBaseTotalAmount');
     $this->cartItem->expects($this->atLeastOnce())->method('getProduct')->willReturnSelf();
     $this->cartItem->expects($this->atLeastOnce())->method('isVirtual')->willReturn(false);
     $this->cartItem->expects($this->once())->method('getParentItem')->willReturn(false);
     $this->cartItem->expects($this->once())->method('getHasChildren')->willReturn(false);
     $this->cartItem->expects($this->once())->method('getWeight')->willReturn(2);
     $this->cartItem->expects($this->atLeastOnce())->method('getQty')->willReturn(2);
     $this->address->expects($this->once())->method('getFreeShipping')->willReturn(true);
     $this->cartItem->expects($this->once())->method('setRowWeight')->with(0);
     $this->address->expects($this->once())->method('setItemQty')->with(2);
     $this->address->expects($this->atLeastOnce())->method('setWeight');
     $this->address->expects($this->atLeastOnce())->method('setFreeMethodWeight');
     $this->address->expects($this->once())->method('collectShippingRates');
     $this->address->expects($this->once())->method('getAllShippingRates')->willReturn([$this->rate]);
     $this->rate->expects($this->once())->method('getCode')->willReturn('flatrate');
     $this->quote->expects($this->once())->method('getStore')->willReturn($this->store);
     $this->rate->expects($this->atLeastOnce())->method('getPrice')->willReturn(5);
     $this->priceCurrency->expects($this->once())->method('convert')->with(5, $this->store)->willReturn(5);
     $this->total->expects($this->once())->method('setShippingAmount')->with(5);
     $this->rate->expects($this->once())->method('getCarrierTitle')->willReturn('Carrier title');
     $this->rate->expects($this->once())->method('getMethodTitle')->willReturn('Method title');
     $this->address->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title');
     $this->address->expects($this->once())->method('getShippingDescription')->willReturn('Carrier title - Method title');
     $this->total->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title');
     $this->shippingModel->collect($this->quote, $this->shippingAssignment, $this->total);
 }
コード例 #13
0
ファイル: QuoteTest.php プロジェクト: nja78/magento2
 public function testPrepareQuoteForNewCustomer()
 {
     $customerAddressMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     $this->addressMock->expects($this->any())->method('exportCustomerAddress')->willReturn($customerAddressMock);
     $this->addressMock->expects($this->any())->method('getData')->willReturn([]);
     $this->addressFactoryMock->expects($this->any())->method('create')->willReturn($this->addressMock);
     $this->quoteMock->expects($this->any())->method('isVirtual')->willReturn(false);
     $this->quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($this->addressMock);
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock);
     $customerDataMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerFactoryMock->expects($this->once())->method('create')->willReturn($customerDataMock);
     $this->copyObjectMock->expects($this->any())->method('getDataFromFieldset')->willReturn([]);
     $this->dataObjectHelper->expects($this->any())->method('populateWithArray')->willReturnSelf();
     $this->assertInstanceOf('Magento\\Quote\\Model\\Quote', $this->quote->prepareQuoteForNewCustomer($this->quoteMock));
 }
コード例 #14
0
 public function testPopulateCustomerInfo()
 {
     $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($this->customerMock);
     $this->customerMock->expects($this->atLeastOnce())->method('getId')->willReturn(null);
     $this->customerMock->expects($this->atLeastOnce())->method('getDefaultBilling')->willReturn(100500);
     $this->quoteMock->expects($this->atLeastOnce())->method('getBillingAddress')->willReturn($this->quoteAddressMock);
     $this->quoteMock->expects($this->atLeastOnce())->method('getShippingAddress')->willReturn($this->quoteAddressMock);
     $this->quoteMock->expects($this->atLeastOnce())->method('setCustomer')->with($this->customerMock)->willReturnSelf();
     $this->quoteMock->expects($this->once())->method('getPasswordHash')->willReturn('password hash');
     $this->quoteAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn(null);
     $this->customerAddressRepositoryMock->expects($this->atLeastOnce())->method('getById')->with(100500)->willReturn($this->customerAddressMock);
     $this->quoteAddressMock->expects($this->atLeastOnce())->method('importCustomerAddressData')->willReturnSelf();
     $this->accountManagementMock->expects($this->once())->method('createAccountWithPasswordHash')->with($this->customerMock, 'password hash')->willReturn($this->customerMock);
     $this->customerManagement->populateCustomerInfo($this->quoteMock);
 }
コード例 #15
0
 /**
  * @dataProvider afterConvertDataProvider
  */
 public function testAfterConvertNullExtensionAttribute($appliedTaxes, $itemsAppliedTaxes)
 {
     $this->model->beforeConvert($this->subjectMock, $this->quoteAddressMock);
     $this->quoteAddressMock->expects($this->once())->method('getAppliedTaxes')->willReturn($appliedTaxes);
     $this->quoteAddressMock->expects($this->once())->method('getItemsAppliedTaxes')->willReturn($itemsAppliedTaxes);
     $orderExtensionAttributeMock = $this->setupOrderExtensionAttributeMock();
     $orderMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $orderMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null);
     $this->orderExtensionFactoryMock->expects($this->once())->method('create')->willReturn($orderExtensionAttributeMock);
     $orderExtensionAttributeMock->expects($this->once())->method('setAppliedTaxes')->with($appliedTaxes);
     $orderExtensionAttributeMock->expects($this->once())->method('setConvertingFromQuote')->with(true);
     $orderExtensionAttributeMock->expects($this->once())->method('setItemAppliedTaxes')->with($itemsAppliedTaxes);
     $orderMock->expects($this->once())->method('setExtensionAttributes')->with($orderExtensionAttributeMock);
     $this->assertEquals($orderMock, $this->model->afterConvert($this->subjectMock, $orderMock));
 }
コード例 #16
0
ファイル: Review.php プロジェクト: whoople/magento2-testing
 /**
  * Retrieve payment method and assign additional template values
  *
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function _beforeToHtml()
 {
     $methodInstance = $this->_quote->getPayment()->getMethodInstance();
     $this->setPaymentMethodTitle($methodInstance->getTitle());
     $this->setShippingRateRequired(true);
     if ($this->_quote->getIsVirtual()) {
         $this->setShippingRateRequired(false);
     } else {
         // prepare shipping rates
         $this->_address = $this->_quote->getShippingAddress();
         $groups = $this->_address->getGroupedAllShippingRates();
         if ($groups && $this->_address) {
             $this->setShippingRateGroups($groups);
             // determine current selected code & name
             foreach ($groups as $code => $rates) {
                 foreach ($rates as $rate) {
                     if ($this->_address->getShippingMethod() == $rate->getCode()) {
                         $this->_currentShippingRate = $rate;
                         break 2;
                     }
                 }
             }
         }
         $canEditShippingAddress = $this->_quote->getMayEditShippingAddress() && $this->_quote->getPayment()->getAdditionalInformation(\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_BUTTON) == 1;
         // misc shipping parameters
         $this->setShippingMethodSubmitUrl($this->getUrl("{$this->_controllerPath}/saveShippingMethod"))->setCanEditShippingAddress($canEditShippingAddress)->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod());
     }
     $this->setEditUrl($this->getUrl("{$this->_controllerPath}/edit"))->setPlaceOrderUrl($this->getUrl("{$this->_controllerPath}/placeOrder"));
     return parent::_beforeToHtml();
 }
コード例 #17
0
 /**
  * @param array $details
  */
 private function updateBillingAddressStep(array $details)
 {
     $this->configMock->expects(self::once())->method('isRequiredBillingAddress')->willReturn(true);
     $this->updateAddressDataStep($this->billingAddressMock, $details['billingAddress']);
     $this->billingAddressMock->expects(self::once())->method('setLastname')->with($details['lastName']);
     $this->billingAddressMock->expects(self::once())->method('setFirstname')->with($details['firstName']);
     $this->billingAddressMock->expects(self::once())->method('setEmail')->with($details['email']);
 }
コード例 #18
0
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  \Magento\Quote\Model\Quote\Address $value
  * @return boolean
  * @throws Zend_Validate_Exception If validation of $value is impossible
  */
 public function isValid($value)
 {
     $messages = [];
     $email = $value->getEmail();
     if (!empty($email) && !\Zend_Validate::is($email, 'EmailAddress')) {
         $messages['invalid_email_format'] = 'Invalid email format';
     }
     $countryId = $value->getCountryId();
     if (!empty($countryId)) {
         $country = $this->countryFactory->create();
         $country->load($countryId);
         if (!$country->getId()) {
             $messages['invalid_country_code'] = 'Invalid country code';
         }
     }
     $this->_addMessages($messages);
     return empty($messages);
 }
コード例 #19
0
 public function setUp()
 {
     $objectManager = new ObjectManager($this);
     $this->taxConfig = $this->getMockBuilder('\\Magento\\Tax\\Model\\Config')->disableOriginalConstructor()->setMethods(['getShippingTaxClass', 'shippingPriceIncludesTax'])->getMock();
     $this->store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock();
     $this->quote = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['__wakeup', 'getStore'])->getMock();
     $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
     $this->address = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->getMock();
     $this->address->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote));
     $methods = ['create'];
     $this->quoteDetailsItemDataObject = $objectManager->getObject('Magento\\Tax\\Model\\Sales\\Quote\\ItemDetails');
     $this->taxClassKeyDataObject = $objectManager->getObject('Magento\\Tax\\Model\\TaxClass\\Key');
     $this->quoteDetailsItemDataObjectFactoryMock = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterfaceFactory', $methods, [], '', false);
     $this->quoteDetailsItemDataObjectFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteDetailsItemDataObject);
     $this->taxClassKeyDataObjectFactoryMock = $this->getMock('Magento\\Tax\\Api\\Data\\TaxClassKeyInterfaceFactory', $methods, [], '', false);
     $this->taxClassKeyDataObjectFactoryMock->expects($this->any())->method('create')->willReturn($this->taxClassKeyDataObject);
     $this->commonTaxCollector = $objectManager->getObject('Magento\\Tax\\Model\\Sales\\Total\\Quote\\CommonTaxCollector', ['taxConfig' => $this->taxConfig, 'quoteDetailsItemDataObjectFactory' => $this->quoteDetailsItemDataObjectFactoryMock, 'taxClassKeyDataObjectFactory' => $this->taxClassKeyDataObjectFactoryMock]);
 }
コード例 #20
0
 public function testAfterSaveShippingMethod()
 {
     $this->shippingAddress->expects($this->once())->method('getShippingMethod')->willReturn('storepickup_store_1');
     $this->shippingAddress->expects($this->once())->method('setCountryId')->with($this->locationData['country_id']);
     $this->shippingAddress->expects($this->once())->method('setRegionId')->with($this->locationData['region_id']);
     $this->shippingAddress->expects($this->once())->method('setPostcode')->with($this->locationData['postcode']);
     $this->shippingAddress->expects($this->once())->method('setCity')->with($this->locationData['city']);
     $this->shippingAddress->expects($this->once())->method('setStreet')->with($this->locationData['street']);
     $this->shippingAddress->expects($this->once())->method('setTelephone')->with($this->locationData['phone']);
     $this->model->afterSaveShippingMethod($this->subject, []);
 }
コード例 #21
0
ファイル: QuoteTest.php プロジェクト: nja78/magento2
 public function testValidateMiniumumAmountNegative()
 {
     $storeId = 1;
     $this->quote->setStoreId($storeId);
     $valueMap = [['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true], ['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true], ['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20], ['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true]];
     $this->scopeConfig->expects($this->any())->method('isSetFlag')->will($this->returnValueMap($valueMap));
     $this->quoteAddressMock->expects($this->once())->method('validateMinimumAmount')->willReturn(false);
     $this->quoteAddressCollectionMock->expects($this->once())->method('setQuoteFilter')->willReturn([$this->quoteAddressMock]);
     $this->assertFalse($this->quote->validateMinimumAmount());
 }
コード例 #22
0
 /**
  * @param QuoteAddressToOrder $subject
  * @param OrderInterface $order
  * @return OrderInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order)
 {
     /** @var \Magento\Sales\Model\Order $order */
     $taxes = $this->quoteAddress->getAppliedTaxes();
     $extensionAttributes = $order->getExtensionAttributes();
     if ($extensionAttributes == null) {
         $extensionAttributes = $this->orderExtensionFactory->create();
     }
     if (!empty($taxes)) {
         $extensionAttributes->setAppliedTaxes($taxes);
         $extensionAttributes->setConvertingFromQuote(true);
     }
     $itemAppliedTaxes = $this->quoteAddress->getItemsAppliedTaxes();
     if (!empty($itemAppliedTaxes)) {
         $extensionAttributes->setItemAppliedTaxes($itemAppliedTaxes);
     }
     $order->setExtensionAttributes($extensionAttributes);
     return $order;
 }
コード例 #23
0
 /**
  * @param null|int $shippingAmount
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function setupAddressMock($shippingAmount = null)
 {
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods([])->getMock();
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['setAppliedRuleIds', 'getStore'])->getMock();
     $quoteMock->expects($this->any())->method('getStore')->willReturn($storeMock);
     $quoteMock->expects($this->any())->method('setAppliedRuleIds')->willReturnSelf();
     $this->addressMock->expects($this->any())->method('getShippingAmountForDiscount')->willReturn($shippingAmount);
     $this->addressMock->expects($this->any())->method('getQuote')->willReturn($quoteMock);
     $this->addressMock->expects($this->any())->method('getCustomAttributesCodes')->willReturn([]);
     return $this->addressMock;
 }
コード例 #24
0
 /**
  * @param QuoteAddressToOrder $subject
  * @param OrderInterface $order
  * @return OrderInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order)
 {
     /** @var \Magento\Sales\Model\Order $order */
     $taxes = $this->quoteAddress->getAppliedTaxes();
     if (is_array($taxes)) {
         if (is_array($order->getAppliedTaxes())) {
             $taxes = array_merge($order->getAppliedTaxes(), $taxes);
         }
         $order->setCustomAttribute('applied_taxes', $taxes);
         $order->setCustomAttribute('converting_from_quote', true);
     }
     $itemAppliedTaxes = $this->quoteAddress->getItemsAppliedTaxes();
     if (is_array($itemAppliedTaxes)) {
         if (is_array($order->getItemAppliedTaxes())) {
             $itemAppliedTaxes = array_merge($order->getItemAppliedTaxes(), $itemAppliedTaxes);
         }
         $order->setCustomAttribute('item_applied_taxes', $itemAppliedTaxes);
     }
     return $order;
 }
コード例 #25
0
ファイル: CheckoutTest.php プロジェクト: razbakov/magento2
    /**
     * @dataProvider initializeQuoteForReviewDataProvider
     */
    public function testInitializeQuoteForReview(
        $paymentMethodNonce,
        $details,
        $expectedShipping,
        $expectedBilling,
        $expectedPaymentAdditionalInfo
    ) {
        $this->verifyIgnoreAddressValidation();
        $this->quoteMock->expects($this->any())
            ->method('getIsVirtual')
            ->willReturn(false);

        $paymentMock = $this->getMockBuilder('\Magento\Quote\Model\Quote\Payment')
            ->disableOriginalConstructor()
            ->getMock();
        $paymentMock->expects($this->once())
            ->method('setMethod')
            ->with(PayPal::METHOD_CODE);

        $this->quoteMock->expects($this->any())
            ->method('getPayment')
            ->willReturn($paymentMock);

        foreach ($expectedShipping as $methodName => $value) {
            $this->shippingAddressMock->expects($this->once())
                ->method($methodName)
                ->with($value)
                ->willReturnSelf();
        }
        foreach ($expectedBilling as $methodName => $value) {
            $this->billingAddressMock->expects($this->once())
                ->method($methodName)
                ->with($value)
                ->willReturnSelf();
        }
        $index = 1;
        foreach ($expectedPaymentAdditionalInfo as $key => $value) {
            $paymentMock->expects($this->at($index))
                ->method('setAdditionalInformation')
                ->with($key, $value);
            $index++;
        }

        $this->quoteMock->expects($this->once())
            ->method('collectTotals');
        $this->quoteRepositoryMock->expects($this->once())
            ->method('save')
            ->with($this->quoteMock);

        $this->model->initializeQuoteForReview($paymentMethodNonce, $details);
    }
コード例 #26
0
 /**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool $shippingPriceInclTax
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
 {
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
     $this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
     $this->address->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $this->address->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $expectedDiscountAmount = $baseShippingAmount;
         } else {
             $this->address->expects($this->never())->method('getBaseShippingDiscountAmount');
             $expectedDiscountAmount = $shippingAmount;
         }
     }
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $this->assertEquals($this->quoteDetailsItemDataObject, $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency));
     if ($shippingAmount) {
         $this->assertEquals($expectedDiscountAmount, $this->quoteDetailsItemDataObject->getDiscountAmount());
     }
 }
コード例 #27
0
ファイル: Billing.php プロジェクト: nja78/magento2
 /**
  * Return Sales Quote Address model
  *
  * @return \Magento\Quote\Model\Quote\Address
  */
 public function getAddress()
 {
     if ($this->_address === null) {
         if ($this->isCustomerLoggedIn()) {
             $this->_address = $this->getQuote()->getBillingAddress();
             if (!$this->_address->getFirstname()) {
                 $this->_address->setFirstname($this->getQuote()->getCustomer()->getFirstname());
             }
             if (!$this->_address->getLastname()) {
                 $this->_address->setLastname($this->getQuote()->getCustomer()->getLastname());
             }
         } else {
             $this->_address = $this->_addressFactory->create();
         }
     }
     return $this->_address;
 }
コード例 #28
0
 /**
  * Fetch totals
  *
  * @param \Magento\Quote\Model\Quote\Address $address
  * @return $this
  */
 public function fetchTotals(\Magento\Quote\Model\Quote\Address $address)
 {
     $amount = $address->getShippingAmount();
     if ($amount != 0) {
         $title = __('Shipping & Handling');
         if ($address->getShippingDescription()) {
             $title .= sprintf(' (%s)', $address->getShippingDescription());
         }
         $address->addTotal(['code' => 'shipping', 'title' => $title, 'value' => $address->getShippingAmount()]);
     }
     return $this;
 }
コード例 #29
0
 public function testPopulateBeforeSaveData()
 {
     /** Preconditions */
     $customerId = 1;
     $customerAddressId = 1;
     $this->_address->setQuote($this->_quote);
     $this->assertNotEquals($customerId, $this->_address->getCustomerId(), "Precondition failed: Customer ID was not set.");
     $this->assertNotEquals(1, $this->_address->getQuoteId(), "Precondition failed: Quote ID was not set.");
     $this->assertNotEquals($customerAddressId, $this->_address->getCustomerAddressId(), "Precondition failed: Customer address ID was not set.");
     /** @var \Magento\Customer\Api\Data\AddressInterfaceFactory $addressFactory */
     $addressFactory = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\AddressInterfaceFactory');
     $customerAddressData = $addressFactory->create()->setId($customerAddressId);
     $this->_address->setCustomerAddressData($customerAddressData);
     $this->_address->save();
     $this->assertEquals($customerId, $this->_address->getCustomerId());
     $this->assertEquals($this->_quote->getId(), $this->_address->getQuoteId());
     $this->assertEquals($customerAddressId, $this->_address->getCustomerAddressId());
 }
コード例 #30
-1
 /**
  * @param QuoteAddressToOrder $subject
  * @param OrderInterface $order
  * @return OrderInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order)
 {
     /** @var \Magento\Sales\Model\Order $order */
     $taxes = $this->quoteAddress->getAppliedTaxes();
     $extensionAttributes = $order->getExtensionAttributes();
     if ($extensionAttributes == null) {
         $extensionAttributes = $this->orderExtensionFactory->create();
     }
     if (!empty($taxes)) {
         foreach ($taxes as $key => $tax) {
             $tax['extension_attributes']['rates'] = $tax['rates'];
             unset($tax['rates']);
             $taxes[$key] = $tax;
         }
         $extensionAttributes->setAppliedTaxes($taxes);
         $extensionAttributes->setConvertingFromQuote(true);
     }
     $itemAppliedTaxes = $this->quoteAddress->getItemsAppliedTaxes();
     $itemAppliedTaxesModified = [];
     if (!empty($itemAppliedTaxes)) {
         foreach ($itemAppliedTaxes as $key => $itemAppliedTaxItem) {
             if (is_array($itemAppliedTaxItem) && !empty($itemAppliedTaxItem)) {
                 foreach ($itemAppliedTaxItem as $itemAppliedTax) {
                     $itemAppliedTaxesModified[$key]['type'] = $itemAppliedTax['item_type'];
                     $itemAppliedTaxesModified[$key]['item_id'] = $itemAppliedTax['item_id'];
                     $itemAppliedTaxesModified[$key]['associated_item_id'] = $itemAppliedTax['associated_item_id'];
                     $itemAppliedTax['extension_attributes']['rates'] = $itemAppliedTax['rates'];
                     unset($itemAppliedTax['rates']);
                     $itemAppliedTaxesModified[$key]['applied_taxes'][] = $itemAppliedTax;
                 }
             }
         }
         $extensionAttributes->setItemAppliedTaxes($itemAppliedTaxesModified);
     }
     $order->setExtensionAttributes($extensionAttributes);
     return $order;
 }