Php Prestashop:显示我的愿望列表标题菜单项上的产品数量

Php Prestashop:显示我的愿望列表标题菜单项上的产品数量,php,smarty,prestashop,prestashop-1.5,prestashop-1.6,Php,Smarty,Prestashop,Prestashop 1.5,Prestashop 1.6,如何显示我的愿望列表标题菜单中的产品数量?这就是我想要的样子: 我试过这样的方法: <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'|coun

如何显示我的愿望列表标题菜单中的产品数量?这就是我想要的样子:

我试过这样的方法:

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


但它似乎只计算我的愿望清单,而不是愿望清单中的产品。

这里有一个快速解决此问题的方法。这不是100%的效率,但它可以做到

  • 转到\modules\blockuserinfo并编辑blockuserinfo.php
  • hookTop()函数更新到此项(这将从已登录用户的活动愿望列表中对产品进行计数,并将值分配给$count\u products变量):

    公共函数钩子($params) { 如果(!$this->active) 返回

    $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');
    
    }

  • 现在我们必须在菜单上显示它。编辑blockuserinfo.tpl 它位于同一目录中,并添加以下内容:

    {l s='Wishlist'mod='blockwishlist'}({$count\u products})

  • 保存所有文件。它应该显示在前端的产品数量

  • *注意:如果用户有多个愿望列表,则该技巧仅适用于愿望列表。它运行正常,但在“blockuserinfo.tpl”中,变量不是$count\u products,必须使用$current\u user。因此,好的补充是:

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

    为什么我的问题被否决了?