Jump to content

[SOLVED] How to add custom text to blockcart.tpl


Recommended Posts

Hi,

I was wondering how to add an {if} statement to the blockcart.tpl (I think this is where it needs to go) to display the amount of the required minimum purchase amount - IF there is one configured in the back office.

It needs to display whatever the value in the back office is set to.
If the minimum purchase is turned off in the back office it should not appear.

I would like it to look something like the attached image:

19875_TfWd8Ubz7tPM27ZgQNvs_t

Link to comment
Share on other sites

Actually that is not what I am after. Prestashop already offers a solution for restricting the minimum purchase in the Back Office (under Preferences/Products) - I currently have it configured to require a minimum purchase of $25.

All I want to do is to DISPLAY this fact to the customer in the cart block above the buttons (rather than have them find out by way of the validation error message that occurs if they don't meet the requirement) - allowing for the fact that I might change the value of the required minimum purchase, or I might 'turn it off' at some stage - otherwise, I could just hard code the wording.

I have tried for several hours to write an {if} statement to do this, looking at other code as examples etc, to no avail. I am not a coder, but sometimes can work things out by learning from existing examples. I usually try to work out a solution for myself before asking for help.

So I know that the statement must say 'if minimum required purchase is ON', show 'this message' and look up/get the value and display it. Or else (if the minimum required purchase is not on) don't display the message at all.

By the way, it's not a minimum number, it's a minimum dollar amount/spend.

Link to comment
Share on other sites

hi! at first I am sorry for confusing amount. I thought you were talking about amount of product. If you see my last post, you will get that.

for it you need to do two things. which requires smarty,php, and sql skills. Anyway, I am writing the solution. Edit the blockcart.php file so that it assigns a variable with the minimum purchase amount. Then edit the blockcart.tpl so that it prints the message and the variable's value...


See you.

Link to comment
Share on other sites

I think you are interpreting this as far more complex than what it is. I don't think you need to write anything complex - it's just adding a piece of text and fetching a value - it's just a matter of knowing how Prestashop refers to certain things. I think there are clues in the following (from order.php), which simply displays a text message in the cart - very similar to what I am trying to do:

/* Check minimal account */
$orderTotal = $cart->getOrderTotal();

$orderTotalDefaultCurrency = Tools::convertPrice($cart->getOrderTotal(true, 1), Currency::getCurrency(intval(Configuration::get('PS_CURRENCY_DEFAULT'))));
$minimalPurchase = floatval(Configuration::get('PS_PURCHASE_MINIMUM'));
if ($orderTotalDefaultCurrency < $minimalPurchase)
{
   $step = 0;
   $errors[] = Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, Currency::getCurrency(intval($cart->id_currency))).
   ' '.Tools::displayError('is required in order to validate your order');
}

if (!$cookie->isLogged() AND in_array($step, array(1, 2, 3)))
   Tools::redirect('authentication.php?back=order.php?step='.$step);

if ($cart->nbProducts())
{



Rocky was able to help me add a custom graphic to my shipping page with a small line of code, conditional on whether or not a shipping charge applied:

{if !$virtual_cart}{/if} 



It seems to me that this is in much the same category, except I need to add text instead of an image.

Link to comment
Share on other sites

yes...that's what I told you. fetch the value in the php file, and display it in the tpl file. You can ask Rocky to write you the codes so that you can copy paste them into the files. If you know a little bit of those things that I stated, you would be able to write codes yourself. Who is gonna write codes for you all the time!

Link to comment
Share on other sites

I find your attitude to be at odds with the spirit of this forum and judging from your other posts, you seem to be treating it as a place simply to allow you to tout for business. I have no objection to programmers advertising their services on forums like these, however, you do not seem to have any sense of the community spirit expected here.

If I was going to hire a programmer, I would hire someone who demonstrated the necessary ability to read and comprehend before they follow up with comments that are entirely irrelevant to the thread.

I think you need to understand a lot more about what is and what isn't already resident in Prestashop before you would be useful to anyone as a programmer for hire for custom Prestashop solutions. Buyer beware.

I'll just hard code the message.

yes...that's what I told you. fetch the value in the php file, and display it in the tpl file


No, that's what I told you. You weren't actually listening.
Link to comment
Share on other sites

Hi, morepork. The thing you're asking for is pretty easy to do, I don't know why would anyone charge anything for it:
(Note that I'm using V 1.3, but these instructions most probably will suit you as well, let me know if they don't)
Open your modules/blockcart/blockcart.php and find:

$smarty->assign(array(
   'products'=> $products,
   // Lot's of other stuff here
));


And add somewhere within this array:

$smarty->assign(array(
   'products'=> $products,
   'purchase_minimum' => Configuration::get('PS_PURCHASE_MINIMUM') != 0 ? Tools::displayPrice(Configuration::get('PS_PURCHASE_MINIMUM'), $currency) : null,
   // Lot's of other stuff here
));


Save the file and close it, now open blockcart.tpl and find:

{if $priceDisplay == 1}


       {l s='Prices are tax excluded' mod='blockcart'}

{/if}


And add these lines after the {/if} statement:

{if $purchase_minimum}


{l s='Purchase minimum' mod='blockcart'}
{$purchase_minimum}

{/if}


Now just style it with global.css to look whatever you want and you're done.
I didn't have time to really put this to the test, but it should work just fine.

Link to comment
Share on other sites

Hi, morepork. The thing you're asking for is pretty easy to do, I don't know why would anyone charge anything for it:
(Note that I'm using V 1.3, but these instructions most probably will suit you as well, let me know if they don't)
Open your modules/blockcart/blockcart.php and find:
$smarty->assign(array(
   'products'=> $products,
   // Lot's of other stuff here
));


And add somewhere within this array:

$smarty->assign(array(
   'products'=> $products,
   'purchase_minimum' => Configuration::get('PS_PURCHASE_MINIMUM') != 0 ? Tools::displayPrice(Configuration::get('PS_PURCHASE_MINIMUM'), $currency) : null,
   // Lot's of other stuff here
));


Save the file and close it, now open blockcart.tpl and find:

{if $priceDisplay == 1}


       {l s='Prices are tax excluded' mod='blockcart'}

{/if}


And add these lines after the {/if} statement:

{if $purchase_minimum}


{l s='Purchase minimum' mod='blockcart'}
{$purchase_minimum}

{/if}


Now just style it with global.css to look whatever you want and you're done.
I didn't have time to really put this to the test, but it should work just fine.



Hi Eihwaz,

You just bit me to that. I was writing the codes for this poor gentleman, then I saw your codes. They are better than mine. I learned something from it. Thank you very much.
Link to comment
Share on other sites

Thankyou both (Eihwaz and Star) so much - this works perfectly! And as you say... a very simple (and elegant) solution.

I think Star has also demonstrated the value of these public forums and how posting solutions helps the whole community - through learning by example, we all boost our skills and understanding. :-)


Eihwaz, I'm sure there are some people who would charge to tell you the time...

Link to comment
Share on other sites

hi! at first I am sorry for confusing amount. I thought you were talking about amount of product. If you see my last post, you will get that.

for it you need to do two things. which requires smarty,php, and sql skills. Anyway, I am writing the solution. Edit the blockcart.php file so that it assigns a variable with the minimum purchase amount. Then edit the blockcart.tpl so that it prints the message and the variable's value...


See you.


Please refer to these lines again. This means fetch a value and show it in your language. I wrote in a programmers style only. And I wrote it before you!

I do not write solution for a single person. I write for all. Because that would help a lot of people within the same time. Here is the article that I wrote on how to edit the output of modules easily. I try to utilize my free time for the best service of people.

http://www.icodebd.com/prestashop-module-editing-tutorial/
Link to comment
Share on other sites

  • 1 month later...
  • 2 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...