Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Quote Class Reference
Inheritance diagram for Quote:
AbstractExtensibleModel CartInterface AbstractModel CustomAttributesDataInterface ExtensibleDataInterface DataObject ExtensibleDataInterface

Public Member Functions

 __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)
 
 getCurrency ()
 
 setCurrency (\Magento\Quote\Api\Data\CurrencyInterface $currency=null)
 
 getItems ()
 
 setItems (array $items=null)
 
 getCreatedAt ()
 
 setCreatedAt ($createdAt)
 
 getUpdatedAt ()
 
 setUpdatedAt ($updatedAt)
 
 getConvertedAt ()
 
 setConvertedAt ($convertedAt)
 
 getIsActive ()
 
 setIsActive ($isActive)
 
 setIsVirtual ($isVirtual)
 
 getItemsCount ()
 
 setItemsCount ($itemsCount)
 
 getItemsQty ()
 
 setItemsQty ($itemsQty)
 
 getOrigOrderId ()
 
 setOrigOrderId ($origOrderId)
 
 getReservedOrderId ()
 
 setReservedOrderId ($reservedOrderId)
 
 getCustomerIsGuest ()
 
 setCustomerIsGuest ($customerIsGuest)
 
 getCustomerNote ()
 
 setCustomerNote ($customerNote)
 
 getCustomerNoteNotify ()
 
 setCustomerNoteNotify ($customerNoteNotify)
 
 getStoreId ()
 
 setStoreId ($storeId)
 
 getStore ()
 
 setStore (\Magento\Store\Model\Store $store)
 
 getSharedStoreIds ()
 
 beforeSave ()
 
 loadByCustomer ($customer)
 
 loadActive ($quoteId)
 
 loadByIdWithoutStore ($quoteId)
 
 assignCustomer (\Magento\Customer\Api\Data\CustomerInterface $customer)
 
 setCustomer (\Magento\Customer\Api\Data\CustomerInterface $customer=null)
 
 getCustomer ()
 
 setCustomerAddressData (array $addresses)
 
 addCustomerAddress (\Magento\Customer\Api\Data\AddressInterface $address)
 
 updateCustomerData (\Magento\Customer\Api\Data\CustomerInterface $customer)
 
 getCustomerGroupId ()
 
 getCustomerTaxClassId ()
 
 setCustomerTaxClassId ($customerTaxClassId)
 
 getAddressesCollection ()
 
 getBillingAddress ()
 
 getShippingAddress ()
 
 getAllShippingAddresses ()
 
 getAllAddresses ()
 
 getAddressById ($addressId)
 
 getAddressByCustomerAddressId ($addressId)
 
 removeAddress ($addressId)
 
 removeAllAddresses ()
 
 addAddress (\Magento\Quote\Api\Data\AddressInterface $address)
 
 setBillingAddress (\Magento\Quote\Api\Data\AddressInterface $address=null)
 
 setShippingAddress (\Magento\Quote\Api\Data\AddressInterface $address=null)
 
 addShippingAddress (\Magento\Quote\Api\Data\AddressInterface $address)
 
 getItemsCollection ($useCache=true)
 
 getAllVisibleItems ()
 
 hasItems ()
 
 hasItemsWithDecimalQty ()
 
 hasProductId ($productId)
 
 getItemById ($itemId)
 
 deleteItem (\Magento\Quote\Model\Quote\Item $item)
 
 removeItem ($itemId)
 
 removeAllItems ()
 
 addItem (\Magento\Quote\Model\Quote\Item $item)
 
 addProduct (\Magento\Catalog\Model\Product $product, $request=null, $processMode=\Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL)
 
 updateItem ($itemId, $buyRequest, $params=null)
 
 getItemByProduct ($product)
 
 getItemsSummaryQty ()
 
 getItemVirtualQty ()
 
 getPaymentsCollection ()
 
 getPayment ()
 
 setPayment (PaymentInterface $payment)
 
 removePayment ()
 
 collectTotals ()
 
 getTotals ()
 
 addMessage ($message, $index='error')
 
 getMessages ()
 
 getErrors ()
 
 setHasError ($flag)
 
 addErrorInfo ( $type='error', $origin=null, $code=null, $message=null, $additionalData=null)
 
 removeErrorInfosByParams ($type, $params)
 
 removeMessageByText ($type, $text)
 
 reserveOrderId ()
 
 isVirtual ()
 
 getIsVirtual ()
 
 hasVirtualItems ()
 
 merge (Quote $quote)
 
 addressCollectionWasSet ()
 
 itemsCollectionWasSet ()
 
 paymentsCollectionWasSet ()
 
 currentPaymentWasSet ()
 
 getCheckoutMethod ($originalMethod=false)
 
 getShippingAddressesItems ()
 
 setCheckoutMethod ($checkoutMethod)
 
 preventSaving ()
 
 isPreventSaving ()
 
 isMultipleShippingAddresses ()
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\Quote\Api\Data\CartExtensionInterface $extensionAttributes)
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from CartInterface
 getId ()
 
 setId ($id)
 
 setCustomer (\Magento\Customer\Api\Data\CustomerInterface $customer=null)
 
 setBillingAddress (\Magento\Quote\Api\Data\AddressInterface $billingAddress=null)
 
 setCurrency (\Magento\Quote\Api\Data\CurrencyInterface $currency=null)
 
 setExtensionAttributes (\Magento\Quote\Api\Data\CartExtensionInterface $extensionAttributes)
 

Data Fields

const CHECKOUT_METHOD_LOGIN_IN = 'login_in'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Data Fields inherited from CartInterface
const KEY_ID = 'id'
 
const KEY_ENTITY_ID = 'entity_id'
 
const KEY_CREATED_AT = 'created_at'
 
const KEY_UPDATED_AT = 'updated_at'
 
const KEY_CONVERTED_AT = 'converted_at'
 
const KEY_IS_ACTIVE = 'is_active'
 
const KEY_IS_VIRTUAL = 'is_virtual'
 
const KEY_ITEMS = 'items'
 
const KEY_ITEMS_COUNT = 'items_count'
 
const KEY_ITEMS_QTY = 'items_qty'
 
const KEY_CUSTOMER = 'customer'
 
const KEY_CHECKOUT_METHOD = 'checkout_method'
 
const KEY_SHIPPING_ADDRESS = 'shipping_address'
 
const KEY_BILLING_ADDRESS = 'billing_address'
 
const KEY_RESERVED_ORDER_ID = 'reserved_order_id'
 
const KEY_ORIG_ORDER_ID = 'orig_order_id'
 
const KEY_CURRENCY = 'currency'
 
const KEY_CUSTOMER_IS_GUEST = 'customer_is_guest'
 
const KEY_CUSTOMER_NOTE = 'customer_note'
 
const KEY_CUSTOMER_NOTE_NOTIFY = 'customer_note_notify'
 
const KEY_CUSTOMER_TAX_CLASS_ID = 'customer_tax_class_id'
 
