3

There are 3 places to store items data in the quote:

  • \Magento\Quote\Model\Quote::$_items
  • \Magento\Quote\Model\Quote::$_data['items']
  • \Magento\Quote\Model\Quote::$_data['items_collection']

\Magento\Quote\Model\Quote

const KEY_ITEMS = 'items';
/**
 * Quote items collection
 *
 * @var \Magento\Eav\Model\Entity\Collection\AbstractCollection
 */
protected $_items;

public function getItems()
{
    return $this->_getData(self::KEY_ITEMS);
}

public function setItems(array $items = null)
{
    return $this->setData(self::KEY_ITEMS, $items);
}

public function getItemsCollection($useCache = true)
{
    if ($this->hasItemsCollection()) {
        return $this->getData('items_collection');
    }
    if (null === $this->_items) {
        $this->_items = $this->_quoteItemCollectionFactory->create();
        $this->extensionAttributesJoinProcessor->process($this->_items);
        $this->_items->setQuote($this);
    }
    return $this->_items;
}

What is the right place to store items data in the quote?

Magento version: 2.1.2

0

You should probably just use the setItems(array $items) method that you mention above.

You can however run setData('items', $items) but that will assign the same items field as setItems(array $items).

In the same way: getData('items') will return the same thing as getItems();

$_data['items'] probably points to $_items;

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.