Jump to content

solution Display price only to login user


Jiten rash (away)
 Share

Recommended Posts

Hello guys If u like to dispaly price only to login users for some privacy..
.
and want--->DISPLAY PRICE ONLY TO LOGIN USERS.
go to backoffice customers and groups edit or tick the correct symbol on guest and customer

 

now the important thing we must display alert to  guest and visitors that they need to login to view prices so we need to add a piece of code homefeatured.tpl product list.tpl product.tpl block special.tpl

note:homefeatured and blockspecial are located in themes/default/modules

 

{if $logged}
        {else}
            <p class="logout">login for prices</p>
        {/if}

 

<span class="price">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span></p>{else}<div style="height:21px;"></div>{/if}{if $logged}
        {else}
            <p class="logout">login for prices</p>
        {/if}

Edited by Jiten rash (see edit history)
  • Like 3

Share this post


Link to post
Share on other sites

sorry demo has been deleted

 

u can also do this it doesnt removes the shoping cart

 

 

ok do this find themes/modules/homefeatured.tpl replace the text marked red with green

u need to find this code marked with red in all

product_list.tpl
product.tpl

In modules:

blockspecial.tpl
homefeatured.tpl

 

<span class="price">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span>

 

 

{if $logged}
{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}<span class="price" style="display: inline;">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
{/if}
{else}
<p class="logged_out">login for prices</p>
{/if}

Edited by Jiten rash (see edit history)
  • Thanks 1

Share this post


Link to post
Share on other sites

  • 1 month later...

:) Thanks to Jiten rash and EI Patron. I'm appreciate for your guides above. I'll try this in my b2b shop soon.

To show message for non-logged users, how about using jQuery jGrowl? http://plugins.jquery.com/jgrowl/

Maybe add this code in necessary TPL-files. 

{if $cookie->isLogged()}
  {else}
  <script type="text/javascript">
    $.jGrowl('{l s='Register or login to see prices'}', { life: 5000 });
  </script>
{/if}
Edited by seanloo (see edit history)

Share this post


Link to post
Share on other sites

  • 3 years later...

Hello. I have last version of prestashop. And I would like show "LOGIN TO SEE PRICE" at the place of the price. The methods written in this post can't be applied because they are for some old version. Someone can help me?

Share this post


Link to post
Share on other sites

It will take a bit of work, but it should be possible. You could override the Tools::displayPrice function. For example, create override/classes/Tools.php with the following:

<?php

class Tools extends ToolsCore
{
    public static function displayPrice($price, $currency = null, $no_utf8 = false, Context $context = null)
    {
        if ($context == null)
            $context = Context::getContext();

        if (!$context->customer->id)
            return 'LOG IN TO SEE PRICE';
        else
            return parent::displayPrice($price, $currency, $no_utf8, $context);
    }
}

This will work for the areas that use PHP to format the price. The areas that use JavaScript to format the price will continue to display prices though. You'll need to create a JavaScript variable called logged that can be used to determine whether a customer is logged in. For example:

var logged = {if $cookie->logged}true{else}false{/if};

Finally, you'll need to find all the calls to formatCurrency inside your theme and add code that checks whether a customer is logged in. For example:

			$('#our_price_display').text(!logged ? 'LOG IN FOR PRICE' : formatCurrency(parseFloat($('#our_price_display').attr('content')), currencyFormat, currencySign, currencyBlank));

Share this post


Link to post
Share on other sites

Hello.

I tried to insert what you wrote but it doesn't work. Maybe I added in the wrong section of the file.

 

However I don't know if it is what I need. 

As you can see in the image in attachment, i would like see the written "Log in to see price" instead of the price.

 

Actually website is configured that if you are not registered, you see nothing and if you are registered, you see price.

 

I want that if you are not registered, you see the written "Login to see price"

 

Thanks

Matteo

post-750231-0-22340300-1476636082_thumb.png

Edited by pinatz (see edit history)

Share this post


Link to post
Share on other sites

@pinatz

 

If you're seeing the price as 0 on the product page, then it means you've missed changing a line of code in themes/<your_theme>/product.js. Make sure every instance of formatCurrency has been changed to !logged ? 'LOG IN FOR PRICE' : formatCurrency

 

Also, make sure you've added the following to the JavaScript variables in product.tpl:

var logged = {if $logged}true{else}false{/if};

Share this post


Link to post
Share on other sites

 

@pinatz

 

If you're seeing the price as 0 on the product page, then it means you've missed changing a line of code in themes/<your_theme>/product.js. Make sure every instance of formatCurrency has been changed to !logged ? 'LOG IN FOR PRICE' : formatCurrency

 

Also, make sure you've added the following to the JavaScript variables in product.tpl:

var logged = {if $logged}true{else}false{/if};

Don't see the price. Price is 0 because in the product price i didn't set price.

Share this post


Link to post
Share on other sites

OK, I've tried to come up with an easier solution. Undo my previous solution (except for the override) and then do the following:

 

1. Go to Customers > Groups and click the tick icon under "Show prices" for the "Visitors" group to disable prices just for logged-out customers.

2. Change the following at about line of 258 of product.tpl:

                        {if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}

to:

						{if !$logged}{l s='LOG IN TO SEE PRICES'}
                        {elseif $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}

This should replace the price with "LOG IN TO SEE PRICES" on the product page. My previous override will change the other prices.

  • Like 1

Share this post


Link to post
Share on other sites

It might be a lot simpler to do this:

 

