0

I have 3 products in the same categoy
I'm trying to display same category products thumbnails in magento catalog/product/view.phtml

<?php
    $productCollection = Mage::getModel('catalog/category')->load($cat_id)
         ->getProductCollection()
         ->addAttributeToSelect('*')
         ->addAttributeToFilter('status', 1);

    $prodIds = $productCollection->getAllIds();

    $prod_siblings = array();
    foreach($prodIds as $productId) 
    {
        $prod =  Mage::getModel('catalog/product')->load($productId);
        $prod_siblings[] = array(
            'url' => $prod->getProductUrl(),
            'name' => $prod->getName(),
            'image' => $this->helper('catalog/image')->init($prod, 'thumbnail')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(75)
            );
    }
?>

with this code, the 3 $prod_siblings have their own name and url (stored in the array), but they are all sharing the same image (the image of the last created product).

nicolast
  • 787
  • 7
  • 20

2 Answers2

0

Try storing product details in an array n den whole arrays in your $prod_siblings. This will look like this:

?php
$productCollection = Mage::getModel('catalog/category')->load($cat_id)
     ->getProductCollection()
     ->addAttributeToSelect('*')
     ->addAttributeToFilter('status', 1);

$prodIds = $productCollection->getAllIds();

$prod_siblings = array();
foreach($prodIds as $productId) 
{
    $prod =  Mage::getModel('catalog/product')->load($productId);
    $product_detail[] = array(
        'url' => $prod->getProductUrl(),
        'name' => $prod->getName(),
        'image' => $this->helper('catalog/image')->init($prod, 'thumbnail')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(75)
        );  array_push($prod_siblings,$product_detail[]);
}?>

Hope this will help you.

ANKIT
  • 341
  • 3
  • 13
  • Put $product_detail = array() instead of $product_detail[] = array() and array_push($prod_siblings,$product_detail); instead of array_push($prod_siblings,$product_detail[]);try.. – ANKIT Apr 03 '13 at 13:22
  • i've found the solution, see my answer, thanks for your help :) – nicolast Apr 03 '13 at 13:47
0

Got it !

found my answer here : How to get a product's image in Magento?

used (string)Mage::helper('catalog/image')->init($prod, 'thumbnail')...

instead of $this->helper('catalog/image')->init($prod, 'thumbnail')...

Community
  • 1
  • 1
nicolast
  • 787
  • 7
  • 20