Jump to content

[Solved] How do I: cart summary - replace comma separated attributes with new line


AppleEater

Recommended Posts

I have products with many attribute groups and customized fields. currenty, the cart summary displays all the attributes with comma separated (","). I am looking for a way to replace the "," with a new-line, like </br>. 

Any advise where I could find the attributes string and modify it?

 

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

Modify theme file : shopping-cart-product-line.tpl

Search :

{$product.attributes|escape:'htmlall':'UTF-8'}

Replace with:

{$product.attributes|escape:'htmlall':'UTF-8'|replace:',':'<br />'}

But be careful, if your attributes group name or the attribute value name contain coma, it will be replaced too.

So much better changing the coma character with <br /> tag by overriding the related classes file Cart.php
In function cacheSomeAttributesLists($ipa_list, $id_lang)
Search

'.$row['attribute_name'].', ';

Replace with

'.$row['attribute_name'].'<br />';
  • Like 3
Link to comment
Share on other sites

Apparently the class change doesn't work in PS1.5.5 ?

 

I've modified /themes/%theme%/override/classes/cart.php with the following lines:

class CartCore extends ObjectModel
{
	public static function cacheSomeAttributesLists($ipa_list, $id_lang)
	{
.
.
.
		foreach ($result as $row)
		{
			self::$_attributesLists[$row['id_product_attribute'].'-'.$id_lang]['attributes'] .= $row['public_group_name'].' : '.$row['attribute_name'].'<br />';
			self::$_attributesLists[$row['id_product_attribute'].'-'.$id_lang]['attributes_small'] .= $row['attribute_name'].'<br />';
		}

	}
}

But this doesn't change the cart summary. see screenshot.

 

post-377525-0-17478400-1381617571_thumb.jpg

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

Do you know how to override classes/controller files ???

 

The override file should be placed on /override/classes/ or override/controller/ directory

And then the override file should begin like this

class ClassName extends ClassNameCore
{
   // your code
}

And Don't forget to delete file : /cache/class_index.php each time you override prestashop classes or controller files
 

Please read the Prestashop documentation my friend.... :P

Link to comment
Share on other sites

Just in regards to this too. I'm currently sort of trying to achieve the same thing, but with an unordered list as opposed to linebreak. 

This is what I currently have (doing override).

 


foreach ($result as $row)
{
self::$_attributesLists[$row['id_product_attribute'].'-'.$id_lang]['attributes'] .= $row['public_group_name'].  ' : '  .$row['attribute_name']. '<br />' ;
self::$_attributesLists[$row['id_product_attribute'].'-'.$id_lang]['attributes_small'] .= $row['attribute_name'].' <br />';
}

But it is printing the <br /> as exactly that, just text. The output comes out as

Color : Metal<br />Size : Small<br />

 

 

Is there something I'm doing wrong as to why it's not outputting as HTML? Or even a way to encase this within <li> tags?

Many thanks in advance.

 

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

Resolved.

Here's the code I got it done with. Silly error on my part.

 

			self::$_attributesLists[$row['id_product_attribute'].'-'.$id_lang]['attributes'] .= '<li>'.$row['public_group_name'].' : '.$row['attribute_name'].'</li>';
			self::$_attributesLists[$row['id_product_attribute'].'-'.$id_lang]['attributes_small'] .= $row['attribute_name'].'';

Thanks much for the help :D

Link to comment
Share on other sites

  • 6 months later...

Hello,

 

I don't know if you'll be able to answer me but, when I try to modify Cart.php with or without an override, the result is the same thing. 

It's written my html code near the attributes. Like : "Color : orange <br /> Taste : Apple"

 

Did you have this problem ?

Link to comment
Share on other sites

  • 2 years later...

I tried the solution relative to Cart.php in Prestashop 1.6.1.5, but it didn't worked. Then I tried the first trick and this did the job.

 

I replaced

{$product.attributes|escape:'htmlall':'UTF-8'}

with

{$product.attributes|escape:'htmlall':'UTF-8'|replace:',':'<br />'}

thank you  gonebdg

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

Hi everyone.

 

I can't solve one issue with textarea input on PS 1.6.

I use One Page Checkout and i have textarea filed for a text message. In the database it is story as a TEXT (the same for VARCHAR), but problem is if i try to add new line of text.

 

For. ex.

If i try to add:

              Demo text 1

              Demo text 2

              Demo text 3

it's saved in database as:

              Demo text 1n Demo text 2nDemo text 3

 

How can i solve this? and, Please, give me any suggestion.

Or, transform/change "n" in SPACE.

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...