Jump to content

Recommended Posts

PrestaShop 1.5.2 Tutorial: Call for Price Modifications

A gift to PrestaShop user from

Shop Save N Earn

 

 

12/15/2012

William R. Williamson

 

PrestaShop 1.5.2 Tutorial: Call for Price Modifications

 

 

 

Hi everyone it's me again, William Williamsons at Shop Save N Earn; with another great tutorial for PrestaShop in which many of my fellow PrestaShop users can definitely use. Firstly I want to say that if anyone knows how I would be able to turn this into a module to release for free as a community project please do at [email protected]. I personally, believe this is a necessity for all shops as many suppliers invoke restrictions that you must follow, which happen to be the most largest suppliers or manufacturers.

 

 

Summary

 

Okay to summarize this tutorial we will edit three files in two different directories product_list.tpl, product.tpl, and products-comparision.tpl in themes/default/ directory of their store and one file in the modules/homefeatured/homefeatured.tpl file. The edits are small and simple so it should be an easy job.

 

A. Find in themes/default/

 

 

Find and open the file product_list.tpl

 

-------------------------------------------------------------------------------------------------------

Find the line below

-------------------------------------------------------------------------------------------------------

<div class="content_price">

-------------------------------------------------------------------------------------------------------

after this line after

-------------------------------------------------------------------------------------------------------

 


{if $product.price < '1.00'}<span [b]class="callforprice">[/b]Call For Price!!!</span>{/if}

-------------------------------------------------------------------------------------------------------

Make sure to create a class in global.css an example is below

-------------------------------------------------------------------------------------------------------


.callforprice {
		font-family: Verdana, Geneva, sans-serif;
		font-size: 14px;
		font-style: italic;
		line-height: normal;
		font-weight: bolder;
		font-variant: normal;
		color: #F00;
		text-decoration: blink;
}

-------------------------------------------------------------------------------------------------------

Find the line below

-------------------------------------------------------------------------------------------------------


{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}<span class="price" style="display: inline;">

-------------------------------------------------------------------------------------------------------

replace it with the line below

-------------------------------------------------------------------------------------------------------

{if isset($product.show_price) && $product.price > '1.00' && $product.show_price && !isset($restricted_country_mode)}<span class="price" style="display: inline;">

-------------------------------------------------------------------------------------------------------

Find and open the file product.tpl

-------------------------------------------------------------------------------------------------------

Find the line beow

-------------------------------------------------------------------------------------------------------

<div class="price">

-------------------------------------------------------------------------------------------------------

After this add the code above

-------------------------------------------------------------------------------------------------------

{if $product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision) < '1.00'}<p class="callforprice">Call For Price!!!</p>{/if}
								{else}

---------------------------------------------------------------------------------------------------------

and make sure it is inserted before the code below

-------------------------------------------------------------------------------------------------------

{if !$priceDisplay || $priceDisplay == 2}
{assign var='productPrice' value=$product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision)}
{assign var='productPriceWithoutRedution' value=$product->getPriceWithoutReduct(false, $smarty.const.NULL)}
{elseif $priceDisplay == 1}
  {assign var='productPrice' value=$product->getPrice(false, $smarty.const.NULL, $priceDisplayPrecision)}

-------------------------------------------------------------------------------------------------------

Find and open the file---products-comparison.tpl

-------------------------------------------------------------------------------------------------------

Find the line below

-------------------------------------------------------------------------------------------------------

<p class="price_container">

-------------------------------------------------------------------------------------------------------

After the line above add

-------------------------------------------------------------------------------------------------------

{if $product->getPrice($taxes_behavior) < '1.00'}<span class="callforprice">Call For Price!!!</span>
{else}

-------------------------------------------------------------------------------------------------------

Make sure it is above the line below

-------------------------------------------------------------------------------------------------------

<span class="price">{convertPrice price=$product->getPrice($taxes_behavior)}</span></p>

-------------------------------------------------------------------------------------------------------

After the line above add the line below

-------------------------------------------------------------------------------------------------------

	
{/if}

-------------------------------------------------------------------------------------------------------

 

B. Find in modules/homefeatured/

 

Find and open the file homefeatured.tpl

 

-------------------------------------------------------------------------------------------------------

Find the line below

-------------------------------------------------------------------------------------------------------

<a class="lnk_more" href="{$product.link}" title="{l s='View' mod='homefeatured'}">{l s='View' mod='homefeatured'}</a>

-------------------------------------------------------------------------------------------------------

After the line above add