const KEY_STORE_ID = 'store_id'
 

Protected Member Functions

 _construct ()
 
 _getAddressByType ($type)
 
 _addCatalogProduct (\Magento\Catalog\Model\Product $product, $qty=1)
 
 addPayment (PaymentInterface $payment)
 
 _setHasError ($flag)
 
 _clearErrorInfo ()
 
 _afterLoad ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_eventPrefix = 'sales_quote'
 
 $_eventObject = 'quote'
 
 $_customer
 
 $_addresses
 
 $_items
 
 $_payments
 
 $_currentPayment
 
 $_errorInfoGroups = []
 
 $_preventSaving = false
 
 $_catalogProduct
 
 $quoteValidator
 
 $_scopeConfig
 
 $_storeManager
 
 $_config
 
 $_quoteAddressFactory
 
 $_customerFactory
 
 $groupRepository
 
 $_quoteItemCollectionFactory
 
 $_quoteItemFactory
 
 $messageFactory
 
 $_statusListFactory
 
 $productRepository
 
 $_quotePaymentFactory
 
 $_quotePaymentCollectionFactory
 
 $_objectCopyService
 
 $addressRepository
 
 $searchCriteriaBuilder
 
 $filterBuilder
 
 $stockRegistry
 
 $itemProcessor
 
 $objectFactory
 
 $extensibleDataObjectConverter
 
 $addressDataFactory
 
 $customerDataFactory
 
 $customerRepository
 
 $currencyFactory
 
 $dataObjectHelper
 
 $extensionAttributesJoinProcessor
 
 $totalsCollector
 
 $totalsReader
 
 $shippingFactory
 
 $shippingAssignmentFactory
 
 $shippingAddressesItems
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Quote model

Supported events: sales_quote_load_after sales_quote_save_before sales_quote_save_after sales_quote_delete_before sales_quote_delete_after

@api @method int getIsMultiShipping() @method Quote setIsMultiShipping(int $value) @method float getStoreToBaseRate() @method Quote setStoreToBaseRate(float $value) @method float getStoreToQuoteRate() @method Quote setStoreToQuoteRate(float $value) @method string getBaseCurrencyCode() @method Quote setBaseCurrencyCode(string $value) @method string getStoreCurrencyCode() @method Quote setStoreCurrencyCode(string $value) @method string getQuoteCurrencyCode() @method Quote setQuoteCurrencyCode(string $value) @method float getGrandTotal() @method Quote setGrandTotal(float $value) @method float getBaseGrandTotal() @method Quote setBaseGrandTotal(float $value) @method int getCustomerId() @method Quote setCustomerId(int $value) @method Quote setCustomerGroupId(int $value) @method string getCustomerEmail() @method Quote setCustomerEmail(string $value) @method string getCustomerPrefix() @method Quote setCustomerPrefix(string $value) @method string getCustomerFirstname() @method Quote setCustomerFirstname(string $value) @method string getCustomerMiddlename() @method Quote setCustomerMiddlename(string $value) @method string getCustomerLastname() @method Quote setCustomerLastname(string $value) @method string getCustomerSuffix() @method Quote setCustomerSuffix(string $value) @method string getCustomerDob() @method Quote setCustomerDob(string $value) @method string getRemoteIp() @method Quote setRemoteIp(string $value) @method string getAppliedRuleIds() @method Quote setAppliedRuleIds(string $value) @method string getPasswordHash() @method Quote setPasswordHash(string $value) @method string getCouponCode() @method Quote setCouponCode(string $value) @method string getGlobalCurrencyCode() @method Quote setGlobalCurrencyCode(string $value) @method float getBaseToGlobalRate() @method Quote setBaseToGlobalRate(float $value) @method float getBaseToQuoteRate() @method Quote setBaseToQuoteRate(float $value) @method string getCustomerTaxvat() @method Quote setCustomerTaxvat(string $value) @method string getCustomerGender() @method Quote setCustomerGender(string $value) @method float getSubtotal() @method Quote setSubtotal(float $value) @method float getBaseSubtotal() @method Quote setBaseSubtotal(float $value) @method float getSubtotalWithDiscount() @method Quote setSubtotalWithDiscount(float $value) @method float getBaseSubtotalWithDiscount() @method Quote setBaseSubtotalWithDiscount(float $value) @method int getIsChanged() @method Quote setIsChanged(int $value) @method int getTriggerRecollect() @method Quote setTriggerRecollect(int $value) @method string getExtShippingInfo() @method Quote setExtShippingInfo(string $value) @method int getGiftMessageId() @method Quote setGiftMessageId(int $value) @method bool|null getIsPersistent() @method Quote setIsPersistent(bool $value) @method Quote setSharedStoreIds(array $values) @method Quote setWebsite($value) @SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 107 of file Quote.php.

Constructor & Destructor Documentation

◆ __construct()

__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 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Api\ExtensionAttributesFactory$extensionFactory
AttributeValueFactory$customAttributeFactory
QuoteValidator$quoteValidator
\Magento\Catalog\Helper\Product$catalogProduct
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\App\Config\ScopeConfigInterface$config
Quote\AddressFactory$quoteAddressFactory
\Magento\Customer\Model\CustomerFactory$customerFactory
\Magento\Customer\Api\GroupRepositoryInterface$groupRepository
\Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory$quoteItemCollectionFactory
Quote\ItemFactory$quoteItemFactory
\Magento\Framework\Message\Factory$messageFactory
Status\ListFactory$statusListFactory
\Magento\Catalog\Api\ProductRepositoryInterface$productRepository
Quote\PaymentFactory$quotePaymentFactory
\Magento\Quote\Model\ResourceModel\Quote\Payment\CollectionFactory$quotePaymentCollectionFactory
\Magento\Framework\DataObject\Copy$objectCopyService
\Magento\CatalogInventory\Api\StockRegistryInterface$stockRegistry
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
Cart\CurrencyFactory$currencyFactory
JoinProcessorInterface$extensionAttributesJoinProcessor
Quote\TotalsCollector$totalsCollector
Quote\TotalsReader$totalsReader
ShippingFactory$shippingFactory
ShippingAssignmentFactory$shippingAssignmentFactory
\Magento\Framework\Model\ResourceModel\AbstractResource | null$resource
\Magento\Framework\Data\Collection\AbstractDb | null$resourceCollection
array$data
\Magento\Sales\Model\OrderIncrementIdChecker | null$orderIncrementIdChecker@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 406 of file Quote.php.

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  }
$addressRepository
$groupRepository
$config
Definition: fraud_order.php:17
$storeManager
$resource
Definition: bulk.php:12
$customerRepository
$messageFactory
Definition: messages.php:10

Member Function Documentation

◆ _addCatalogProduct()

_addCatalogProduct ( \Magento\Catalog\Model\Product  $product,
  $qty = 1 
)
protected

Adding catalog product object data to quote

Parameters
\Magento\Catalog\Model\Product$product
int$qty
Returns
\Magento\Quote\Model\Quote\Item @SuppressWarnings(PHPMD.UnusedFormalParameter)

