0

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?

Matteo Enna
  • 1,285
  • 1
  • 15
  • 36
albera4
  • 33
  • 1
  • 1
  • 6

1 Answers1

0

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.

  • Ok, but will that variable save the customer group of the user? I've never used a custom variable in prestashop. Could you give me more details? – albera4 Nov 27 '15 at 11:43