-------------------------------------------------------------------------------------------------------

{if $product.price < '1.00'}<span class="callforprice"><br/>Call For Price!!!</span>
																{else}  

-------------------------------------------------------------------------------------------------------

But make sure it is above the line below

-------------------------------------------------------------------------------------------------------

{if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}<p class="price_container"><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}

-------------------------------------------------------------------------------------------------------

After the above lines add the line below

-------------------------------------------------------------------------------------------------------

{/if}

-------------------------------------------------------------------------------------------------------

 

That's it folks, hope it has helped.

 

 

Conclusion

 

Well that concludes our tutorial, however there may be more edits that could result in the pricing showing, which must also be modified. Although, doing the modifications this way ensures it still does not show a real price just 0.00, thus saving the business owner from losing their partnership and supplier contact. I like to play it safe personally. As always please be kind, if there are any issues errors or typo's please email me the corrections in a positive manner.

 

Also if this tutorial helps you and you use it please shoot some back links to me at http://www.shopsavenearn.com thanks.

 

Here is a pdf version

PrestaShop 1.5.2 Tutorial- Call for Price Modifications.pdf

Link to comment
Share on other sites

  • 4 months later...

hello and thanks for this great guide!

 

I seem to have encountered a problem where I add the following into product.tpl:

{if $product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision) < '1.00'}<p class="callforprice">Call For Price!!!</p>{/if}

{else}

 

and it unfortunately breaks my template. moving the right column into my center column, seems as the {else} statement creates this error.

 

I'm using 1.5.4, would you mind helping with this problem?

Link to comment
Share on other sites

For 1.5.4 do the following and let me know if it works for you.

 

 

Find and open the file product.tpl

 

-------------------------------------------------------------------------------------------------------

Find the lines below

-------------------------------------------------------------------------------------------------------

<div class="price">

<p class="our_price_display">

{if $priceDisplay >= 0 && $priceDisplay <= 2}

<span id="our_price_display">{convertPrice price=$productPrice}</span>

<!--{if $tax_enabled && ((isset($display_tax_label) && $display_tax_label == 1) OR !isset($display_tax_label))}

{if $priceDisplay == 1}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}

{/if}-->

{/if}

</p>

-------------------------------------------------------------------------------------------------------

Replace with

-------------------------------------------------------------------------------------------------------

<div class="price">

<p class="our_price_display">

 

{if $product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision) < '1.00'}<p class="callforprice">Call For Price!!!</p>{/if}

 

{if $priceDisplay >= 0 && $priceDisplay <= 2 && $product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision) > '1.00'}

<span id="our_price_display">{convertPrice price=$productPrice}</span>

<!--{if $tax_enabled && ((isset($display_tax_label) && $display_tax_label == 1) OR !isset($display_tax_label))}

{if $priceDisplay == 1 && $product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision) > '1.00'}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}

{/if}-->

{/if}

</p>

-------------------------------------------------------------------------------------------------------

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

First of all, thanks for your piece. Great you take the time to educate us :-)

 

 

Looks like there is a small error in this line (Also explains the error of cybert11):

 

{if $product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision) < '1.00'}<p class="callforprice">Call For Price!!!</p>{/if}

{else}

 

 

The {/if} should be moved after the {else} + code that should be inside the else part

(Just like you do in homefeatured.tpl, where you add the {/if} at the end)

 

Another small thing in product_list.tpl. If price exactly equals 1, this code is 'undefined'

 

{if isset($product.show_price) && $product.price > '1.00' && $product.show_price && !isset($restricted_country_mode)}<span class="price" style="display: inline;">

 

change into

 

{if isset($product.show_price) && $product.price >= '1.00' && $product.show_price && !isset($restricted_country_mode)}<span class="price" style="display: inline;">

 

Hope this helps,

Pascal

Edited by PascalVG (see edit history)
  • Like 1
Link to comment
Share on other sites

Yeah I am not very good with smarty as I am just getting versed in it. thanks for the fix. It is the 1.54 edit so should work now. However if you do not make your store validate orders for at least $1.00 they can order it for $0.00. By no means is this a fix for the issue of needing a call for price module, but for those like me with a very limited income it can help us provide such things when suppliers say we must. I know companies like samsung do these and require resellers to do so as well.

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

Hello, I'm happy to report this worked well. And I'm uploading my new website as I'm typing this.

 

My product.tpl was slightly different, and I just added it after the existing code as ShopSaveEarn explained.

resulting code:

 

