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

问题描述 投票:2回答:2

如何显示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>

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

php smarty prestashop prestashop-1.5 prestashop-1.6
2个回答
2
投票

这是这个问题的快速解决方案。这不是100%有效,但它会做到这一点。

  1. 转到\ modules \ blockuserinfo并编辑blockuserinfo.php
  2. 将hookTop()函数更新为此(这将计算已记录用户的活动心愿单中的产品并将值分配给$ count_products变量): 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. 现在我们必须在菜单上显示它。编辑它位于同一目录下的blockuserinfo.tpl并添加: {l s ='Wishlist'mod ='blockwishlist'}({$ count_products})
  4. 保存所有文件。它应该在前端显示产品的数量

*注意:如果用户有多个愿望清单,则该技巧仅适用于愿望清单


0
投票

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

{l s='Wishlist' mod='blockwishlist'} ({$current_user})
© www.soinside.com 2019 - 2024. All rights reserved.