public function testSetStreet() { $this->_fillMinimumRequiredFields($this->_addressBuilder); $tmpAddress = $this->_addressBuilder->create(); $street = $tmpAddress->getStreet(); $street[] = 'Line_1'; $this->_addressBuilder->populate($tmpAddress); $this->_addressBuilder->setStreet($street); $address = $this->_addressBuilder->create(); $this->_assertMinimumRequiredFields($address); $this->assertEquals('Line_1', $address->getStreet()[1]); }
/** * Helper function that returns an Address Data Object that matches the data from customer_two_address fixture * * @return \Magento\Customer\Service\V1\Data\AddressBuilder */ private function _createSecondAddressBuilder() { return $this->_addressBuilder->populate($this->_expectedAddresses[1])->setId(null); }
/** * 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); }
/** * Prepare quote for customer order submit * * @return void */ protected function _prepareCustomerQuote() { $quote = $this->getQuote(); $billing = $quote->getBillingAddress(); $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress(); $customer = $this->_customerAccountService->getCustomer($this->getCustomerSession()->getCustomerId()); $hasDefaultBilling = (bool) $customer->getDefaultBilling(); $hasDefaultShipping = (bool) $customer->getDefaultShipping(); if ($shipping && !$shipping->getSameAsBilling() && (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook())) { $shippingAddress = $shipping->exportCustomerAddressData(); if (!$hasDefaultShipping) { //Make provided address as default shipping address $shippingAddress = $this->_addressBuilder->populate($shippingAddress)->setDefaultShipping(true)->create(); $hasDefaultShipping = true; } $quote->addCustomerAddressData($shippingAddress); $shipping->setCustomerAddressData($shippingAddress); } if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) { $billingAddress = $billing->exportCustomerAddressData(); if (!$hasDefaultBilling) { //Make provided address as default shipping address $this->_addressBuilder->populate($billingAddress); if (!$hasDefaultShipping) { //Make provided address as default shipping address $this->_addressBuilder->setDefaultShipping(true); } $this->_addressBuilder->setDefaultBilling(true); $billingAddress = $this->_addressBuilder->create(); } $quote->addCustomerAddressData($billingAddress); $billing->setCustomerAddressData($billingAddress); } }