Esempio n. 1
0
 /**
  * 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);
     }
 }