Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Basic PHP Question
 
bobbrodie
Sr. Member
 
Avatar
Total Posts:  132
Joined:  2008-04-02
Philadelphia, PA
 

I have the following, and I want to access the array of $_product->getTypeInstance()->getUsedProducts()

foreach ($_product->getTypeInstance()->getUsedProducts() as $item{
        
echo $item->getId() . "\n";
        echo 
$item->getImage() . "\n";
    
}

so, if this would output 26 27 28 29 30 31 32 33 34 35 I need:

$item[26] to be /G/8/G8BLA_1.jpg
$item[27] to be /G/8/G8GRE_1.jpg

and so on.

I’m going to take this and use it for an image switcher with this code (testing):

<script>
    
jQuery(document).ready(function(){
        jQuery
("#attribute<?php echo $_attribute->getAttributeId() ?>").change(function(){
            
var productId spConfig.config.attributes[<?php echo $_attribute->getAttributeId() ?>].options[this.selectedIndex-1].products;
            
alert(productId);
        
});
    
});
</script>

I’m going to load the php array and then use those variables to load the necessary images. This image switcher will be universal and I will integrate it with a blank theme and upload to the community.

Thanks,
Bob Brodie

 
Magento Community Magento Community
Magento Community
Magento Community
 
phlux0r
Member
 
Avatar
Total Posts:  73
Joined:  2008-03-09
Auckland, New Zealand
 

While I fail to see a direct question in your post here, I assume you are asking how to create a data structure that associates the id’s with the images in your foreach statement.

myImageArray = array();
foreach (
$_product->getTypeInstance()->getUsedProducts() as $item{
        myImageArray[$item
->getId()$item->getImage();
    

// so myImageArray will be indexed by ID and the elements will be the image URL's
// ie. myImageArray[26] = '/G/8/G8BLA_1.jpg '

HTH

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top