Jump to content

layer cart pop up window on add to cart event, no attribute name, only values


Kerm

Recommended Posts

Hello,

 

When i add product in my cart i see cart layer pop up window, and in the block which are displayed attributes of the products, I see only the values of the selected attributes but not their names.

It should be as follows: Size: 2XL, Color: Red. But i have only: 2XL, Red....

 

It not right. Can some one help me? How add attribute names in this block?

Link to comment
Share on other sites

The variable that displays selected combination values stored in a file blockcart-json.tpl:

"attributes": {$product.attributes_small|json_encode},

How can i fix this line for add attribute names?

Link to comment
Share on other sites

Maybe it can be done more easily, other ways to solve this problem, I have not found.
 
First need edit function "hookAjaxCall" inside blockcart.php, near line 234, after this rule:
 

if (is_array($res) && ($id_product = Tools::getValue('id_product')) && Configuration::get('PS_BLOCK_CART_SHOW_CROSSSELLING'))
	{
		$this->smarty->assign('orderProducts', OrderDetail::getCrossSells($id_product, $this->context->language->id,
			Configuration::get('PS_BLOCK_CART_XSELL_LIMIT')));
		$res['crossSelling'] = $this->display(__FILE__, 'crossselling.tpl');
	}

And before this line:
 

$res = Tools::jsonEncode($res);

Need to insert the following code:
 

$id_shop = (int)Context::getContext()->shop->id;
$id_lang = (int)Context::getContext()->cookie->id_lang;

foreach ($res['products'] as $key => &$product) {
	if(isset($product['idCombination'])){
		$id_ombination = $product['idCombination'];
		if(!empty($id_ombination)){
			$attr_ids = Db::getInstance()->ExecuteS('
				SELECT ac.`id_attribute`, ac.`id_product_attribute`
				FROM `'._DB_PREFIX_.'product_attribute_combination` ac
				WHERE `id_product_attribute` = '.$id_ombination.'
			');
			foreach ($attr_ids as $key => &$id_attribute) {
				if(isset($id_attribute['id_attribute'])){
					$id_attriute = $id_attribute['id_attribute'];
					$attr_name = Db::getInstance()->ExecuteS('
						SELECT a.`id_attribute_group`, a.`id_attribute`, ag.`public_name` as group_name, al.name as attribute_name
						FROM `'._DB_PREFIX_.'attribute` a
						LEFT JOIN `'._DB_PREFIX_.'attribute_group` alg ON (alg.`id_attribute_group` = a.`id_attribute_group`)
						LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.`id_attribute` = a.`id_attribute` AND al.`id_lang` = '.$id_lang.')
						LEFT JOIN `'._DB_PREFIX_.'attribute_shop` als ON (als.`id_attribute` = a.`id_attribute` AND als.`id_shop` = '.$id_shop.')
						LEFT JOIN `'._DB_PREFIX_.'attribute_group_shop` ags ON (ags.`id_attribute_group` = a.`id_attribute_group` AND ags.`id_shop` = '.$id_shop.')
						LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` ag ON (ag.`id_attribute_group` = ags.`id_attribute_group` AND ag.`id_lang` = '.$id_lang.')
						WHERE a.`id_attribute` = '.$id_attriute.'
						GROUP BY a.`id_attribute_group`
						ORDER BY a.`id_attribute_group` DESC
					');
					$id_attribute['id_attribute_group'] = $attr_name[0]['id_attribute_group'];
					$id_attribute['group_name'] = $attr_name[0]['group_name'];
					$id_attribute['attribute_name'] = $attr_name[0]['attribute_name'];
					$id_attribute['attribute_fullname'] = '<strong class="dark">'.$attr_name[0]['group_name'].'</strong>'.$this->l(': ').$attr_name[0]['attribute_name'];
				}
			}
			$attribute_fullname = '';
			foreach ($attr_ids as $key => $value) {
				$attribute_fullname .= $value['attribute_fullname'].', ';
			}
			$attribute_fullname = trim($attribute_fullname, ', ');
			// $product['attributes_info'] = $attr_ids;
			$product['attributes_full'] = $attribute_fullname;
		}
	}
}

After need edit ajax-cart.js file in module dir (/themes/your_theme/js/modules/blockcart).
On line 735 find this code:
 

$('#layer_cart_product_attributes').html(product.attributes);

And change on this:
 

$('#layer_cart_product_attributes').html(product.attributes_full.replace(/\,/g,'<br>'));

Thats all!
Screenshot:

post-231092-0-52858900-1445936402_thumb.jpg
 
 
 
If you also need to see this information in top blockcart module hook, you need change code in ajax-cart.js near line 615:

Before "if (this.hasAttributes)" insert a new row:

 


var attributes_full = $.trim($('<strong />').html(this.attributes_full).text());

After, change this line near:
 

content += '<div class="product-atributes"><a href="' + this.link + '" title="' + this.name + '">' + this.attributes + '</a></div>';

to:
 

content += '<div class="product-atributes"><a href="' + this.link + '" title="' + this.name + '">' + attributes_full + '</a></div>';

And also edit blockcart.tpl file near line 70 find this code:
 

{if isset($product.attributes_small)}
	<div class="product-atributes">
		<a href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'html':'UTF-8'}" title="{l s='Product detail' mod='blockcart'}">{$product.attributes_small}</a>
	</div>
{/if}

And replace it on this one:
 

{if isset($product.attributes)}
	<div class="product-atributes">
		<a href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'html':'UTF-8'}" title="{l s='Product detail' mod='blockcart'}">{$product.attributes|replace:' :':':'}</a>
	</div>
{/if}

Screenshot:

post-231092-0-03526600-1445936700_thumb.jpg

Edited by Kerm (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 year later...

There is an easier solution. First you need to override blockcart-json.tpl by putting it into /themes/your-theme/modules/blockcart folder if it's not already there. Then below line 46

"attributes": {$product.attributes_small|json_encode},
you add this line

"attributes_full": {$product.attributes|json_encode},
After that /themes/your-theme/js/modules/blockcart/ajax-cart.js you just have to replace line around 743

$('#layer_cart_product_attributes').html(product.attributes);
with the line Kerm posted

$('#layer_cart_product_attributes').html(product.attributes_full.replace(/\,/g,'<br>'));
and that's it. The name of the attributes won't get bolded but i thinks it's no problem. Edited by janskopljak (see edit history)
  • Like 1
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...