Jump to content

Hide Volume Discount from non logged in customers


Sergio

Recommended Posts

Hello Guys. I´ve configured volume price (block with Discount in each prodcut). But it always shown, also when i am not logged in. How can set volume price only after logged in?

 

I have set groups to what can be seen, through the backoffice, but "Volume Discount" is not a module we can hide in groups settings.

 

Using Prestashop 1.6.1.24

 

I appreciate any help.

Edited by Sergio
Added info (see edit history)
Link to comment
Share on other sites

I know that if I comment out this piece of code in "products.tpl", the volume discout stays disabled, but unfortunately it stays disabled for all goups. I want it enabled only for the group "Customers"

 

{*
{if (isset($quantity_discounts) && count($quantity_discounts) > 0)}
            <!-- quantity discount -->
            <section class="page-product-box">
                <h3 class="page-product-heading">{l s='Volume discounts'}</h3>
                <div id="quantityDiscount">
                    <table class="std table-product-discounts">
                        <thead>
                            <tr>
                                <th>{l s='Quantity'}</th>
                                <th>{if $display_discount_price}{l s='Price'}{else}{l s='Discount'}{/if}</th>
                                <th>{l s='You Save'}</th>
                            </tr>
                        </thead>
                        <tbody>
                        {foreach from=$quantity_discounts item='quantity_discount' name='quantity_discounts'}
                            {if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
                                {$realDiscountPrice=$quantity_discount.base_price|floatval-$quantity_discount.real_value|floatval}
                            {else}
                                {$realDiscountPrice=$quantity_discount.base_price|floatval*(1 - $quantity_discount.reduction)|floatval}
                            {/if}
                            <tr class="quantityDiscount_{$quantity_discount.id_product_attribute}" data-real-discount-value="{convertPrice price = $realDiscountPrice}" data-discount-type="{$quantity_discount.reduction_type}" data-discount="{$quantity_discount.real_value|floatval}" data-discount-quantity="{$quantity_discount.quantity|intval}">
                                <td>
                                    {$quantity_discount.quantity|intval}
                                </td>
                                <td>
                                    {if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
                                        {if $display_discount_price}
                                            {if $quantity_discount.reduction_tax == 0 && !$quantity_discount.price}
                                                {convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction_with_tax)|floatval}
                                            {else}
                                                {convertPrice price=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
                                            {/if}
                                        {else}
                                            {convertPrice price=$quantity_discount.real_value|floatval}
                                        {/if}
                                    {else}
                                        {if $display_discount_price}
                                            {if $quantity_discount.reduction_tax == 0}
                                                {convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction_with_tax)|floatval}
                                            {else}
                                                {convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
                                            {/if}
                                        {else}
                                            {$quantity_discount.real_value|floatval}%
                                        {/if}
                                    {/if}
                                </td>
                                <td>
                                    <span>{l s='Up to'}</span>
                                    {if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
                                        {$discountPrice=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
                                    {else}
                                        {$discountPrice=$productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
                                    {/if}
                                    {$discountPrice=$discountPrice * $quantity_discount.quantity}
                                    {$qtyProductPrice=$productPriceWithoutReduction|floatval * $quantity_discount.quantity}
                                    {convertPrice price=$qtyProductPrice - $discountPrice}
                                </td>
                            </tr>
                        {/foreach}
                        </tbody>
                    </table>
                </div>
            </section>
        {/if}
*}
 

Link to comment
Share on other sites

./classes/controller/FrontController.php

in function init -> // Deprecated

change to:

// Deprecated
        $this->context->smarty->assign(array(
            'id_currency_cookie' => (int)$currency->id,
            'logged'             => $this->context->customer->isLogged(),
	'customer_group'             => Customer::getDefaultGroupId($this->context->customer->id), // added
            'customerName'       => ($this->context->customer->logged ? $this->context->cookie->customer_firstname.' '.$this->context->cookie->customer_lastname : false)
        ));

 

and in TPL:

{if $logged && $customer_group == '2'}
.....
{/if}

 

Edited by Guest (see edit history)
Link to comment
Share on other sites

28 minutes ago, Guest said:

./classes/controller/FrontController.php

in function init -> // Deprecated

change to:


// Deprecated
        $this->context->smarty->assign(array(
            'id_currency_cookie' => (int)$currency->id,
            'logged'             => $this->context->customer->isLogged(),
	'customer_group'             => Customer::getDefaultGroupId($this->context->customer->id)), // added
            'customerName'       => ($this->context->customer->logged ? $this->context->cookie->customer_firstname.' '.$this->context->cookie->customer_lastname : false)
        ));

 

and in TPL:


{if $logged && $customer_group == '2'}
.....
{/if}

 

Hi Daniel,

 

Thanks for the help, but it doesn't work. As soon as i add the line in Frontcontroller, after cleaning cache and all, i got a 500 error and nothing else.

Link to comment
Share on other sites

Because there is an error in the code.
I repaired.
If you understand php at least a little, you will see a mistake.

There are two parentheses instead of one )), // added

 

Ctrl + C and Ctrl + V are not enough!

Edited by Guest (see edit history)
Link to comment
Share on other sites

2 minutes ago, Guest said:

Because there is an error in the code.
I repaired.
If you understand php at least a little, you will see a mistake.

There are two parentheses instead of one )), // added

Sorry, my bad. I haven't noticed, and my php is rusty 😉

Link to comment
Share on other sites

47 minutes ago, Sergio said:

Hi Daniel,

 

Thanks for the help, but it doesn't work. As soon as i add the line in Frontcontroller, after cleaning cache and all, i got a 500 error and nothing else.

Ok, Volume discount as gone, i have to select for group 3 it's my customer group ID, but not only the Volume discount hides from non logged in, as the details of the products also hide.

Link to comment
Share on other sites

Update only this line:

{if (isset($quantity_discounts) && count($quantity_discounts) > 0)}

to:

{if (isset($quantity_discounts) && count($quantity_discounts) > 0) && $logged == '1' && $customer_group == '3'}
Link to comment
Share on other sites

6 hours ago, Guest said:

Update only this line:



{if (isset($quantity_discounts) && count($quantity_discounts) > 0)}

to:



{if (isset($quantity_discounts) && count($quantity_discounts) > 0) && $logged == '1' && $customer_group == '3'}

Daniel thank you for your coding. It works as intended.

Edited by Sergio (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...