/** * @param Address $object * @param array $data * @return OrderInterface */ public function convert(Address $object, $data = []) { $orderData = $this->objectCopyService->getDataFromFieldset( 'quote_convert_address', 'to_order', $object ); /** * @var $order \Magento\Sales\Model\Order */ $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()) ->setIncrementId($object->getQuote()->getReservedOrderId()); $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 Address $object * @param array $data * @return OrderAddressInterface */ public function convert(Address $object, $data = []) { $orderAddress = $this->orderAddressRepository->create(); $orderAddressData = $this->objectCopyService->getDataFromFieldset('quote_convert_address', 'to_order_address', $object); $this->dataObjectHelper->populateWithArray($orderAddress, array_merge($orderAddressData, $data), '\\Magento\\Sales\\Api\\Data\\OrderAddressInterface'); return $orderAddress; }
/** * @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 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->orderPaymentRepository->create(); $this->dataObjectHelper->populateWithArray($orderPayment, array_merge($paymentData, $data), '\\Magento\\Sales\\Api\\Data\\OrderPaymentInterface'); $orderPayment->setAdditionalInformation(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; }
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)); }
/** * @param SampleInterface $sample * @return SampleInterface * @throws \Magento\Framework\Exception\LocalizedException */ public function build(SampleInterface $sample) { $downloadableData = $this->objectCopyService->getDataFromFieldset('downloadable_data', 'to_sample', $this->data); $this->dataObjectHelper->populateWithArray($sample, array_merge($this->data, $downloadableData), SampleInterface::class); if ($sample->getSampleType() === \Magento\Downloadable\Helper\Download::LINK_TYPE_FILE) { if (!isset($this->data['file'])) { throw new \Magento\Framework\Exception\LocalizedException(__('Sample file not provided')); } $fileName = $this->downloadableFile->moveFileFromTmp($this->getComponent()->getBaseTmpPath(), $this->getComponent()->getBasePath(), $this->data['file']); $sample->setSampleFile($fileName); } if (!$sample->getSortOrder()) { $sample->setSortOrder(1); } $this->resetData(); return $sample; }
/** * @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; }
/** * @param \Magento\Downloadable\Api\Data\LinkInterface $link * @param array $sample * @return \Magento\Downloadable\Api\Data\LinkInterface * @throws \Magento\Framework\Exception\LocalizedException */ private function buildSample(\Magento\Downloadable\Api\Data\LinkInterface $link, array $sample) { if (!empty($sample['url']) || !empty($sample['file'])) { $downloadableLinkSampleData = $this->objectCopyService->getDataFromFieldset('downloadable_link_sample_data', 'to_link_sample', $this->data['sample']); $this->dataObjectHelper->populateWithArray($link, array_merge($this->data, $downloadableLinkSampleData), \Magento\Downloadable\Api\Data\LinkInterface::class); if ($link->getSampleType() === \Magento\Downloadable\Helper\Download::LINK_TYPE_FILE) { $linkSampleFileName = $this->downloadableFile->moveFileFromTmp($this->getComponent()->getBaseSampleTmpPath(), $this->getComponent()->getBaseSamplePath(), $sample['file']); $link->setSampleFile($linkSampleFileName); } } return $link; }
/** * 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); }