Foreach remove duplicate images

Asked

Viewed 93 times

1

I have code below that pulls the images of the products of the shopping cart of the Gento, but it is displaying duplicate, IE, when it lists the images it displays twice the same image.

<?php 
    $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems() ;  

        foreach($items as $item) {                                   
            echo '<img style="width: 75px; height: 75px;" src="'.$this->helper('catalog/image')->init($item->getProduct(), 'small_image').'"/>';

        }

?>

I’d like to show off just once, end this loop.

1 answer

1

array_unique($array)

<?php 
    $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems() ;  

    $items = array_unique($items);

        foreach($items as $item) {                                   
            echo '<img style="width: 75px; height: 75px;" src="'.$this->helper('catalog/image')->init($item->getProduct(), 'small_image').'"/>';

        }

?>
  • Dude vlw by the help, but even so it didn’t work yet, it keeps doubling.

  • So the problem is before. When adding the product in the cart you need to add once only.

  • So I also thought about it, but it’s right, problem is that it just duplicating images, for example if it has a product it displays a single image and if it has two products it lists twice and if I have 3 products it will list 3 times.

  • Makes a count($items) under the $items. It is to bring the quantity of products in the cart.

  • Could you help me on how to make this Count

  • I’m having little trouble with that

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.