l2phmode Posted August 24, 2016 Share Posted August 24, 2016 (edited) It is necessary to solve this problem. Instead, the product color display images of the combination product. How Get $attribute.id_image? <ul id="color_to_pick_list" class="clearfix"> {assign var="default_colorpicker" value=""} {foreach from=$group.attributes key=id_attribute item=group_attribute} {assign var='img_color_exists' value=file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')} <li{if $group.default == $id_attribute} class="selected"{/if}> <a href="{$link->getProductLink($product)|escape:'html':'UTF-8'}" id="color_{$id_attribute|intval}" name="{$colors.$id_attribute.name|escape:'html':'UTF-8'}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" {if !$img_color_exists && isset($colors.$id_attribute.value) && $colors.$id_attribute.value} style="background-image:url({$link->getImageLink($product->link_rewrite, $attribute.id_image, 'small_default')|escape:'html':'UTF-8'});"{/if} title="{$colors.$id_attribute.name|escape:'html':'UTF-8'}" {if $img_color_exists}style="background: url({$img_col_dir}{$id_attribute|intval}.jpg) repeat;"{/if}></a> </li> {if ($group.default == $id_attribute)} {$default_colorpicker = $id_attribute} {/if} {/foreach} </ul> Please tell me how to do? Edited August 24, 2016 by l2phmode (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted August 25, 2016 Share Posted August 25, 2016 You can't because the combination images are linked to combinations, not to attributes. However, if you always have only one attribute and the combination images are always in the same order as the attributes, you could use the {$combinationImages} variable to get the image IDs. For example, you could use code like the following: <ul id="color_to_pick_list" class="clearfix"> {assign var="default_colorpicker" value=""} {foreach from=$group.attributes key=id_attribute item=group_attribute name=attributes} {assign var='id_image' value=0} {foreach from=$combinationImages item=combinationImage name=combinations} {if $smarty.foreach.combinations.iteration == $smarty.foreach.attributes.iteration} {assign var='id_image' value=$combinationImage.0.id_image} {/if} {/foreach} {* {assign var='img_color_exists' value=file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')}*} <li{if $group.default == $id_attribute} class="selected"{/if}> <a href="{$link->getProductLink($product)|escape:'html':'UTF-8'}" id="color_{$id_attribute|intval}" name="{$colors.$id_attribute.name|escape:'html':'UTF-8'}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" {*{if !$img_color_exists && isset($colors.$id_attribute.value) && $colors.$id_attribute.value}*}{if $id_image} style="background-image:url({$link->getImageLink($product->link_rewrite, $id_image, 'small_default')|escape:'html':'UTF-8'}); background-size:100%"{/if} title="{$colors.$id_attribute.name|escape:'html':'UTF-8'}"{* {if $img_color_exists}style="background: url({$img_col_dir}{$id_attribute|intval}.jpg) repeat;"{/if}*}></a> </li> {if ($group.default == $id_attribute)} {$default_colorpicker = $id_attribute} {/if} {/foreach} </ul> I wasn't sure what you intended to do with the existing texture, so I just commented out that code. 1 Link to comment Share on other sites More sharing options...
l2phmode Posted August 30, 2016 Author Share Posted August 30, 2016 Thank you for example. But it is not really suitable for the variant with multiple attributes. I made one more example but it shows the 2 different images for different color. How can bind to ps_attribute_image? What would be the correct operation. <ul id="color_to_pick_list" class="clearfix"> {assign var="default_colorpicker" value=""} {foreach from=$group.attributes key=id_attribute item=group_attribute} {assign var='img_color_exists' value=file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')} {foreach from=$combinationImages item='combination' key='combinationId' name='f_combinationImages'} {foreach from=$combination item='image' name='f_combinationImage'} {if $previd != $image.id_image} <li{if $group.default == $id_attribute} class="selected"{/if}> <a href="{$link->getProductLink($product)|escape:'html':'UTF-8'}" id="color_{$id_attribute|intval}" name="{$colors.$id_attribute.name|escape:'html':'UTF-8'}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}"{if !$img_color_exists && isset($colors.$id_attribute.value) && $colors.$id_attribute.value} style="background-image:url({$link->getImageLink($product->link_rewrite, $image.id_image, 'small_default')|escape:'html':'UTF-8'});width:100px;height:100px;"{/if} title="{$colors.$id_attribute.name|escape:'html':'UTF-8'}" {if $img_color_exists}style="background: url({$img_col_dir}{$id_attribute|intval}.jpg) repeat;"{/if}></a> </li> {/if} {/foreach} {assign var="previd" value=$image.id_image} {/foreach} {if ($group.default == $id_attribute)} {$default_colorpicker = $id_attribute} {/if} {/foreach} </ul> Link to comment Share on other sites More sharing options...
l2phmode Posted August 30, 2016 Author Share Posted August 30, 2016 {if isset($combinationImages)} {foreach from=$combinationImages item='combination' key='combinationId' name='f_combinationImages'} {foreach from=$combination item='image' name='f_combinationImage'} {if $previd != $image.id_image} {assign (to array) $color_image = $image.id_image} {/if} {/foreach} {assign var="previd" value=$image.id_image} {/foreach} {/if} //// Outpu background-image:url({$link->getImageLink($product->link_rewrite, $color_image.number, 'small_default')|escape:'html':'UTF-8'}) I think this design would help . I think this design would help . Link to comment Share on other sites More sharing options...
Kaper Posted April 13, 2020 Share Posted April 13, 2020 (edited) Any working solution for 1.6 guys? Thanks I can´t get it to work properly ... I have used this code: <ul id="color_to_pick_list" class="clearfix"> {assign var="default_colorpicker" value=""} {foreach from=$group.attributes key=id_attribute item=group_attribute name=attributes} {assign var='id_image' value=0} {foreach from=$combinationImages item=combinationImage name=combinations} {if $smarty.foreach.combinations.iteration == $smarty.foreach.attributes.iteration} {assign var='id_image' value=$combinationImage.0.id_image} {/if} {/foreach} {*{assign var='img_color_exists' value=file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')}*} <li{if $group.default == $id_attribute} class="selected"{/if}> <a href="{$link->getProductLink($product)|escape:'html':'UTF-8'}" id="color_{$id_attribute|intval}" name="{$colors.$id_attribute.name|escape:'html':'UTF-8'}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" {*{if !$img_color_exists && isset($colors.$id_attribute.value) && $colors.$id_attribute.value}*}{if $id_image} style="background-image:url({$link->getImageLink($product->link_rewrite, $id_image, 'small_default')|escape:'html':'UTF-8'}); background-size:100%"{/if} title="{$colors.$id_attribute.name|escape:'html':'UTF-8'}"{* {if $img_color_exists}style="background: url({$img_col_dir}{$id_attribute|intval}.jpg) repeat;"{/if}*}></a> </li> {if ($group.default == $id_attribute)} {$default_colorpicker = $id_attribute} {/if} {/foreach} </ul> And it shows as: Can you please help? ... Appreciate your time! Hope you are doing well Edited April 13, 2020 by Kaper (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now