Jump to content

[SOLVED]Whishlist block with images


yacorro

Recommended Posts

Hi,

 

Is it possible to edit whishlist module in a way so it can display small images instead of list of products?

So after customer add product to whishlist, he can see thumbnails not list in block whishlist.

 

Thx for help.

Link to comment
Share on other sites

Hi yacorro,

 

I played a little with it. Maybe try the following: (Code from Prestashop Version 1.5.4.1)

 

Edit file : /modules/blockwishlist/blockwishlist.php (Make a backup, just in case you don't like the change, or there's something wrong in my modification!)

 

Find the function: public function hookRightColumn($params)

 

 

Add the piece of code between:

// ADD THIS BLOCK TO GET THE COVER PICTURES

piece of code to add...

// END OF BLOCK TO ADD

 

public function hookRightColumn($params)
{
 global $errors;
 require_once(dirname(__FILE__).'/WishList.php');
 if ($this->context->customer->isLogged())
 {
  $wishlists = Wishlist::getByIdCustomer($this->context->customer->id);
  if (empty($this->context->cookie->id_wishlist) === true ||
WishList::exists($this->context->cookie->id_wishlist, $this->context->customer->id) === false)
  {
if (!sizeof($wishlists))
 $id_wishlist = false;
else
{
 $id_wishlist = (int)($wishlists[0]['id_wishlist']);
 $this->context->cookie->id_wishlist = (int)($id_wishlist);
}
  }
  else
$id_wishlist = $this->context->cookie->id_wishlist;

//  ADD THIS BLOCK TO GET THE COVER PICTURES
  if ($id_wishlist)
  {
$wishlist = new WishList($id_wishlist);
$products = WishList::getProductByIdCustomer($id_wishlist, $wishlist->id_customer,
  $this->context->language->id, null, true);
for ($i = 0; $i < sizeof($products); ++$i)
{
 $obj = new Product((int)($products[$i]['id_product']), false,
   $this->context->language->id);
 if (!Validate::isLoadedObject($obj))
  continue;
 else
 {
  $images = $obj->getImages($this->context->language->id);
  foreach ($images AS $k => $image)
  {
   if ($image['cover'])
   {
	$products[$i]['cover'] = $obj->id.'-'.$image['id_image'];
	break;
   }
  }
  if (!isset($products[$i]['cover']))
   $products[$i]['cover'] = $this->context->language->iso_code.'-default';
 }
}
  }
// END OF BLOCK TO ADD

  $this->smarty->assign(array(
'id_wishlist' => $id_wishlist,
'isLogged' => true,
'wishlist_products' => ($id_wishlist == false ? false : $products),  // CHANGE TO $products
'wishlists' => $wishlists,
'ptoken' => Tools::getToken(false)));
 }
 else
  $this->smarty->assign(array('wishlist_products' => false, 'wishlists' => false));

 return ($this->display(__FILE__, 'blockwishlist.tpl'));
}

 

Just below the added block, change the red value in the smarty array:

 

$this->smarty->assign(array(

'id_wishlist' => $id_wishlist,

'isLogged' => true,

'wishlist_products' => ($id_wishlist == false ? false : $products), // CHANGE TO $products

'wishlists' => $wishlists,

'ptoken' => Tools::getToken(false)));

}

 

save the file.

 

 

Then edit the file:

themes/<your theme folder>/modules/blockwishlist/blockwishlist.tpl:

 

and add the red lines:

 

<div id="wishlist_block" class="block account">

<p class="title_block">

<a href="{$wishlist_link}">{l s='Wishlist' mod='blockwishlist'}</a>

</p>

<div class="block_content">

<div id="wishlist_block_list" class="expanded">

{if $wishlist_products}

<dl class="products">

{foreach from=$wishlist_products item=product name=i}

<dt class="{if $smarty.foreach.i.first}first_item{elseif $smarty.foreach.i.last}last_item{else}item{/if}">

<span class="quantity-formated"><span class="quantity">{$product.quantity|intval}</span>x</span>

<a class="cart_block_product_name"

href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category_rewrite)}" title="{$product.name|escape:'htmlall':'UTF-8'}">

{$product.name|truncate:30:'...'|escape:'htmlall':'UTF-8'}

<img src="{$link->getImageLink($product.link_rewrite, $product.cover, 'medium_default')}" alt="{$product.name|escape:'htmlall':'UTF-8'}" height="60" width="60">

</a>

 

save the file and check if it works by reloading the page with the wish list block. (Temporarily turn OFF smarty cache and force recompile of templates in Advanced parameters -> performance,otherwise you might not see the changes)

 

Hope this helps,

pascal

 

N.B. I ADDED the picture, didn't take away the text. You can do that of course if needed in (the tpl file).

