That Software Guy, Inc.'s Logo

Software Consulting Services
Need Help? Call That Software Guy!


Adding Conditional Messages on the Product Info page

Relevance: Zen Cart™ 1.3.0.* and forward
Cost: Free, but donation appreciated

Conditional Messages are messages which are switched on and off based on certain conditions, such as whether the product has a certain id or is in a certain category. For instance, if you are using the Quantity Discounts Contribution for certain products only, you would want this sort of logic.

Create your custom template if you haven't already done so.

Customize the product_info page. Assuming your template is called "custom," copy
includes/templates/template_default/templates/tpl_product_info_display.php
to
includes/templates/custom/templates
Now let's suppose you're going to use the text from the Quantity Discount FAQ, which is
<?php
  $value = "ot_quantity_discount.php"; 
  include(zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . 
          '/modules/order_total/', $value, 'false'));
  include(DIR_WS_MODULES . "order_total/" . $value);
  $discount = new ot_quantity_discount();  
  echo '<div class="content" id="discountPolicy">'; 
  echo '<h2>' . STORE_POLICY . '</h2>'; 
  echo $discount->get_html_policy();
  echo '<br /></div>'; 
?>
For brevity, in remaining examples, the code between <?php and ?> will be referred to as simply "***CODE***".

Suppose we want to add this code right after the product description. Look for
<!--eof Product description -->
<br class="clearBoth" />
and add it right there. Now how do we make it conditional?

If this text only applies to product 25, use this logic:
<?php
if ((int)$_GET['products_id'] == 25) 
{
   ***CODE***
}
?>

If the text only applies to product 25 or product 26, use
<?php
if ( ((int)$_GET['products_id'] == 25) ||
     ((int)$_GET['products_id'] == 26) )
{
   ***CODE***
}
?>

If the text applies to everything EXCEPT product 25 or 26, use
<?php
if ( ((int)$_GET['products_id'] != 25) &&
     ((int)$_GET['products_id'] != 26) )
{
   ***CODE***
}
?>

If you want to specify a category instead of a product id, use the variable $current_category_id. For instance, if the text applies to everything EXCEPT category 1 or category 2, use
<?php
if ( ($current_category_id != 1) &&
     ($current_category_id != 2) )
{
   ***CODE***
}
?>

If you want to do something special for call for price products, use
<?php
if (zen_get_products_price_is_call((int)$_GET['products_id']))
{
   ***CODE***
}
?>


This tip was developed in October, 2006, and was first submitted to the Zen Cart Support Forum in this thread on October 25, 2006.


If the information you learned reading this site is helping your store make more money, please consider making a donation. Thank you!


Want more Zen Cart?     Tips and Tricks     Contributions     Extensions     Custom Software     Newsletter

   Terms | Privacy | SiteMap | Newsletter | Contact Me | ©2003-2008 That Software Guy, Inc.