Jump to content

Get selected ID's attribut or texture URL in cart


Recommended Posts

Hi,

As is the case on the product template, I want display the selected the texture/color of attribute for each product in the basket (not only they names).

After several days looking for a solution, I dare to ask if anyone would be able to help me...
The only ones properties that which gives something in cart-detailed-product-line.tpl are:
- $product.attributes" : only attribute names given (not even ID: wtf?)!
- $product.url : complete URL with URI containing the selected attribute, but without possibility to recover only attribute's ID from Smarty.

And I did not find any API doc, with the variables available. So I am here...

Thanks for help.

texture_in_cart.jpg

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

  • 2 weeks later...

Thanks, but nothing more with $product, I had already checked.

It's not really elegant, but that work:

{foreach from=$product.attributes key="attribute" item="value"}
	<div class="product-line-info variants">
        {$clear1 = "{$product.url|regex_replace:'/[^\d*]+$/':''}"}
        {$clear2 = "{$clear1|regex_replace:'/^(.*[\/])/':''}"}
        {$img_id = "{$clear2}"}
        <div class="texture" style="background-image: url({$urls.img_ps_url}co/{$img_id}.jpg)"></div>
	</div>
{/foreach}

I didn't succeed in uniting the two RegEx conditions, so I cut in two steps.

result.jpg

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

  • 1 year later...

Hello @fujitsuDev

I'm pretty new to programming , finally I understood what you did.

I've copy pasted you code inside my cart-detailed-product-line.tpl file without success.

I've just needed to truncate in order to cut off the ID of the variant.

	  <div class="variants">
        {$clear1 = "{$product.url|regex_replace:'/[^\d*]+$/':''}"}
        {$clear2 = "{$clear1|regex_replace:'/^(.*[\/])/':''}"}
        {$img_id = "{$clear2|truncate:3:""}"}
        <div class="texture" style="background-image: url({$urls.img_ps_url}co/{$img_id}.jpg); width:50px; height:50px"></div>
	</div>

Do you know how to cut until the "-" (dash) intead of truncating the first 3 chars?

Thanks.

Edited by zenerry
found a solution (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...