Jump to content

Problem with cart title lenght


Recommended Posts

Hi all, how ca i fix this problem with lenght of title? My page http://presta.simplydesign.sk/index.php

 

blockcart.tpl

<a class="cart_block_product_name" href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'html'}" title="{$product.name|truncate:100:'...'|escape:html:'UTF-8'}">
				{$product.name|truncate:15:'...'|escape:html:'UTF-8'}</a>

 

blockcart-json.tpl

 
{ldelim}
"products": [
{if $products}
{foreach from=$products item=product name='products'}
{assign var='productId' value=$product.id_product}
{assign var='productAttributeId' value=$product.id_product_attribute}
{ldelim}
"id":            {$product.id_product},
"link":          "{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|addslashes|replace:'\\\'':'\''}",
"quantity":      {$product.cart_quantity},
"priceByLine":   "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
"name":          "{$product.name|html_entity_decode:2:'UTF-8'|truncate:15:'...':true|escape:'htmlall'}",
"price":         "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
"price_float":   "{$product.total}",
"idCombination": {if isset($product.attributes_small)}{$productAttributeId}{else}0{/if},
"idAddressDelivery": {if isset($product.id_address_delivery)}{$product.id_address_delivery}{else}0{/if},
"is_gift" : {if isset($product.is_gift) && $product.is_gift}1{else}0{/if},
{if isset($product.attributes_small)}
"hasAttributes": true,
"attributes":    "{$product.attributes_small|addslashes|replace:'\\\'':'\''}",
{else}
"hasAttributes": false,
{/if}
"hasCustomizedDatas": {if isset($customizedDatas.$productId.$productAttributeId)}true{else}false{/if},
"customizedDatas":[
{if isset($customizedDatas.$productId.$productAttributeId[$product.id_address_delivery])}
{foreach from=$customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] key='id_customization' item='customization' name='customizedDatas'}{ldelim}
{* This empty line was made in purpose (product addition debug), please leave it here *}
"customizationId": {$id_customization},
"quantity": "{$customization.quantity}",
"datas": [
{foreach from=$customization.datas key='type' item='datas' name='customization'}
{ldelim}
"type": "{$type}",
"datas":
[
{foreach from=$datas key='index' item='data' name='datas'}
{ldelim}
"index": {$index},
"value": "{Tools::nl2br($data.value|addslashes|replace: '\\\'':'\'')}",
"truncatedValue": "{Tools::nl2br($data.value|truncate:28:'...'|addslashes|replace: '\\\'':'\'')}"
{rdelim}{if !$smarty.foreach.datas.last},{/if}
{/foreach}]
{rdelim}{if !$smarty.foreach.customization.last},{/if}
{/foreach}
]
{rdelim}{if !$smarty.foreach.customizedDatas.last},{/if}
{/foreach}
{/if}
]
{rdelim}{if !$smarty.foreach.products.last},{/if}
{/foreach}{/if}
],
"discounts": [
{if $discounts}{foreach from=$discounts item=discount name='discounts'}
{ldelim}
"id":              "{$discount.id_discount}",
"name":            "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}",
"description":     "{$discount.description|addslashes|replace:'\\\'':'\''}",
"nameDescription": "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}",
"code":            "{$discount.code}",
"link":            "{$link->getPageLink("$order_process", true, NULL, "deleteDiscount={$discount.id_discount}")|escape:'html'}",
"price":           "{if $priceDisplay == 1}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_tax_exc}{else}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_real}{/if}",
"price_float":     "{if $priceDisplay == 1}{$discount.value_tax_exc}{else}{$discount.value_real}{/if}"
{rdelim}
{if !$smarty.foreach.discounts.last},{/if}
{/foreach}{/if}
],
"shippingCost": "{$shipping_cost|html_entity_decode:2:'UTF-8'}",
"shippingCostFloat": "{$shipping_cost_float|html_entity_decode:2:'UTF-8'}",
{if isset($tax_cost)}
"taxCost": "{$tax_cost|html_entity_decode:2:'UTF-8'}",
{/if}
"wrappingCost": "{$wrapping_cost|html_entity_decode:2:'UTF-8'}",
"nbTotalProducts": "{$nb_total_products}",
"total": "{$total|html_entity_decode:2:'UTF-8'}",
"productTotal": "{$product_total|html_entity_decode:2:'UTF-8'}",
{if isset($errors) && $errors}
"hasError" : true,
"errors" : [
{foreach from=$errors key=k item=error name='errors'}
"{$error|addslashes|html_entity_decode:2:'UTF-8'}"
{if !$smarty.foreach.errors.last},{/if}
{/foreach}
]
{else}
"hasError" : false
{/if}
{rdelim}
 