We can't modify existing child items

Definition at line 1695 of file Quote.php.

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  }
getItemByProduct($product)
Definition: Quote.php:1813
addItem(\Magento\Quote\Model\Quote\Item $item)
Definition: Quote.php:1577

◆ _afterLoad()

_afterLoad ( )
protected

Trigger collect totals after loading, if required

Returns
$this

Definition at line 2416 of file Quote.php.

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  }

◆ _clearErrorInfo()

_clearErrorInfo ( )
protected

Clears list of errors, associated with this quote. Also automatically removes error-flag from oneself.

Returns
$this

Definition at line 2096 of file Quote.php.

2097  {
2098  $this->_errorInfoGroups = [];
2099  $this->_setHasError(false);
2100  return $this;
2101  }

◆ _construct()

_construct ( )
protected

Init resource model

Returns
void

Definition at line 500 of file Quote.php.

501  {
502  $this->_init(\Magento\Quote\Model\ResourceModel\Quote::class);
503  }

◆ _getAddressByType()

_getAddressByType (   $type)
protected

Retrieve quote address by type

Parameters
string$type
Returns
Address

Definition at line 1133 of file Quote.php.

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  }
$address
Definition: customer.php:38
$type
Definition: item.phtml:13
else addAddress
Definition: book.phtml:101

◆ _setHasError()

_setHasError (   $flag)
protected

Sets flag, whether this quote has some error associated with it.

@codeCoverageIgnore

Parameters
bool$flag
Returns
$this

Definition at line 2066 of file Quote.php.

2067  {
2068  return $this->setData('has_error', $flag);
2069  }

◆ addAddress()

addAddress ( \Magento\Quote\Api\Data\AddressInterface  $address)

Add address.

Parameters
\Magento\Quote\Api\Data\AddressInterface$address
Returns
$this

Definition at line 1310 of file Quote.php.

1311  {
1312  $address->setQuote($this);
1313  if (!$address->getId()) {
1314  $this->getAddressesCollection()->addItem($address);
1315  }
1316  return $this;
1317  }
$address
Definition: customer.php:38

◆ addCustomerAddress()

addCustomerAddress ( \Magento\Customer\Api\Data\AddressInterface  $address)

Add address to the customer, created out of a Data Object

TODO refactor in scope of MAGETWO-19930

Parameters
\Magento\Customer\Api\Data\AddressInterface$address
Returns
$this

Definition at line 1042 of file Quote.php.

1043  {
1044  $addresses = (array)$this->getCustomer()->getAddresses();
1045  $addresses[] = $address;
1046  $this->getCustomer()->setAddresses($addresses);
1047  $this->updateCustomerData($this->getCustomer());
1048  return $this;
1049  }
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38
updateCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
Definition: Quote.php:1057

◆ addErrorInfo()

addErrorInfo (   $type = 'error',
  $origin = null,
  $code = null,
  $message = null,
  $additionalData = null 
)

Adds error information to the quote. Automatically sets error flag.

Parameters
string$typeAn internal error type ('error', 'qty', etc.), passed then to adding messages routine
string | null$originUsually a name of module, that embeds error
int | null$codeError code, unique for origin, that sets it
string | null$messageError message
\Magento\Framework\DataObject | null$additionalDataAny additional data, that caller would like to store
Returns
$this

Definition at line 2113 of file Quote.php.

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  }
addMessage($message, $index='error')
Definition: Quote.php:2008
$message
$type
Definition: item.phtml:13
$code
Definition: info.phtml:12

◆ addItem()

addItem ( \Magento\Quote\Model\Quote\Item  $item)

Adding new item to quote

Parameters
\Magento\Quote\Model\Quote\Item$item
Returns
$this
Exceptions

Definition at line 1577 of file Quote.php.

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  }
getItemsCollection($useCache=true)
Definition: Quote.php:1380

◆ addMessage()

addMessage (   $message,
  $index = 'error' 
)

Add message.

Parameters
string$message
string$index
Returns
$this

Definition at line 2008 of file Quote.php.

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  }
$message
$index
Definition: list.phtml:44

◆ addPayment()

addPayment ( PaymentInterface  $payment)
protected

Adds a payment to quote

Parameters
PaymentInterface$payment
Returns
$this

Definition at line 1937 of file Quote.php.

1938  {
1939  $payment->setQuote($this);
1940  if (!$payment->getId()) {
1941  $this->getPaymentsCollection()->addItem($payment);
1942  }
1943  return $this;
1944  }
$payment
Definition: order.php:17

◆ addProduct()

addProduct ( \Magento\Catalog\Model\Product  $product,
  $request = null,
  $processMode = \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL 
)

Add product. Returns error message if product type instance can't prepare product.

Parameters
mixed$product
null | float | \Magento\Framework\DataObject$request
null | string$processMode
Returns
\Magento\Quote\Model\Quote\Item|string
Exceptions

Error message

If prepare process return one object

As parent item we should always use the item of first added product

Definition at line 1598 of file Quote.php.

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  }
getItemByProduct($product)
Definition: Quote.php:1813
__()
Definition: __.php:13
$message
addItem(\Magento\Quote\Model\Quote\Item $item)
Definition: Quote.php:1577
$errors
Definition: overview.phtml:9
$items

◆ addressCollectionWasSet()

addressCollectionWasSet ( )

Checks if it was set

Returns
bool

Definition at line 2432 of file Quote.php.

2433  {
2434  return null !== $this->_addresses;
2435  }

◆ addShippingAddress()

addShippingAddress ( \Magento\Quote\Api\Data\AddressInterface  $address)

Add shipping address.

Parameters
\Magento\Quote\Api\Data\AddressInterface$address
Returns
$this

Definition at line 1367 of file Quote.php.

1368  {
1369  $this->setShippingAddress($address);
1370  return $this;
1371  }
setShippingAddress(\Magento\Quote\Api\Data\AddressInterface $address=null)
Definition: Quote.php:1344
$address
Definition: customer.php:38

◆ assignCustomer()

assignCustomer ( \Magento\Customer\Api\Data\CustomerInterface  $customer)

Assign customer model object data to quote

Parameters
\Magento\Customer\Api\Data\CustomerInterface$customer
Returns
$this

Definition at line 911 of file Quote.php.

912  {
913  return $this->assignCustomerWithAddressChange($customer);
914  }
$customer
Definition: customers.php:11

◆ beforeSave()

beforeSave ( )

Prepare data before save

Returns
$this

Currency logic

global - currency which is set for default in backend base - currency which is set for current website. all attributes that have 'base_' prefix saved in this currency quote/order - currency which was selected by customer or configured by admin for current store. currency in which customer sees price thought all checkout.

Rates: base_to_global & base_to_quote/base_to_order

Definition at line 804 of file Quote.php.

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  }
setIsVirtual($isVirtual)
Definition: Quote.php:620
setUpdatedAt($updatedAt)
Definition: Quote.php:580

