0

I was trying to get the information of the items in the cart and got it using the code below, the problem is that I need to get a lot of other information. And when giving a var_dump($cart), it showed the cart information. As in this example I saw on the internet, "$item->getProduct()" is used to get the elements. How can I give a var_dump() inside the $item variable to find out the values ​​that are inside the item?

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
    $productId = $item->getProduct()->getId();
    $productPrice = $item->getProduct()->getPrice();
}

1 Answer 1

1

You can do something like this to get cart item.

$quote = Mage::helper('checkout/cart')->getCart()->getQuote();
$value = [];
foreach ($quote->getAllItems() as $item) {
$value[]= array (
 'id' => $item->getSku(),
 'quantity' => $item->getQty(),
 'price' => $item->getParentItemId()?  $item->getParentItem()->getPrice(): $item->getPrice()
  );
  }

Happy Coding. :)

2
  • First of all, thank you very much for the reply! But what I need is to know how I discover the modules that seek information. And already taking advantage of how would I get the image of the product that is in the cart?
    – lucas
    Commented Aug 18, 2021 at 4:07
  • You can check over this for image. magento.stackexchange.com/questions/92795/… Commented Aug 18, 2021 at 4:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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