/** * Test getShippingRate method */ public function testGetShippingRate() { $rate = $this->getMock('Magento\\Sales\\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()); }
/** * Fetch customer balance * * @param \Magento\Sales\Model\Quote\Address $address * @return $this */ public function fetchTotals(\Magento\Sales\Model\Quote\Address $address) { $custbalance = $address->getCustbalanceAmount(); if ($custbalance != 0) { $address->addTotal(array('code' => 'custbalance', 'title' => __('Store Credit'), 'value' => -$custbalance)); } return $this; }
/** * Fetch totals * * @param \Magento\Sales\Model\Quote\Address $address * @return $this */ public function fetchTotals(\Magento\Sales\Model\Quote\Address $address) { $amount = $address->getTaxAmount(); if ($amount != 0) { $address->addTotal(array('code' => 'tax', 'title' => __('Tax'), 'value' => $amount)); } return $this; }
/** * @param bool $inclTax */ private function _prepareTestGetShippingPrice($inclTax) { $rate = $this->getMock('Magento\\Sales\\Model\\Quote\\Address\\Rate', ['__wakeup'], [], '', false); $rate->setPrice(self::SHIPPING_PRICE); $this->shippingAddress->setShippingMethod(self::SHIPPING_METHOD); $this->shippingAddress->expects($this->once())->method('getShippingRateByCode')->with(self::SHIPPING_METHOD)->will($this->returnValue($rate)); $this->taxHelper->expects($this->once())->method('getShippingPrice')->with(self::SHIPPING_PRICE, $inclTax ? $this->isTrue() : $this->isFalse(), $this->shippingAddress)->will($this->returnValue(self::SHIPPING_PRICE_WITH_TAX)); $this->store->expects($this->once())->method('formatPrice')->with(self::SHIPPING_PRICE_WITH_TAX)->will($this->returnValue(self::SHIPPING_PRICE_FORMATTED)); }
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()); }
/** * @param \Magento\Sales\Model\Quote\Address $address * @return $this */ public function collect(\Magento\Sales\Model\Quote\Address $address) { $address->setCustbalanceAmount(0); $address->setBaseCustbalanceAmount(0); $address->setGrandTotal($address->getGrandTotal() - $address->getCustbalanceAmount()); $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseCustbalanceAmount()); return $this; }
/** * Fetch discount * * @param \Magento\Sales\Model\Quote\Address $address * @return $this */ public function fetchTotals(\Magento\Sales\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(array('code' => 'discount', 'title' => $title, 'value' => -$amount)); } return $this; }
/** * @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, array $expectedValue) { $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)); foreach ($addressData as $key => $value) { $this->address->setData($key, $value); } $shippingDataObject = $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency); $this->assertEquals($expectedValue, $shippingDataObject->__toArray()); //call it again, make sure we get the same output $shippingDataObject = $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency); $this->assertEquals($expectedValue, $shippingDataObject->__toArray()); }
/** * Retrieve payment method and assign additional template values * * @return $this */ 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(); }
/** * 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\Sales\Model\Quote\Address $value * @return boolean * @throws Zend_Validate_Exception If validation of $value is impossible */ public function isValid($value) { $messages = array(); $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); }
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()); }
/** * @covers \Magento\SalesRule\Model\Rule\Action\Discount\CartFixed::calculate */ public function testCalculate() { $this->rule->setData(array('id' => 1, 'discount_amount' => 10.0)); $this->address->expects($this->any())->method('getCartFixedRules')->will($this->returnValue(array())); $store = $this->getMock('Magento\\Store\\Model\\Store', array(), array(), '', 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(array(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); }
public function testRemoveAllAddresses() { $id = 1; $this->quoteAddressCollectionMock->expects($this->once())->method('setQuoteFilter')->with($id)->will($this->returnSelf()); $this->quoteAddressMock->expects($this->any())->method('getAddressType')->will($this->returnValue(\Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING)); $this->quoteAddressMock->expects($this->any())->method('isDeleted')->will($this->returnValue(false)); $this->quoteAddressMock->expects($this->once())->method('getId')->will($this->returnValue($id)); $this->quoteAddressMock->expects($this->once())->method('getDeleteImmediately')->will($this->returnValue(true)); $iterator = new \ArrayIterator([$id => $this->quoteAddressMock]); $this->quoteAddressCollectionMock->expects($this->any())->method('getIterator')->will($this->returnValue($iterator)); $this->quoteAddressCollectionMock->expects($this->once())->method('removeItemByKey')->with($id)->will($this->returnValue($iterator)); $this->quote->setId($id); $result = $this->quote->removeAllAddresses(); $this->assertInstanceOf('Magento\\Sales\\Model\\Quote', $result); }
/** * Convert address data object to quote address model * * @param \Magento\Checkout\Service\V1\Data\Cart\Address $dataObject * @param \Magento\Sales\Model\Quote\Address $address * @return \Magento\Sales\Model\Quote\Address */ public function convertDataObjectToModel($dataObject, $address) { $address->setData($dataObject->__toArray()); //set custom attributes $customAttributes = $dataObject->getCustomAttributes(); /** @var \Magento\Framework\Service\Data\AttributeValue $attributeData */ foreach ($customAttributes as $attributeData) { $address->setData($attributeData->getAttributeCode(), $attributeData->getValue()); } //set fields with custom logic $address->setStreet($dataObject->getStreet()); $address->setRegionId($dataObject->getRegion()->getRegionId()); $address->setRegion($dataObject->getRegion()->getRegion()); return $address; }
/** * Return Sales Quote Address model * * @return \Magento\Sales\Model\Quote\Address */ public function getAddress() { if (is_null($this->_address)) { if ($this->isCustomerLoggedIn()) { $this->_address = $this->getQuote()->getBillingAddress(); if (!$this->_address->getFirstname()) { $this->_address->setFirstname($this->getQuote()->getCustomerData()->getFirstname()); } if (!$this->_address->getLastname()) { $this->_address->setLastname($this->getQuote()->getCustomerData()->getLastname()); } } else { $this->_address = $this->_addressFactory->create(); } } return $this->_address; }
/** * Fetch totals * * @param \Magento\Sales\Model\Quote\Address $address * @return $this */ public function fetchTotals(\Magento\Sales\Model\Quote\Address $address) { $amount = $address->getShippingAmount(); if ($amount != 0) { $title = __('Shipping & Handling'); if ($address->getShippingDescription()) { $title .= sprintf(' (%s)', $address->getShippingDescription()); } $address->addTotal(array('code' => 'shipping', 'title' => $title, 'value' => $address->getShippingAmount())); } return $this; }
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\Service\V1\Data\AddressBuilder $addressBuilder */ $addressBuilder = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\Data\\AddressBuilder'); $customerAddressData = $addressBuilder->setId($customerAddressId)->create(); $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()); }
/** * @param Address $address * @return string */ public function getEditBillingAddressUrl($address) { return $this->getUrl('*/checkout_address/editBilling', array('id' => $address->getCustomerAddressId())); }
/** * Add shipping totals information to address object * * @param \Magento\Sales\Model\Quote\Address $address * @return $this */ public function fetch(\Magento\Sales\Model\Quote\Address $address) { $amount = $address->getShippingAmount(); $shippingDescription = $address->getShippingDescription(); if ($amount != 0 || $shippingDescription) { $title = $shippingDescription ? __('Shipping & Handling (%1)', $shippingDescription) : __('Shipping & Handling'); $address->addTotal(array('code' => $this->getCode(), 'title' => $title, 'value' => $amount)); } return $this; }
/** * Get nominal items only * * @param \Magento\Sales\Model\Quote\Address $address * @return array */ protected function _getAddressItems(\Magento\Sales\Model\Quote\Address $address) { return $address->getAllNominalItems(); }
/** * Attempt to collect address shipping rates and return them for further usage in instant update API * Returns empty array if it was impossible to obtain any shipping rate * If there are shipping rates obtained, the method must return one of them as default. * * @param Address $address * @param bool $mayReturnEmpty * @param bool $calculateTax * @return array|false */ protected function _prepareShippingOptions(Address $address, $mayReturnEmpty = false, $calculateTax = false) { $options = array(); $i = 0; $iMin = false; $min = false; $userSelectedOption = null; foreach ($address->getGroupedAllShippingRates() as $group) { foreach ($group as $rate) { $amount = (double) $rate->getPrice(); if ($rate->getErrorMessage()) { continue; } $isDefault = $address->getShippingMethod() === $rate->getCode(); $amountExclTax = $this->_taxData->getShippingPrice($amount, false, $address); $amountInclTax = $this->_taxData->getShippingPrice($amount, true, $address); $options[$i] = new \Magento\Framework\Object(['is_default' => $isDefault, 'name' => trim("{$rate->getCarrierTitle()} - {$rate->getMethodTitle()}", ' -'), 'code' => $rate->getCode(), 'amount' => $amountExclTax]); if ($calculateTax) { $options[$i]->setTaxAmount($amountInclTax - $amountExclTax + $address->getTaxAmount() - $address->getShippingTaxAmount()); } if ($isDefault) { $userSelectedOption = $options[$i]; } if (false === $min || $amountInclTax < $min) { $min = $amountInclTax; $iMin = $i; } $i++; } } if ($mayReturnEmpty && is_null($userSelectedOption)) { $options[] = new \Magento\Framework\Object(['is_default' => true, 'name' => __('N/A'), 'code' => 'no_rate', 'amount' => 0.0]); if ($calculateTax) { $options[$i]->setTaxAmount($address->getTaxAmount()); } } elseif (is_null($userSelectedOption) && isset($options[$iMin])) { $options[$iMin]->setIsDefault(true); } // Magento will transfer only first 10 cheapest shipping options if there are more than 10 available. if (count($options) > 10) { usort($options, array(get_class($this), 'cmpShippingOptions')); array_splice($options, 10); // User selected option will be always included in options list if (!is_null($userSelectedOption) && !in_array($userSelectedOption, $options)) { $options[9] = $userSelectedOption; } } return $options; }
/** * @param $expectedMergedRuleIds * @param \Magento\Sales\Model\Quote\Address|\Magento\Sales\Model\Quote $object * @return $this */ protected function assertObjectHasRuleIdsSet($expectedMergedRuleIds, $object) { $array = explode(',', $object->getAppliedRuleIds()); sort($array); $this->assertEquals($expectedMergedRuleIds, join(',', $array)); return $this; }
/** * Convert address discount description array to string * * @param Address $address * @param string $separator * @return $this */ public function prepareDescription($address, $separator = ', ') { $descriptionArray = $address->getDiscountDescriptionArray(); if (!$descriptionArray && $address->getQuote()->getItemVirtualQty() > 0) { $descriptionArray = $address->getQuote()->getBillingAddress()->getDiscountDescriptionArray(); } $description = $descriptionArray && is_array($descriptionArray) ? implode($separator, array_unique($descriptionArray)) : ''; $address->setDiscountDescription($description); return $this; }
/** * Add total * * @param \Magento\Sales\Model\Quote\Address $address * @return $this */ public function fetchTotals(\Magento\Sales\Model\Quote\Address $address) { $address->addTotal(array('code' => 'subtotal', 'title' => __('Subtotal'), 'value' => $address->getSubtotal())); return $this; }
/** * Set shipping address * * @param Address $address * @return $this */ public function setShippingAddress(Address $address) { if ($this->getIsMultiShipping()) { $this->addAddress($address->setAddressType(Address::TYPE_SHIPPING)); } else { $old = $this->getShippingAddress(); if (!empty($old)) { $old->addData($address->getData()); } else { $this->addAddress($address->setAddressType(Address::TYPE_SHIPPING)); } } return $this; }
/** * @param Product $product * @param null|false|\Magento\Sales\Model\Quote\Address $shipping * @param null|false|\Magento\Sales\Model\Quote\Address $billing * @param Website $website * @param bool $calculateTax * @param bool $ignoreDiscount * @return \Magento\Framework\Object[] */ public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null, $ignoreDiscount = false) { $result = array(); $allWeee = $this->getWeeeTaxAttributeCodes(); if (!$allWeee) { return $result; } $websiteId = $this->_storeManager->getWebsite($website)->getId(); /** @var \Magento\Store\Model\Store $store */ $store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore(); /** @var \Magento\Tax\Model\Calculation $calculator */ $calculator = $this->_calculationFactory->create(); if ($shipping) { $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId(); } else { $customerTaxClass = null; } $rateRequest = $calculator->getRateRequest($shipping, $billing, $customerTaxClass, $store); $defaultRateRequest = $calculator->getDefaultRateRequest($store); $discountPercent = 0; if (!$ignoreDiscount && $this->weeeConfig->isDiscounted($store)) { $discountPercent = $this->_getDiscountPercentForProduct($product); } $productAttributes = $product->getTypeInstance()->getSetAttributes($product); foreach ($productAttributes as $code => $attribute) { if (in_array($code, $allWeee)) { $attributeSelect = $this->getResource()->getReadConnection()->select(); $attributeSelect->from($this->getResource()->getTable('weee_tax'), 'value')->where('attribute_id = ?', (int) $attribute->getId())->where('website_id IN(?)', array($websiteId, 0))->where('country = ?', $rateRequest->getCountryId())->where('state IN(?)', array($rateRequest->getRegionId(), '*'))->where('entity_id = ?', (int) $product->getId())->limit(1); $order = array('state ' . \Magento\Framework\DB\Select::SQL_DESC, 'website_id ' . \Magento\Framework\DB\Select::SQL_DESC); $attributeSelect->order($order); $value = $this->getResource()->getReadConnection()->fetchOne($attributeSelect); if ($value) { if ($discountPercent) { $value = $this->_storeManager->getStore()->roundPrice($value - $value * $discountPercent / 100); } $taxAmount = $amount = 0; $amount = $value; if ($calculateTax && $this->weeeConfig->isTaxable($store)) { /** @var \Magento\Tax\Model\Calculation $calculator */ $defaultPercent = $calculator->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId())); $currentPercent = $calculator->getRate($rateRequest->setProductClassId($product->getTaxClassId())); if ($this->_taxData->priceIncludesTax($store)) { $amountInclTax = $value / (100 + $defaultPercent) * (100 + $currentPercent); //round the "golden price" $amountInclTax = $store->roundPrice($amountInclTax); $taxAmount = $amountInclTax - $amountInclTax / (100 + $currentPercent) * 100; $taxAmount = $store->roundPrice($taxAmount); } else { $appliedRates = $this->_calculationFactory->create()->getAppliedRates($rateRequest); if (count($appliedRates) > 1) { $taxAmount = 0; foreach ($appliedRates as $appliedRate) { $taxRate = $appliedRate['percent']; $taxAmount += $this->_storeManager->getStore()->roundPrice($value * $taxRate / 100); } } else { $taxAmount = $this->_storeManager->getStore()->roundPrice($value * $currentPercent / 100); } $taxAmount = $store->roundPrice($value * $currentPercent / 100); } } $one = new \Magento\Framework\Object(); $one->setName(__($attribute->getFrontend()->getLabel()))->setAmount($amount)->setTaxAmount($taxAmount)->setCode($attribute->getAttributeCode()); $result[] = $one; } } } return $result; }
/** * Set coupon code to address if $rule contains validated coupon * * @param Address $address * @param \Magento\SalesRule\Model\Rule $rule * @param mixed $couponCode * @return $this */ public function maintainAddressCouponCode($address, $rule, $couponCode) { /* Rule is a part of rules collection, which includes only rules with 'No Coupon' type or with validated coupon. As a result, if rule uses coupon code(s) ('Specific' or 'Auto' Coupon Type), it always contains validated coupon */ if ($rule->getCouponType() != \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON) { $address->setCouponCode($couponCode); } return $this; }
/** * Create customerAddressDataObject and save it in the Model\Quote so that it can be used to persist later. * * @param CustomerDataObject $customerDataObject * @param \Magento\Sales\Model\Quote\Address $quoteCustomerAddress * @return void * @throws \InvalidArgumentException */ protected function _prepareCustomerAddress($customerDataObject, $quoteCustomerAddress) { // Possible that customerId is null for new customers $customerId = $customerDataObject->getId(); $quoteCustomerAddress->setCustomerId($customerId); $customerAddressDataObject = $quoteCustomerAddress->exportCustomerAddressData(); $quoteAddressId = $quoteCustomerAddress->getCustomerAddressId(); $addressType = $quoteCustomerAddress->getAddressType(); if ($quoteAddressId) { /** Update existing address */ $existingAddressDataObject = $this->_customerAddressService->getAddress($quoteAddressId); /** Update customer address data */ $customerAddressDataObject = $this->_customerAddressBuilder->mergeDataObjects($existingAddressDataObject, $customerAddressDataObject); } elseif ($addressType == CustomerAddressDataObject::ADDRESS_TYPE_SHIPPING) { try { $billingAddressDataObject = $this->_customerAddressService->getDefaultBillingAddress($customerId); } catch (\Exception $e) { /** Billing address does not exist. */ } $isShippingAsBilling = $quoteCustomerAddress->getSameAsBilling(); if (isset($billingAddressDataObject) && $isShippingAsBilling) { /** Set existing billing address as default shipping */ $customerAddressDataObject = $this->_customerAddressBuilder->populate($billingAddressDataObject)->setDefaultShipping(true)->create(); } } switch ($addressType) { case CustomerAddressDataObject::ADDRESS_TYPE_BILLING: if (is_null($customerDataObject->getDefaultBilling())) { $customerAddressDataObject = $this->_customerAddressBuilder->populate($customerAddressDataObject)->setDefaultBilling(true)->create(); } break; case CustomerAddressDataObject::ADDRESS_TYPE_SHIPPING: if (is_null($customerDataObject->getDefaultShipping())) { $customerAddressDataObject = $this->_customerAddressBuilder->populate($customerAddressDataObject)->setDefaultShipping(true)->create(); } break; default: throw new \InvalidArgumentException('Customer address type is invalid.'); } $this->getQuote()->addCustomerAddressData($customerAddressDataObject); }
/** * Assign subtotal amount and label to address object * * @param Address $address * @return $this */ public function fetch(Address $address) { $address->addTotal(array('code' => $this->getCode(), 'title' => __('Subtotal'), 'value' => $address->getSubtotal())); return $this; }
/** * Process row amount based on FPT total amount configuration setting * * @param \Magento\Sales\Model\Quote\Address $address * @param float $rowValueExclTax * @param float $baseRowValueExclTax * @param float $rowValueInclTax * @param float $baseRowValueInclTax * @return $this */ protected function processTotalAmount($address, $rowValueExclTax, $baseRowValueExclTax, $rowValueInclTax, $baseRowValueInclTax) { if ($this->weeeData->includeInSubtotal($this->_store)) { $address->addTotalAmount('subtotal', $rowValueExclTax); $address->addBaseTotalAmount('subtotal', $baseRowValueExclTax); } else { $address->addTotalAmount('weee', $rowValueExclTax); $address->addBaseTotalAmount('weee', $baseRowValueExclTax); } $address->setSubtotalInclTax($address->getSubtotalInclTax() + $rowValueInclTax); $address->setBaseSubtotalInclTax($address->getBaseSubtotalInclTax() + $baseRowValueInclTax); return $this; }