◆ collectTotals()

collectTotals ( )

Collect totals

Returns
$this

Definition at line 1978 of file Quote.php.

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  }

◆ currentPaymentWasSet()

currentPaymentWasSet ( )

Checks if it was set

Returns
bool

Definition at line 2462 of file Quote.php.

2463  {
2464  return null !== $this->_currentPayment;
2465  }

◆ deleteItem()

deleteItem ( \Magento\Quote\Model\Quote\Item  $item)

Delete quote item. If it does not have identifier then it will be only removed from collection

Parameters
\Magento\Quote\Model\Quote\Item$item
Returns
$this

Definition at line 1495 of file Quote.php.

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  }
getItemsCollection($useCache=true)
Definition: Quote.php:1380
$quoteItem
Definition: quote.php:38
$items

◆ getAddressByCustomerAddressId()

getAddressByCustomerAddressId (   $addressId)

Get address by customer address id.

Parameters
int | string$addressId
Returns
Address|false

Definition at line 1220 of file Quote.php.

1221  {
1222  foreach ($this->getAddressesCollection() as $address) {
1223  if (!$address->isDeleted() && $address->getCustomerAddressId() == $addressId) {
1224  return $address;
1225  }
1226  }
1227  return false;
1228  }
$address
Definition: customer.php:38

◆ getAddressById()

getAddressById (   $addressId)

Get address by id.

Parameters
int$addressId
Returns
Address|false

Definition at line 1204 of file Quote.php.

1205  {
1206  foreach ($this->getAddressesCollection() as $address) {
1207  if ($address->getId() == $addressId) {
1208  return $address;
1209  }
1210  }
1211  return false;
1212  }
$address
Definition: customer.php:38

◆ getAddressesCollection()

getAddressesCollection ( )

Retrieve quote address collection

Returns
\Magento\Eav\Model\Entity\Collection\AbstractCollection

Definition at line 1113 of file Quote.php.

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  }
$address
Definition: customer.php:38

◆ getAllAddresses()

getAllAddresses ( )

Get all quote addresses

Returns
\Magento\Quote\Model\Quote\Address[]

Definition at line 1187 of file Quote.php.

1188  {
1189  $addresses = [];
1190  foreach ($this->getAddressesCollection() as $address) {
1191  if (!$address->isDeleted()) {
1192  $addresses[] = $address;
1193  }
1194  }
1195  return $addresses;
1196  }
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38

◆ getAllShippingAddresses()

getAllShippingAddresses ( )

Get all shipping addresses.

Returns
array

Definition at line 1171 of file Quote.php.

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  }
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38

◆ getAllVisibleItems()

getAllVisibleItems ( )

Get array of all items what can be display directly

Returns
\Magento\Quote\Model\Quote\Item[]

Definition at line 1415 of file Quote.php.

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  }
getItemsCollection($useCache=true)
Definition: Quote.php:1380
$items

◆ getBillingAddress()

getBillingAddress ( )

Retrieve quote billing address

Returns
Address

Implements CartInterface.

Definition at line 1151 of file Quote.php.

◆ getCheckoutMethod()

getCheckoutMethod (   $originalMethod = false)

Return checkout method code

Parameters
boolean$originalMethodif true return defined method from beginning
Returns
string

Definition at line 2473 of file Quote.php.

2474  {
2475  if ($this->getCustomerId() && !$originalMethod) {
2476  return self::CHECKOUT_METHOD_LOGIN_IN;
2477  }
2478  return $this->_getData(self::KEY_CHECKOUT_METHOD);
2479  }

◆ getConvertedAt()

getConvertedAt ( )

Returns the cart conversion date and time.

Returns
string|null Cart conversion date and time. Otherwise, null.

Implements CartInterface.

Definition at line 588 of file Quote.php.

589  {
590  return $this->_getData(self::KEY_CONVERTED_AT);
591  }

◆ getCreatedAt()

getCreatedAt ( )

Returns the cart creation date and time.

Returns
string|null Cart creation date and time. Otherwise, null.

Implements CartInterface.

Definition at line 556 of file Quote.php.

557  {
558  return $this->_getData(self::KEY_CREATED_AT);
559  }

◆ getCurrency()

getCurrency ( )

Returns information about quote currency, such as code, exchange rate, and so on.

Returns
\Magento\Quote\Api\Data\CurrencyInterface|null Quote currency information. Otherwise, null. @codeCoverageIgnoreStart

Implements CartInterface.

Definition at line 511 of file Quote.php.

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  }

◆ getCustomer()

getCustomer ( )

Retrieve customer model object

Returns
\Magento\Customer\Api\Data\CustomerInterface|\Magento\Framework\Api\ExtensibleDataInterface

@TODO: Remove the method after all external usages are refactored in MAGETWO-19930 _customer and _customerFactory variables should be eliminated as well

Implements CartInterface.

Definition at line 999 of file Quote.php.

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  }

◆ getCustomerGroupId()

getCustomerGroupId ( )

Retrieve customer group id

Returns
int

Definition at line 1070 of file Quote.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ getCustomerIsGuest()

getCustomerIsGuest ( )

True for guest customers, false for logged in customers

Returns
bool|null

Implements CartInterface.

Definition at line 692 of file Quote.php.

693  {
694  return $this->_getData(self::KEY_CUSTOMER_IS_GUEST);
695  }

◆ getCustomerNote()

getCustomerNote ( )

Customer notice text

Returns
string|null

Implements CartInterface.

Definition at line 708 of file Quote.php.

709  {
710  return $this->_getData(self::KEY_CUSTOMER_NOTE);
711  }

◆ getCustomerNoteNotify()

getCustomerNoteNotify ( )

Send customer notification flag

Returns
bool|null

Implements CartInterface.

Definition at line 724 of file Quote.php.

725  {
726  return $this->_getData(self::KEY_CUSTOMER_NOTE_NOTIFY);
727  }

◆ getCustomerTaxClassId()

getCustomerTaxClassId ( )

Get customer tax class ID.

Returns
int|null

tax class can vary at any time. so instead of using the value from session, we need to retrieve from db every time to get the correct tax class

Implements CartInterface.

Definition at line 1084 of file Quote.php.

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  }
setCustomerTaxClassId($customerTaxClassId)
Definition: Quote.php:1103

◆ getErrors()

getErrors ( )

Retrieve current quote errors

Returns
array

Definition at line 2046 of file Quote.php.

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  }
$message
$errors
Definition: overview.phtml:9

◆ getExtensionAttributes()

getExtensionAttributes ( )

Retrieve existing extension attributes object or create a new one.

Returns
\Magento\Quote\Api\Data\CartExtensionInterface|null

Implements CartInterface.

Definition at line 2575 of file Quote.php.

◆ getIsActive()

getIsActive ( )

Determines whether the cart is still active.

Returns
bool|null Active status flag value. Otherwise, null.

Implements CartInterface.

