Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Quote.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Quote\Model;
7 
18 
108 {
112  const CHECKOUT_METHOD_LOGIN_IN = 'login_in';
113 
117  protected $_eventPrefix = 'sales_quote';
118 
122  protected $_eventObject = 'quote';
123 
129  protected $_customer;
130 
136  protected $_addresses;
137 
143  protected $_items;
144 
150  protected $_payments;
151 
155  protected $_currentPayment;
156 
162  protected $_errorInfoGroups = [];
163 
169  protected $_preventSaving = false;
170 
176  protected $_catalogProduct;
177 
183  protected $quoteValidator;
184 
190  protected $_scopeConfig;
191 
195  protected $_storeManager;
196 
200  protected $_config;
201 
206 
210  protected $_customerFactory;
211 
217  protected $groupRepository;
218 
223 
228 
232  protected $messageFactory;
233 
238 
243 
248 
253 
258 
265 
272 
278  protected $filterBuilder;
279 
283  protected $stockRegistry;
284 
288  protected $itemProcessor;
289 
293  protected $objectFactory;
294 
299 
304 
309 
314 
318  protected $currencyFactory;
319 
323  protected $dataObjectHelper;
324 
329 
333  protected $totalsCollector;
334 
338  protected $totalsReader;
339 
343  protected $shippingFactory;
344 
349 
356 
360  private $orderIncrementIdChecker;
361 
406  public function __construct(
407  \Magento\Framework\Model\Context $context,
408  \Magento\Framework\Registry $registry,
409  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
410  AttributeValueFactory $customAttributeFactory,
411  \Magento\Quote\Model\QuoteValidator $quoteValidator,
412  \Magento\Catalog\Helper\Product $catalogProduct,
413  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
416  \Magento\Quote\Model\Quote\AddressFactory $quoteAddressFactory,
417  \Magento\Customer\Model\CustomerFactory $customerFactory,
419  \Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory $quoteItemCollectionFactory,
420  \Magento\Quote\Model\Quote\ItemFactory $quoteItemFactory,
421  \Magento\Framework\Message\Factory $messageFactory,
422  \Magento\Sales\Model\Status\ListFactory $statusListFactory,
424  \Magento\Quote\Model\Quote\PaymentFactory $quotePaymentFactory,
425  \Magento\Quote\Model\ResourceModel\Quote\Payment\CollectionFactory $quotePaymentCollectionFactory,
426  \Magento\Framework\DataObject\Copy $objectCopyService,
427  \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
428  \Magento\Quote\Model\Quote\Item\Processor $itemProcessor,
429  \Magento\Framework\DataObject\Factory $objectFactory,
431  \Magento\Framework\Api\SearchCriteriaBuilder $criteriaBuilder,
432  \Magento\Framework\Api\FilterBuilder $filterBuilder,
433  \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory,
434  \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerDataFactory,
436  \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
437  \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter,
438  \Magento\Quote\Model\Cart\CurrencyFactory $currencyFactory,
439  JoinProcessorInterface $extensionAttributesJoinProcessor,
440  Quote\TotalsCollector $totalsCollector,
441  Quote\TotalsReader $totalsReader,
442  \Magento\Quote\Model\ShippingFactory $shippingFactory,
443  \Magento\Quote\Model\ShippingAssignmentFactory $shippingAssignmentFactory,
444  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
445  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
446  array $data = [],
447  \Magento\Sales\Model\OrderIncrementIdChecker $orderIncrementIdChecker = null
448  ) {
449  $this->quoteValidator = $quoteValidator;
450  $this->_catalogProduct = $catalogProduct;
451  $this->_scopeConfig = $scopeConfig;
452  $this->_storeManager = $storeManager;
453  $this->_config = $config;
454  $this->_quoteAddressFactory = $quoteAddressFactory;
455  $this->_customerFactory = $customerFactory;
456  $this->groupRepository = $groupRepository;
457  $this->_quoteItemCollectionFactory = $quoteItemCollectionFactory;
458  $this->_quoteItemFactory = $quoteItemFactory;
459  $this->messageFactory = $messageFactory;
460  $this->_statusListFactory = $statusListFactory;
461  $this->productRepository = $productRepository;
462  $this->_quotePaymentFactory = $quotePaymentFactory;
463  $this->_quotePaymentCollectionFactory = $quotePaymentCollectionFactory;
464  $this->_objectCopyService = $objectCopyService;
465  $this->addressRepository = $addressRepository;
466  $this->searchCriteriaBuilder = $criteriaBuilder;
467  $this->filterBuilder = $filterBuilder;
468  $this->stockRegistry = $stockRegistry;
469  $this->itemProcessor = $itemProcessor;
470  $this->objectFactory = $objectFactory;
471  $this->addressDataFactory = $addressDataFactory;
472  $this->customerDataFactory = $customerDataFactory;
473  $this->customerRepository = $customerRepository;
474  $this->dataObjectHelper = $dataObjectHelper;
475  $this->extensibleDataObjectConverter = $extensibleDataObjectConverter;
476  $this->currencyFactory = $currencyFactory;
477  $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
478  $this->totalsCollector = $totalsCollector;
479  $this->totalsReader = $totalsReader;
480  $this->shippingFactory = $shippingFactory;
481  $this->shippingAssignmentFactory = $shippingAssignmentFactory;
482  $this->orderIncrementIdChecker = $orderIncrementIdChecker ?: ObjectManager::getInstance()
483  ->get(\Magento\Sales\Model\OrderIncrementIdChecker::class);
484  parent::__construct(
485  $context,
486  $registry,
487  $extensionFactory,
488  $customAttributeFactory,
489  $resource,
490  $resourceCollection,
491  $data
492  );
493  }
494 
500  protected function _construct()
501  {
502  $this->_init(\Magento\Quote\Model\ResourceModel\Quote::class);
503  }
504 
511  public function getCurrency()
512  {
513  $currency = $this->getData(self::KEY_CURRENCY);
514  if (!$currency) {
515  $currency = $this->currencyFactory->create()
516  ->setGlobalCurrencyCode($this->getGlobalCurrencyCode())
517  ->setBaseCurrencyCode($this->getBaseCurrencyCode())
518  ->setStoreCurrencyCode($this->getStoreCurrencyCode())
519  ->setQuoteCurrencyCode($this->getQuoteCurrencyCode())
520  ->setStoreToBaseRate($this->getStoreToBaseRate())
521  ->setStoreToQuoteRate($this->getStoreToQuoteRate())
522  ->setBaseToGlobalRate($this->getBaseToGlobalRate())
523  ->setBaseToQuoteRate($this->getBaseToQuoteRate());
524  $this->setData(self::KEY_CURRENCY, $currency);
525  }
526  return $currency;
527  }
528 
532  public function setCurrency(\Magento\Quote\Api\Data\CurrencyInterface $currency = null)
533  {
534  return $this->setData(self::KEY_CURRENCY, $currency);
535  }
536 
540  public function getItems()
541  {
542  return $this->_getData(self::KEY_ITEMS);
543  }
544 
548  public function setItems(array $items = null)
549  {
550  return $this->setData(self::KEY_ITEMS, $items);
551  }
552 
556  public function getCreatedAt()
557  {
558  return $this->_getData(self::KEY_CREATED_AT);
559  }
560 
564  public function setCreatedAt($createdAt)
565  {
566  return $this->setData(self::KEY_CREATED_AT, $createdAt);
567  }
568 
572  public function getUpdatedAt()
573  {
574  return $this->_getData(self::KEY_UPDATED_AT);
575  }
576 
580  public function setUpdatedAt($updatedAt)
581  {
582  return $this->setData(self::KEY_UPDATED_AT, $updatedAt);
583  }
584 
588  public function getConvertedAt()
589  {
590  return $this->_getData(self::KEY_CONVERTED_AT);
591  }
592 
596  public function setConvertedAt($convertedAt)
597  {
598  return $this->setData(self::KEY_CONVERTED_AT, $convertedAt);
599  }
600 
604  public function getIsActive()
605  {
606  return $this->_getData(self::KEY_IS_ACTIVE);
607  }
608 
612  public function setIsActive($isActive)
613  {
614  return $this->setData(self::KEY_IS_ACTIVE, $isActive);
615  }
616 
620  public function setIsVirtual($isVirtual)
621  {
622  return $this->setData(self::KEY_IS_VIRTUAL, $isVirtual);
623  }
624 
628  public function getItemsCount()
629  {
630  return $this->_getData(self::KEY_ITEMS_COUNT);
631  }
632 
636  public function setItemsCount($itemsCount)
637  {
638  return $this->setData(self::KEY_ITEMS_COUNT, $itemsCount);
639  }
640 
644  public function getItemsQty()
645  {
646  return $this->_getData(self::KEY_ITEMS_QTY);
647  }
648 
652  public function setItemsQty($itemsQty)
653  {
654  return $this->setData(self::KEY_ITEMS_QTY, $itemsQty);
655  }
656 
660  public function getOrigOrderId()
661  {
662  return $this->_getData(self::KEY_ORIG_ORDER_ID);
663  }
664 
668  public function setOrigOrderId($origOrderId)
669  {
670  return $this->setData(self::KEY_ORIG_ORDER_ID, $origOrderId);
671  }
672 
676  public function getReservedOrderId()
677  {
678  return $this->_getData(self::KEY_RESERVED_ORDER_ID);
679  }
680 
684  public function setReservedOrderId($reservedOrderId)
685  {
686  return $this->setData(self::KEY_RESERVED_ORDER_ID, $reservedOrderId);
687  }
688 
692  public function getCustomerIsGuest()
693  {
694  return $this->_getData(self::KEY_CUSTOMER_IS_GUEST);
695  }
696 
700  public function setCustomerIsGuest($customerIsGuest)
701  {
702  return $this->setData(self::KEY_CUSTOMER_IS_GUEST, $customerIsGuest);
703  }
704 
708  public function getCustomerNote()
709  {
710  return $this->_getData(self::KEY_CUSTOMER_NOTE);
711  }
712 
716  public function setCustomerNote($customerNote)
717  {
718  return $this->setData(self::KEY_CUSTOMER_NOTE, $customerNote);
719  }
720 
724  public function getCustomerNoteNotify()
725  {
726  return $this->_getData(self::KEY_CUSTOMER_NOTE_NOTIFY);
727  }
728 
732  public function setCustomerNoteNotify($customerNoteNotify)
733  {
734  return $this->setData(self::KEY_CUSTOMER_NOTE_NOTIFY, $customerNoteNotify);
735  }
736 
737  //@codeCoverageIgnoreEnd
738 
742  public function getStoreId()
743  {
744  if (!$this->hasStoreId()) {
745  return $this->_storeManager->getStore()->getId();
746  }
747  return (int)$this->_getData(self::KEY_STORE_ID);
748  }
749 
753  public function setStoreId($storeId)
754  {
755  $this->setData(self::KEY_STORE_ID, (int)$storeId);
756  return $this;
757  }
758 
764  public function getStore()
765  {
766  return $this->_storeManager->getStore($this->getStoreId());
767  }
768 
775  public function setStore(\Magento\Store\Model\Store $store)
776  {
777  $this->setStoreId($store->getId());
778  return $this;
779  }
780 
786  public function getSharedStoreIds()
787  {
788  $ids = $this->_getData('shared_store_ids');
789  if ($ids === null || !is_array($ids)) {
790  $website = $this->getWebsite();
791  if ($website) {
792  return $website->getStoreIds();
793  }
794  return $this->getStore()->getWebsite()->getStoreIds();
795  }
796  return $ids;
797  }
798 
804  public function beforeSave()
805  {
819  $globalCurrencyCode = $this->_config->getValue(
820  \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
821  'default'
822  );
823  $baseCurrency = $this->getStore()->getBaseCurrency();
824 
825  if ($this->hasForcedCurrency()) {
826  $quoteCurrency = $this->getForcedCurrency();
827  } else {
828  $quoteCurrency = $this->getStore()->getCurrentCurrency();
829  }
830 
831  $this->setGlobalCurrencyCode($globalCurrencyCode);
832  $this->setBaseCurrencyCode($baseCurrency->getCode());
833  $this->setStoreCurrencyCode($baseCurrency->getCode());
834  $this->setQuoteCurrencyCode($quoteCurrency->getCode());
835 
836  $this->setBaseToGlobalRate($baseCurrency->getRate($globalCurrencyCode));
837  $this->setBaseToQuoteRate($baseCurrency->getRate($quoteCurrency));
838 
839  if (!$this->hasChangedFlag() || $this->getChangedFlag() == true) {
840  $this->setIsChanged(1);
841  } else {
842  $this->setIsChanged(0);
843  }
844 
845  if ($this->_customer) {
846  $this->setCustomerId($this->_customer->getId());
847  }
848 
849  //mark quote if it has virtual products only
850  $this->setIsVirtual($this->getIsVirtual());
851 
852  if ($this->hasDataChanges()) {
853  $this->setUpdatedAt(null);
854  }
855 
856  parent::beforeSave();
857  }
858 
866  public function loadByCustomer($customer)
867  {
868  /* @TODO: remove this if after external usages of loadByCustomerId are refactored in MAGETWO-19935 */
869  if ($customer instanceof \Magento\Customer\Model\Customer || $customer instanceof CustomerInterface) {
870  $customerId = $customer->getId();
871  } else {
872  $customerId = (int)$customer;
873  }
874  $this->_getResource()->loadByCustomerId($this, $customerId);
875  $this->_afterLoad();
876  return $this;
877  }
878 
885  public function loadActive($quoteId)
886  {
887  $this->_getResource()->loadActive($this, $quoteId);
888  $this->_afterLoad();
889  return $this;
890  }
891 
899  {
900  $this->_getResource()->loadByIdWithoutStore($this, $quoteId);
901  $this->_afterLoad();
902  return $this;
903  }
904 
912  {
913  return $this->assignCustomerWithAddressChange($customer);
914  }
915 
924  public function assignCustomerWithAddressChange(
926  Address $billingAddress = null,
928  ) {
929  if ($customer->getId()) {
930  $this->setCustomer($customer);
931 
932  if (null !== $billingAddress) {
933  $this->setBillingAddress($billingAddress);
934  } else {
935  try {
936  $defaultBillingAddress = $this->addressRepository->getById($customer->getDefaultBilling());
937  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
938  //
939  }
940  if (isset($defaultBillingAddress)) {
942  $billingAddress = $this->_quoteAddressFactory->create();
943  $billingAddress->importCustomerAddressData($defaultBillingAddress);
944  $this->setBillingAddress($billingAddress);
945  }
946  }
947 
948  if (null === $shippingAddress) {
949  try {
950  $defaultShippingAddress = $this->addressRepository->getById($customer->getDefaultShipping());
951  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
952  //
953  }
954  if (isset($defaultShippingAddress)) {
956  $shippingAddress = $this->_quoteAddressFactory->create();
957  $shippingAddress->importCustomerAddressData($defaultShippingAddress);
958  } else {
959  $shippingAddress = $this->_quoteAddressFactory->create();
960  }
961  }
963  }
964 
965  return $this;
966  }
967 
974  public function setCustomer(\Magento\Customer\Api\Data\CustomerInterface $customer = null)
975  {
976  /* @TODO: Remove the method after all external usages are refactored in MAGETWO-19930 */
977  $this->_customer = $customer;
978  $this->setCustomerId($customer->getId());
979  $origAddresses = $customer->getAddresses();
980  $customer->setAddresses([]);
981  $customerDataFlatArray = $this->objectFactory->create(
982  $this->extensibleDataObjectConverter->toFlatArray(
983  $customer,
984  [],
985  \Magento\Customer\Api\Data\CustomerInterface::class
986  )
987  );
988  $customer->setAddresses($origAddresses);
989  $this->_objectCopyService->copyFieldsetToTarget('customer_account', 'to_quote', $customerDataFlatArray, $this);
990 
991  return $this;
992  }
993 
999  public function getCustomer()
1000  {
1005  if (null === $this->_customer) {
1006  try {
1007  $this->_customer = $this->customerRepository->getById($this->getCustomerId());
1008  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
1009  $this->_customer = $this->customerDataFactory->create();
1010  $this->_customer->setId(null);
1011  }
1012  }
1013 
1014  return $this->_customer;
1015  }
1016 
1023  public function setCustomerAddressData(array $addresses)
1024  {
1025  foreach ($addresses as $address) {
1026  if (!$address->getId()) {
1027  $this->addCustomerAddress($address);
1028  }
1029  }
1030 
1031  return $this;
1032  }
1033 
1043  {
1044  $addresses = (array)$this->getCustomer()->getAddresses();
1045  $addresses[] = $address;
1046  $this->getCustomer()->setAddresses($addresses);
1047  $this->updateCustomerData($this->getCustomer());
1048  return $this;
1049  }
1050 
1058  {
1059  $quoteCustomer = $this->getCustomer();
1060  $this->dataObjectHelper->mergeDataObjects(CustomerInterface::class, $quoteCustomer, $customer);
1061  $this->setCustomer($quoteCustomer);
1062  return $this;
1063  }
1064 
1070  public function getCustomerGroupId()
1071  {
1072  if ($this->hasData('customer_group_id')) {
1073  return $this->getData('customer_group_id');
1074  } elseif ($this->getCustomerId()) {
1075  return $this->getCustomer()->getGroupId();
1076  } else {
1078  }
1079  }
1080 
1084  public function getCustomerTaxClassId()
1085  {
1090  //if (!$this->getData('customer_group_id') && !$this->getData('customer_tax_class_id')) {
1091  $groupId = $this->getCustomerGroupId();
1092  if ($groupId !== null) {
1093  $taxClassId = $this->groupRepository->getById($this->getCustomerGroupId())->getTaxClassId();
1094  $this->setCustomerTaxClassId($taxClassId);
1095  }
1096 
1097  return $this->getData(self::KEY_CUSTOMER_TAX_CLASS_ID);
1098  }
1099 
1103  public function setCustomerTaxClassId($customerTaxClassId)
1104  {
1105  return $this->setData(self::KEY_CUSTOMER_TAX_CLASS_ID, $customerTaxClassId);
1106  }
1107 
1113  public function getAddressesCollection()
1114  {
1115  if (null === $this->_addresses) {
1116  $this->_addresses = $this->_quoteAddressFactory->create()->getCollection()->setQuoteFilter($this->getId());
1117 
1118  if ($this->getId()) {
1119  foreach ($this->_addresses as $address) {
1120  $address->setQuote($this);
1121  }
1122  }
1123  }
1124  return $this->_addresses;
1125  }
1126 
1133  protected function _getAddressByType($type)
1134  {
1135  foreach ($this->getAddressesCollection() as $address) {
1136  if ($address->getAddressType() == $type && !$address->isDeleted()) {
1137  return $address;
1138  }
1139  }
1140 
1141  $address = $this->_quoteAddressFactory->create()->setAddressType($type);
1142  $this->addAddress($address);
1143  return $address;
1144  }
1145 
1151  public function getBillingAddress()
1152  {
1154  }
1155 
1161  public function getShippingAddress()
1162  {
1164  }
1165 
1171  public function getAllShippingAddresses()
1172  {
1173  $addresses = [];
1174  foreach ($this->getAddressesCollection() as $address) {
1175  if ($address->getAddressType() == Address::TYPE_SHIPPING && !$address->isDeleted()) {
1176  $addresses[] = $address;
1177  }
1178  }
1179  return $addresses;
1180  }
1181 
1187  public function getAllAddresses()
1188  {
1189  $addresses = [];
1190  foreach ($this->getAddressesCollection() as $address) {
1191  if (!$address->isDeleted()) {
1192  $addresses[] = $address;
1193  }
1194  }
1195  return $addresses;
1196  }
1197 
1204  public function getAddressById($addressId)
1205  {
1206  foreach ($this->getAddressesCollection() as $address) {
1207  if ($address->getId() == $addressId) {
1208  return $address;
1209  }
1210  }
1211  return false;
1212  }
1213 
1220  public function getAddressByCustomerAddressId($addressId)
1221  {
1222  foreach ($this->getAddressesCollection() as $address) {
1223  if (!$address->isDeleted() && $address->getCustomerAddressId() == $addressId) {
1224  return $address;
1225  }
1226  }
1227  return false;
1228  }
1229 
1236  public function getShippingAddressByCustomerAddressId($addressId)
1237  {
1239  foreach ($this->getAddressesCollection() as $address) {
1240  if (!$address->isDeleted() &&
1241  $address->getAddressType() == Address::TYPE_SHIPPING &&
1242  $address->getCustomerAddressId() == $addressId
1243  ) {
1244  return $address;
1245  }
1246  }
1247  return false;
1248  }
1249 
1256  public function removeAddress($addressId)
1257  {
1258  foreach ($this->getAddressesCollection() as $address) {
1259  if ($address->getId() == $addressId) {
1260  $address->isDeleted(true);
1261  break;
1262  }
1263  }
1264  return $this;
1265  }
1266 
1272  public function removeAllAddresses()
1273  {
1274  $addressByType = [];
1275  $addressesCollection = $this->getAddressesCollection();
1276 
1277  // mark all addresses as deleted
1278  foreach ($addressesCollection as $address) {
1279  $type = $address->getAddressType();
1280  if (!isset($addressByType[$type]) || $addressByType[$type]->getId() > $address->getId()) {
1281  $addressByType[$type] = $address;
1282  }
1283  $address->isDeleted(true);
1284  }
1285 
1286  // create new billing and shipping addresses filled with default values, set this data to existing records
1287  foreach ($addressByType as $type => $address) {
1288  $id = $address->getId();
1289  $emptyAddress = $this->_getAddressByType($type);
1290  $address->setData($emptyAddress->getData())->setId($id)->isDeleted(false);
1291  $emptyAddress->setDeleteImmediately(true);
1292  }
1293 
1294  // remove newly created billing and shipping addresses from collection to avoid senseless delete queries
1295  foreach ($addressesCollection as $key => $item) {
1296  if ($item->getDeleteImmediately()) {
1297  $addressesCollection->removeItemByKey($key);
1298  }
1299  }
1300 
1301  return $this;
1302  }
1303 
1310  public function addAddress(\Magento\Quote\Api\Data\AddressInterface $address)
1311  {
1312  $address->setQuote($this);
1313  if (!$address->getId()) {
1314  $this->getAddressesCollection()->addItem($address);
1315  }
1316  return $this;
1317  }
1318 
1325  public function setBillingAddress(\Magento\Quote\Api\Data\AddressInterface $address = null)
1326  {
1327  $old = $this->getAddressesCollection()->getItemById($address->getId())
1328  ?? $this->getBillingAddress();
1329  if (!empty($old)) {
1330  $old->addData($address->getData());
1331  } else {
1332  $this->addAddress($address->setAddressType(Address::TYPE_BILLING));
1333  }
1334 
1335  return $this;
1336  }
1337 
1344  public function setShippingAddress(\Magento\Quote\Api\Data\AddressInterface $address = null)
1345  {
1346  if ($this->getIsMultiShipping()) {
1347  $this->addAddress($address->setAddressType(Address::TYPE_SHIPPING));
1348  } else {
1349  $old = $this->getAddressesCollection()->getItemById($address->getId())
1350  ?? $this->getShippingAddress();
1351  if (!empty($old)) {
1352  $old->addData($address->getData());
1353  } else {
1354  $this->addAddress($address->setAddressType(Address::TYPE_SHIPPING));
1355  }
1356  }
1357 
1358  return $this;
1359  }
1360 
1368  {
1369  $this->setShippingAddress($address);
1370  return $this;
1371  }
1372 
1380  public function getItemsCollection($useCache = true)
1381  {
1382  if ($this->hasItemsCollection()) {
1383  return $this->getData('items_collection');
1384  }
1385  if (null === $this->_items) {
1386  $this->_items = $this->_quoteItemCollectionFactory->create();
1387  $this->extensionAttributesJoinProcessor->process($this->_items);
1388  $this->_items->setQuote($this);
1389  }
1390  return $this->_items;
1391  }
1392 
1398  public function getAllItems()
1399  {
1400  $items = [];
1401  foreach ($this->getItemsCollection() as $item) {
1403  if (!$item->isDeleted()) {
1404  $items[] = $item;
1405  }
1406  }
1407  return $items;
1408  }
1409 
1415  public function getAllVisibleItems()
1416  {
1417  $items = [];
1418  foreach ($this->getItemsCollection() as $item) {
1419  if (!$item->isDeleted() && !$item->getParentItemId() && !$item->getParentItem()) {
1420  $items[] = $item;
1421  }
1422  }
1423  return $items;
1424  }
1425 
1431  public function hasItems()
1432  {
1433  return sizeof($this->getAllItems()) > 0;
1434  }
1435 
1441  public function hasItemsWithDecimalQty()
1442  {
1443  foreach ($this->getAllItems() as $item) {
1444  $stockItemDo = $this->stockRegistry->getStockItem(
1445  $item->getProduct()->getId(),
1446  $item->getStore()->getWebsiteId()
1447  );
1448  if ($stockItemDo->getItemId() && $stockItemDo->getIsQtyDecimal()) {
1449  return true;
1450  }
1451  }
1452  return false;
1453  }
1454 
1461  public function hasProductId($productId)
1462  {
1463  foreach ($this->getAllItems() as $item) {
1464  if ($item->getProductId() == $productId) {
1465  return true;
1466  }
1467  }
1468 
1469  return false;
1470  }
1471 
1478  public function getItemById($itemId)
1479  {
1480  foreach ($this->getItemsCollection() as $item) {
1481  if ($item->getId() == $itemId) {
1482  return $item;
1483  }
1484  }
1485 
1486  return false;
1487  }
1488 
1495  public function deleteItem(\Magento\Quote\Model\Quote\Item $item)
1496  {
1497  if ($item->getId()) {
1498  $this->removeItem($item->getId());
1499  } else {
1500  $quoteItems = $this->getItemsCollection();
1501  $items = [$item];
1502  if ($item->getHasChildren()) {
1503  foreach ($item->getChildren() as $child) {
1504  $items[] = $child;
1505  }
1506  }
1507  foreach ($quoteItems as $key => $quoteItem) {
1508  foreach ($items as $item) {
1509  if ($quoteItem->compare($item)) {
1510  $quoteItems->removeItemByKey($key);
1511  }
1512  }
1513  }
1514  }
1515 
1516  return $this;
1517  }
1518 
1525  public function removeItem($itemId)
1526  {
1527  $item = $this->getItemById($itemId);
1528 
1529  if ($item) {
1530  $item->setQuote($this);
1534  $this->setIsMultiShipping(false);
1535  $item->isDeleted(true);
1536  if ($item->getHasChildren()) {
1537  foreach ($item->getChildren() as $child) {
1538  $child->isDeleted(true);
1539  }
1540  }
1541 
1542  $parent = $item->getParentItem();
1543  if ($parent) {
1544  $parent->isDeleted(true);
1545  }
1546 
1547  $this->_eventManager->dispatch('sales_quote_remove_item', ['quote_item' => $item]);
1548  }
1549 
1550  return $this;
1551  }
1552 
1558  public function removeAllItems()
1559  {
1560  foreach ($this->getItemsCollection() as $itemId => $item) {
1561  if ($item->getId() === null) {
1562  $this->getItemsCollection()->removeItemByKey($itemId);
1563  } else {
1564  $item->isDeleted(true);
1565  }
1566  }
1567  return $this;
1568  }
1569 
1577  public function addItem(\Magento\Quote\Model\Quote\Item $item)
1578  {
1579  $item->setQuote($this);
1580  if (!$item->getId()) {
1581  $this->getItemsCollection()->addItem($item);
1582  $this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);
1583  }
1584  return $this;
1585  }
1586 
1598  public function addProduct(
1599  \Magento\Catalog\Model\Product $product,
1600  $request = null,
1601  $processMode = \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL
1602  ) {
1603  if ($request === null) {
1604  $request = 1;
1605  }
1606  if (is_numeric($request)) {
1607  $request = $this->objectFactory->create(['qty' => $request]);
1608  }
1609  if (!$request instanceof \Magento\Framework\DataObject) {
1610  throw new \Magento\Framework\Exception\LocalizedException(
1611  __('We found an invalid request for adding product to quote.')
1612  );
1613  }
1614 
1615  if (!$product->isSalable()) {
1616  throw new \Magento\Framework\Exception\LocalizedException(
1617  __('Product that you are trying to add is not available.')
1618  );
1619  }
1620 
1621  $cartCandidates = $product->getTypeInstance()->prepareForCartAdvanced($request, $product, $processMode);
1622 
1626  if (is_string($cartCandidates) || $cartCandidates instanceof \Magento\Framework\Phrase) {
1627  return (string)$cartCandidates;
1628  }
1629 
1633  if (!is_array($cartCandidates)) {
1634  $cartCandidates = [$cartCandidates];
1635  }
1636 
1637  $parentItem = null;
1638  $errors = [];
1639  $item = null;
1640  $items = [];
1641  foreach ($cartCandidates as $candidate) {
1642  // Child items can be sticked together only within their parent
1643  $stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
1644  $candidate->setStickWithinParent($stickWithinParent);
1645 
1646  $item = $this->getItemByProduct($candidate);
1647  if (!$item) {
1648  $item = $this->itemProcessor->init($candidate, $request);
1649  $item->setQuote($this);
1650  $item->setOptions($candidate->getCustomOptions());
1651  $item->setProduct($candidate);
1652  // Add only item that is not in quote already
1653  $this->addItem($item);
1654  }
1655  $items[] = $item;
1656 
1660  if (!$parentItem) {
1661  $parentItem = $item;
1662  }
1663  if ($parentItem && $candidate->getParentProductId() && !$item->getParentItem()) {
1664  $item->setParentItem($parentItem);
1665  }
1666 
1667  $this->itemProcessor->prepare($item, $request, $candidate);
1668 
1669  // collect errors instead of throwing first one
1670  if ($item->getHasError()) {
1671  foreach ($item->getMessage(false) as $message) {
1672  if (!in_array($message, $errors)) {
1673  // filter duplicate messages
1674  $errors[] = $message;
1675  }
1676  }
1677  }
1678  }
1679  if (!empty($errors)) {
1680  throw new \Magento\Framework\Exception\LocalizedException(__(implode("\n", $errors)));
1681  }
1682 
1683  $this->_eventManager->dispatch('sales_quote_product_add_after', ['items' => $items]);
1684  return $parentItem;
1685  }
1686 
1695  protected function _addCatalogProduct(\Magento\Catalog\Model\Product $product, $qty = 1)
1696  {
1697  $newItem = false;
1698  $item = $this->getItemByProduct($product);
1699  if (!$item) {
1700  $item = $this->_quoteItemFactory->create();
1701  $item->setQuote($this);
1702  if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
1703  $item->setStoreId($this->getStore()->getId());
1704  } else {
1705  $item->setStoreId($this->_storeManager->getStore()->getId());
1706  }
1707  $newItem = true;
1708  }
1709 
1713  if ($item->getId() && $product->getParentProductId()) {
1714  return $item;
1715  }
1716 
1717  $item->setOptions($product->getCustomOptions())->setProduct($product);
1718 
1719  // Add only item that is not in quote already (there can be other new or already saved item
1720  if ($newItem) {
1721  $this->addItem($item);
1722  }
1723 
1724  return $item;
1725  }
1726 
1750  public function updateItem($itemId, $buyRequest, $params = null)
1751  {
1752  $item = $this->getItemById($itemId);
1753  if (!$item) {
1754  throw new \Magento\Framework\Exception\LocalizedException(
1755  __('This is the wrong quote item id to update configuration.')
1756  );
1757  }
1758  $productId = $item->getProduct()->getId();
1759 
1760  //We need to create new clear product instance with same $productId
1761  //to set new option values from $buyRequest
1762  $product = clone $this->productRepository->getById($productId, false, $this->getStore()->getId());
1763 
1764  if (!$params) {
1765  $params = new \Magento\Framework\DataObject();
1766  } elseif (is_array($params)) {
1767  $params = new \Magento\Framework\DataObject($params);
1768  }
1769  $params->setCurrentConfig($item->getBuyRequest());
1770  $buyRequest = $this->_catalogProduct->addParamsToBuyRequest($buyRequest, $params);
1771 
1772  $buyRequest->setResetCount(true);
1773  $resultItem = $this->addProduct($product, $buyRequest);
1774 
1775  if (is_string($resultItem)) {
1776  throw new \Magento\Framework\Exception\LocalizedException(__($resultItem));
1777  }
1778 
1779  if ($resultItem->getParentItem()) {
1780  $resultItem = $resultItem->getParentItem();
1781  }
1782 
1783  if ($resultItem->getId() != $itemId) {
1788  $this->removeItem($itemId);
1789  $items = $this->getAllItems();
1790  foreach ($items as $item) {
1791  if ($item->getProductId() == $productId && $item->getId() != $resultItem->getId()) {
1792  if ($resultItem->compare($item)) {
1793  // Product configuration is same as in other quote item
1794  $resultItem->setQty($resultItem->getQty() + $item->getQty());
1795  $this->removeItem($item->getId());
1796  break;
1797  }
1798  }
1799  }
1800  } else {
1801  $resultItem->setQty($buyRequest->getQty());
1802  }
1803 
1804  return $resultItem;
1805  }
1806 
1813  public function getItemByProduct($product)
1814  {
1815  foreach ($this->getAllItems() as $item) {
1816  if ($item->representProduct($product)) {
1817  return $item;
1818  }
1819  }
1820  return false;
1821  }
1822 
1828  public function getItemsSummaryQty()
1829  {
1830  $qty = $this->getData('all_items_qty');
1831  if (null === $qty) {
1832  $qty = 0;
1833  foreach ($this->getAllItems() as $item) {
1834  if ($item->getParentItem()) {
1835  continue;
1836  }
1837 
1838  $children = $item->getChildren();
1839  if ($children && $item->isShipSeparately()) {
1840  foreach ($children as $child) {
1841  $qty += $child->getQty() * $item->getQty();
1842  }
1843  } else {
1844  $qty += $item->getQty();
1845  }
1846  }
1847  $this->setData('all_items_qty', $qty);
1848  }
1849  return $qty;
1850  }
1851 
1857  public function getItemVirtualQty()
1858  {
1859  $qty = $this->getData('virtual_items_qty');
1860  if (null === $qty) {
1861  $qty = 0;
1862  foreach ($this->getAllItems() as $item) {
1863  if ($item->getParentItem()) {
1864  continue;
1865  }
1866 
1867  $children = $item->getChildren();
1868  if ($children && $item->isShipSeparately()) {
1869  foreach ($children as $child) {
1870  if ($child->getProduct()->getIsVirtual()) {
1871  $qty += $child->getQty();
1872  }
1873  }
1874  } else {
1875  if ($item->getProduct()->getIsVirtual()) {
1876  $qty += $item->getQty();
1877  }
1878  }
1879  }
1880  $this->setData('virtual_items_qty', $qty);
1881  }
1882  return $qty;
1883  }
1884 
1885  /*********************** PAYMENTS ***************************/
1886 
1892  public function getPaymentsCollection()
1893  {
1894  if (null === $this->_payments) {
1895  $this->_payments = $this->_quotePaymentCollectionFactory->create()->setQuoteFilter($this->getId());
1896 
1897  if ($this->getId()) {
1898  foreach ($this->_payments as $payment) {
1899  $payment->setQuote($this);
1900  }
1901  }
1902  }
1903  return $this->_payments;
1904  }
1905 
1911  public function getPayment()
1912  {
1913  if (null === $this->_currentPayment || !$this->_currentPayment) {
1914  $this->_currentPayment = $this->_quotePaymentCollectionFactory->create()
1915  ->setQuoteFilter($this->getId())
1916  ->getFirstItem();
1917  }
1918  if ($payment = $this->_currentPayment) {
1919  if ($this->getId()) {
1920  $payment->setQuote($this);
1921  }
1922  if (!$payment->isDeleted()) {
1923  return $payment;
1924  }
1925  }
1926  $payment = $this->_quotePaymentFactory->create();
1927  $this->addPayment($payment);
1928  return $payment;
1929  }
1930 
1938  {
1939  $payment->setQuote($this);
1940  if (!$payment->getId()) {
1941  $this->getPaymentsCollection()->addItem($payment);
1942  }
1943  return $this;
1944  }
1945 
1953  {
1954  if (!$this->getIsMultiPayment() && ($old = $this->getPayment())) {
1955  $payment->setId($old->getId());
1956  }
1957  $this->addPayment($payment);
1958 
1959  return $payment;
1960  }
1961 
1967  public function removePayment()
1968  {
1969  $this->getPayment()->isDeleted(true);
1970  return $this;
1971  }
1972 
1978  public function collectTotals()
1979  {
1980  if ($this->getTotalsCollectedFlag()) {
1981  return $this;
1982  }
1983 
1984  $total = $this->totalsCollector->collect($this);
1985  $this->addData($total->getData());
1986 
1987  $this->setTotalsCollectedFlag(true);
1988  return $this;
1989  }
1990 
1996  public function getTotals()
1997  {
1998  return $this->totalsReader->fetch($this, $this->getData());
1999  }
2000 
2008  public function addMessage($message, $index = 'error')
2009  {
2010  $messages = $this->getData('messages');
2011  if (null === $messages) {
2012  $messages = [];
2013  }
2014 
2015  if (isset($messages[$index])) {
2016  return $this;
2017  }
2018 
2019  $message = $this->messageFactory->create(\Magento\Framework\Message\MessageInterface::TYPE_ERROR, $message);
2020 
2021  $messages[$index] = $message;
2022  $this->setData('messages', $messages);
2023  return $this;
2024  }
2025 
2031  public function getMessages()
2032  {
2033  $messages = $this->getData('messages');
2034  if (null === $messages) {
2035  $messages = [];
2036  $this->setData('messages', $messages);
2037  }
2038  return $messages;
2039  }
2040 
2046  public function getErrors()
2047  {
2048  $errors = [];
2049  foreach ($this->getMessages() as $message) {
2050  /* @var $error \Magento\Framework\Message\AbstractMessage */
2052  $errors[] = $message;
2053  }
2054  }
2055  return $errors;
2056  }
2057 
2066  protected function _setHasError($flag)
2067  {
2068  return $this->setData('has_error', $flag);
2069  }
2070 
2081  public function setHasError($flag)
2082  {
2083  if ($flag) {
2084  $this->addErrorInfo();
2085  } else {
2086  $this->_clearErrorInfo();
2087  }
2088  return $this;
2089  }
2090 
2096  protected function _clearErrorInfo()
2097  {
2098  $this->_errorInfoGroups = [];
2099  $this->_setHasError(false);
2100  return $this;
2101  }
2102 
2113  public function addErrorInfo(
2114  $type = 'error',
2115  $origin = null,
2116  $code = null,
2117  $message = null,
2118  $additionalData = null
2119  ) {
2120  if (!isset($this->_errorInfoGroups[$type])) {
2121  $this->_errorInfoGroups[$type] = $this->_statusListFactory->create();
2122  }
2123 
2124  $this->_errorInfoGroups[$type]->addItem($origin, $code, $message, $additionalData);
2125 
2126  if ($message !== null) {
2127  $this->addMessage($message, $type);
2128  }
2129  $this->_setHasError(true);
2130 
2131  return $this;
2132  }
2133 
2145  {
2146  if ($type && !isset($this->_errorInfoGroups[$type])) {
2147  return $this;
2148  }
2149 
2150  $errorLists = [];
2151  if ($type) {
2152  $errorLists[] = $this->_errorInfoGroups[$type];
2153  } else {
2154  $errorLists = $this->_errorInfoGroups;
2155  }
2156 
2157  foreach ($errorLists as $type => $errorList) {
2158  $removedItems = $errorList->removeItemsByParams($params);
2159  foreach ($removedItems as $item) {
2160  if ($item['message'] !== null) {
2161  $this->removeMessageByText($type, $item['message']);
2162  }
2163  }
2164  }
2165 
2166  $errorsExist = false;
2167  foreach ($this->_errorInfoGroups as $errorListCheck) {
2168  if ($errorListCheck->getItems()) {
2169  $errorsExist = true;
2170  break;
2171  }
2172  }
2173  if (!$errorsExist) {
2174  $this->_setHasError(false);
2175  }
2176 
2177  return $this;
2178  }
2179 
2187  public function removeMessageByText($type, $text)
2188  {
2189  $messages = $this->getData('messages');
2190  if (null === $messages) {
2191  $messages = [];
2192  }
2193 
2194  if (!isset($messages[$type])) {
2195  return $this;
2196  }
2197 
2198  $message = $messages[$type];
2199  if ($message instanceof \Magento\Framework\Message\AbstractMessage) {
2200  $message = $message->getText();
2201  } elseif (!is_string($message)) {
2202  return $this;
2203  }
2204  if ($message == $text) {
2205  unset($messages[$type]);
2206  $this->setData('messages', $messages);
2207  }
2208  return $this;
2209  }
2210 
2216  public function reserveOrderId()
2217  {
2218  if (!$this->getReservedOrderId()) {
2219  $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
2220  } else {
2221  //checking if reserved order id was already used for some order
2222  //if yes reserving new one if not using old one
2223  if ($this->orderIncrementIdChecker->isIncrementIdUsed($this->getReservedOrderId())) {
2224  $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
2225  }
2226  }
2227  return $this;
2228  }
2229 
2238  public function validateMinimumAmount($multishipping = false)
2239  {
2240  $storeId = $this->getStoreId();
2241  $minOrderActive = $this->_scopeConfig->isSetFlag(
2242  'sales/minimum_order/active',
2244  $storeId
2245  );
2246  if (!$minOrderActive) {
2247  return true;
2248  }
2249  $minOrderMulti = $this->_scopeConfig->isSetFlag(
2250  'sales/minimum_order/multi_address',
2251  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
2252  $storeId
2253  );
2254  $minAmount = $this->_scopeConfig->getValue(
2255  'sales/minimum_order/amount',
2256  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
2257  $storeId
2258  );
2259  $taxInclude = $this->_scopeConfig->getValue(
2260  'sales/minimum_order/tax_including',
2261  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
2262  $storeId
2263  );
2264 
2265  $addresses = $this->getAllAddresses();
2266 
2267  if (!$multishipping) {
2268  foreach ($addresses as $address) {
2269  /* @var $address Address */
2270  if (!$address->validateMinimumAmount()) {
2271  return false;
2272  }
2273  }
2274  return true;
2275  }
2276 
2277  if (!$minOrderMulti) {
2278  foreach ($addresses as $address) {
2279  $taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
2280  foreach ($address->getQuote()->getItemsCollection() as $item) {
2282  $amount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $taxes;
2283  if ($amount < $minAmount) {
2284  return false;
2285  }
2286  }
2287  }
2288  } else {
2289  $baseTotal = 0;
2290  foreach ($addresses as $address) {
2291  $taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
2292  $baseTotal += $address->getBaseSubtotalWithDiscount() + $taxes;
2293  }
2294  if ($baseTotal < $minAmount) {
2295  return false;
2296  }
2297  }
2298  return true;
2299  }
2300 
2306  public function isVirtual()
2307  {
2308  $isVirtual = true;
2309  $countItems = 0;
2310  foreach ($this->getItemsCollection() as $_item) {
2311  /* @var $_item \Magento\Quote\Model\Quote\Item */
2312  if ($_item->isDeleted() || $_item->getParentItemId()) {
2313  continue;
2314  }
2315  $countItems++;
2316  if (!$_item->getProduct()->getIsVirtual()) {
2317  $isVirtual = false;
2318  break;
2319  }
2320  }
2321  return $countItems == 0 ? false : $isVirtual;
2322  }
2323 
2330  public function getIsVirtual()
2331  {
2332  return intval($this->isVirtual());
2333  }
2334 
2340  public function hasVirtualItems()
2341  {
2342  $hasVirtual = false;
2343  foreach ($this->getItemsCollection() as $item) {
2344  if ($item->getParentItemId()) {
2345  continue;
2346  }
2347  if ($item->getProduct()->isVirtual()) {
2348  $hasVirtual = true;
2349  }
2350  }
2351  return $hasVirtual;
2352  }
2353 
2360  public function merge(Quote $quote)
2361  {
2362  $this->_eventManager->dispatch(
2363  $this->_eventPrefix . '_merge_before',
2364  [$this->_eventObject => $this, 'source' => $quote]
2365  );
2366 
2367  foreach ($quote->getAllVisibleItems() as $item) {
2368  $found = false;
2369  foreach ($this->getAllItems() as $quoteItem) {
2370  if ($quoteItem->compare($item)) {
2371  $quoteItem->setQty($quoteItem->getQty() + $item->getQty());
2372  $this->itemProcessor->merge($item, $quoteItem);
2373  $found = true;
2374  break;
2375  }
2376  }
2377 
2378  if (!$found) {
2379  $newItem = clone $item;
2380  $this->addItem($newItem);
2381  if ($item->getHasChildren()) {
2382  foreach ($item->getChildren() as $child) {
2383  $newChild = clone $child;
2384  $newChild->setParentItem($newItem);
2385  $this->addItem($newChild);
2386  }
2387  }
2388  }
2389  }
2390 
2394  if (!$this->getId()) {
2395  $this->getShippingAddress();
2396  $this->getBillingAddress();
2397  }
2398 
2399  if ($quote->getCouponCode()) {
2400  $this->setCouponCode($quote->getCouponCode());
2401  }
2402 
2403  $this->_eventManager->dispatch(
2404  $this->_eventPrefix . '_merge_after',
2405  [$this->_eventObject => $this, 'source' => $quote]
2406  );
2407 
2408  return $this;
2409  }
2410 
2416  protected function _afterLoad()
2417  {
2418  // collect totals and save me, if required
2419  if (1 == $this->getTriggerRecollect()) {
2420  $this->collectTotals()
2421  ->setTriggerRecollect(0)
2422  ->save();
2423  }
2424  return parent::_afterLoad();
2425  }
2426 
2432  public function addressCollectionWasSet()
2433  {
2434  return null !== $this->_addresses;
2435  }
2436 
2442  public function itemsCollectionWasSet()
2443  {
2444  return null !== $this->_items;
2445  }
2446 
2452  public function paymentsCollectionWasSet()
2453  {
2454  return null !== $this->_payments;
2455  }
2456 
2462  public function currentPaymentWasSet()
2463  {
2464  return null !== $this->_currentPayment;
2465  }
2466 
2473  public function getCheckoutMethod($originalMethod = false)
2474  {
2475  if ($this->getCustomerId() && !$originalMethod) {
2476  return self::CHECKOUT_METHOD_LOGIN_IN;
2477  }
2478  return $this->_getData(self::KEY_CHECKOUT_METHOD);
2479  }
2480 
2486  public function getShippingAddressesItems()
2487  {
2488  if ($this->shippingAddressesItems !== null) {
2489  return $this->shippingAddressesItems;
2490  }
2491  $items = [];
2492  $addresses = $this->getAllAddresses();
2493  foreach ($addresses as $address) {
2494  foreach ($address->getAllItems() as $item) {
2495  if ($item->getParentItemId()) {
2496  continue;
2497  }
2498  if ($item->getProduct()->getIsVirtual()) {
2499  $items[] = $item;
2500  continue;
2501  }
2502  if ($item->getQty() > 1) {
2503  for ($itemIndex = 0, $itemQty = $item->getQty(); $itemIndex < $itemQty; $itemIndex++) {
2504  if ($itemIndex == 0) {
2505  $addressItem = $item;
2506  } else {
2507  $addressItem = clone $item;
2508  }
2509  $addressItem->setQty(1)->setCustomerAddressId($address->getCustomerAddressId())->save();
2510  $items[] = $addressItem;
2511  }
2512  } else {
2513  $item->setCustomerAddressId($address->getCustomerAddressId());
2514  $items[] = $item;
2515  }
2516  }
2517  }
2518  $this->shippingAddressesItems = $items;
2519  return $items;
2520  }
2521 
2530  public function setCheckoutMethod($checkoutMethod)
2531  {
2532  return $this->setData(self::KEY_CHECKOUT_METHOD, $checkoutMethod);
2533  }
2534 
2542  public function preventSaving()
2543  {
2544  $this->_preventSaving = true;
2545  return $this;
2546  }
2547 
2555  public function isPreventSaving()
2556  {
2557  return $this->_preventSaving;
2558  }
2559 
2566  {
2567  return \count($this->getAllShippingAddresses()) > 1;
2568  }
2569 
2575  public function getExtensionAttributes()
2576  {
2577  return $this->_getExtensionAttributes();
2578  }
2579 
2586  public function setExtensionAttributes(\Magento\Quote\Api\Data\CartExtensionInterface $extensionAttributes)
2587  {
2589  }
2590 }
$old
Definition: website.php:27
$addressRepository
setIsVirtual($isVirtual)
Definition: Quote.php:620
setReservedOrderId($reservedOrderId)
Definition: Quote.php:684
$groupRepository
merge(Quote $quote)
Definition: Quote.php:2360
addMessage($message, $index='error')
Definition: Quote.php:2008
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$billingAddress
Definition: order.php:25
$customer
Definition: customers.php:11
addErrorInfo( $type='error', $origin=null, $code=null, $message=null, $additionalData=null)
Definition: Quote.php:2113
return false
Definition: gallery.phtml:36
setOrigOrderId($origOrderId)
Definition: Quote.php:668
setCustomer(\Magento\Customer\Api\Data\CustomerInterface $customer=null)
Definition: Quote.php:974
$config
Definition: fraud_order.php:17
$id
Definition: fieldset.phtml:14
setIsActive($isActive)
Definition: Quote.php:612
setCheckoutMethod($checkoutMethod)
Definition: Quote.php:2530
setShippingAddress(\Magento\Quote\Api\Data\AddressInterface $address=null)
Definition: Quote.php:1344
setCustomerNote($customerNote)
Definition: Quote.php:716
$addresses
Definition: address_list.php:7
addProduct(\Magento\Catalog\Model\Product $product, $request=null, $processMode=\Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL)
Definition: Quote.php:1598
removeErrorInfosByParams($type, $params)
Definition: Quote.php:2144
const CHECKOUT_METHOD_LOGIN_IN
Definition: Quote.php:112
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
$quote
deleteItem(\Magento\Quote\Model\Quote\Item $item)
Definition: Quote.php:1495
$shippingAddress
Definition: order.php:40
getItemByProduct($product)
Definition: Quote.php:1813
getAddressById($addressId)
Definition: Quote.php:1204
$storeManager
addPayment(PaymentInterface $payment)
Definition: Quote.php:1937
setItemsQty($itemsQty)
Definition: Quote.php:652
__()
Definition: __.php:13
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
$resource
Definition: bulk.php:12
getAddressByCustomerAddressId($addressId)
Definition: Quote.php:1220
$message
getItemsCollection($useCache=true)
Definition: Quote.php:1380
setPayment(PaymentInterface $payment)
Definition: Quote.php:1952
$customerRepository
$address
Definition: customer.php:38
$amount
Definition: order.php:14
$payment
Definition: order.php:17
$type
Definition: item.phtml:13
assignCustomer(\Magento\Customer\Api\Data\CustomerInterface $customer)
Definition: Quote.php:911
setExtensionAttributes(\Magento\Quote\Api\Data\CartExtensionInterface $extensionAttributes)
Definition: Quote.php:2586
getCheckoutMethod($originalMethod=false)
Definition: Quote.php:2473
$_item
Definition: default.phtml:11
removeMessageByText($type, $text)
Definition: Quote.php:2187
addItem(\Magento\Quote\Model\Quote\Item $item)
Definition: Quote.php:1577
setCreatedAt($createdAt)
Definition: Quote.php:564
setCurrency(\Magento\Quote\Api\Data\CurrencyInterface $currency=null)
Definition: Quote.php:532
$quoteItem
Definition: quote.php:38
hasProductId($productId)
Definition: Quote.php:1461
updateItem($itemId, $buyRequest, $params=null)
Definition: Quote.php:1750
setItemsCount($itemsCount)
Definition: Quote.php:636
addCustomerAddress(\Magento\Customer\Api\Data\AddressInterface $address)
Definition: Quote.php:1042
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Quote\Model\QuoteValidator $quoteValidator, \Magento\Catalog\Helper\Product $catalogProduct, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Quote\Model\Quote\AddressFactory $quoteAddressFactory, \Magento\Customer\Model\CustomerFactory $customerFactory, \Magento\Customer\Api\GroupRepositoryInterface $groupRepository, \Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory $quoteItemCollectionFactory, \Magento\Quote\Model\Quote\ItemFactory $quoteItemFactory, \Magento\Framework\Message\Factory $messageFactory, \Magento\Sales\Model\Status\ListFactory $statusListFactory, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Quote\Model\Quote\PaymentFactory $quotePaymentFactory, \Magento\Quote\Model\ResourceModel\Quote\Payment\CollectionFactory $quotePaymentCollectionFactory, \Magento\Framework\DataObject\Copy $objectCopyService, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, \Magento\Quote\Model\Quote\Item\Processor $itemProcessor, \Magento\Framework\DataObject\Factory $objectFactory, \Magento\Customer\Api\AddressRepositoryInterface $addressRepository, \Magento\Framework\Api\SearchCriteriaBuilder $criteriaBuilder, \Magento\Framework\Api\FilterBuilder $filterBuilder, \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory, \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerDataFactory, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter, \Magento\Quote\Model\Cart\CurrencyFactory $currencyFactory, JoinProcessorInterface $extensionAttributesJoinProcessor, Quote\TotalsCollector $totalsCollector, Quote\TotalsReader $totalsReader, \Magento\Quote\Model\ShippingFactory $shippingFactory, \Magento\Quote\Model\ShippingAssignmentFactory $shippingAssignmentFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], \Magento\Sales\Model\OrderIncrementIdChecker $orderIncrementIdChecker=null)
Definition: Quote.php:406
loadByIdWithoutStore($quoteId)
Definition: Quote.php:898
setCustomerIsGuest($customerIsGuest)
Definition: Quote.php:700
$extensionAttributes
Definition: payment.php:22
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest
loadByCustomer($customer)
Definition: Quote.php:866
addAddress(\Magento\Quote\Api\Data\AddressInterface $address)
Definition: Quote.php:1310
setItems(array $items=null)
Definition: Quote.php:548
$children
Definition: actions.phtml:11
setCustomerAddressData(array $addresses)
Definition: Quote.php:1023
setCustomerNoteNotify($customerNoteNotify)
Definition: Quote.php:732
setBillingAddress(\Magento\Quote\Api\Data\AddressInterface $address=null)
Definition: Quote.php:1325
updateCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
Definition: Quote.php:1057
addShippingAddress(\Magento\Quote\Api\Data\AddressInterface $address)
Definition: Quote.php:1367
else addAddress
Definition: book.phtml:101
setCustomerTaxClassId($customerTaxClassId)
Definition: Quote.php:1103
setUpdatedAt($updatedAt)
Definition: Quote.php:580
$messageFactory
Definition: messages.php:10
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$_items
Definition: list.phtml:15
$index
Definition: list.phtml:44
$errors
Definition: overview.phtml:9
removeAddress($addressId)
Definition: Quote.php:1256
_addCatalogProduct(\Magento\Catalog\Model\Product $product, $qty=1)
Definition: Quote.php:1695
setConvertedAt($convertedAt)
Definition: Quote.php:596
setStore(\Magento\Store\Model\Store $store)
Definition: Quote.php:775
$code
Definition: info.phtml:12
$items