The difference between the two teams of selection of products for purchases in Magento

In Magento, if you need to get / get product information in a basket, you can do this in one of two possible ways that will provide you with all the purchased items in an array: -

  • $cartItems1 = $cart->getQuote()->getAllItems();
  • $cartItems2 = $cart->getItems()->getData();

But before using either of the two above methods, you need to initialize the shopping cart object as: -

$cart = new Mage_Checkout_Model_Cart();
$cart->init();

Can anyone describe in detail what both options provide, and their differences among themselves, as well as their possible use.

In any case, such a parameter is available in Magento, can anyone highlight it?

+3
source share
1 answer

Cart Quote, .

$cart- > getItems():

public function getItems()
{
  return $this->getQuote()->getAllVisibleItems();
}

- Quote. , : getAllVisibleItems() getAllItems()?

:

public function getAllItems()
{
    $items = array();
    foreach ($this->getItemsCollection() as $item) {
        if (!$item->isDeleted()) {
            $items[] =  $item;
        }
    }
    return $items;
}

public function getAllVisibleItems()
{
    $items = array();
    foreach ($this->getItemsCollection() as $item) {
        if (!$item->isDeleted() && !$item->getParentItemId()) {
            $items[] =  $item;
        }
    }
    return $items;
}

: getAllVisibleItems() :

!$item->getParentItemId()

, ( , , ). , getAllItems().

?

:

$productCollection = $cart->getQuote()->getItemsCollection();
+10

Source: https://habr.com/ru/post/1750050/


All Articles