2

How can I show the number of products from my wishlist header menu? This is how I want to look like this:

I tried something like this:

<a href="/index.php?fc=module&module=blockwishlist&controller=mywishlist" 
title="{l s='My wishlists' mod='blockwishlist'}" 
rel="nofollow">{l s='Wishlist' mod='blockwishlist'} ({'wishlist'|count})
</a>

But it seems to count my wishlists and not my products from the wishlist.

1
  • Why my question have been downvoted?
    – Dan
    Aug 19, 2014 at 11:52

2 Answers 2

2

Here's a quick solution for this problem. This is not 100% efficient but it will do the trick.

  1. Go to \modules\blockuserinfo and edit blockuserinfo.php
  2. Update hookTop() function to this (This will count the products from the active wishlist of the logged user and assign the value to $count_products variable) :

    public function hookTop($params) { if (!$this->active) return;

    $current_user = (int)$this->context->cookie->id_customer;
    
    $id_wishlist = Db::getInstance()->getValue("SELECT id_wishlist FROM `"._DB_PREFIX_."wishlist` WHERE id_customer = '$current_user'");
    $count_products = Db::getInstance()->getValue("SELECT COUNT(id_wishlist_product) FROM `"._DB_PREFIX_."wishlist_product` WHERE id_wishlist = '$id_wishlist'");
    
    
    $this->smarty->assign(array(
        'current_user' => $count_products,
        'cart' => $this->context->cart,
        'cart_qties' => $this->context->cart->nbProducts(),
        'logged' => $this->context->customer->isLogged(),
        'customerName' => ($this->context->customer->logged ? $this->context->customer->firstname.' '.$this->context->customer->lastname : false),
        'firstName' => ($this->context->customer->logged ? $this->context->customer->firstname : false),
        'lastName' => ($this->context->customer->logged ? $this->context->customer->lastname : false),
        'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order'
    ));
    return $this->display(__FILE__, 'blockuserinfo.tpl');
    

    }

  3. Now we have to display it on the menu. Edit blockuserinfo.tpl that it's in the same directory and add this:

    {l s='Wishlist' mod='blockwishlist'} ({$count_products})

  4. Save all files. It should displayed in the frontend the number of products

*Note: If the user has multiple wishlists, the trick will work just for a wishlist

0

It runs OK, but in "blockuserinfo.tpl" the variable is not $count_products, you must use $current_user. So, the good line to add is:

{l s='Wishlist' mod='blockwishlist'} ({$current_user})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.