ajax-cart.js

				if ($('#cart_block_product_'+ domIdProduct).length == 0)
				{
					var productId = parseInt(this.id);
					var productAttributeId = (this.hasAttributes ? parseInt(this.attributes) : 0);
					var content =  '<dt class="hidden" id="cart_block_product_' + domIdProduct + '">';
					content += '<span class="quantity-formated"><span class="quantity">' + this.quantity + '</span>x</span>';
					var min = this.name.indexOf(';', 100);
					var name = (this.name.length > 100 ? this.name.substring(0, 100) + '...' : this.name);
					content += '<a href="' + this.link + '" title="' + this.name + '" class="cart_block_product_name">' + this.name + '</a>';
Edited by tozi (see edit history)
Link to comment
Share on other sites

Hi.

 

The name is truncated when it's passed to the javascript function.

 

You need to override the 'modules/blockcart/blockcart-json.tpl' file and remove the truncate function on line 36.

 

Also remove the truncate function from 'modules/blockcart/blockcart.tpl'

 

Regards.

Robin.

The CartExpert Team

Edited by CartExpert.net (see edit history)
Link to comment
Share on other sites

Remove the truncate at the product name (not the discount name):

"name":          "{$product.name|html_entity_decode:2:'UTF-8'|truncate:15:'...':true|escape:'htmlall'}",

Edit the javascript file:

var name = (this.name.length > 100 ? this.name.substring(0, 100) + '...' : this.name);
var name_short = this.name.substring(0, 15) + '...' : this.name; // YOU CAN CHANGE 15 TO OTHER VALUE
content += '<a href="' + this.link + '" title="' + this.name + '" class="cart_block_product_name">' +name_short + '</a>';

Regards.

Robin.

The CartExpert Team

Edited by CartExpert.net (see edit history)
Link to comment
Share on other sites

Yes,I set there 11 characters. And? Showing it's still the same. 

<a class="cart_block_product_name" href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'html'}" title="{$product.name|escape:html:'UTF-8'}">
				{$product.name|truncate:11:'...'|escape:html:'UTF-8'}</a>
Edited by tozi (see edit history)
Link to comment
Share on other sites

In ajax-cart.js i set (I do not know if I got it right. But it does not work.)

var min = this.name.indexOf(';', 10);
var name = (this.name.length > 12 ? this.name.substring(0, ((min - 10) <= 7) ? min : 10) + '...' : this.name);
content += '<a href="' + this.link + '" title="' + this.name + '" class="cart_block_product_name">' + this.name + '</a>';
Edited by tozi (see edit history)
Link to comment
Share on other sites

Still do not understand. 

So i must rewrite some in here?

<a class="cart_block_product_name" href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'html'}" title="{$product.name|escape:html:'UTF-8'}">
				{$product.name|truncate:16:'...'|escape:html:'UTF-8'}</a>

or here?

var name = (this.name.length > 30 ? this.name.substring(0, ((min - 10) <= 7) ? min : 10) + '...' : this.name);
					content += '<a href="' + this.link + '" title="' + this.name + '" class="cart_block_product_name">' + this.name + '</a>';

I'm confused.

Link to comment
Share on other sites

this.name is the long version.

name is the truncated version.

 

You are putting 'name' (the truncated version) in the title.

 

And your javascript file shows no changes, it has this line:

content += '<a href="' + this.link + '" title="' + this.name + '" class="cart_block_product_name">' + this.name + '</a>';

 

Regards.

Robin.

The CartExpert Team

Link to comment
Share on other sites

I dont know when is the problem...

 

blockcart-json.tpl