Edited by PascalVG
Added some comment at the end.. (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hi PascalVG and thank you for sharing your solution!

 

I have done what you said, and your solution work... but...

 

if i add a new product to wishlist, ajax don't add image.

 

I have edited blockwishlist-ajax.tpl adding link to image, but image are not loaded.

	<dl class="products" style="{if $products}border-bottom:1px solid #fff;{/if}">
	{foreach from=$products item=product name=i}
		<dt class="{if $smarty.foreach.i.first}first_item{elseif $smarty.foreach.i.last}last_item{else}item{/if}">
<img src="{$link->getImageLink($product.link_rewrite, $product.cover, 'small_default')}" alt="{$product.name|escape:'htmlall':'UTF-8'}" height="45" width="45">
			<span class="quantity-formated"><span class="quantity">{$product.quantity|intval}</span>x</span>
			<a class="cart_block_product_name" href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category_rewrite)|escape:'html'}" title="{$product.name|escape:'htmlall':'UTF-8'}" style="font-weight:bold;">{$product.name|truncate:13:'...'|escape:'htmlall':'UTF-8'}</a>
			<span class="remove_link"><a  rel="nofollow" href="javascript:;" onclick="javascript:WishlistCart('wishlist_block_list', 'delete', '{$product.id_product}', {$product.id_product_attribute}, '0', '{if isset($token)}{$token}{/if}');" title="{l s='remove this product from my wishlist' mod='blockwishlist'}"></a></class>
		</dt>
		
	{/foreach}
	</dl>

This is my blockwishlist-ajax.tpl edited... but dont work.

 

Ajax should send correct img link to tpl file... I am not able to make the change to the javascript file to load the image. Can you help me?

 

Best Regards,

Simone Giusti

 

PS:  this is my site, with wishlist module working:

www.iltuogarden.it

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

SOLVED!! 

 

in whishlist.php edit getProductByIdCustomer() as follow:

