简体   繁体   中英

Prestashop: disable add-to-cart button depending on user group and product

I use Prestashop 1.6.2 and I have a problem trying to add this function.

I am a little bit new trying to mod prestashop, the thing is that I have some products that can be bought only for professionals. Everytime a user registers it's assigned to a user group (professional and no-professional).

I know I can hide the categories for specific user groups, but this method is not perfect, due to if they know the name of the product or search it, they can still access the product page and buy it.

Is there any smarty variable to edit the product.tpl so it displays the button with the conditions above? Or a module or another way to do this?

I don't know exactly is there is a variable already set in smarty or not, but your can define your customer variable with object of customer: Find controllers/front/ProductController.php file, find method assignPriceAndTax and in the end of it you will find something similar to this:

$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),
        ));

Add to this array

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

This variable you can use on the product page. You can use the same way to close those buttons for all 'buy-windows' on your site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM