Prestashop:根据用户组和产品禁用“添加到购物车”按钮

时间:2015-11-26 08:53:59

标签: button smarty prestashop prestashop-1.6 usergroups

我使用Prestashop 1.6.2并且在尝试添加此功能时遇到问题。

我尝试修改prestashop有点新,事情是我有一些产品只能为专业人士购买。每次用户注册时,都会将其分配给用户组(专业人员和非专业人员)。

我知道我可以隐藏特定用户组的类别,但这种方法并不完美,因为如果他们知道产品名称或搜索产品,他们仍然可以访问产品页面并购买。

是否有任何智能变量可以编辑product.tpl,以便显示上述条件的按钮?或模块或其他方式来做到这一点?

1 个答案:

答案 0 :(得分:0)

我不知道是否已经在smarty中设置了变量,但您可以使用客户对象定义客户变量: 找到controllers / front / ProductController.php文件,找到assignPriceAndTax方法,最后你会发现类似的东西:

$this->context->smarty->assign(array(
            'quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (float)$tax, $ecotax_tax_amount),
            'ecotax_tax_inc' => $ecotax_tax_amount,
            'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2),
            'ecotaxTax_rate' => $ecotax_rate,
            'productPriceWithoutEcoTax' => (float)$product_price_without_eco_tax,
            'group_reduction' => $group_reduction,
            'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address),
            'ecotax' => (!count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((float)$this->product->ecotax) : 0),
            'tax_enabled' => Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'),
            'customer_group_without_tax' => Group::getPriceDisplayMethod($this->context->customer->id_default_group),
        ));

添加到此数组

'customer_object' => $this->context->customer,

您可以在产品页面上使用此变量。 您可以使用相同的方法关闭网站上所有“买入窗口”的按钮。