Definition at line 604 of file Quote.php.

605  {
606  return $this->_getData(self::KEY_IS_ACTIVE);
607  }

◆ getIsVirtual()

getIsVirtual ( )

Check quote for virtual product only

Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Implements CartInterface.

Definition at line 2330 of file Quote.php.

2331  {
2332  return intval($this->isVirtual());
2333  }

◆ getItemById()

getItemById (   $itemId)

Retrieve item model object by item identifier

Parameters
int$itemId
Returns
\Magento\Quote\Model\Quote\Item|false

Definition at line 1478 of file Quote.php.

1479  {
1480  foreach ($this->getItemsCollection() as $item) {
1481  if ($item->getId() == $itemId) {
1482  return $item;
1483  }
1484  }
1485 
1486  return false;
1487  }
getItemsCollection($useCache=true)
Definition: Quote.php:1380

◆ getItemByProduct()

getItemByProduct (   $product)

Retrieve quote item by product id

Parameters
\Magento\Catalog\Model\Product$product
Returns
\Magento\Quote\Model\Quote\Item|bool

Definition at line 1813 of file Quote.php.

1814  {
1815  foreach ($this->getAllItems() as $item) {
1816  if ($item->representProduct($product)) {
1817  return $item;
1818  }
1819  }
1820  return false;
1821  }

◆ getItems()

getItems ( )

Lists items in the cart.

Returns
\Magento\Quote\Api\Data\CartItemInterface[]|null Array of items. Otherwise, null.

Implements CartInterface.

Definition at line 540 of file Quote.php.

541  {
542  return $this->_getData(self::KEY_ITEMS);
543  }

◆ getItemsCollection()

getItemsCollection (   $useCache = true)

Retrieve quote items collection

Parameters
bool$useCache
Returns
\Magento\Eav\Model\Entity\Collection\AbstractCollection @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 1380 of file Quote.php.

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  }
$_items
Definition: list.phtml:15

◆ getItemsCount()

getItemsCount ( )

Returns the number of different items or products in the cart.

Returns
int|null Number of different items or products in the cart. Otherwise, null.

Implements CartInterface.

Definition at line 628 of file Quote.php.

629  {
630  return $this->_getData(self::KEY_ITEMS_COUNT);
631  }

◆ getItemsQty()

getItemsQty ( )

Returns the total quantity of all cart items.

Returns
float|null Total quantity of all cart items. Otherwise, null.

Implements CartInterface.

Definition at line 644 of file Quote.php.

645  {
646  return $this->_getData(self::KEY_ITEMS_QTY);
647  }

◆ getItemsSummaryQty()

getItemsSummaryQty ( )

Get items summary qty.

Returns
int

Definition at line 1828 of file Quote.php.

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  }
$children
Definition: actions.phtml:11

◆ getItemVirtualQty()

getItemVirtualQty ( )

Get item virtual qty.

Returns
int

Definition at line 1857 of file Quote.php.

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  }
$children
Definition: actions.phtml:11

◆ getMessages()

getMessages ( )

Retrieve current quote messages

Returns
array

Definition at line 2031 of file Quote.php.

2032  {
2033  $messages = $this->getData('messages');
2034  if (null === $messages) {
2035  $messages = [];
2036  $this->setData('messages', $messages);
2037  }
2038  return $messages;
2039  }

◆ getOrigOrderId()

getOrigOrderId ( )

Returns the original order ID for the cart.

Returns
int|null Original order ID. Otherwise, null.

Implements CartInterface.

Definition at line 660 of file Quote.php.

661  {
662  return $this->_getData(self::KEY_ORIG_ORDER_ID);
663  }

◆ getPayment()

getPayment ( )

Get payment.

Returns
\Magento\Quote\Model\Quote\Payment

Definition at line 1911 of file Quote.php.

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  }
addPayment(PaymentInterface $payment)
Definition: Quote.php:1937
$payment
Definition: order.php:17

◆ getPaymentsCollection()

getPaymentsCollection ( )

Get payments collection.

Returns
\Magento\Eav\Model\Entity\Collection\AbstractCollection

Definition at line 1892 of file Quote.php.

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  }
$payment
Definition: order.php:17

◆ getReservedOrderId()

getReservedOrderId ( )

Returns the reserved order ID for the cart.

Returns
int|null Reserved order ID. Otherwise, null.

Implements CartInterface.

Definition at line 676 of file Quote.php.

677  {
678  return $this->_getData(self::KEY_RESERVED_ORDER_ID);
679  }

◆ getSharedStoreIds()

getSharedStoreIds ( )

Get all available store ids for quote

Returns
array

Definition at line 786 of file Quote.php.

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  }

◆ getShippingAddress()

getShippingAddress ( )

Retrieve quote shipping address

Returns
Address

Definition at line 1161 of file Quote.php.

◆ getShippingAddressesItems()

getShippingAddressesItems ( )

Get quote items assigned to different quote addresses populated per item qty.

Returns
array

Definition at line 2486 of file Quote.php.

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  }
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38
$items

◆ getStore()

getStore ( )

Get quote store model object

Returns
\Magento\Store\Model\Store

Definition at line 764 of file Quote.php.

765  {
766  return $this->_storeManager->getStore($this->getStoreId());
767  }

◆ getStoreId()

getStoreId ( )

Get store identifier

Returns
int

Implements CartInterface.

Definition at line 742 of file Quote.php.

743  {
744  if (!$this->hasStoreId()) {
745  return $this->_storeManager->getStore()->getId();
746  }
747  return (int)$this->_getData(self::KEY_STORE_ID);
748  }

◆ getTotals()

getTotals ( )

Get all quote totals (sorted by priority)

Returns
AddressTotal[]

Definition at line 1996 of file Quote.php.

1997  {
1998  return $this->totalsReader->fetch($this, $this->getData());
1999  }

◆ getUpdatedAt()

getUpdatedAt ( )

Returns the cart last update date and time.

Returns
string|null Cart last update date and time. Otherwise, null.

Implements CartInterface.

Definition at line 572 of file Quote.php.

573  {
574  return $this->_getData(self::KEY_UPDATED_AT);
575  }

◆ hasItems()

hasItems ( )

Checking items availability

Returns
bool

Definition at line 1431 of file Quote.php.

1432  {
1433  return sizeof($this->getAllItems()) > 0;
1434  }

◆ hasItemsWithDecimalQty()

hasItemsWithDecimalQty ( )

Checking availability of items with decimal qty

Returns
bool

Definition at line 1441 of file Quote.php.

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  }

◆ hasProductId()

hasProductId (   $productId)

Checking product exist in Quote

Parameters
int$productId
Returns
bool

Definition at line 1461 of file Quote.php.

1462  {
1463  foreach ($this->getAllItems() as $item) {
1464  if ($item->getProductId() == $productId) {
1465  return true;
1466  }
1467  }
1468 
1469  return false;
1470  }

◆ hasVirtualItems()

hasVirtualItems ( )

Has a virtual products on quote

Returns
bool

Definition at line 2340 of file Quote.php.

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  }
getItemsCollection($useCache=true)
Definition: Quote.php:1380

◆ isMultipleShippingAddresses()

isMultipleShippingAddresses ( )

Check if there are more than one shipping address

Returns
bool

Definition at line 2565 of file Quote.php.

2566  {
2567  return \count($this->getAllShippingAddresses()) > 1;
2568  }

◆ isPreventSaving()

isPreventSaving ( )

Check if model can be saved

@codeCoverageIgnore

Returns
bool

Definition at line 2555 of file Quote.php.

2556  {
2557  return $this->_preventSaving;
2558  }

◆ isVirtual()

isVirtual ( )

Check quote for virtual product only

Returns
bool

Definition at line 2306 of file Quote.php.

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  }
return false
Definition: gallery.phtml:36
getItemsCollection($useCache=true)
Definition: Quote.php:1380
$_item
Definition: default.phtml:11

◆ itemsCollectionWasSet()

itemsCollectionWasSet ( )

Checks if it was set

Returns
bool

Definition at line 2442 of file Quote.php.

2443  {
2444  return null !== $this->_items;
2445  }
$_items
Definition: list.phtml:15

◆ loadActive()

loadActive (   $quoteId)

Loading only active quote

Parameters
int$quoteId
Returns
$this

Definition at line 885 of file Quote.php.

886  {
887  $this->_getResource()->loadActive($this, $quoteId);
888  $this->_afterLoad();
889  return $this;
890  }

◆ loadByCustomer()

loadByCustomer (   $customer)

Loading quote data by customer

Parameters
\Magento\Customer\Model\Customer | int$customer
Deprecated:
101.0.0
Returns
$this

Definition at line 866 of file Quote.php.

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  }
$customer
Definition: customers.php:11

◆ loadByIdWithoutStore()

loadByIdWithoutStore (   $quoteId)

Loading quote by identifier

Parameters
int$quoteId
Returns
$this

Definition at line 898 of file Quote.php.

899  {
900  $this->_getResource()->loadByIdWithoutStore($this, $quoteId);
901  $this->_afterLoad();
902  return $this;
903  }

◆ merge()

merge ( Quote  $quote)

Merge quotes

Parameters
Quote$quote
Returns
$this

Init shipping and billing address if quote is new

Definition at line 2360 of file Quote.php.

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  }
$quote
addItem(\Magento\Quote\Model\Quote\Item $item)
Definition: Quote.php:1577
$quoteItem
Definition: quote.php:38

◆ paymentsCollectionWasSet()

paymentsCollectionWasSet ( )

Checks if it was set

Returns
bool

Definition at line 2452 of file Quote.php.

2453  {
2454  return null !== $this->_payments;
2455  }

◆ preventSaving()

preventSaving ( )

Prevent quote from saving

@codeCoverageIgnore

Returns
$this

Definition at line 2542 of file Quote.php.

2543  {
2544  $this->_preventSaving = true;
2545  return $this;
2546  }

◆ removeAddress()

removeAddress (   $addressId)

Remove address.

Parameters
int | string$addressId
Returns
$this

Definition at line 1256 of file Quote.php.

1257  {
1258  foreach ($this->getAddressesCollection() as $address) {
1259  if ($address->getId() == $addressId) {
1260  $address->isDeleted(true);
1261  break;
1262  }
1263  }
1264  return $this;
1265  }
$address
Definition: customer.php:38

◆ removeAllAddresses()

removeAllAddresses ( )

Leave no more than one billing and one shipping address, fill them with default data

Returns
$this

Definition at line 1272 of file Quote.php.

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  }
$id
Definition: fieldset.phtml:14
$address
Definition: customer.php:38
$type
Definition: item.phtml:13

◆ removeAllItems()

removeAllItems ( )

Mark all quote items as deleted (empty quote)

Returns
$this

Definition at line 1558 of file Quote.php.

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  }
getItemsCollection($useCache=true)
Definition: Quote.php:1380

◆ removeErrorInfosByParams()

removeErrorInfosByParams (   $type,
  $params 
)

Removes error infos, that have parameters equal to passed in $params. $params can have following keys (if not set - then any item is good for this key): 'origin', 'code', 'message'

Parameters
string$typeAn internal error type ('error', 'qty', etc.), passed then to adding messages routine
array$params
Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 2144 of file Quote.php.

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  }
$type
Definition: item.phtml:13
removeMessageByText($type, $text)
Definition: Quote.php:2187
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ removeItem()

removeItem (   $itemId)

Remove quote item by item identifier

Parameters
int$itemId
Returns
$this

If we remove item from quote - we can't use multishipping mode

Definition at line 1525 of file Quote.php.

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  }

◆ removeMessageByText()

removeMessageByText (   $type,
  $text 
)

Removes message by text

Parameters
string$type
string$text
Returns
$this

Definition at line 2187 of file Quote.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
$message
$type
Definition: item.phtml:13

◆ removePayment()

removePayment ( )

Remove payment.

Returns
$this

Definition at line 1967 of file Quote.php.

1968  {
1969  $this->getPayment()->isDeleted(true);
1970  return $this;
1971  }

◆ reserveOrderId()

reserveOrderId ( )

Generate new increment order id and associate it with current quote

Returns
$this

Definition at line 2216 of file Quote.php.

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  }
setReservedOrderId($reservedOrderId)
Definition: Quote.php:684

◆ setBillingAddress()

setBillingAddress ( \Magento\Quote\Api\Data\AddressInterface  $address = null)

Set billing address.

Parameters
\Magento\Quote\Api\Data\AddressInterface$address
Returns
$this

Definition at line 1325 of file Quote.php.

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  }
$old
Definition: website.php:27
$address
Definition: customer.php:38
else addAddress
Definition: book.phtml:101

◆ setCheckoutMethod()

setCheckoutMethod (   $checkoutMethod)

Sets the payment method that is used to process the cart.

@codeCoverageIgnore

Parameters
string$checkoutMethod
Returns
$this

Definition at line 2530 of file Quote.php.

2531  {
2532  return $this->setData(self::KEY_CHECKOUT_METHOD, $checkoutMethod);
2533  }

◆ setConvertedAt()

setConvertedAt (   $convertedAt)

Sets the cart conversion date and time.

Parameters
string$convertedAt
Returns
$this

Implements CartInterface.

Definition at line 596 of file Quote.php.

597  {
598  return $this->setData(self::KEY_CONVERTED_AT, $convertedAt);
599  }

◆ setCreatedAt()

setCreatedAt (   $createdAt)

Sets the cart creation date and time.

Parameters
string$createdAt
Returns
$this

Implements CartInterface.

Definition at line 564 of file Quote.php.

565  {
566  return $this->setData(self::KEY_CREATED_AT, $createdAt);
567  }

◆ setCurrency()

setCurrency ( \Magento\Quote\Api\Data\CurrencyInterface  $currency = null)