<div class="price">
   {if !$priceDisplay || $priceDisplay == 2}
 {assign var='productPrice' value=$product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision)}
 {assign var='productPriceWithoutReduction' value=$product->getPriceWithoutReduct(false, $smarty.const.NULL)}
   {elseif $priceDisplay == 1}
 {assign var='productPrice' value=$product->getPrice(false, $smarty.const.NULL, $priceDisplayPrecision)}
 {assign var='productPriceWithoutReduction' value=$product->getPriceWithoutReduct(true, $smarty.const.NULL)}
   {/if}
  <p class="our_price_display">
{if $product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision) < '1.00'}<p class="callforprice">Call For Price!!!</p>{/if}
{if $priceDisplay >= 0 && $priceDisplay <= 2 && $product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision) > '1.00'}
<span id="our_price_display">{convertPrice price=$productPrice}</span>
<!--{if $tax_enabled && ((isset($display_tax_label) && $display_tax_label == 1) OR !isset($display_tax_label))}
{if $priceDisplay == 1 && $product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision) > '1.00'}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}
{/if}-->
{/if}
</p>

 

 

Thanks for the help

  • Like 1
Link to comment
Share on other sites

Just to shed some light on the variables. These variables are set in the .php files that load the smarty template. For example in product.php file you will see the following piece of code.

 

self::$smarty->assign(array(

'pictures' => $files,

'textFields' => $textFields));

 

So in this example the variables are assigned to the smarty object before being passed or assigned to the smarty template for display.

 

Hope that helps.

  • Like 1
Link to comment
Share on other sites

Hi Doulas,

Thanks for your post. Do you have any idea where those Global variables are specifically set? Templatin needs the $priceDisplay in particular... myself am curious after the paths to the diverse folders {$img_dir} etc...

 

Thanks,

Pascal

  • Like 1
Link to comment
Share on other sites

I use prestashop 1.4.7.0 . I just checked out frontcontroller.php and found this piece of code. Hope it sheds more light.

 

$smarty->assign(array(

'link' => $link,

'cart' => $cart,

'currency' => $currency,

'cookie' => $cookie,

'page_name' => $page_name,

'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,

'base_dir_ssl' => $protocol_link.Tools::getShopDomainSsl().__PS_BASE_URI__,

'content_dir' => $protocol_content.Tools::getServerName().__PS_BASE_URI__,

'tpl_dir' => _PS_THEME_DIR_,

'modules_dir' => _MODULE_DIR_,

'mail_dir' => _MAIL_DIR_,

'lang_iso' => $ps_language->iso_code,

'come_from' => Tools::getHttpHost(true, true).Tools::htmlentitiesUTF8(str_replace('\'', '', urldecode($_SERVER['REQUEST_URI']))),

'cart_qties' => (int)$cart->nbProducts(),

'currencies' => Currency::getCurrencies(),

'languages' => Language::getLanguages(),

'priceDisplay' => Product::getTaxCalculationMethod(),

'add_prod_display' => (int)Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),

'shop_name' => Configuration::get('PS_SHOP_NAME'),

'roundMode' => (int)Configuration::get('PS_PRICE_ROUND_MODE'),

'use_taxes' => (int)Configuration::get('PS_TAX'),

'display_tax_label' => (bool)$display_tax_label,

'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'),

'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),

'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE'),

));

  • Like 2
Link to comment
Share on other sites

Then for the image directories. I understand that most constants are defines in /config/defines.inc.php. Here you will see lines such as this

define('_PS_THEME_DIR_', _PS_ROOT_DIR_.'/themes/'._THEME_NAME_.'/');

define('_PS_IMG_DIR_', _PS_ROOT_DIR_.'/img/');

 

then I believe the constant _PS_IMG_DIR_ is equated somewhere in the templates as $img_dir

 

Thats how I get it. I hope it sheds more light and if you further research you will get the exact lines. If you are using an IDE like netbeans try a search for $img_dir in the whole project and you should find the templates where they are listed.

 

Hope this is also useful.

  • Like 1
Link to comment
Share on other sites

Perfect!

Frontcontroller.php indeed, also in 1.5.3.1. Thanks!

 

 

So templatin, looking in this file (/classes/controller/frontcontroller.php)

you see the 'definition' of priceDisplay, being:

'priceDisplay' => Product::getTaxCalculationMethod(),

 

So it's a function call to above mentioned function, not directly a fixed value.

  • Like 1
Link to comment
Share on other sites

  • 10 months later...

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...