0

I'm trying to get all the the different kind of product images from the Media-gallery (see code below). Product with the black-11 SKU is my black-product but it doesn't show that product image. What is wrong with the code. I noticed this with all the product so maybe it's a sorting problem or initiating

<?php
require '../app/Mage.php';
Mage::app("default");

$gallery_images = Mage::getModel('catalog/product')->load('black-11')->getMediaGalleryImages();

$items = array();

foreach($gallery_images as $g_image) {
  echo "URL: " . $g_image['url'] . "<br/>";
}
?>

3 Answers 3

1

the load method accepts numeric ID's only. Try the following

Mage::getModel('catalog/product')->load('black-11', 'sku')[....]

or

$productId = Mage::getModel('catalog/product')->getIdBySku('black-11');
Mage::getModel('catalog/product')->load($productId)[....]
1

This is wrong with your code ->load('black-11').
The load method takes as parameter the PK of the entity you are trying to retrieve.
Use ->load('black-11', 'sku') instead.

1

As far as I know:

->load() expects an ID while you using an SKU.

So please try:

->loadbysku('your-sku') or ->loadbyattribute('sku','your-sku')

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.