back office-->customers-->groups-->edit visitor-->disable 'show' prices.

 

ps will then not display prices all throught the visitors non-logged visit.

 

Then rather then putting in code to check for login status, use the .tpl variable when price is to be displayed  or not.

Share this post


Link to post
Share on other sites

  • 2 weeks later...

OK, I've tried to come up with an easier solution. Undo my previous solution (except for the override) and then do the following:

 

1. Go to Customers > Groups and click the tick icon under "Show prices" for the "Visitors" group to disable prices just for logged-out customers.

2. Change the following at about line of 258 of product.tpl:

                        {if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}

to:

						{if !$logged}{l s='LOG IN TO SEE PRICES'}
                        {elseif $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}

This should replace the price with "LOG IN TO SEE PRICES" on the product page. My previous override will change the other prices.

 

PERFECT! IT WORKS! YOU'RE GREAT

How can I write in english in English language and in Italian in Italian language?

 

How can I change the dimension and the bond font?

:)

Share this post


Link to post
Share on other sites

You can go to Localization > Translations > Front office translations and then scroll down to the "product" section to translate the text into different languages. I think to make it easier to format, change the first line to:

						{if !$logged}<span class="login_price">{l s='LOG IN TO SEE PRICES'}</span>

Then you can add CSS code like the following to style it:

.login_price {
    font-weight: bold;
}

Share this post


Link to post
Share on other sites

 

You can go to Localization > Translations > Front office translations and then scroll down to the "product" section to translate the text into different languages. I think to make it easier to format, change the first line to:

						{if !$logged}<span class="login_price">{l s='LOG IN TO SEE PRICES'}</span>

Then you can add CSS code like the following to style it:

.login_price {
    font-weight: bold;
}

Fantastic! It works with translation.

But with CSS i don't see differences. I modified product.css file. Is it correct?

Share this post


Link to post
Share on other sites

Ok.. I tried but nothing.

I modified the product.css file in the themes/mytheme/css folder adding in the end of the file 

 

#product.login_price {
    font-weight: bold!important;
}
 
I recompiled files and and deleted cache. Nothing :(

Share this post


Link to post
Share on other sites

 

Try adding a space:

#product .login_price {
    font-weight: bold!important;
}

Nothing.. no bold! It is not so important.. I wuold like see in bold, but if it is not possible, it doesn't matter

Share this post


Link to post
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
  • 2 months later...

OK, I've tried to come up with an easier solution. Undo my previous solution (except for the override) and then do the following:

 

1. Go to Customers > Groups and click the tick icon under "Show prices" for the "Visitors" group to disable prices just for logged-out customers.

2. Change the following at about line of 258 of product.tpl:

                        {if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}

to:

						{if !$logged}{l s='LOG IN TO SEE PRICES'}
                        {elseif $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}

This should replace the price with "LOG IN TO SEE PRICES" on the product page. My previous override will change the other prices.

How about the Prestashop 1.7  , cant find what you said. 

Share this post


Link to post
Share on other sites

In PrestaShop v1.7, the prices are in themes/classic/templates/catalog/product.tpl, themes/classic/templates/catalog/_partials/product-prices.tpl, themes/classic/templates/catalog/listing/product-list.tpl, themes/classic/templates/catalog/_partials/miniatures/pack-product.tpl, themes/classic/templates/catalog/_partials/miniatures/product.tpl. You'll need to find all the {$product.price}, {$product.price_tax_inc} and {$product.price_amount} in those files and add {if !$logged}{l s='LOG IN TO SEE PRICES' d='Shop.Theme.Catalog'}{else} before them and {/if} after.

Share this post


Link to post
Share on other sites

 

In PrestaShop v1.7, the prices are in themes/classic/templates/catalog/product.tpl, themes/classic/templates/catalog/_partials/product-prices.tpl, themes/classic/templates/catalog/listing/product-list.tpl, themes/classic/templates/catalog/_partials/miniatures/pack-product.tpl, themes/classic/templates/catalog/_partials/miniatures/product.tpl. You'll need to find all the {$product.price}, {$product.price_tax_inc} and {$product.price_amount} in those files and add {if !$logged}{l s='LOG IN TO SEE PRICES' d='Shop.Theme.Catalog'}{else} before them and {/if} after.

 

Hello,

 

I followed your given steps in PS v1.7. The prices are visible to only to logged in user but I am not able to display message "Login to see prices" to a guest or visitor. Can you please advice further. 

Share this post


Link to post
Share on other sites

  • 1 year later...
On 16/2/2017 at 7:58 AM, rocky said:
In PrestaShop v1.7, the prices are in themes/classic/templates/catalog/product.tpl, themes/classic/templates/catalog/_partials/product-prices.tpl, themes/classic/templates/catalog/listing/product-list.tpl, themes/classic/templates/catalog/_partials/miniatures/pack-product.tpl, themes/classic/templates/catalog/_partials/miniatures/product.tpl. You'll need to find all the {$product.price}, {$product.price_tax_inc} and {$product.price_amount} in those files and add {if !$logged}{l s='LOG IN TO SEE PRICES' d='Shop.Theme.Catalog'}{else} before them and {/if} after.

 

Hi Rocky, I use PS 1.7.2.4

your changes work!

I would like that the text "LOG IN TO SEE PRICES" appears when I disable SHOW PRICE for visitors, in manage customers group. And not when customers are not logged.

Can you help me? it possible this?

thanks

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More