public static function getProductByIdCustomer($id_wishlist, $id_customer, $id_lang, $id_product = null, $quantity = false)
	{
		if (!Validate::isUnsignedId($id_customer) OR
			!Validate::isUnsignedId($id_lang) OR
			!Validate::isUnsignedId($id_wishlist))
			die (Tools::displayError());
		$products = Db::getInstance()->executeS('
		SELECT wp.`id_product`, wp.`quantity`, img.`id_image`, p.`quantity` AS product_quantity, pl.`name`, wp.`id_product_attribute`, wp.`priority`, pl.link_rewrite, cl.link_rewrite AS category_rewrite
		FROM `'._DB_PREFIX_.'wishlist_product` wp
		LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = wp.`id_product`
		'.Shop::addSqlAssociation('product', 'p').'
		LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON pl.`id_product` = wp.`id_product`'.Shop::addSqlRestrictionOnLang('pl').'
		LEFT JOIN `'._DB_PREFIX_.'wishlist` w ON w.`id_wishlist` = wp.`id_wishlist`
		LEFT JOIN `'._DB_PREFIX_.'image` img ON img.`id_product` = wp.`id_product`
		LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON cl.`id_category` = product_shop.`id_category_default` AND cl.id_lang='.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
		WHERE w.`id_customer` = '.(int)($id_customer).'
		AND pl.`id_lang` = '.(int)($id_lang).'
		AND img.`cover` = 1
		AND wp.`id_wishlist` = '.(int)($id_wishlist).
		(empty($id_product) === false ? ' AND wp.`id_product` = '.(int)($id_product) : '').
		($quantity == true ? ' AND wp.`quantity` != 0': '').'
		GROUP BY p.id_product, wp.id_product_attribute');
		if (empty($products) === true OR !sizeof($products))
			return array();
		for ($i = 0; $i < sizeof($products); ++$i)
		{

			$products[$i]['cover'] = $products[$i]['id_image'];	 			
			
			if (isset($products[$i]['id_product_attribute']) AND
				Validate::isUnsignedInt($products[$i]['id_product_attribute']))
			{
				$result = Db::getInstance()->executeS('
				SELECT al.`name` AS attribute_name, pa.`quantity` AS "attribute_quantity"
				FROM `'._DB_PREFIX_.'product_attribute_combination` pac
				LEFT JOIN `'._DB_PREFIX_.'attribute` a ON (a.`id_attribute` = pac.`id_attribute`)
				LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`)
				LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)($id_lang).')
				LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)($id_lang).')
				LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
				'.Shop::addSqlAssociation('product_attribute', 'pa').'
				WHERE pac.`id_product_attribute` = '.(int)($products[$i]['id_product_attribute']));
				$products[$i]['attributes_small'] = '';
				if ($result)
					foreach ($result AS $k => $row)
						$products[$i]['attributes_small'] .= $row['attribute_name'].', ';
				$products[$i]['attributes_small'] = rtrim($products[$i]['attributes_small'], ', ');
				if (isset($result[0]))
					$products[$i]['attribute_quantity'] = $result[0]['attribute_quantity'];
			}
			else
				$products[$i]['attribute_quantity'] = $products[$i]['product_quantity'];
				
				
				
				
				
			
		}
		return ($products);
	}
Link to comment
Share on other sites

  • 3 months later...

Hi PascalVG and tuxinside,

 

I was looking for a solution like this one but it's not working on my store. I have PS 1.4.8.2.

 

First, i just edited the blockwishlist-ajax.tpl and the blockwishlist.tpl to place this code:

<img src="{$link->getImageLink($product.link_rewrite, $product.cover, 'medium_default')}" alt="{$product.name|escape:'htmlall':'UTF-8'}"">

The problem is that the images are broken. On my store, the link becomes:

<img src="http://www.mysite.com/prestashop/img/p/-medium.jpg" alt="MyProduct">

I got -medium.jpg but no id_image...

 

Then i saw this post and tried to replicate it with no success. Another thing: my module is not on the right column but in the top/header with a click to show up (like the login here at the Prestashop site). So, my blockwishlist.php is a bit different:

 

 

 

public function hookHeader($params)
{
/*Tools::addCSS(($this->_path).'blockwishlist.css', 'all');*/
Tools::addJS( ($this->_path).'assets/script.js', 'all');
return $this->display(__FILE__, 'blockwishlist-header.tpl');
}


public function hookTop($params)
{
global $smarty, $errors;


require_once(dirname(__FILE__).'/WishList.php');
if ($params['cookie']->isLogged())
{
$wishlists = Wishlist::getByIdCustomer($params['cookie']->id_customer);
if (empty($params['cookie']->id_wishlist) === true ||
WishList::exists($params['cookie']->id_wishlist, $params['cookie']->id_customer) === false)
{
if (!sizeof($wishlists))
$id_wishlist = false;
else
{
$id_wishlist = (int)($wishlists[0]['id_wishlist']);
$params['cookie']->id_wishlist = (int)($id_wishlist);
}
}
else
$id_wishlist = $params['cookie']->id_wishlist;
$smarty->assign(array(
'id_wishlist' => $id_wishlist,
'isLogged' => true,
'wishlist_products' => ($id_wishlist == false ? false : WishList::getProductByIdCustomer($id_wishlist, $params['cookie']->id_customer, $params['cookie']->id_lang, null, true)),
'wishlists' => $wishlists,
'ptoken' => Tools::getToken(false)));
}
else
$smarty->assign(array('wishlist_products' => false, 'wishlists' => false));
return ($this->display(__FILE__, 'blockwishlist.tpl'));
}


public function hookLeftColumn($params)
{
return $this->hookRightColumn($params);
}

When i paste the code that PascalVG posted (not in the hookRightColum but in the topRightColum), the page is blank whit a "fatal error".

I don't know if the reason is that ithe code must be placed only on the hookRightColum or a code/syntax issue (PascalVG is for PS 1.5). Regarding this, i noticed some differences in the 1.5 and my 1.4.8.2 code:

global $smarty, $errors; opposed to global $errors;

But the main difference that i can see is that i have $params instead of $this:

if ($params['cookie']->isLogged()) opposed to if ($this->context->customer->isLogged()

You can see the many different instances on the code i posted from my blockwishlist.php file that illustrates this.

Or must i edit the script.js and/or the blockwishlist-header.tpl files?

 

So, if anyone can help me out it would be great.

Thanks.

Link to comment
Share on other sites

Hi mtm,

Sorry for the late reply, had a fever and cold this week, couldn't bring myself to sit behind the computer...

 

thanks for the feedback. Can you quickly summarise what you did to make it work? This may be useful for others with similar problems. 

 

Thanks, and happy selling!

pascal.

Link to comment
Share on other sites

Hi PascalVG,

 

Hope you're healthy now!
 
In fact, i was about to to post because it's kinda solved... I explain: the block has now images but the ajax part is not working, because the images are broken when i change the whishlist in the drop down list.
 
How i solved the images issue: Similar to the solution for the 1.5 version. In my case, the code that you said to add in the blockwishlist.ph file to the public function hookRightColumn($params), i copied it from the private function _displayProducts($id_wishlist) that i have a few lines and pasted at the end in the public function hookHeader($params), following your directions (see the differences of my case above). So, for this part i used the code from my file. It was not working because of PS diferent versions of the syntax code, i guess.
For the rest, i did the editing in the blockwishlist.tpl and in the wishlist.php files like you and tuxinside sugested.
 
Now, what's not working is the ajaz refresh of the images when i change the whishlist in the drop down menu in the block. The images are broken and only works well with a page refresh.
What i got in Chrome from the console is the following error:

 

WishlistChangeDefault.$.ajax.success ajax-wishlist.js:85
c.extend.handleSuccess jquery-1.4.4.min.js:142
c.extend.ajax.w.onreadystatechange jquery-1.4.4.min.js:141

The problem, from what i understand is in the ajax-whishlist.js file and the line 85 in the WishlistChangeDefault function:

 

function WishlistChangeDefault(id, id_wishlist)
{
$.ajax({
type: 'GET',
url: baseDir + 'modules/blockwishlist/cart.php',
async: true,
data: 'id_wishlist=' + id_wishlist + '&token=' + static_token,
cache: false,
success: function(data)
{
$('#' + id).slideUp('normal');
document.getElementById(id).innerHTML = data;
$('#' + id).slideDown('normal');
}
});
}
 
The line 85 in the function:
 
document.getElementById(id).innerHTML = data;
 
Can anyone help me how to figure out this?
Thanks.
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...