Definition at line 532 of file Quote.php.

533  {
534  return $this->setData(self::KEY_CURRENCY, $currency);
535  }

◆ setCustomer()

setCustomer ( \Magento\Customer\Api\Data\CustomerInterface  $customer = null)

Define customer object

Parameters
\Magento\Customer\Api\Data\CustomerInterface$customer
Returns
$this

Definition at line 974 of file Quote.php.

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  }
$customer
Definition: customers.php:11

◆ setCustomerAddressData()

setCustomerAddressData ( array  $addresses)

Substitute customer addresses

Parameters

Definition at line 1023 of file Quote.php.

1024  {
1025  foreach ($addresses as $address) {
1026  if (!$address->getId()) {
1027  $this->addCustomerAddress($address);
1028  }
1029  }
1030 
1031  return $this;
1032  }
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38
addCustomerAddress(\Magento\Customer\Api\Data\AddressInterface $address)
Definition: Quote.php:1042

◆ setCustomerIsGuest()

setCustomerIsGuest (   $customerIsGuest)

Sets true for guest customers, false for logged in customers

Parameters
bool$customerIsGuest
Returns
$this

Implements CartInterface.

Definition at line 700 of file Quote.php.

701  {
702  return $this->setData(self::KEY_CUSTOMER_IS_GUEST, $customerIsGuest);
703  }

◆ setCustomerNote()

setCustomerNote (   $customerNote)

Sets Customer notice text

Parameters
string$customerNote
Returns
$this

Implements CartInterface.

Definition at line 716 of file Quote.php.

717  {
718  return $this->setData(self::KEY_CUSTOMER_NOTE, $customerNote);
719  }

◆ setCustomerNoteNotify()

setCustomerNoteNotify (   $customerNoteNotify)

Sets send customer notification flag

Parameters
bool$customerNoteNotify
Returns
$this

Implements CartInterface.

Definition at line 732 of file Quote.php.

733  {
734  return $this->setData(self::KEY_CUSTOMER_NOTE_NOTIFY, $customerNoteNotify);
735  }

◆ setCustomerTaxClassId()

setCustomerTaxClassId (   $customerTaxClassId)

Set customer tax class ID.

Parameters
int$customerTaxClassId
Returns
$this

Implements CartInterface.

Definition at line 1103 of file Quote.php.

1104  {
1105  return $this->setData(self::KEY_CUSTOMER_TAX_CLASS_ID, $customerTaxClassId);
1106  }

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Quote\Api\Data\CartExtensionInterface  $extensionAttributes)

Set an extension attributes object.

Parameters
\Magento\Quote\Api\Data\CartExtensionInterface$extensionAttributes
Returns
$this

Definition at line 2586 of file Quote.php.

2587  {
2589  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
$extensionAttributes
Definition: payment.php:22

◆ setHasError()

setHasError (   $flag)

Sets flag, whether this quote has some error associated with it. When TRUE - also adds 'unknown' error information to list of quote errors. When FALSE - clears whole list of quote errors. It's recommended to use addErrorInfo() instead - to be able to remove error statuses later.

Parameters
bool$flag
Returns
$this
See also
addErrorInfo()

Definition at line 2081 of file Quote.php.

2082  {
2083  if ($flag) {
2084  $this->addErrorInfo();
2085  } else {
2086  $this->_clearErrorInfo();
2087  }
2088  return $this;
2089  }
addErrorInfo( $type='error', $origin=null, $code=null, $message=null, $additionalData=null)
Definition: Quote.php:2113

◆ setIsActive()

setIsActive (   $isActive)

Sets whether the cart is still active.

Parameters
bool$isActive
Returns
$this

Implements CartInterface.

Definition at line 612 of file Quote.php.

613  {
614  return $this->setData(self::KEY_IS_ACTIVE, $isActive);
615  }

◆ setIsVirtual()

setIsVirtual (   $isVirtual)

Definition at line 620 of file Quote.php.

621  {
622  return $this->setData(self::KEY_IS_VIRTUAL, $isVirtual);
623  }

◆ setItems()

setItems ( array  $items = null)

Sets items in the cart.

Parameters

Implements CartInterface.

Definition at line 548 of file Quote.php.

549  {
550  return $this->setData(self::KEY_ITEMS, $items);
551  }
$items

◆ setItemsCount()

setItemsCount (   $itemsCount)

Sets the number of different items or products in the cart.

Parameters
int$itemsCount
Returns
$this

Implements CartInterface.

Definition at line 636 of file Quote.php.

637  {
638  return $this->setData(self::KEY_ITEMS_COUNT, $itemsCount);
639  }

◆ setItemsQty()

setItemsQty (   $itemsQty)

Sets the total quantity of all cart items.

Parameters
float$itemQty
Returns
$this

Implements CartInterface.

Definition at line 652 of file Quote.php.

653  {
654  return $this->setData(self::KEY_ITEMS_QTY, $itemsQty);
655  }

◆ setOrigOrderId()

setOrigOrderId (   $origOrderId)

Sets the original order ID for the cart.

Parameters
int$origOrderId
Returns
$this

Implements CartInterface.

Definition at line 668 of file Quote.php.

669  {
670  return $this->setData(self::KEY_ORIG_ORDER_ID, $origOrderId);
671  }

◆ setPayment()

setPayment ( PaymentInterface  $payment)

Sets payment to current quote

Parameters
PaymentInterface$payment
Returns
PaymentInterface

Definition at line 1952 of file Quote.php.

1953  {
1954  if (!$this->getIsMultiPayment() && ($old = $this->getPayment())) {
1955  $payment->setId($old->getId());
1956  }
1957  $this->addPayment($payment);
1958 
1959  return $payment;
1960  }
$old
Definition: website.php:27
addPayment(PaymentInterface $payment)
Definition: Quote.php:1937
$payment
Definition: order.php:17

◆ setReservedOrderId()

setReservedOrderId (   $reservedOrderId)

Sets the reserved order ID for the cart.

Parameters
int$reservedOrderId
Returns
$this

Implements CartInterface.

Definition at line 684 of file Quote.php.

685  {
686  return $this->setData(self::KEY_RESERVED_ORDER_ID, $reservedOrderId);
687  }

◆ setShippingAddress()

setShippingAddress ( \Magento\Quote\Api\Data\AddressInterface  $address = null)

Set shipping address

Parameters
\Magento\Quote\Api\Data\AddressInterface$address
Returns
$this

Definition at line 1344 of file Quote.php.

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  }
$old
Definition: website.php:27
$address
Definition: customer.php:38
else addAddress
Definition: book.phtml:101

◆ setStore()

setStore ( \Magento\Store\Model\Store  $store)

Declare quote store model

Parameters
\Magento\Store\Model\Store$store
Returns
$this

Definition at line 775 of file Quote.php.

776  {
777  $this->setStoreId($store->getId());
778  return $this;
779  }

◆ setStoreId()

setStoreId (   $storeId)

Sets store identifier

