| ||||||||||
![]() |
Shopping cart software Solutions for online shops and malls | |||||||||
![]() |
![]() |
|
X-Cart Home | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Speed up Smarty templates by taking out {math} functions | ||||
![]() |
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
![]() To get more speed out of your templates, remove the {math} function from your product.tpl template (and others) to PHP. I will cover product.tpl, but any other template that uses {math} will also benefit if you do likewise (such as products.tpl or products_t.tpl). The {math} function is eval()'d each time it is called and is extremely slow. Some usages of the {math} function can be over 450% slower than doing the same in native PHP code.
Find the function func_select_product in func.php and add this to the $product = func_query_first( SQL statement to replace the 'savings' and 'discount' math calculations: Code:
Below the select statement, add the following to replace the 'mq' math calculation: Code:
In product.tpl: Find your $discount and change it to:$product.discount|string_format:'%d' Find $savings and change it to: $product.savings|string_format:'%f' Find the {section} loop that uses $mq and change it to: $product.min_quantity Lastly, go back and comment out all of the code in product.tpl that originally calculated these values by enclosing them in {* and *}. If everything looks as it should when you load a product, then you can delete that template code you commented out if you'd like. I cannot remember if there are any other {math} functions in product.tpl, as that was one speed issue I jumped at early on. If anyone feels like posting their success with this or other templates and how you did it, don't hesitate to let everyone know. I'd love to be able to post steps for the rest of the templates I know but current time constraints won't allow for it. ![]()
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#2
|
|||||||
|
|||||||
![]() Oooooo....more speed! Thanks as always for these useful tips NuAlpha! Before long you will have X-Cart loading as quickly as an html site!
![]()
__________________
Padraic Ryan Ryan Design Studio Professional E-Commerce Development |
|||||||
#3
|
|||||||
|
|||||||
![]() If anyone has already applied this code, please note that I forgot to paste a critical part and I had to update it to encase the min_quantity assignment in if ($product) {.
![]() If you don't do this then $product will always evaluate to true in subsequent IF conditionals regardless of whether a product was actually found.
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#4
|
|||||||
|
|||||||
![]() Here is another minor improvement, though I don't know if many will get much use out of this one.
Change the contents of skin1/customer/main/alter_currency_value.tpl to the following to eliminate the {math} function: Code:
A more useful modification might be in skin1/customer/main/cart.tpl where you can also replace: Code:
With: Code:
Note that these only works if you have Smarty 2.6.5 or later installed.
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#5
|
|||||||
|
|||||||
![]() Quote:
Does this work for 4.0.11? Bit confused. In my func.php I have the following: Code:
I'm not exactly sure where to add NuAlpha's code (ie., after the SELECT statement, before, in the middle, as a replacement...) Could somebody post an example of what the finished snippet of code in func.php should look like? Not being cheeky, I'm just uncertain how to proceed with this correctly. Cheers, DB
__________________
Version 4.0.16 |
|||||||
#6
|
|||||||
|
|||||||
![]() This was designed with 3.5.14 in mind. We are working on the upgrade to 4.0.x now that it has been declared "stable" and hope to have all of these changes in place in time for 4.0.13 or 4.0.14 at the latest.
I will post that code modified code when we are done with the transition if someone else doesn't post it before me. If you don't see something here by mid April, make a post here and I will drop by to see what I can do.
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#7
|
|||||||
|
|||||||
![]() Thanks, Nu.
I will definitely be interested in the branch 4.x adaption of this mod - looks very nice, kudos. Regards, DB
__________________
Version 4.0.16 |
|||||||
#8
|
|||||||
|
|||||||
![]() Hi NuAlpha,
Did you check your mod can work in X-cart 4.7.0 or above? If yes, would mind to give more details how to make it work since I cannot follow you from your previous posts as the func.php is a very long list. Thanks and regards, Andy X-Cart 4.7.0 |
|||||||
#9
|
|||||||
|
|||||||
![]() Quote:
Don't you mean 4.0.7 instead of 4.7.0? ![]() I have only tested this on 3.5.14 so far.
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#10
|
|||||||
|
|||||||
![]() Hi NuAlpha,
I am so sorry I have the typo error of my X-cart version. It should be V.4.0.7 instead of v.4.7.0 Regards, Andy |
|||||||
|
|||
X-Cart forums © 2001-2020
|