Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you look at the code of the Cart and Quote classes everything will become clear.</p> <p>Here's the code for $cart->getItems():</p> <pre><code>public function getItems() { return $this-&gt;getQuote()-&gt;getAllVisibleItems(); } </code></pre> <p>Plain and simple - it just calls a method of the Quote object. So the question now is: <strong>What is the difference between <em>getAllVisibleItems()</em> and <em>getAllItems()</em>?</strong></p> <p>Let's look at the code of both methods:</p> <pre><code>public function getAllItems() { $items = array(); foreach ($this-&gt;getItemsCollection() as $item) { if (!$item-&gt;isDeleted()) { $items[] = $item; } } return $items; } public function getAllVisibleItems() { $items = array(); foreach ($this-&gt;getItemsCollection() as $item) { if (!$item-&gt;isDeleted() &amp;&amp; !$item-&gt;getParentItemId()) { $items[] = $item; } } return $items; } </code></pre> <p>The only difference: <em>getAllVisibleItems()</em> has an additional check for each item:</p> <pre><code>!$item-&gt;getParentItemId() </code></pre> <p>which tests if the product has a parent (in other words, it tests if it is a simple product). So this method's return array will be missing simple products, as opposed to <em>getAllItems()</em>.</p> <p><strong>Are there any other ways to retrieve items?</strong> </p> <p>One would be to directly get the product collection from the quote object:</p> <pre><code>$productCollection = $cart-&gt;getQuote()-&gt;getItemsCollection(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload