I'm building a t-shirt website, and I'm looking into having the customer be able to choose certain shirt attributes such as hoodie/t-shirt, shirt color, etc.

Using imagecache actions, I've looked into setting up a separate image style for each variation type (such as black hoodie) which then renders the shirt design onto a template for a black hoodie. I've gotten this to work as individual image styles. I've looked into the solution proposed here (in the second answer) to create an image style called 'clothing' that then runs a 'custom action' image effect to determine the image style to actually render. Using the code in the linked answer, I was able to modify it to do a check on:


and grab the tid of the attribute (such as shirt color) and then run a taxonomy_term_load to check the attribute name.

I've gotten this to work (tentatively), and I can handle the base-level PHP to do the comparing and logic to check the attributes. The problem that I'm having is that when I change an attribute (such as shirt color), the $image_context['entity'] object is not updated and/or the image style is not re-rendered.

How can I cause the image style to be re-processed when a user changes an attribute on the add to cart form? I know little on this, but I've read that I could possibly us a custom module and hook_commerce_cart_attributes_refresh_alter.

I don't know much about the syntax of this function, and I don't know how to trigger a change to the $image_context['entity'] object and/or refresh the image style. In a worst-case-scenario, I would even be willing to change the value of the object and reload the page, but this would not be ideal.

Can I just dpm the values from inside hook_commerce_cart_attributes_refresh_alter and grab the new values, and set them accordingly inside $image_context['entity']? i.e. would the image style automatically be re-triggered because the new product image would be grabbed?

Is this possible?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.