Jump to content

Get attribute image


Recommended Posts

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?

post-1242650-0-39466200-1472049426_thumb.jpg

Edited by l2phmode (see edit history)
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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>

 

post-1242650-0-70044200-1472592078_thumb.jpg

Link to comment
Share on other sites

{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

  • 3 years later...

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:

1121334635_OperaSnmkaobrazovky_2020-04-13_110801_najlepsiamoda_sk.png.384d613f6803d9326eb43605edcb1839.png

 

Can you please help? :( ... Appreciate your time! Hope you are doing well

 

Edited by Kaper (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...