{ldelim}
"products": [
{if $products}
{foreach from=$products item=product name='products'}
{assign var='productId' value=$product.id_product}
{assign var='productAttributeId' value=$product.id_product_attribute}
	{ldelim}
		"id":            {$product.id_product},
		"link":          "{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|addslashes|replace:'\\\'':'\''}",
		"quantity":      {$product.cart_quantity},
		"priceByLine":   "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
		"name":          "{$product.name|html_entity_decode:2:'UTF-8'|truncate:16:'...':true|escape:'htmlall'}",
		"price":         "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
		"price_float":   "{$product.total}",
		"idCombination": {if isset($product.attributes_small)}{$productAttributeId}{else}0{/if},
		"idAddressDelivery": {if isset($product.id_address_delivery)}{$product.id_address_delivery}{else}0{/if},
		"is_gift" : {if isset($product.is_gift) && $product.is_gift}1{else}0{/if},
{if isset($product.attributes_small)}
		"hasAttributes": true,
		"attributes":    "{$product.attributes_small|addslashes|replace:'\\\'':'\''}",
{else}
		"hasAttributes": false,
{/if}
		"hasCustomizedDatas": {if isset($customizedDatas.$productId.$productAttributeId)}true{else}false{/if},
		"customizedDatas":[
		{if isset($customizedDatas.$productId.$productAttributeId[$product.id_address_delivery])}
		{foreach from=$customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] key='id_customization' item='customization' name='customizedDatas'}{ldelim}
{* This empty line was made in purpose (product addition debug), please leave it here *}
			"customizationId":	{$id_customization},
			"quantity":			"{$customization.quantity}",
			"datas": [
				{foreach from=$customization.datas key='type' item='datas' name='customization'}
				{ldelim}
					"type":	"{$type}",
					"datas":
					[
					{foreach from=$datas key='index' item='data' name='datas'}
						{ldelim}
						"index":			{$index},
						"value":			"{Tools::nl2br($data.value|addslashes|replace: '\\\'':'\'')}",
						"truncatedValue":	"{Tools::nl2br($data.value|truncate:28:'...'|addslashes|replace: '\\\'':'\'')}"
						{rdelim}{if !$smarty.foreach.datas.last},{/if}
					{/foreach}]
				{rdelim}{if !$smarty.foreach.customization.last},{/if}
				{/foreach}
			]
		{rdelim}{if !$smarty.foreach.customizedDatas.last},{/if}
		{/foreach}
		{/if}
		]
	{rdelim}{if !$smarty.foreach.products.last},{/if}
{/foreach}{/if}
],
"discounts": [
{if $discounts}{foreach from=$discounts item=discount name='discounts'}
	{ldelim}
		"id":              "{$discount.id_discount}",
		"name":            "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}",
		"description":     "{$discount.description|addslashes|replace:'\\\'':'\''}",
		"nameDescription": "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}",
		"code":            "{$discount.code}",
		"link":            "{$link->getPageLink("$order_process", true, NULL, "deleteDiscount={$discount.id_discount}")|escape:'html'}",
		"price":           "{if $priceDisplay == 1}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_tax_exc}{else}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_real}{/if}",
		"price_float":     "{if $priceDisplay == 1}{$discount.value_tax_exc}{else}{$discount.value_real}{/if}"
	{rdelim}
	{if !$smarty.foreach.discounts.last},{/if}
{/foreach}{/if}
],
"shippingCost": "{$shipping_cost|html_entity_decode:2:'UTF-8'}",
"shippingCostFloat": "{$shipping_cost_float|html_entity_decode:2:'UTF-8'}",
{if isset($tax_cost)}
"taxCost": "{$tax_cost|html_entity_decode:2:'UTF-8'}",
{/if}
"wrappingCost": "{$wrapping_cost|html_entity_decode:2:'UTF-8'}",
"nbTotalProducts": "{$nb_total_products}",
"total": "{$total|html_entity_decode:2:'UTF-8'}",
"productTotal": "{$product_total|html_entity_decode:2:'UTF-8'}",
{if isset($errors) && $errors}
"hasError" : true,
"errors" : [
{foreach from=$errors key=k item=error name='errors'}
	"{$error|addslashes|html_entity_decode:2:'UTF-8'}"
	{if !$smarty.foreach.errors.last},{/if}
{/foreach}
]
{else}
"hasError" : false
{/if}
{rdelim}

ajax-cart.js

var min = this.name.indexOf(';', 10);
var name = (this.name.length > 12 ? this.name.substring(0, ((min - 10) <= 7) ? min : 10) + '...' : this.name);
var name_short = this.name.substring(0, 100) + '...'; 
content += '<a href="' + this.link + '" title="' + this.name + '" class="cart_block_product_name">' + this.name + '</a>';

blockcart.tpl

<a class="cart_block_product_name" href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'html'}" title="{$product.name|escape:html:'UTF-8'}">
				{$product.name|truncate:15:'...'|escape:html:'UTF-8'}</a>
Link to comment
Share on other sites

var name = this.name.substring(0, 30) + '...';

'name' is supposed to be the long name, yet you are truncating it!

 

These two lines:

var name = this.name.substring(0, 30) + '...';
var name_short = this.name.substring(0, 30) + '...';

will give the same result, like:

x = 2+2

y = 2+2

 

First, you need to remove the truncation on the name in the two tpl files (blockcart-json.tpl and blockcart.tpl)

Second, you need to have a truncated version of the name in the javascript file, so use only

var name_short = this.name.substring(0, 30) + '...';

 

Display short name in the <a> tag and put this.name in title.

 

Regards.

Robin.

The CartExpert Team

Link to comment
Share on other sites

Yet works. But after reloading the page it wrong again. 

 

var min = this.name.indexOf(';', 10);
var name = (this.name.length > 12 ? this.name.substring(0, ((min - 10) <= 7) ? min : 10) + '...' : this.name);
var name_short = this.name.substring(0, 12) + '...'; 
content += '<a href="' + this.link + '" title="' + this.name + '" class="cart_block_product_name">' + name_short + '</a>';
Edited by tozi (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...