Products’ URL: Template File Changes for Zen Cart 1.5.3 and later

 v1.5.3, v1.5.4, zen-cart  Comments Off on Products’ URL: Template File Changes for Zen Cart 1.5.3 and later
Apr 302015
 

Starting with Zen Cart v1.5.3, the built-in handling that displays a product’s URL was changed.  If you are upgrading your store from a previous version of Zen Cart and you want your products’ URLs to continue to properly display, make sure to merge the following changes into your template’s tpl_*_display.php files.  In each file, look for:

<!--bof Product URL -->
<?php
  if (zen_not_null($products_url)) {
    if ($flag_show_product_info_url == 1) {
?>
    <p id="productInfoLink" class="productGeneral centeredContent"><?php echo sprintf(TEXT_MORE_INFORMATION, zen_href_link(FILENAME_REDIRECT, 'action=url&goto=' . urlencode($products_url), 'NONSSL', true, false)); ?></p>
<?php
    } // $flag_show_product_info_url
  }
?>
<!--eof Product URL -->

and make sure that the highlighted section is changed to:

<!--bof Product URL -->
<?php
  if (zen_not_null($products_url)) {
    if ($flag_show_product_info_url == 1) {
?>
    <p id="productInfoLink" class="productGeneral centeredContent"><?php echo sprintf(TEXT_MORE_INFORMATION, zen_href_link(FILENAME_REDIRECT, 'action=product&products_id=' . zen_output_string_protected($_GET['products_id']), 'NONSSL', true, false)); ?></p>
<?php 
    } // $flag_show_product_info_url 
  } ?> <!--eof Product URL -->

Making that change will allow your Zen Cart v1.5.3+ store to continue to properly display your products’ URLs.

Another Template-Override Method

 hints, php, plugins, zen-cart  Comments Off on Another Template-Override Method
Jan 272014
 

When you’re developing a plugin that needs to make major modifications to an existing Zen Cart template file, it can be difficult and/or cumbersome to add the required conditional statements and keep your code readable.  Zen Cart has a built-in mechanism to help!

The file /includes/templates/{current template}/common/main_template_vars.php (loaded by your store’s /index.php) sets the name of the file to be loaded to provide the formatting for the current page (page_name).  That file is either

  1. /includes/modules/pages/page_name/main_template_vars.php, if that file exists.
  2. /includes/templates/{current template}/templates/tpl_page_name_default.php, otherwise.

For example, to create a template override for a major change to the formatting of the account_history_info page for a plugin I’ve got in the works, I created the file /includes/modules/pages/account_history_info/main_template_vars.php and programmed that file to contain:

$tpl_page_body = ($is_multiship_order) ? '/tpl_account_history_info_multiship.php' : '/tpl_account_history_info_default.php';
require($template->get_template_dir($tpl_page_body,DIR_WS_TEMPLATE, $current_page_base,'templates'). $tpl_page_body);

That code will load the either my customized template or the built-in, default formatting template, depending on whether or not the order currently being displayed contains multiple ship-to addresses. Now, I can fully separate the formatting required to support the multiple ship-to addresses!

Watch the Zen Cart forums for the availability announcement for the Multiple Ship-To Addresses plugin!