Prestashop:显示我的心愿单标题菜单项上的产品数量

时间:2014-08-19 11:25:20

标签: php smarty prestashop prestashop-1.5 prestashop-1.6

如何显示wishlist标题菜单中的产品数量?我希望看起来像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>

但这似乎是我的愿望清单,而不是我的愿望清单中的产品。

2 个答案:

答案 0 :(得分:2)

这是解决此问题的快速解决方案。这不是100%有效,但它可以解决问题。

  1. 转到 \ modules \ blockuserinfo 并修改 blockuserinfo.php
  2. 更新 hookTop()功能(这将计算已记录用户的活动心愿单中的产品,并将值分配给 $ count_products 变量) :

    public function hookTop($ params)     {         if(!$ this-&gt; 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');
    

    }

  3. 现在我们必须在菜单上显示它。修改 blockuserinfo.tpl 它在同一目录中并添加:

    {l s =&#39;愿望清单&#39; mod =&#39; blockwishlist&#39;}({$ count_products})

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

  5. *注意:如果用户有多个愿望清单,那么这个技巧只适用于愿望清单

答案 1 :(得分:0)

它运行正常,但在“blockuserinfo.tpl”中变量不是$ count_products,您必须使用$ current_user。所以,要添加的好行是:

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