示例#1
0
文件: Quote.php 项目: nja78/magento2
 /**
  * @param \Magento\Quote\Model\Quote $quote
  * @return \Magento\Quote\Model\Quote
  */
 public function prepareQuoteForNewCustomer(\Magento\Quote\Model\Quote $quote)
 {
     $billing = $quote->getBillingAddress();
     $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
     $billing->setDefaultBilling(true);
     if ($shipping && !$shipping->getSameAsBilling()) {
         $shipping->setDefaultShipping(true);
         $address = $shipping->exportCustomerAddress();
         $shipping->setCustomerAddressData($address);
     } elseif ($shipping) {
         $billing->setDefaultShipping(true);
     }
     $address = $shipping->exportCustomerAddress();
     $billing->setCustomerAddressData($address);
     foreach (['customer_dob', 'customer_taxvat', 'customer_gender'] as $attribute) {
         if ($quote->getData($attribute) && !$billing->getData($attribute)) {
             $billing->setData($attribute, $quote->getData($attribute));
         }
     }
     $customer = $this->customerFactory->create();
     $this->dataObjectHelper->populateWithArray($customer, $this->copyObject->getDataFromFieldset('checkout_onepage_billing', 'to_customer', $billing), '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $customer->setEmail($quote->getCustomerEmail());
     $customer->setPrefix($quote->getCustomerPrefix());
     $customer->setFirstname($quote->getCustomerFirstname());
     $customer->setMiddlename($quote->getCustomerMiddlename());
     $customer->setLastname($quote->getCustomerLastname());
     $customer->setSuffix($quote->getCustomerSuffix());
     $quote->setCustomer($customer);
     $quote->addCustomerAddress($billing->exportCustomerAddress());
     if ($shipping->hasCustomerAddress()) {
         $quote->addCustomerAddress($shipping->exportCustomerAddress());
     }
     return $quote;
 }
 /**
  * @param Address $object
  * @param array $data
  * @return OrderAddressInterface
  */
 public function convert(Address $object, $data = [])
 {
     $orderAddressData = $this->objectCopyService->getDataFromFieldset('quote_convert_address', 'to_order_address', $object);
     $orderAddress = $this->orderAddressFactory->create();
     $this->dataObjectHelper->populateWithArray($orderAddress, array_merge($orderAddressData, $data), '\\Magento\\Sales\\Api\\Data\\OrderAddressInterface');
     return $orderAddress;
 }
示例#3
0
 /**
  * @param Address $object
  * @param array $data
  * @return OrderInterface
  */
 public function convert(Address $object, $data = [])
 {
     $orderData = $this->objectCopyService->getDataFromFieldset('quote_convert_address', 'to_order', $object);
     $order = $this->orderFactory->create();
     $this->dataObjectHelper->populateWithArray($order, array_merge($orderData, $data), '\\Magento\\Sales\\Api\\Data\\OrderInterface');
     $order->setStoreId($object->getQuote()->getStoreId())->setQuoteId($object->getQuote()->getId());
     $this->objectCopyService->copyFieldsetToTarget('sales_convert_quote', 'to_order', $object->getQuote(), $order);
     $this->eventManager->dispatch('sales_convert_quote_to_order', ['order' => $order, 'quote' => $object->getQuote()]);
     return $order;
 }
 /**
  * @param Payment $object
  * @param array $data
  * @return OrderPaymentInterface
  */
 public function convert(Payment $object, $data = [])
 {
     $paymentData = $this->objectCopyService->getDataFromFieldset('quote_convert_payment', 'to_order_payment', $object);
     $orderPayment = $this->orderPaymentFactory->create();
     $this->dataObjectHelper->populateWithArray($orderPayment, array_merge($paymentData, $data), '\\Magento\\Sales\\Api\\Data\\OrderPaymentInterface');
     $orderPayment->setAdditionalInformation(serialize(array_merge($object->getAdditionalInformation(), [Substitution::INFO_KEY_TITLE => $object->getMethodInstance()->getTitle()])));
     // set directly on the model
     $orderPayment->setCcNumber($object->getCcNumber());
     $orderPayment->setCcCid($object->getCcCid());
     return $orderPayment;
 }
示例#5
0
 public function testGetDataFromFieldsetWhenFieldDoesNotExists()
 {
     $fields['code']['aspect'] = [];
     $this->fieldsetConfigMock->expects($this->once())->method('getFieldset')->with('fieldset', 'global')->will($this->returnValue($fields));
     $this->sourceMock->expects($this->never())->method('getDataUsingMethod');
     $this->assertEquals([], $this->copy->getDataFromFieldset('fieldset', 'aspect', $this->sourceMock));
 }
示例#6
0
 /**
  * @param Item|AddressItem $item
  * @param array $data
  * @return OrderItemInterface
  */
 public function convert($item, $data = [])
 {
     $options = $item->getProductOrderOptions();
     if (!$options) {
         $options = $item->getProduct()->getTypeInstance()->getOrderOptions($item->getProduct());
     }
     $orderItemData = $this->objectCopyService->getDataFromFieldset('quote_convert_item', 'to_order_item', $item);
     if (!$item->getNoDiscount()) {
         $data = array_merge($data, $this->objectCopyService->getDataFromFieldset('quote_convert_item', 'to_order_item_discount', $item));
     }
     $orderItem = $this->orderItemFactory->create();
     $this->dataObjectHelper->populateWithArray($orderItem, array_merge($orderItemData, $data), '\\Magento\\Sales\\Api\\Data\\OrderItemInterface');
     $orderItem->setProductOptions($options);
     if ($item->getParentItem()) {
         $orderItem->setQtyOrdered($orderItemData[OrderItemInterface::QTY_ORDERED] * $item->getParentItem()->getQty());
     }
     return $orderItem;
 }
示例#7
0
 /**
  * Prepare quote for customer registration and customer order submit
  *
  * @return void
  */
 protected function _prepareNewCustomerQuote()
 {
     $quote = $this->getQuote();
     $billing = $quote->getBillingAddress();
     $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
     $customer = $quote->getCustomer();
     $customerBillingData = $billing->exportCustomerAddress();
     $dataArray = $this->_objectCopyService->getDataFromFieldset('checkout_onepage_quote', 'to_customer', $quote);
     $this->dataObjectHelper->populateWithArray($customer, $dataArray, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $quote->setCustomer($customer)->setCustomerId(true);
     $customerBillingData->setIsDefaultBilling(true);
     if ($shipping) {
         if (!$shipping->getSameAsBilling()) {
             $customerShippingData = $shipping->exportCustomerAddress();
             $customerShippingData->setIsDefaultShipping(true);
             $shipping->setCustomerAddressData($customerShippingData);
             // Add shipping address to quote since customer Data Object does not hold address information
             $quote->addCustomerAddress($customerShippingData);
         } else {
             $shipping->setCustomerAddressData($customerBillingData);
             $customerBillingData->setIsDefaultShipping(true);
         }
     } else {
         $customerBillingData->setIsDefaultShipping(true);
     }
     $billing->setCustomerAddressData($customerBillingData);
     // TODO : Eventually need to remove this legacy hack
     // Add billing address to quote since customer Data Object does not hold address information
     $quote->addCustomerAddress($customerBillingData);
 }
示例#8
0
 /**
  * Prepare quote for customer registration and customer order submit
  * and restore magento customer data from quote
  *
  * @return void
  */
 protected function _prepareNewCustomerQuote()
 {
     $quote = $this->_quote;
     $billing = $quote->getBillingAddress();
     $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
     /** @var \Magento\Customer\Service\V1\Data\AddressBuilder $billingAddressBuilder */
     $billingAddressBuilder = $this->_addressBuilderFactory->create();
     $customerBilling = $billingAddressBuilder->populate($billing->exportCustomerAddressData())->setDefaultBilling(true);
     if ($shipping && !$shipping->getSameAsBilling()) {
         /** @var \Magento\Customer\Service\V1\Data\AddressBuilder $shippingAddressBuilder */
         $shippingAddressBuilder = $this->_addressBuilderFactory->create();
         $customerShipping = $shippingAddressBuilder->populate($shipping->exportCustomerAddressData())->setDefaultShipping(true)->create();
         $shipping->setCustomerAddressData($customerShipping);
     } elseif ($shipping) {
         $customerBilling->setDefaultShipping(true);
     }
     $customerBilling = $customerBilling->create();
     $billing->setCustomerAddressData($customerBilling);
     /**
      * @todo integration with dynamic attributes customer_dob, customer_taxvat, customer_gender
      */
     if ($quote->getCustomerDob() && !$billing->getCustomerDob()) {
         $billing->setCustomerDob($quote->getCustomerDob());
     }
     if ($quote->getCustomerTaxvat() && !$billing->getCustomerTaxvat()) {
         $billing->setCustomerTaxvat($quote->getCustomerTaxvat());
     }
     if ($quote->getCustomerGender() && !$billing->getCustomerGender()) {
         $billing->setCustomerGender($quote->getCustomerGender());
     }
     $customerData = $this->_objectCopyService->getDataFromFieldset('checkout_onepage_billing', 'to_customer', $billing);
     $customer = $this->_customerBuilder->populateWithArray($customerData);
     $customer->setEmail($quote->getCustomerEmail());
     $customer->setPrefix($quote->getCustomerPrefix());
     $customer->setFirstname($quote->getCustomerFirstname());
     $customer->setMiddlename($quote->getCustomerMiddlename());
     $customer->setLastname($quote->getCustomerLastname());
     $customer->setSuffix($quote->getCustomerSuffix());
     $quote->setCustomerData($customer->create())->addCustomerAddressData($customerBilling);
     if (isset($customerShipping)) {
         $quote->addCustomerAddressData($customerShipping);
     }
 }