Parameters
int$storeId
Returns
$this

Implements CartInterface.

Definition at line 753 of file Quote.php.

754  {
755  $this->setData(self::KEY_STORE_ID, (int)$storeId);
756  return $this;
757  }

◆ setUpdatedAt()

setUpdatedAt (   $updatedAt)

Sets the cart last update date and time.

Parameters
string$updatedAt
Returns
$this

Implements CartInterface.

Definition at line 580 of file Quote.php.

581  {
582  return $this->setData(self::KEY_UPDATED_AT, $updatedAt);
583  }

◆ updateCustomerData()

updateCustomerData ( \Magento\Customer\Api\Data\CustomerInterface  $customer)

Update customer data object

Parameters
\Magento\Customer\Api\Data\CustomerInterface$customer
Returns
$this

Definition at line 1057 of file Quote.php.

1058  {
1059  $quoteCustomer = $this->getCustomer();
1060  $this->dataObjectHelper->mergeDataObjects(CustomerInterface::class, $quoteCustomer, $customer);
1061  $this->setCustomer($quoteCustomer);
1062  return $this;
1063  }
$customer
Definition: customers.php:11
setCustomer(\Magento\Customer\Api\Data\CustomerInterface $customer=null)
Definition: Quote.php:974

◆ updateItem()

updateItem (   $itemId,
  $buyRequest,
  $params = null 
)

Updates quote item with new configuration

$params sets how current item configuration must be taken into account and additional options. It's passed to \Magento\Catalog\Helper\Product->addParamsToBuyRequest() to compose resulting buyRequest.

Basically it can hold

  • 'current_config', \Magento\Framework\DataObject or array - current buyRequest that configures product in this item, used to restore currently attached files
  • 'files_prefix': string[a-z0-9_] - prefix that was added at frontend to names of file options (file inputs), so they won't intersect with other submitted options

For more options see \Magento\Catalog\Helper\Product->addParamsToBuyRequest()

Parameters
int$itemId
\Magento\Framework\DataObject$buyRequest
null | array | \Magento\Framework\DataObject$params
Returns
\Magento\Quote\Model\Quote\Item
Exceptions

Product configuration didn't stick to original quote item It either has same configuration as some other quote item's product or completely new configuration

Definition at line 1750 of file Quote.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
addProduct(\Magento\Catalog\Model\Product $product, $request=null, $processMode=\Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL)
Definition: Quote.php:1598
__()
Definition: __.php:13
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$items

Field Documentation

◆ $_addresses

$_addresses
protected

Definition at line 136 of file Quote.php.

◆ $_catalogProduct

$_catalogProduct
protected

Definition at line 176 of file Quote.php.

◆ $_config

$_config
protected

Definition at line 200 of file Quote.php.

◆ $_currentPayment

$_currentPayment
protected

Definition at line 155 of file Quote.php.

◆ $_customer

$_customer
protected

Definition at line 129 of file Quote.php.

◆ $_customerFactory

$_customerFactory
protected

Definition at line 210 of file Quote.php.

◆ $_errorInfoGroups

$_errorInfoGroups = []
protected

Definition at line 162 of file Quote.php.

◆ $_eventObject

$_eventObject = 'quote'
protected

Definition at line 122 of file Quote.php.

◆ $_eventPrefix

$_eventPrefix = 'sales_quote'
protected

Definition at line 117 of file Quote.php.

◆ $_items

$_items
protected

Definition at line 143 of file Quote.php.

◆ $_objectCopyService

$_objectCopyService
protected

Definition at line 257 of file Quote.php.

◆ $_payments

$_payments
protected

Definition at line 150 of file Quote.php.

◆ $_preventSaving

$_preventSaving = false
protected

Definition at line 169 of file Quote.php.

◆ $_quoteAddressFactory

$_quoteAddressFactory
protected

Definition at line 205 of file Quote.php.

◆ $_quoteItemCollectionFactory

$_quoteItemCollectionFactory
protected

Definition at line 222 of file Quote.php.

◆ $_quoteItemFactory

$_quoteItemFactory
protected

Definition at line 227 of file Quote.php.

◆ $_quotePaymentCollectionFactory

$_quotePaymentCollectionFactory
protected

Definition at line 252 of file Quote.php.

◆ $_quotePaymentFactory

$_quotePaymentFactory
protected

Definition at line 247 of file Quote.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 190 of file Quote.php.

◆ $_statusListFactory

$_statusListFactory
protected

Definition at line 237 of file Quote.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 195 of file Quote.php.

◆ $addressDataFactory

$addressDataFactory
protected

Definition at line 303 of file Quote.php.

◆ $addressRepository

$addressRepository
protected

Definition at line 264 of file Quote.php.

◆ $currencyFactory

$currencyFactory
protected

Definition at line 318 of file Quote.php.

◆ $customerDataFactory

$customerDataFactory
protected

Definition at line 308 of file Quote.php.

◆ $customerRepository

$customerRepository
protected

Definition at line 313 of file Quote.php.

◆ $dataObjectHelper

$dataObjectHelper
protected

Definition at line 323 of file Quote.php.

◆ $extensibleDataObjectConverter

$extensibleDataObjectConverter
protected

Definition at line 298 of file Quote.php.

◆ $extensionAttributesJoinProcessor

$extensionAttributesJoinProcessor
protected

Definition at line 328 of file Quote.php.

◆ $filterBuilder

$filterBuilder
protected

Definition at line 278 of file Quote.php.

◆ $groupRepository

$groupRepository
protected

Definition at line 217 of file Quote.php.

◆ $itemProcessor

$itemProcessor
protected

Definition at line 288 of file Quote.php.

◆ $messageFactory

$messageFactory
protected

Definition at line 232 of file Quote.php.

◆ $objectFactory

$objectFactory
protected

Definition at line 293 of file Quote.php.

◆ $productRepository

$productRepository
protected

Definition at line 242 of file Quote.php.

◆ $quoteValidator

$quoteValidator
protected

Definition at line 183 of file Quote.php.

◆ $searchCriteriaBuilder

$searchCriteriaBuilder
protected

Definition at line 271 of file Quote.php.

◆ $shippingAddressesItems

$shippingAddressesItems
protected

Definition at line 355 of file Quote.php.

◆ $shippingAssignmentFactory

$shippingAssignmentFactory
protected

Definition at line 348 of file Quote.php.

◆ $shippingFactory

$shippingFactory
protected

Definition at line 343 of file Quote.php.

◆ $stockRegistry

$stockRegistry
protected

Definition at line 283 of file Quote.php.

◆ $totalsCollector

$totalsCollector
protected

Definition at line 333 of file Quote.php.

◆ $totalsReader

$totalsReader
protected

Definition at line 338 of file Quote.php.

◆ CHECKOUT_METHOD_LOGIN_IN

const CHECKOUT_METHOD_LOGIN_IN = 'login_in'

Checkout login method key

Definition at line 112 of file Quote.php.


The documentation for this class was generated from the following file: