Forums / All Other Contributions/Addons / Adding Boilerplate text to the Zen Cart Product Description 158

Adding Boilerplate text to the Zen Cart Product Description 158

Views: 1,577

Results 1 to 5 of 5
27 Nov 2022, 2:03 AM
#1
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,187
Plugin Contributions:
0

Adding Boilerplate text to the Zen Cart Product Description 158

zen cart 158 fresh install
PHP Version: 7.4.33 (Zend: 3.4.0)
Mods: clone a template, display logs, OPC, Bootstrap 3.4

@swguy
I receive 2 error logs when inserting the 2 PHP file within the zen cart structure from your website installition instructions.

[26-Nov-2022 18:53:03 America/Denver] PHP Notice:  Undefined variable:  descr_stringlist in  /includes/templates/boot_horn/templates/tpl_product_info_display.php on  line 117
[26-Nov-2022 18:53:03 America/Denver] Request URI:  /index.php?main_page=product_info&cPath=302_305_312&products_id=328,  IP address: 216.177.186.199, Language id 1
#1   require(/includes/templates/boot_horn/templates/tpl_product_info_display.php)  called at  [/includes/modules/pages/product_info/main_template_vars.php:156]
#2  require(/includes/modules/pages/product_info/main_template_vars.php)  called at [/includes/templates/boot_horn/common/tpl_main_page.php:202]
#3  require(/includes/templates/boot_horn/common/tpl_main_page.php) called at [/index.php:94]
--> PHP Warning: Invalid argument supplied for foreach() in  /includes/templates/boot_horn/templates/tpl_product_info_display.php on  line 117.

Website instructions:

Create a customized copy of   includes/templates/custom/templates/tpl_product_info_display.php  (from  includes/templates/template_default/templates/tpl_product_info_display.php) 

You will be defining your boilerplate strings in a file  called includes/languages/english/extra_definitions/my_defines.php   Each string will have a PHP "define" statement, and all the strings will be listed in an array.  In this way,  users can simply add and delete strings by editing this one file, rather than having to dig into the internals of Zen Cart. 

We'll use a simple example:  
<?php  $descr_stringlist = array("PHP_ONE_WEEK_DELAY", "PHP_TWO_WEEK_DELAY", "PHP_THREE_WEEK_DELAY");   define('PHP_ONE_WEEK_DELAY', 'These decals will be shipped in one week after receiving your order.');  define('PHP_TWO_WEEK_DELAY', 'These decals will be shipped in two weeks after receiving your order.');  define('PHP_THREE_WEEK_DELAY', 'These decals will be shipped in three weeks after receiving your order.');   ?>   
We've defined three constants and added each one to a list called descr_stringlist. 

Now go back to  includes/templates/custom/templates/tpl_product_info_display.php   Change   <!--bof Product description --> <?php if ($products_description != '') { ?> <div id="productDescription" class="productGeneral biggerText"><?php echo stripslashes($products_description); ?></div> <?php } ?> <!--eof Product description -->   to 
  <!--bof Product description --> <?php if ($products_description != '') { ?> <div id="productDescription" class="productGeneral biggerText"> <?php  $stripped_products_description = $products_description; foreach ($descr_stringlist as $varname) {     $stripped_products_description = str_replace($varname, constant($varname), $stripped_products_description); } ?> <?php echo stripslashes($stripped_products_description); ?></div> <?php } ?> <!--eof Product description -->   

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.

Zen Cart Certified hosting at myZenCartHost.com.

27 Nov 2022, 10:15 AM
#2
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: Adding Boilerplate text to the Zen Cart Product Description 158

For reasons long forgotten, but after a lot of experimentation, I ended up locating the file in
\includes\languages\english\extra_definitions\boilerplate_text.php

and using this format

$GLOBALS['boilerplate_array'] = [
'ATEQ_TPMS_UPDATE',
'ATEQ_TPMS_COMPANY', etc...
]

I use a function with this to do the replacement where necessary.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

27 Nov 2022, 1:18 PM
#3
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: Adding Boilerplate text to the Zen Cart Product Description 158

In Zen Cart 1.5.8, you have to global the stringlist explicitly.

$descr_stringlist = array("PHP_ONE_WEEK_DELAY", ...
$GLOBALS['descr_stringlist'] = $descr_stringlist;

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

27 Nov 2022, 2:57 PM
#4
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,187
Plugin Contributions:
0

Re: Adding Boilerplate text to the Zen Cart Product Description 158

@swguy

Thank you for the updated code for this small module and ran perfectly without any debug files. :smile:

includes/languages/english/extra_definitions/YOUR_TEMPLATE/my_defines.php ```html
$descr_stringlist = array("PHP_ONE_WEEK_DELAY", "PHP_TWO_WEEK_DELAY", "PHP_THREE_WEEK_DELAY");
$GLOBALS['descr_stringlist'] = $descr_stringlist;
define('PHP_ONE_WEEK_DELAY', 'Notice this unique species of Horned Lizards is only found in these general areas, which is shown on the left in this regional map.');
define('PHP_TWO_WEEK_DELAY', 'These decals will be shipped in two weeks after receiving your order.');
define('PHP_THREE_WEEK_DELAY', 'These decals will be shipped in three weeks after receiving your order.');

?>

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.

Zen Cart Certified hosting at myZenCartHost.com.

27 Nov 2022, 3:07 PM
#5
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: Adding Boilerplate text to the Zen Cart Product Description 158

This is an artifact of the way language files are processed in 1.5.8. I will add it to the release specific upgrade considerations on next checkin.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.