Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:17:45+00:00 2026-06-08T10:17:45+00:00

I’m currently working on getting images for product options showing up on my first

  • 0

I’m currently working on getting images for product options showing up on my first magento build. I have this figured out for bundled product, like so:

screenshot

I’m obtaining urls of related images (swatches, for example) when the options for the select gets built. Now I’m trying to do the same with configurable products, but it does not seem to be as straightforward.

Configurable products are built from simple products which represent each iteration of available options. Great. I can obviously upload images for each simple product, and that would be a good start to a solution to this.

For example:
Chair has 3 upholstery and 2 armrest choices (6 simple products).
For chair 2/b I upload upholstery swatch 2 and armrest swatch b, and label them accordingly. When the options get built, I grab image urls associated with each simple product by their label (maybe grabbing all images for that label and removing duplicates or something?)…

In Magento, I see:

In theme/catalog/product/view/type/option/configurable.phtml

<?php foreach($_attributes as $_attribute): ?>
    ..// 
    <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
        <option><?php echo $this->__('Choose an Option...') ?></option>
    </select>
    ..//
</div>
<?php endforeach; ?>
<script type="text/javascript">
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>

Unlike the bundle, the configurable product select/options are injected onto the page via javascript (in js/varien/configurable.js). This class is then reliant on getJsonConfig() to supply all information after that.

At this point, it seems I should be able to obtain a simple product’s image url information from that object. Tho I see no logic dealing with images at all in configurable.js. How would I go about obtaining those urls and associating them with the related option selects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:17:47+00:00Added an answer on June 8, 2026 at 10:17 am

    You can get an array of simple products used in the configurable by using the getUsedProducts() method. This method is not part of the standard product model, but can be found in app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php, so you’ll need to first get the configurable product model using getTypeInstance(). That method accepts a single parameter stating whether or not you’d like to return the type model as a singleton (I did).

    foreach ($_product->getTypeInstance(true)->getUsedProducts() as $simpleProduct) {
        // From this you should be able to get the image url
    }
    

    UPDATE

    In spConfig as created by Mage_Catalog_Block_Product_View_Type_Configurable::getJsonConfig() there is an options array containing the product_ids specific to that configurable option.

    spConfig :
      attributes : {
        603 : {
          id      : 603,
          code    : part_state,
          label   : "Part State",
          options : [
            {
              id       : 648,
              label    : Harvested,
              price    : 0,
              products : [204379]   // <-- Simple Product ID
            },
            {
              id       : 647,
              label    : New,
              price    : 0,
              products : [224333]
            }]
        },
      ...
    

    At this point, you can either:

    1. Extend getJsonConfig to include a simple product image URL, or
    2. Create a mapping of simple product IDs to image URLs

    I’ll give you an example of #2 so you can see what functions you might use.

    $spImages = array();
    foreach ($this->getAllowProducts() as $_sp) {
        $spImages[$_sp->getId()] = 
            (string)$this->helper('catalog/image')
                ->init($_sp, 'small_image')
                ->resize(40,40);
    }
    // It is necessary to cast the URL to a `string` because the actual work done by
    // Mage_Catalog_Helper_Image happens in the `__toString()` method... weird!
    
    <script type="text/javascript">
        var spImages = <?php echo json_encode($spImages); ?>;
    </script>
    

    Now that you have a way to associate an image URL with a simple product ID, you’ll need to update the image based on the current selected option. Magento’s Product.Config has a configureElement() method that is triggered when the <select class="super-attribute-select"> changes, so I would tap into that. If you’re not comfortable doing that, you’ve got all the information in spConfig.config and spImages from which you could write your own onChange event handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.