Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Create.php
Go to the documentation of this file.
1 <?php
8 
17 use Psr\Log\LoggerInterface;
18 
27 class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\Model\Cart\CartInterface
28 {
32  const XML_PATH_DEFAULT_EMAIL_DOMAIN = 'customer/create_account/email_domain';
33 
39  protected $_session;
40 
46  protected $_wishlist;
47 
53  protected $_cart;
54 
60  protected $_compareList;
61 
67  protected $_needCollect;
68 
74  protected $_needCollectCart = false;
75 
81  protected $_isValidate = false;
82 
88  protected $_errors = [];
89 
95  protected $_quote;
96 
102  protected $_coreRegistry = null;
103 
107  protected $_logger;
108 
114  protected $_eventManager = null;
115 
119  protected $_salesConfig;
120 
124  protected $_objectManager;
125 
130 
134  protected $messageManager;
135 
139  protected $quoteInitializer;
140 
145 
150 
154  protected $addressFactory;
155 
160 
164  protected $groupRepository;
165 
169  protected $_scopeConfig;
170 
174  protected $stockRegistry;
175 
179  protected $emailSender;
180 
184  protected $quoteItemUpdater;
185 
189  protected $objectFactory;
190 
195 
199  protected $customerFactory;
200 
206  protected $customerMapper;
207 
211  protected $quoteRepository;
212 
216  protected $quoteManagement;
217 
221  protected $dataObjectHelper;
222 
226  protected $orderManagement;
227 
231  protected $quoteFactory;
232 
238  private $serializer;
239 
243  private $dataObjectConverter;
244 
278  public function __construct(
280  \Magento\Framework\Event\ManagerInterface $eventManager,
281  \Magento\Framework\Registry $coreRegistry,
282  \Magento\Sales\Model\Config $salesConfig,
283  \Magento\Backend\Model\Session\Quote $quoteSession,
284  \Psr\Log\LoggerInterface $logger,
285  \Magento\Framework\DataObject\Copy $objectCopyService,
286  \Magento\Framework\Message\ManagerInterface $messageManager,
287  Product\Quote\Initializer $quoteInitializer,
290  \Magento\Customer\Api\Data\AddressInterfaceFactory $addressFactory,
291  \Magento\Customer\Model\Metadata\FormFactory $metadataFormFactory,
293  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
294  \Magento\Sales\Model\AdminOrder\EmailSender $emailSender,
295  \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
298  \Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
299  \Magento\Customer\Api\AccountManagementInterface $accountManagement,
300  \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory,
302  \Magento\Quote\Api\CartManagementInterface $quoteManagement,
303  \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
305  \Magento\Quote\Model\QuoteFactory $quoteFactory,
306  array $data = [],
307  \Magento\Framework\Serialize\Serializer\Json $serializer = null,
308  ExtensibleDataObjectConverter $dataObjectConverter = null
309  ) {
310  $this->_objectManager = $objectManager;
311  $this->_eventManager = $eventManager;
312  $this->_coreRegistry = $coreRegistry;
313  $this->_salesConfig = $salesConfig;
314  $this->_session = $quoteSession;
315  $this->_logger = $logger;
316  $this->_objectCopyService = $objectCopyService;
317  $this->quoteInitializer = $quoteInitializer;
318  $this->messageManager = $messageManager;
319  $this->customerRepository = $customerRepository;
320  $this->addressRepository = $addressRepository;
321  $this->addressFactory = $addressFactory;
322  $this->_metadataFormFactory = $metadataFormFactory;
323  $this->customerFactory = $customerFactory;
324  $this->groupRepository = $groupRepository;
325  $this->_scopeConfig = $scopeConfig;
326  $this->emailSender = $emailSender;
327  $this->stockRegistry = $stockRegistry;
328  $this->quoteItemUpdater = $quoteItemUpdater;
329  $this->objectFactory = $objectFactory;
330  $this->quoteRepository = $quoteRepository;
331  $this->accountManagement = $accountManagement;
332  $this->customerMapper = $customerMapper;
333  $this->quoteManagement = $quoteManagement;
334  $this->dataObjectHelper = $dataObjectHelper;
335  $this->orderManagement = $orderManagement;
336  $this->quoteFactory = $quoteFactory;
337  $this->serializer = $serializer ?: ObjectManager::getInstance()
338  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
339  parent::__construct($data);
340  $this->dataObjectConverter = $dataObjectConverter ?: ObjectManager::getInstance()
341  ->get(ExtensibleDataObjectConverter::class);
342  }
343 
350  public function setIsValidate($flag)
351  {
352  $this->_isValidate = (bool)$flag;
353  return $this;
354  }
355 
362  public function getIsValidate()
363  {
364  return $this->_isValidate;
365  }
366 
373  protected function _getQuoteItem($item)
374  {
375  if ($item instanceof \Magento\Quote\Model\Quote\Item) {
376  return $item;
377  } elseif (is_numeric($item)) {
378  return $this->getSession()->getQuote()->getItemById($item);
379  }
380 
381  return false;
382  }
383 
389  public function initRuleData()
390  {
391  $this->_coreRegistry->register(
392  'rule_data',
393  new \Magento\Framework\DataObject(
394  [
395  'store_id' => $this->_session->getStore()->getId(),
396  'website_id' => $this->_session->getStore()->getWebsiteId(),
397  'customer_group_id' => $this->getCustomerGroupId()
398  ]
399  )
400  );
401 
402  return $this;
403  }
404 
411  public function setRecollect($flag)
412  {
413  $this->_needCollect = $flag;
414  return $this;
415  }
416 
423  public function recollectCart()
424  {
425  if ($this->_needCollectCart === true) {
426  $this->getCustomerCart()->collectTotals();
427  $this->quoteRepository->save($this->getCustomerCart());
428  }
429  $this->setRecollect(true);
430 
431  return $this;
432  }
433 
439  public function saveQuote()
440  {
441  if (!$this->getQuote()->getId()) {
442  return $this;
443  }
444 
445  if ($this->_needCollect) {
446  $this->getQuote()->collectTotals();
447  }
448 
449  $this->quoteRepository->save($this->getQuote());
450  return $this;
451  }
452 
458  public function getSession()
459  {
460  return $this->_session;
461  }
462 
468  public function getQuote()
469  {
470  if (!$this->_quote) {
471  $this->_quote = $this->getSession()->getQuote();
472  }
473 
474  return $this->_quote;
475  }
476 
483  public function setQuote(\Magento\Quote\Model\Quote $quote)
484  {
485  $this->_quote = $quote;
486  return $this;
487  }
488 
498  public function initFromOrder(\Magento\Sales\Model\Order $order)
499  {
500  $session = $this->getSession();
501  $session->setData($order->getReordered() ? 'reordered' : 'order_id', $order->getId());
502  $session->setCurrencyId($order->getOrderCurrencyCode());
503  /* Check if we edit guest order */
504  $session->setCustomerId($order->getCustomerId() ?: false);
505  $session->setStoreId($order->getStoreId());
506 
507  /* Initialize catalog rule data with new session values */
508  $this->initRuleData();
509  foreach ($order->getItemsCollection($this->_salesConfig->getAvailableProductTypes(), true) as $orderItem) {
510  /* @var $orderItem \Magento\Sales\Model\Order\Item */
511  if (!$orderItem->getParentItem()) {
512  $qty = $orderItem->getQtyOrdered();
513  if (!$order->getReordered()) {
514  $qty -= max($orderItem->getQtyShipped(), $orderItem->getQtyInvoiced());
515  }
516 
517  if ($qty > 0) {
518  $item = $this->initFromOrderItem($orderItem, $qty);
519  if (is_string($item)) {
520  throw new \Magento\Framework\Exception\LocalizedException(__($item));
521  }
522  }
523  }
524  }
525 
526  $shippingAddress = $order->getShippingAddress();
527  if ($shippingAddress) {
528  $shippingAddress->setSameAsBilling($this->isAddressesAreEqual($order));
529  }
530 
531  $this->_initBillingAddressFromOrder($order);
532  $this->_initShippingAddressFromOrder($order);
533 
534  $quote = $this->getQuote();
535  if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
536  $this->setShippingAsBilling(1);
537  }
538 
539  $this->setShippingMethod($order->getShippingMethod());
540  $quote->getShippingAddress()->setShippingDescription($order->getShippingDescription());
541 
542  $orderCouponCode = $order->getCouponCode();
543  if ($orderCouponCode) {
544  $quote->setCouponCode($orderCouponCode);
545  }
546 
547  if ($quote->getCouponCode()) {
548  $quote->collectTotals();
549  }
550 
551  $this->_objectCopyService->copyFieldsetToTarget('sales_copy_order', 'to_edit', $order, $quote);
552 
553  $this->_eventManager->dispatch('sales_convert_order_to_quote', ['order' => $order, 'quote' => $quote]);
554 
555  if (!$order->getCustomerId()) {
556  $quote->setCustomerIsGuest(true);
557  }
558 
559  if ($session->getUseOldShippingMethod(true)) {
560  /*
561  * if we are making reorder or editing old order
562  * we need to show old shipping as preselected
563  * so for this we need to collect shipping rates
564  */
565  $this->collectShippingRates();
566  } else {
567  /*
568  * if we are creating new order then we don't need to collect
569  * shipping rates before customer hit appropriate button
570  */
571  $this->collectRates();
572  }
573 
574  $quote->getShippingAddress()->unsCachedItemsAll();
575  $quote->setTotalsCollectedFlag(false);
576 
577  $this->quoteRepository->save($quote);
578 
579  return $this;
580  }
581 
588  protected function _initBillingAddressFromOrder(\Magento\Sales\Model\Order $order)
589  {
590  $this->getQuote()->getBillingAddress()->setCustomerAddressId('');
591  $this->_objectCopyService->copyFieldsetToTarget(
592  'sales_copy_order_billing_address',
593  'to_order',
594  $order->getBillingAddress(),
595  $this->getQuote()->getBillingAddress()
596  );
597  }
598 
605  protected function _initShippingAddressFromOrder(\Magento\Sales\Model\Order $order)
606  {
607  $orderShippingAddress = $order->getShippingAddress();
608  $quoteShippingAddress = $this->getQuote()->getShippingAddress()->setCustomerAddressId(
609  ''
610  )->setSameAsBilling(
611  $orderShippingAddress && $orderShippingAddress->getSameAsBilling()
612  );
613  $this->_objectCopyService->copyFieldsetToTarget(
614  'sales_copy_order_shipping_address',
615  'to_order',
616  $orderShippingAddress,
618  );
619  }
620 
628  public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $qty = null)
629  {
630  if (!$orderItem->getId()) {
631  return $this;
632  }
633 
634  $product = $this->_objectManager->create(
635  \Magento\Catalog\Model\Product::class
636  )->setStoreId(
637  $this->getSession()->getStoreId()
638  )->load(
639  $orderItem->getProductId()
640  );
641 
642  if ($product->getId()) {
643  $product->setSkipCheckRequiredOption(true);
644  $buyRequest = $orderItem->getBuyRequest();
645  if (is_numeric($qty)) {
646  $buyRequest->setQty($qty);
647  }
648  $item = $this->getQuote()->addProduct($product, $buyRequest);
649  if (is_string($item)) {
650  return $item;
651  }
652 
653  if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
654  $item->addOption(
655  new \Magento\Framework\DataObject(
656  [
657  'product' => $item->getProduct(),
658  'code' => 'additional_options',
659  'value' => $this->serializer->serialize($additionalOptions)
660  ]
661  )
662  );
663  }
664 
665  $this->_eventManager->dispatch(
666  'sales_convert_order_item_to_quote_item',
667  ['order_item' => $orderItem, 'quote_item' => $item]
668  );
669  return $item;
670  }
671 
672  return $this;
673  }
674 
681  public function getCustomerWishlist($cacheReload = false)
682  {
683  if ($this->_wishlist !== null && !$cacheReload) {
684  return $this->_wishlist;
685  }
686 
687  $customerId = (int)$this->getSession()->getCustomerId();
688  if ($customerId) {
689  $this->_wishlist = $this->_objectManager->create(\Magento\Wishlist\Model\Wishlist::class);
690  $this->_wishlist->loadByCustomerId($customerId, true);
691  $this->_wishlist->setStore(
692  $this->getSession()->getStore()
693  )->setSharedStoreIds(
694  $this->getSession()->getStore()->getWebsite()->getStoreIds()
695  );
696  } else {
697  $this->_wishlist = false;
698  }
699 
700  return $this->_wishlist;
701  }
702 
708  public function getCustomerCart()
709  {
710  if ($this->_cart !== null) {
711  return $this->_cart;
712  }
713 
714  $this->_cart = $this->quoteFactory->create();
715 
716  $customerId = (int)$this->getSession()->getCustomerId();
717  $storeId = (int)$this->getSession()->getStoreId();
718  if ($customerId) {
719  try {
720  $this->_cart = $this->quoteRepository->getForCustomer($customerId, [$storeId]);
721  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
722  $this->_cart->setStore($this->getSession()->getStore());
723  $customerData = $this->customerRepository->getById($customerId);
724  $this->_cart->assignCustomer($customerData);
725  $this->quoteRepository->save($this->_cart);
726  }
727  }
728 
729  return $this->_cart;
730  }
731 
737  public function getCustomerCompareList()
738  {
739  if ($this->_compareList !== null) {
740  return $this->_compareList;
741  }
742  $customerId = (int)$this->getSession()->getCustomerId();
743  if ($customerId) {
744  $this->_compareList = $this->_objectManager->create(
745  \Magento\Catalog\Model\Product\Compare\ListCompare::class
746  );
747  } else {
748  $this->_compareList = false;
749  }
750 
751  return $this->_compareList;
752  }
753 
759  public function getCustomerGroupId()
760  {
761  $groupId = $this->getQuote()->getCustomerGroupId();
762  if (!$groupId) {
763  $groupId = $this->getSession()->getCustomerGroupId();
764  }
765 
766  return $groupId;
767  }
768 
780  public function moveQuoteItem($item, $moveTo, $qty)
781  {
782  $item = $this->_getQuoteItem($item);
783  if ($item) {
784  $removeItem = false;
785  $moveTo = explode('_', $moveTo);
786  switch ($moveTo[0]) {
787  case 'order':
788  $info = $item->getBuyRequest();
789  $info->setOptions($this->_prepareOptionsForRequest($item))->setQty($qty);
790 
791  $product = $this->_objectManager->create(
792  \Magento\Catalog\Model\Product::class
793  )->setStoreId(
794  $this->getQuote()->getStoreId()
795  )->load(
796  $item->getProduct()->getId()
797  );
798 
799  $product->setSkipCheckRequiredOption(true);
800  $newItem = $this->getQuote()->addProduct($product, $info);
801 
802  if (is_string($newItem)) {
803  throw new \Magento\Framework\Exception\LocalizedException(__($newItem));
804  }
805  $product->unsSkipCheckRequiredOption();
806  $newItem->checkData();
807  $this->_needCollectCart = true;
808  break;
809  case 'cart':
810  $cart = $this->getCustomerCart();
811  if ($cart && $item->getOptionByCode('additional_options') === null) {
812  //options and info buy request
813  $product = $this->_objectManager->create(
814  \Magento\Catalog\Model\Product::class
815  )->setStoreId(
816  $this->getQuote()->getStoreId()
817  )->load(
818  $item->getProduct()->getId()
819  );
820 
821  $info = $item->getOptionByCode('info_buyRequest');
822  if ($info) {
823  $info = new \Magento\Framework\DataObject(
824  $this->serializer->unserialize($info->getValue())
825  );
826  $info->setQty($qty);
827  $info->setOptions($this->_prepareOptionsForRequest($item));
828  } else {
829  $info = new \Magento\Framework\DataObject(
830  [
831  'product_id' => $product->getId(),
832  'qty' => $qty,
833  'options' => $this->_prepareOptionsForRequest($item)
834  ]
835  );
836  }
837 
838  $cartItem = $cart->addProduct($product, $info);
839  if (is_string($cartItem)) {
840  throw new \Magento\Framework\Exception\LocalizedException(__($cartItem));
841  }
842  $cartItem->setPrice($item->getProduct()->getPrice());
843  $this->_needCollectCart = true;
844  $removeItem = true;
845  }
846  break;
847  case 'wishlist':
848  $wishlist = null;
849  if (!isset($moveTo[1])) {
850  $wishlist = $this->_objectManager->create(
851  \Magento\Wishlist\Model\Wishlist::class
852  )->loadByCustomerId(
853  $this->getSession()->getCustomerId(),
854  true
855  );
856  } else {
857  $wishlist = $this->_objectManager->create(
858  \Magento\Wishlist\Model\Wishlist::class
859  )->load($moveTo[1]);
860  if (!$wishlist->getId() || $wishlist->getCustomerId() != $this->getSession()->getCustomerId()
861  ) {
862  $wishlist = null;
863  }
864  }
865  if (!$wishlist) {
866  throw new \Magento\Framework\Exception\LocalizedException(
867  __('We can\'t find this wish list.')
868  );
869  }
870  $wishlist->setStore(
871  $this->getSession()->getStore()
872  )->setSharedStoreIds(
873  $this->getSession()->getStore()->getWebsite()->getStoreIds()
874  );
875 
876  if ($wishlist->getId() && $item->getProduct()->isVisibleInSiteVisibility()) {
877  $info = $item->getBuyRequest();
878  $info->setOptions(
880  )->setQty(
881  $qty
882  )->setStoreId(
883  $this->getSession()->getStoreId()
884  );
885  $wishlist->addNewItem($item->getProduct(), $info);
886  $removeItem = true;
887  }
888  break;
889  case 'remove':
890  $removeItem = true;
891  break;
892  default:
893  break;
894  }
895  if ($removeItem) {
896  $this->getQuote()->deleteItem($item);
897  }
898  $this->setRecollect(true);
899  }
900 
901  return $this;
902  }
903 
914  public function applySidebarData($data)
915  {
916  if (isset($data['add_order_item'])) {
917  foreach ($data['add_order_item'] as $orderItemId => $value) {
918  /* @var $orderItem \Magento\Sales\Model\Order\Item */
919  $orderItem = $this->_objectManager->create(\Magento\Sales\Model\Order\Item::class)->load($orderItemId);
921  if (is_string($item)) {
922  throw new \Magento\Framework\Exception\LocalizedException(__($item));
923  }
924  }
925  }
926  if (isset($data['add_cart_item'])) {
927  foreach ($data['add_cart_item'] as $itemId => $qty) {
928  $item = $this->getCustomerCart()->getItemById($itemId);
929  if ($item) {
930  $this->moveQuoteItem($item, 'order', $qty);
931  $this->removeItem($itemId, 'cart');
932  }
933  }
934  }
935  if (isset($data['add_wishlist_item'])) {
936  foreach ($data['add_wishlist_item'] as $itemId => $qty) {
937  $item = $this->_objectManager->create(
938  \Magento\Wishlist\Model\Item::class
939  )->loadWithOptions(
940  $itemId,
941  'info_buyRequest'
942  );
943  if ($item->getId()) {
944  $this->addProduct($item->getProduct(), $item->getBuyRequest()->toArray());
945  }
946  }
947  }
948  if (isset($data['add'])) {
949  foreach ($data['add'] as $productId => $qty) {
950  $this->addProduct($productId, ['qty' => $qty]);
951  }
952  }
953  if (isset($data['remove'])) {
954  foreach ($data['remove'] as $itemId => $from) {
955  $this->removeItem($itemId, $from);
956  }
957  }
958  if (isset($data['empty_customer_cart']) && (int)$data['empty_customer_cart'] == 1) {
959  $this->getCustomerCart()->removeAllItems()->collectTotals();
960  $this->quoteRepository->save($this->getCustomerCart());
961  }
962 
963  $this->recollectCart();
964 
965  return $this;
966  }
967 
975  public function removeItem($itemId, $from)
976  {
977  switch ($from) {
978  case 'quote':
979  $this->removeQuoteItem($itemId);
980  break;
981  case 'cart':
982  $cart = $this->getCustomerCart();
983  if ($cart) {
984  $cart->removeItem($itemId);
985  $this->_needCollectCart = true;
986  }
987  break;
988  case 'wishlist':
989  $wishlist = $this->getCustomerWishlist();
990  if ($wishlist) {
991  $item = $this->_objectManager->create(\Magento\Wishlist\Model\Item::class)->load($itemId);
992  $item->delete();
993  }
994  break;
995  case 'compared':
996  $this->_objectManager->create(
997  \Magento\Catalog\Model\Product\Compare\Item::class
998  )->load($itemId)->delete();
999  break;
1000  }
1001 
1002  return $this;
1003  }
1004 
1011  public function removeQuoteItem($item)
1012  {
1013  $this->getQuote()->removeItem($item);
1014  $this->setRecollect(true);
1015 
1016  return $this;
1017  }
1018 
1029  public function addProduct($product, $config = 1)
1030  {
1031  if (!is_array($config) && !$config instanceof \Magento\Framework\DataObject) {
1032  $config = ['qty' => $config];
1033  }
1034  $config = new \Magento\Framework\DataObject($config);
1035 
1036  if (!$product instanceof \Magento\Catalog\Model\Product) {
1037  $productId = $product;
1038  $product = $this->_objectManager->create(
1039  \Magento\Catalog\Model\Product::class
1040  )->setStore(
1041  $this->getSession()->getStore()
1042  )->setStoreId(
1043  $this->getSession()->getStoreId()
1044  )->load(
1045  $product
1046  );
1047  if (!$product->getId()) {
1048  throw new \Magento\Framework\Exception\LocalizedException(
1049  __('We could not add a product to cart by the ID "%1".', $productId)
1050  );
1051  }
1052  }
1053 
1054  $item = $this->quoteInitializer->init($this->getQuote(), $product, $config);
1055 
1056  if (is_string($item)) {
1057  throw new \Magento\Framework\Exception\LocalizedException(__($item));
1058  }
1059  $item->checkData();
1060  $this->setRecollect(true);
1061 
1062  return $this;
1063  }
1064 
1071  public function addProducts(array $products)
1072  {
1073  foreach ($products as $productId => $config) {
1074  $config['qty'] = isset($config['qty']) ? (double)$config['qty'] : 1;
1075  try {
1076  $this->addProduct($productId, $config);
1077  } catch (\Magento\Framework\Exception\LocalizedException $e) {
1078  $this->messageManager->addErrorMessage($e->getMessage());
1079  } catch (\Exception $e) {
1080  return $e;
1081  }
1082  }
1083 
1084  return $this;
1085  }
1086 
1094  public function updateQuoteItems($items)
1095  {
1096  if (!is_array($items)) {
1097  return $this;
1098  }
1099 
1100  try {
1101  foreach ($items as $itemId => $info) {
1102  if (!empty($info['configured'])) {
1103  $item = $this->getQuote()->updateItem($itemId, $this->objectFactory->create($info));
1104  $info['qty'] = (double)$item->getQty();
1105  } else {
1106  $item = $this->getQuote()->getItemById($itemId);
1107  if (!$item) {
1108  continue;
1109  }
1110  $info['qty'] = (double)$info['qty'];
1111  }
1112  $this->quoteItemUpdater->update($item, $info);
1113  if ($item && !empty($info['action'])) {
1114  $this->moveQuoteItem($item, $info['action'], $item->getQty());
1115  }
1116  }
1117  } catch (\Magento\Framework\Exception\LocalizedException $e) {
1118  $this->recollectCart();
1119  throw $e;
1120  } catch (\Exception $e) {
1121  $this->_logger->critical($e);
1122  }
1123  $this->recollectCart();
1124 
1125  return $this;
1126  }
1127 
1138  protected function _parseOptions(\Magento\Quote\Model\Quote\Item $item, $additionalOptions)
1139  {
1140  $productOptions = $this->_objectManager->get(
1141  \Magento\Catalog\Model\Product\Option\Type\DefaultType::class
1142  )->setProduct(
1143  $item->getProduct()
1144  )->getProductOptions();
1145 
1146  $newOptions = [];
1147  $newAdditionalOptions = [];
1148 
1149  foreach (explode("\n", $additionalOptions) as $_additionalOption) {
1150  if (strlen(trim($_additionalOption))) {
1151  try {
1152  if (strpos($_additionalOption, ':') === false) {
1153  throw new \Magento\Framework\Exception\LocalizedException(
1154  __('There is an error in one of the option rows.')
1155  );
1156  }
1157  list($label, $value) = explode(':', $_additionalOption, 2);
1158  } catch (\Exception $e) {
1159  throw new \Magento\Framework\Exception\LocalizedException(
1160  __('There is an error in one of the option rows.')
1161  );
1162  }
1163  $label = trim($label);
1164  $value = trim($value);
1165  if (empty($value)) {
1166  continue;
1167  }
1168 
1169  if (array_key_exists($label, $productOptions)) {
1170  $optionId = $productOptions[$label]['option_id'];
1171  $option = $item->getProduct()->getOptionById($optionId);
1172 
1173  $group = $this->_objectManager->get(
1174  \Magento\Catalog\Model\Product\Option::class
1175  )->groupFactory(
1176  $option->getType()
1177  )->setOption(
1178  $option
1179  )->setProduct(
1180  $item->getProduct()
1181  );
1182 
1183  $parsedValue = $group->parseOptionValue($value, $productOptions[$label]['values']);
1184 
1185  if ($parsedValue !== null) {
1186  $newOptions[$optionId] = $parsedValue;
1187  } else {
1188  $newAdditionalOptions[] = ['label' => $label, 'value' => $value];
1189  }
1190  } else {
1191  $newAdditionalOptions[] = ['label' => $label, 'value' => $value];
1192  }
1193  }
1194  }
1195 
1196  return ['options' => $newOptions, 'additional_options' => $newAdditionalOptions];
1197  }
1198 
1209  {
1210  $optionIds = $item->getOptionByCode('option_ids');
1211  if ($optionIds) {
1212  foreach (explode(',', $optionIds->getValue()) as $optionId) {
1213  $item->removeOption('option_' . $optionId);
1214  }
1215  $item->removeOption('option_ids');
1216  }
1217  if ($item->getOptionByCode('additional_options')) {
1218  $item->removeOption('additional_options');
1219  }
1220  $item->save();
1221  if (!empty($options['options'])) {
1222  $item->addOption(
1223  new \Magento\Framework\DataObject(
1224  [
1225  'product' => $item->getProduct(),
1226  'code' => 'option_ids',
1227  'value' => implode(',', array_keys($options['options']))
1228  ]
1229  )
1230  );
1231 
1232  foreach ($options['options'] as $optionId => $optionValue) {
1233  $item->addOption(
1234  new \Magento\Framework\DataObject(
1235  [
1236  'product' => $item->getProduct(),
1237  'code' => 'option_' . $optionId,
1238  'value' => $optionValue
1239  ]
1240  )
1241  );
1242  }
1243  }
1244  if (!empty($options['additional_options'])) {
1245  $item->addOption(
1246  new \Magento\Framework\DataObject(
1247  [
1248  'product' => $item->getProduct(),
1249  'code' => 'additional_options',
1250  'value' => $this->serializer->serialize($options['additional_options'])
1251  ]
1252  )
1253  );
1254  }
1255 
1256  return $this;
1257  }
1258 
1265  protected function _prepareOptionsForRequest($item)
1266  {
1267  $newInfoOptions = [];
1268  $optionIds = $item->getOptionByCode('option_ids');
1269  if ($optionIds) {
1270  foreach (explode(',', $optionIds->getValue()) as $optionId) {
1271  $option = $item->getProduct()->getOptionById($optionId);
1272  $optionValue = $item->getOptionByCode('option_' . $optionId)->getValue();
1273 
1274  $group = $this->_objectManager->get(
1275  \Magento\Catalog\Model\Product\Option::class
1276  )->groupFactory(
1277  $option->getType()
1278  )->setOption(
1279  $option
1280  )->setQuoteItem(
1281  $item
1282  );
1283 
1284  $newInfoOptions[$optionId] = $group->prepareOptionValueForRequest($optionValue);
1285  }
1286  }
1287 
1288  return $newInfoOptions;
1289  }
1290 
1297  protected function _parseCustomPrice($price)
1298  {
1299  $price = $this->_objectManager->get(\Magento\Framework\Locale\FormatInterface::class)->getNumber($price);
1300  $price = $price > 0 ? $price : 0;
1301 
1302  return $price;
1303  }
1304 
1310  public function getShippingAddress()
1311  {
1312  return $this->getQuote()->getShippingAddress();
1313  }
1314 
1322  {
1323  $customerForm = $this->_metadataFormFactory->create(
1325  'adminhtml_checkout',
1326  $this->customerMapper->toFlatArray($customer),
1327  false,
1328  CustomerForm::IGNORE_INVISIBLE
1329  );
1330 
1331  return $customerForm;
1332  }
1333 
1342  protected function _setQuoteAddress(\Magento\Quote\Model\Quote\Address $address, array $data)
1343  {
1344  $isAjax = !$this->getIsValidate();
1345 
1346  // Region is a Data Object, so it is represented by an array. validateData() doesn't understand arrays, so we
1347  // need to merge region data with address data. This is going to be removed when we switch to use address Data
1348  // Object instead of the address model.
1349  // Note: if we use getRegion() here it will pull region from db using the region_id
1350  $data = isset($data['region']) && is_array($data['region']) ? array_merge($data, $data['region']) : $data;
1351 
1352  $addressForm = $this->_metadataFormFactory->create(
1353 
1355  'adminhtml_customer_address',
1356  $data,
1357  $isAjax,
1358  CustomerForm::DONT_IGNORE_INVISIBLE,
1359  []
1360  );
1361 
1362  // prepare request
1363  // save original request structure for files
1364  if ($address->getAddressType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING) {
1365  $requestData = ['order' => ['shipping_address' => $data]];
1366  $requestScope = 'order/shipping_address';
1367  } else {
1368  $requestData = ['order' => ['billing_address' => $data]];
1369  $requestScope = 'order/billing_address';
1370  }
1371  $request = $addressForm->prepareRequest($requestData);
1372  $addressData = $addressForm->extractData($request, $requestScope);
1373  if ($this->getIsValidate()) {
1374  $errors = $addressForm->validateData($addressData);
1375  if ($errors !== true) {
1376  if ($address->getAddressType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING) {
1377  $typeName = __('Shipping Address: ');
1378  } else {
1379  $typeName = __('Billing Address: ');
1380  }
1381  foreach ($errors as $error) {
1382  $this->_errors[] = $typeName . $error;
1383  }
1384  $address->setData($addressForm->restoreData($addressData));
1385  } else {
1386  $address->setData($addressForm->compactData($addressData));
1387  }
1388  } else {
1389  $address->addData($addressForm->restoreData($addressData));
1390  }
1391 
1392  return $this;
1393  }
1394 
1401  public function setShippingAddress($address)
1402  {
1403  if (is_array($address)) {
1404  $shippingAddress = $this->_objectManager->create(
1405  \Magento\Quote\Model\Quote\Address::class
1406  )->setData(
1407  $address
1408  )->setAddressType(
1410  );
1411  if (!$this->getQuote()->isVirtual()) {
1413  }
1418  $saveInAddressBook = (int)(!empty($address['save_in_address_book']));
1419  $shippingAddress->setData('save_in_address_book', $saveInAddressBook);
1420  }
1421  if ($address instanceof \Magento\Quote\Model\Quote\Address) {
1423  }
1424 
1425  $this->setRecollect(true);
1426  $this->getQuote()->setShippingAddress($shippingAddress);
1427 
1428  return $this;
1429  }
1430 
1438  public function setShippingAsBilling($flag)
1439  {
1440  if ($flag) {
1441  $tmpAddress = clone $this->getBillingAddress();
1442  $tmpAddress->unsAddressId()->unsAddressType();
1443  $data = $tmpAddress->getData();
1444  $data['save_in_address_book'] = 0;
1445  // Do not duplicate address (billing address will do saving too)
1446  $this->getShippingAddress()->addData($data);
1447  }
1448  $this->getShippingAddress()->setSameAsBilling($flag);
1449  $this->setRecollect(true);
1450  return $this;
1451  }
1452 
1458  public function getBillingAddress()
1459  {
1460  return $this->getQuote()->getBillingAddress();
1461  }
1462 
1469  public function setBillingAddress($address)
1470  {
1471  if (!is_array($address)) {
1472  return $this;
1473  }
1474 
1475  $billingAddress = $this->_objectManager->create(Address::class)
1476  ->setData($address)
1477  ->setAddressType(Address::TYPE_BILLING);
1478 
1480 
1485  $saveInAddressBook = (int)(!empty($address['save_in_address_book']));
1486  $billingAddress->setData('save_in_address_book', $saveInAddressBook);
1487 
1488  $quote = $this->getQuote();
1489  if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
1490  $address['save_in_address_book'] = 0;
1491  $this->setShippingAddress($address);
1492  }
1493 
1494  // not assigned billing address should be saved as new
1495  // but if quote already has the billing address it won't be overridden
1496  if (empty($billingAddress->getCustomerAddressId())) {
1497  $billingAddress->setCustomerAddressId(null);
1498  $quote->getBillingAddress()->setCustomerAddressId(null);
1499  }
1500  $quote->setBillingAddress($billingAddress);
1501 
1502  return $this;
1503  }
1504 
1511  public function setShippingMethod($method)
1512  {
1513  $this->getShippingAddress()->setShippingMethod($method);
1514  $this->setRecollect(true);
1515 
1516  return $this;
1517  }
1518 
1524  public function resetShippingMethod()
1525  {
1526  $this->getShippingAddress()->setShippingMethod(false);
1527  $this->getShippingAddress()->removeAllShippingRates();
1528 
1529  return $this;
1530  }
1531 
1537  public function collectShippingRates()
1538  {
1539  $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
1540  $this->collectRates();
1541 
1542  return $this;
1543  }
1544 
1550  public function collectRates()
1551  {
1552  $this->getQuote()->collectTotals();
1553  }
1554 
1561  public function setPaymentMethod($method)
1562  {
1563  $this->getQuote()->getPayment()->setMethod($method);
1564  return $this;
1565  }
1566 
1573  public function setPaymentData($data)
1574  {
1575  if (!isset($data['method'])) {
1576  $data['method'] = $this->getQuote()->getPayment()->getMethod();
1577  }
1578  $this->getQuote()->getPayment()->importData($data);
1579 
1580  return $this;
1581  }
1582 
1589  public function applyCoupon($code)
1590  {
1591  $code = trim((string)$code);
1592  $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
1593 
1594  if (empty($code)) {
1595  $this->getQuote()->getShippingAddress()->setFreeShipping(0);
1596  }
1597  $this->getQuote()->setCouponCode($code);
1598  $this->setRecollect(true);
1599 
1600  return $this;
1601  }
1602 
1609  public function setAccountData($accountData)
1610  {
1611  $customer = $this->getQuote()->getCustomer();
1612  if (empty($accountData['email'])) {
1613  $accountData['email'] = $customer->getEmail();
1614  }
1615  $form = $this->_createCustomerForm($customer);
1616 
1617  // emulate request
1618  $request = $form->prepareRequest($accountData);
1619  $data = $form->extractData($request);
1620  $data = $form->restoreData($data);
1621  $customer = $this->customerFactory->create();
1622  $this->dataObjectHelper->populateWithArray(
1623  $customer,
1624  $data,
1625  \Magento\Customer\Api\Data\CustomerInterface::class
1626  );
1627  $this->getQuote()->updateCustomerData($customer);
1628  $data = [];
1629 
1630  $customerData = $this->customerMapper->toFlatArray($customer);
1631  foreach ($form->getAttributes() as $attribute) {
1632  $code = sprintf('customer_%s', $attribute->getAttributeCode());
1633  $data[$code] = isset($customerData[$attribute->getAttributeCode()])
1634  ? $customerData[$attribute->getAttributeCode()]
1635  : null;
1636  }
1637 
1638  if (isset($data['customer_group_id'])) {
1639  $customerGroup = $this->groupRepository->getById($data['customer_group_id']);
1640  $data['customer_tax_class_id'] = $customerGroup->getTaxClassId();
1641  $this->setRecollect(true);
1642  }
1643 
1644  $this->getQuote()->addData($data);
1645 
1646  return $this;
1647  }
1648 
1657  public function importPostData($data)
1658  {
1659  if (is_array($data)) {
1660  $this->addData($data);
1661  } else {
1662  return $this;
1663  }
1664 
1665  if (isset($data['account'])) {
1666  $this->setAccountData($data['account']);
1667  }
1668 
1669  if (isset($data['comment'])) {
1670  $this->getQuote()->addData($data['comment']);
1671  if (empty($data['comment']['customer_note_notify'])) {
1672  $this->getQuote()->setCustomerNoteNotify(false);
1673  } else {
1674  $this->getQuote()->setCustomerNoteNotify(true);
1675  }
1676  }
1677 
1678  if (isset($data['billing_address'])) {
1679  $this->setBillingAddress($data['billing_address']);
1680  }
1681 
1682  if (isset($data['shipping_address'])) {
1683  $this->setShippingAddress($data['shipping_address']);
1684  }
1685 
1686  if (isset($data['shipping_method'])) {
1687  $this->setShippingMethod($data['shipping_method']);
1688  }
1689 
1690  if (isset($data['payment_method'])) {
1691  $this->setPaymentMethod($data['payment_method']);
1692  }
1693 
1694  if (isset($data['coupon']['code'])) {
1695  $this->applyCoupon($data['coupon']['code']);
1696  }
1697 
1698  return $this;
1699  }
1700 
1707  protected function _customerIsInStore($store)
1708  {
1709  $customer = $this->getQuote()->getCustomer();
1710 
1711  return $customer->getWebsiteId() == $store->getWebsiteId()
1712  || $this->accountManagement->isCustomerInStore($customer->getWebsiteId(), $store->getId());
1713  }
1714 
1722  {
1723  $form = $this->_createCustomerForm($customer);
1724  // emulate request
1725  $request = $form->prepareRequest(['order' => $this->getData()]);
1726  $data = $form->extractData($request, 'order/account');
1727  $validationResults = $this->accountManagement->validate($customer);
1728  if (!$validationResults->isValid()) {
1729  $errors = $validationResults->getMessages();
1730  if (is_array($errors)) {
1731  foreach ($errors as $error) {
1732  $this->_errors[] = $error;
1733  }
1734  }
1735  }
1736  $data = $form->restoreData($data);
1737  foreach ($data as $key => $value) {
1738  if ($value !== null) {
1739  unset($data[$key]);
1740  }
1741  }
1742 
1743  $this->dataObjectHelper->populateWithArray(
1744  $customer,
1745  $data,
1746  \Magento\Customer\Api\Data\CustomerInterface::class
1747  );
1748  return $customer;
1749  }
1750 
1761  public function _prepareCustomer()
1762  {
1763  if ($this->getQuote()->getCustomerIsGuest()) {
1764  return $this;
1765  }
1767  $store = $this->getSession()->getStore();
1768  $customer = $this->getQuote()->getCustomer();
1769 
1770  if ($customer->getId() && !$this->_customerIsInStore($store)) {
1773  $customer->setId(null)
1774  ->setStoreId($store->getId())
1775  ->setWebsiteId($store->getWebsiteId())
1776  ->setCreatedAt(null);
1778  } else if (!$customer->getId()) {
1780  $customerBillingAddressDataObject = $this->getBillingAddress()->exportCustomerAddress();
1781  $customer->setSuffix($customerBillingAddressDataObject->getSuffix())
1782  ->setFirstname($customerBillingAddressDataObject->getFirstname())
1783  ->setLastname($customerBillingAddressDataObject->getLastname())
1784  ->setMiddlename($customerBillingAddressDataObject->getMiddlename())
1785  ->setPrefix($customerBillingAddressDataObject->getPrefix())
1786  ->setStoreId($store->getId())
1787  ->setWebsiteId($store->getWebsiteId())
1788  ->setEmail($this->_getNewCustomerEmail());
1790  }
1791  $this->getQuote()->setCustomer($customer);
1792 
1793  if ($this->getBillingAddress()->getSaveInAddressBook()) {
1794  $this->_prepareCustomerAddress($this->getQuote()->getCustomer(), $this->getBillingAddress());
1795  $address = $this->getBillingAddress()->setCustomerId($this->getQuote()->getCustomer()->getId());
1796  $this->setBillingAddress($address);
1797  }
1798  if (!$this->getQuote()->isVirtual() && $this->getShippingAddress()->getSaveInAddressBook()) {
1799  $this->_prepareCustomerAddress($this->getQuote()->getCustomer(), $this->getShippingAddress());
1800  $address = $this->getShippingAddress()->setCustomerId($this->getQuote()->getCustomer()->getId());
1801  $this->setShippingAddress($address);
1802  }
1803  $this->getBillingAddress()->setCustomerId($customer->getId());
1804  $this->getQuote()->updateCustomerData($this->getQuote()->getCustomer());
1805 
1806  $customer = $this->getQuote()->getCustomer();
1807  $origAddresses = $customer->getAddresses(); // save original addresses
1808  $customer->setAddresses([]);
1809  $customerData = $this->customerMapper->toFlatArray($customer);
1810  $customer->setAddresses($origAddresses); // restore original addresses
1811  foreach ($this->_createCustomerForm($customer)->getUserAttributes() as $attribute) {
1812  if (isset($customerData[$attribute->getAttributeCode()])) {
1813  $quoteCode = sprintf('customer_%s', $attribute->getAttributeCode());
1814  $this->getQuote()->setData($quoteCode, $customerData[$attribute->getAttributeCode()]);
1815  }
1816  }
1817 
1818  return $this;
1819  }
1820 
1830  protected function _prepareCustomerAddress($customer, $quoteCustomerAddress)
1831  {
1832  // Possible that customerId is null for new customers
1833  $quoteCustomerAddress->setCustomerId($customer->getId());
1834  $customerAddress = $quoteCustomerAddress->exportCustomerAddress();
1835  $quoteAddressId = $quoteCustomerAddress->getCustomerAddressId();
1836  $addressType = $quoteCustomerAddress->getAddressType();
1837  if ($quoteAddressId) {
1839  $existingAddressDataObject = $this->addressRepository->getById($quoteAddressId);
1841  $this->dataObjectHelper->mergeDataObjects(
1842  get_class($existingAddressDataObject),
1843  $existingAddressDataObject,
1845  );
1846  $customerAddress = $existingAddressDataObject;
1847  } elseif ($addressType == \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING) {
1848  try {
1849  $billingAddressDataObject = $this->accountManagement->getDefaultBillingAddress($customer->getId());
1850  } catch (\Exception $e) {
1852  }
1853  $isShippingAsBilling = $quoteCustomerAddress->getSameAsBilling();
1854  if (isset($billingAddressDataObject) && $isShippingAsBilling) {
1857  $customerAddress->setIsDefaultShipping(true);
1858  }
1859  }
1860 
1861  switch ($addressType) {
1862  case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_BILLING:
1863  if ($customer->getDefaultBilling() === null) {
1864  $customerAddress->setIsDefaultBilling(true);
1865  }
1866  break;
1867  case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING:
1868  if ($customer->getDefaultShipping() === null) {
1869  $customerAddress->setIsDefaultShipping(true);
1870  }
1871  break;
1872  default:
1873  throw new \InvalidArgumentException('Customer address type is invalid.');
1874  }
1875  $this->getQuote()->setCustomer($customer);
1876  $this->getQuote()->addCustomerAddress($customerAddress);
1877  }
1878 
1884  protected function _prepareQuoteItems()
1885  {
1886  foreach ($this->getQuote()->getAllItems() as $item) {
1887  $options = [];
1888  $productOptions = $item->getProduct()->getTypeInstance()->getOrderOptions($item->getProduct());
1889  if ($productOptions) {
1890  $productOptions['info_buyRequest']['options'] = $this->_prepareOptionsForRequest($item);
1892  }
1893  $addOptions = $item->getOptionByCode('additional_options');
1894  if ($addOptions) {
1895  $options['additional_options'] = $this->serializer->unserialize($addOptions->getValue());
1896  }
1897  $item->setProductOrderOptions($options);
1898  }
1899  return $this;
1900  }
1901 
1907  public function createOrder()
1908  {
1909  $this->_prepareCustomer();
1910  $this->_validate();
1911  $quote = $this->getQuote();
1912  $this->_prepareQuoteItems();
1913 
1914  $orderData = [];
1915  if ($this->getSession()->getOrder()->getId()) {
1916  $oldOrder = $this->getSession()->getOrder();
1917  $originalId = $oldOrder->getOriginalIncrementId();
1918  if (!$originalId) {
1919  $originalId = $oldOrder->getIncrementId();
1920  }
1921  $orderData = [
1922  'original_increment_id' => $originalId,
1923  'relation_parent_id' => $oldOrder->getId(),
1924  'relation_parent_real_id' => $oldOrder->getIncrementId(),
1925  'edit_increment' => $oldOrder->getEditIncrement() + 1,
1926  'increment_id' => $originalId . '-' . ($oldOrder->getEditIncrement() + 1)
1927  ];
1928  $quote->setReservedOrderId($orderData['increment_id']);
1929  }
1930  $order = $this->quoteManagement->submit($quote, $orderData);
1931 
1932  if ($this->getSession()->getOrder()->getId()) {
1933  $oldOrder = $this->getSession()->getOrder();
1934  $oldOrder->setRelationChildId($order->getId());
1935  $oldOrder->setRelationChildRealId($order->getIncrementId());
1936  $oldOrder->save();
1937  $this->orderManagement->cancel($oldOrder->getEntityId());
1938  $order->save();
1939  }
1940  if ($this->getSendConfirmation()) {
1941  $this->emailSender->send($order);
1942  }
1943 
1944  $this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
1945 
1946  return $order;
1947  }
1948 
1957  protected function _validate()
1958  {
1959  if (!$this->getSession()->getStore()->getId()) {
1960  throw new \Magento\Framework\Exception\LocalizedException(__('Please select a store'));
1961  }
1962  $items = $this->getQuote()->getAllItems();
1963 
1964  if (count($items) === 0) {
1965  $this->_errors[] = __('Please specify order items.');
1966  }
1967 
1968  foreach ($items as $item) {
1970  $messages = $item->getMessage(false);
1971  if ($item->getHasError() && is_array($messages) && !empty($messages)) {
1972  $this->_errors = array_merge($this->_errors, $messages);
1973  }
1974  }
1975 
1976  if (!$this->getQuote()->isVirtual()) {
1977  if (!$this->getQuote()->getShippingAddress()->getShippingMethod()) {
1978  $this->_errors[] = __('The shipping method is missing. Select the shipping method and try again.');
1979  }
1980  }
1981 
1982  if (!$this->getQuote()->getPayment()->getMethod()) {
1983  $this->_errors[] = __("The payment method isn't selected. Enter the payment method and try again.");
1984  } else {
1985  $method = $this->getQuote()->getPayment()->getMethodInstance();
1986  if (!$method->isAvailable($this->getQuote())) {
1987  $this->_errors[] = __('This payment method is not available.');
1988  } else {
1989  try {
1990  $method->validate();
1991  } catch (\Magento\Framework\Exception\LocalizedException $e) {
1992  $this->_errors[] = $e->getMessage();
1993  }
1994  }
1995  }
1996  if (!empty($this->_errors)) {
1998  $logger = ObjectManager::getInstance()->get(LoggerInterface::class);
1999  foreach ($this->_errors as $error) {
2000  $logger->error($error);
2001  $this->messageManager->addErrorMessage($error);
2002  }
2003 
2004  throw new \Magento\Framework\Exception\LocalizedException(__('Validation is failed.'));
2005  }
2006 
2007  return $this;
2008  }
2009 
2015  protected function _getNewCustomerEmail()
2016  {
2017  return $this->getData('account/email');
2018  }
2019 
2026  private function isAddressesAreEqual(Order $order)
2027  {
2028  $shippingAddress = $order->getShippingAddress();
2029  $billingAddress = $order->getBillingAddress();
2030  $shippingData = $this->dataObjectConverter->toFlatArray($shippingAddress, [], OrderAddressInterface::class);
2031  $billingData = $this->dataObjectConverter->toFlatArray($billingAddress, [], OrderAddressInterface::class);
2032  unset(
2033  $shippingData['address_type'],
2034  $shippingData['entity_id'],
2035  $billingData['address_type'],
2036  $billingData['entity_id']
2037  );
2038 
2039  return $shippingData == $billingData;
2040  }
2041 }
initFromOrder(\Magento\Sales\Model\Order $order)
Definition: Create.php:498
$customerData
getData($key='', $index=null)
Definition: DataObject.php:119
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$billingAddress
Definition: order.php:25
$objectManager
Definition: bootstrap.php:17
$customer
Definition: customers.php:11
$orderItem
Definition: order.php:30
$config
Definition: fraud_order.php:17
$quote
$shippingAddress
Definition: order.php:40
$group
Definition: sections.phtml:16
$order
Definition: order.php:55
setQuote(\Magento\Quote\Model\Quote $quote)
Definition: Create.php:483
__()
Definition: __.php:13
_assignOptionsToItem(\Magento\Quote\Model\Quote\Item $item, $options)
Definition: Create.php:1208
$price
initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $qty=null)
Definition: Create.php:628
getCustomerWishlist($cacheReload=false)
Definition: Create.php:681
$logger
$address
Definition: customer.php:38
$addressData
Definition: order.php:19
$wishlist
Definition: wishlist.php:10
_setQuoteAddress(\Magento\Quote\Model\Quote\Address $address, array $data)
Definition: Create.php:1342
_parseOptions(\Magento\Quote\Model\Quote\Item $item, $additionalOptions)
Definition: Create.php:1138
$label
Definition: details.phtml:21
$value
Definition: gender.phtml:16
moveQuoteItem($item, $moveTo, $qty)
Definition: Create.php:780
$billingData
_createCustomerForm(\Magento\Customer\Api\Data\CustomerInterface $customer)
Definition: Create.php:1321
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest
$method
Definition: info.phtml:13
_validateCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
Definition: Create.php:1721
_initBillingAddressFromOrder(\Magento\Sales\Model\Order $order)
Definition: Create.php:588
_prepareCustomerAddress($customer, $quoteCustomerAddress)
Definition: Create.php:1830
__construct(\Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Registry $coreRegistry, \Magento\Sales\Model\Config $salesConfig, \Magento\Backend\Model\Session\Quote $quoteSession, \Psr\Log\LoggerInterface $logger, \Magento\Framework\DataObject\Copy $objectCopyService, \Magento\Framework\Message\ManagerInterface $messageManager, Product\Quote\Initializer $quoteInitializer, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, \Magento\Customer\Api\AddressRepositoryInterface $addressRepository, \Magento\Customer\Api\Data\AddressInterfaceFactory $addressFactory, \Magento\Customer\Model\Metadata\FormFactory $metadataFormFactory, \Magento\Customer\Api\GroupRepositoryInterface $groupRepository, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Sales\Model\AdminOrder\EmailSender $emailSender, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, \Magento\Quote\Model\Quote\Item\Updater $quoteItemUpdater, \Magento\Framework\DataObject\Factory $objectFactory, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Customer\Api\AccountManagementInterface $accountManagement, \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory, \Magento\Customer\Model\Customer\Mapper $customerMapper, \Magento\Quote\Api\CartManagementInterface $quoteManagement, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Sales\Api\OrderManagementInterface $orderManagement, \Magento\Quote\Model\QuoteFactory $quoteFactory, array $data=[], \Magento\Framework\Serialize\Serializer\Json $serializer=null, ExtensibleDataObjectConverter $dataObjectConverter=null)
Definition: Create.php:278
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
addProduct($product, $config=1)
Definition: Create.php:1029
_initShippingAddressFromOrder(\Magento\Sales\Model\Order $order)
Definition: Create.php:605
$quoteShippingAddress
$errors
Definition: overview.phtml:9
$customerAddress
$code
Definition: info.phtml:12
$items