Page 1 of 32 12311 ... LastLast
Results 1 to 10 of 318
  1. #1
    Join Date
    Oct 2006
    Posts
    5,486
    Plugin Contributions
    12

    Default Using one single listing template

    Special listing, all listing, new listing, category listing. .....

    Ever feel so frustrated because you have to edit too many template files to get a consistent look for your site?

    Here is a trick on how to use just one template (tested)

    1. First, let me go on a bit about the way ZC works (assuming I understand it correctly):
    When you visit a page, say index.php?main_page=products_all, ZC will load the file header_php.php inside includes/modules/pages/products_all.
    This file usually contains the code that will gather all information needed before displaying.

    The the template file will be loaded at includes/templates/your_template/templates/tpl_products_all_default.php
    This file uses all info gathered in the header file, then displays it.

    2. Here goes the trick: what if we can use the same template file? wouldn't it be cool?
    KK, lets peek into includes/modules/pages/products_all/header_php.php
    PHP Code:
    <?php
    /**
     * products_all  header_php.php
     *
     * @package page
     * @copyright Copyright 2003-2006 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: header_php.php 4261 2006-08-25 04:35:20Z ajeh $
     */

      
    require(DIR_WS_MODULES zen_get_module_directory('require_languages.php'));



      
    $breadcrumb->add(NAVBAR_TITLE);
    // display order dropdown
      
    $disp_order_default PRODUCT_ALL_LIST_SORT_DEFAULT;
      require(
    DIR_WS_MODULES zen_get_module_directory(FILENAME_LISTING_DISPLAY_ORDER));

      
    $products_all_array = array();

      
    $products_all_query_raw "SELECT p.products_type, p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id,
                                        p.products_date_added, m.manufacturers_name, p.products_model, p.products_quantity, p.products_weight, p.product_is_call,
                                        p.product_is_always_free_shipping, p.products_qty_box_status
                                 FROM " 
    TABLE_PRODUCTS " p
                                 LEFT JOIN " 
    TABLE_MANUFACTURERS " m ON (p.manufacturers_id = m.manufacturers_id), " TABLE_PRODUCTS_DESCRIPTION " pd
                                 WHERE p.products_status = 1
                                 AND p.products_id = pd.products_id
                                 AND pd.language_id = :languageID " 
    $order_by;

      
    $products_all_query_raw $db->bindVars($products_all_query_raw':languageID'$_SESSION['languages_id'], 'integer');
      
    $products_all_split = new splitPageResults($products_all_query_rawMAX_DISPLAY_PRODUCTS_ALL);

    //check to see if we are in normal mode ... not showcase, not maintenance, etc
      
    $show_submit zen_run_normal();

    // check whether to use multiple-add-to-cart, and whether top or bottom buttons are displayed
      
    if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART and $show_submit == true and $products_all_split->number_of_rows 0) {

        
    // check how many rows
        
    $check_products_all $db->Execute($products_all_split->sql_query);
        
    $how_many 0;
        while (!
    $check_products_all->EOF) {
          if (
    zen_has_product_attributes($check_products_all->fields['products_id'])) {
          } else {
    // needs a better check v1.3.1
            
    if ($check_products_all->fields['products_qty_box_status'] != 0) {
              if (
    zen_get_products_allow_add_to_cart($check_products_all->fields['products_id']) !='N') {
                if (
    $check_products_all->fields['product_is_call'] == 0) {
                  if ((
    SHOW_PRODUCTS_SOLD_OUT_IMAGE == and $check_products_all->fields['products_quantity'] > 0) or SHOW_PRODUCTS_SOLD_OUT_IMAGE == 0) {
                    if (
    $check_products_all->fields['products_type'] != 3) {
                      if (
    zen_has_product_attributes($check_products_all->fields['products_id']) < 1) {
                        
    $how_many++;
                      }
                    }
                  }
                }
              }
            }
          }
          
    $check_products_all->MoveNext();
        }

        if ( ((
    $how_many and $show_submit == true and $products_all_split->number_of_rows 0) and (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART == or  PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART == 3)) ) {
          
    $show_top_submit_button true;
        } else {
          
    $show_top_submit_button false;
        }
        if ( ((
    $how_many and $show_submit == true and $products_all_split->number_of_rows 0) and (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART >= 2)) ) {
          
    $show_bottom_submit_button true;
        } else {
          
    $show_bottom_submit_button false;
        }
      }
    ?>
    Huhm, so it basically just queries the products, then doing some checking and such.
    Now lets look at includes/templates/your_template/templates/tpl_products_all_default.php (assuming we are using the default one here)
    [to be continued-typing]
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  2. #2
    Join Date
    Oct 2006
    Posts
    5,486
    Plugin Contributions
    12

    Default Re: Using one single listing template

    PHP Code:
    <?php
    /**
     * Page Template
     *
     * @package templateSystem
     * @copyright Copyright 2003-2005 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: tpl_products_all_default.php 2603 2005-12-19 20:22:08Z wilt $
     */
    ?>
    <div class="centerColumn" id="allProductsDefault">

    <h1 id="allProductsDefaultHeading"><?php echo HEADING_TITLE?></h1>

    <?php
    require($template->get_template_dir('/tpl_modules_listing_display_order.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_listing_display_order.php'); ?>

    <br class="clearBoth" />

    <?php
      
    if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART and $show_submit == true and $products_all_split->number_of_rows 0) {
    ?>

    <?php
        
    if ($show_top_submit_button == true or $show_bottom_submit_button == true) {
          echo 
    zen_draw_form('multiple_products_cart_quantity'zen_href_link(FILENAME_PRODUCTS_ALLzen_get_all_get_params(array('action')) . 'action=multiple_products_add_product'), 'post''enctype="multipart/form-data"');
        }
      }
    ?>

    <?php
      
    if ($show_top_submit_button == true) {
    // only show when there is something to submit
    ?>
    <div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_ADD_PRODUCTS_TO_CARTBUTTON_ADD_PRODUCTS_TO_CART_ALT'id="submit1" name="submit1"'); ?></div>

    <?php
      
    // top submit button
    ?>
    <br class="clearBoth" />

    <?php
      
    if (($products_all_split->number_of_rows 0) && ((PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3'))) {
    ?>
      <div id="allProductsListingTopNumber" class="navSplitPagesResult back"><?php echo $products_all_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS_ALL); ?></div>
      <div id="allProductsListingTopLinks" class="navSplitPagesLinks forward"><?php echo TEXT_RESULT_PAGE ' ' $products_all_split->display_links(MAX_DISPLAY_PAGE_LINKSzen_get_all_get_params(array('page''info''x''y''main_page'))); ?></div>
    <?php
      
    }
    ?>
    <br class="clearBoth" />

    <?php
    /**
     * display the new products
     */
    require($template->get_template_dir('/tpl_modules_products_all_listing.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_products_all_listing.php'); ?>

    <?php
      
    if (($products_all_split->number_of_rows 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
    ?>
      <div id="allProductsListingBottomNumber" class="navSplitPagesResult back"><?php echo $products_all_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS_ALL); ?></div>
      <div id="allProductsListingBottomLinks" class="navSplitPagesLinks forward"><?php echo TEXT_RESULT_PAGE ' ' $products_all_split->display_links(MAX_DISPLAY_PAGE_LINKSzen_get_all_get_params(array('page''info''x''y''main_page'))); ?></div>
    <?php
      
    }
    ?>
    <br class="clearBoth" />

    <?php
      
    if ($show_bottom_submit_button == true) {
    // only show when there is something to submit
    ?>
      <div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_ADD_PRODUCTS_TO_CARTBUTTON_ADD_PRODUCTS_TO_CART_ALT'id="submit2" name="submit1"'); ?></div>

    <?php
      
    }  // bottom submit button
    ?>

    <?php
    // only end form if form is created
        
    if ($show_top_submit_button == true or $show_bottom_submit_button == true) {
    ?>
    </form>
    <?php // end if form is made ?>
    </div>
    Huhm, so it calls tpl_modules_products_all_listing.php? What does this file do?
    PHP Code:
    <?php
    /**
     * Module Template
     *
     * Loaded automatically by index.php?main_page=products_all.<br />
     * Displays listing of All Products
     *
     * @package templateSystem
     * @copyright Copyright 2003-2006 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: tpl_modules_products_all_listing.php 4629 2006-09-28 15:29:18Z ajeh $
     */
    ?>
    <table border="0" width="100%" cellspacing="2" cellpadding="2">
              <tr>
                <td colspan="3"><hr /></td>
              </tr>
    <?php
      $group_id 
    zen_get_configuration_key_value('PRODUCT_ALL_LIST_GROUP_ID');

      if (
    $products_all_split->number_of_rows 0) {
        
    $products_all $db->Execute($products_all_split->sql_query);
        
    $row_counter 0;
        while (!
    $products_all->EOF) {
          
    $row_counter++;

          if (
    PRODUCT_ALL_LIST_IMAGE != '0') {
            if (
    $products_all->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) {
              
    $display_products_image str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_IMAGE31));
            } else {
              
    $display_products_image '<a href="' zen_href_link(zen_get_info_page($products_all->fields['products_id']), 'products_id=' $products_all->fields['products_id']) . '">' zen_image(DIR_WS_IMAGES $products_all->fields['products_image'], $products_all->fields['products_name'], IMAGE_PRODUCT_ALL_LISTING_WIDTHIMAGE_PRODUCT_ALL_LISTING_HEIGHT) . '</a>' str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_IMAGE31));
            }
          } else {
            
    $display_products_image '';
          }
          if (
    PRODUCT_ALL_LIST_NAME != '0') {
            
    $display_products_name '<a href="' zen_href_link(zen_get_info_page($products_all->fields['products_id']), 'products_id=' $products_all->fields['products_id']) . '"><strong>' $products_all->fields['products_name'] . '</strong></a>' str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_NAME31));
          } else {
            
    $display_products_name '';
          }

          if (
    PRODUCT_ALL_LIST_MODEL != '0' and zen_get_show_product_switch($products_all->fields['products_id'], 'model')) {
            
    $display_products_model TEXT_PRODUCTS_MODEL $products_all->fields['products_model'] . str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_MODEL31));
          } else {
            
    $display_products_model '';
          }

          if (
    PRODUCT_ALL_LIST_WEIGHT != '0' and zen_get_show_product_switch($products_all->fields['products_id'], 'weight')) {
            
    $display_products_weight TEXT_PRODUCTS_WEIGHT $products_all->fields['products_weight'] . TEXT_SHIPPING_WEIGHT str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_WEIGHT31));
          } else {
            
    $display_products_weight '';
          }

          if (
    PRODUCT_ALL_LIST_QUANTITY != '0' and zen_get_show_product_switch($products_all->fields['products_id'], 'quantity')) {
            if (
    $products_all->fields['products_quantity'] <= 0) {
              
    $display_products_quantity TEXT_OUT_OF_STOCK str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_QUANTITY31));
            } else {
              
    $display_products_quantity TEXT_PRODUCTS_QUANTITY $products_all->fields['products_quantity'] . str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_QUANTITY31));
            }
          } else {
            
    $display_products_quantity '';
          }

          if (
    PRODUCT_ALL_LIST_DATE_ADDED != '0' and zen_get_show_product_switch($products_all->fields['products_id'], 'date_added')) {
            
    $display_products_date_added TEXT_DATE_ADDED ' ' zen_date_long($products_all->fields['products_date_added']) . str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_DATE_ADDED31));
          } else {
            
    $display_products_date_added '';
          }

          if (
    PRODUCT_ALL_LIST_MANUFACTURER != '0' and zen_get_show_product_switch($products_all->fields['products_id'], 'manufacturer')) {
            
    $display_products_manufacturers_name = ($products_all->fields['manufacturers_name'] != '' TEXT_MANUFACTURER ' ' $products_all->fields['manufacturers_name'] . str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_MANUFACTURER31)) : '');
          } else {
            
    $display_products_manufacturers_name '';
          }

          if ((
    PRODUCT_ALL_LIST_PRICE != '0' and zen_get_products_allow_add_to_cart($products_all->fields['products_id']) == 'Y') and zen_check_show_prices() == true) {
            
    $products_price zen_get_products_display_price($products_all->fields['products_id']);
            
    $display_products_price TEXT_PRICE ' ' $products_price str_repeat('<br clear="all" />'substr(PRODUCT_ALL_LIST_PRICE31)) . (zen_get_show_product_switch($products_all->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($products_all->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON '<br />' '') : '');
          } else {
            
    $display_products_price '';
          }

    // more info in place of buy now
          
    if (PRODUCT_ALL_BUY_NOW != '0' and zen_get_products_allow_add_to_cart($products_all->fields['products_id']) == 'Y') {
            if (
    zen_has_product_attributes($products_all->fields['products_id'])) {
              
    $link '<a href="' zen_href_link(zen_get_info_page($products_all->fields['products_id']), 'products_id=' $products_all->fields['products_id']) . '">' MORE_INFO_TEXT '</a>';
            } else {
    //          $link= '<a href="' . zen_href_link(FILENAME_PRODUCTS_ALL, zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_all->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</a>';
              
    if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART && $products_all->fields['products_qty_box_status'] != 0) {
    //            $how_many++;
                
    $link TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART "<input type=\"text\" name=\"products_id[" $products_all->fields['products_id'] . "]\" value=\"0\" size=\"4\" />";
              } else {
                
    $link '<a href="' zen_href_link(FILENAME_PRODUCTS_ALLzen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' $products_all->fields['products_id']) . '">' zen_image_button(BUTTON_IMAGE_BUY_NOWBUTTON_BUY_NOW_ALT) . '</a>&nbsp;';
              }
            }

            
    $the_button $link;
            
    $products_link '<a href="' zen_href_link(zen_get_info_page($products_all->fields['products_id']), 'products_id=' $products_all->fields['products_id']) . '">' MORE_INFO_TEXT '</a>';
            
    $display_products_button zen_get_buy_now_button($products_all->fields['products_id'], $the_button$products_link) . '<br />' zen_get_products_quantity_min_units_display($products_all->fields['products_id']) . str_repeat('<br clear="all" />'substr(PRODUCT_ALL_BUY_NOW31));
          } else {
            
    $link '<a href="' zen_href_link(zen_get_info_page($products_all->fields['products_id']), 'products_id=' $products_all->fields['products_id']) . '">' MORE_INFO_TEXT '</a>';
            
    $the_button $link;
            
    $products_link '<a href="' zen_href_link(zen_get_info_page($products_all->fields['products_id']), 'products_id=' $products_all->fields['products_id']) . '">' MORE_INFO_TEXT '</a>';
            
    $display_products_button zen_get_buy_now_button($products_all->fields['products_id'], $the_button$products_link) . '<br />' zen_get_products_quantity_min_units_display($products_all->fields['products_id']) . str_repeat('<br clear="all" />'substr(PRODUCT_ALL_BUY_NOW31));
          }

          if (
    PRODUCT_ALL_LIST_DESCRIPTION != '0') {
            
    $disp_text zen_get_products_description($products_all->fields['products_id']);
            
    $disp_text zen_clean_html($disp_text);

            
    $display_products_description stripslashes(zen_trunc_string($disp_text150'<a href="' zen_href_link(zen_get_info_page($products_all->fields['products_id']), 'products_id=' $products_all->fields['products_id']) . '"> ' MORE_INFO_TEXT '</a>'));
          } else {
            
    $display_products_description '';
          }

    ?>
              <tr class="<?php echo ((int)($row_counter/2)==($row_counter/2)) ? 'productListing-even' 'productListing-odd'?>">
                <td width="<?php echo IMAGE_PRODUCT_ALL_LISTING_WIDTH 10?>" valign="top" class="main" align="center">
                  <?php
                    $disp_sort_order 
    $db->Execute("select configuration_key, configuration_value from " TABLE_CONFIGURATION " where configuration_group_id='" $group_id "' and (configuration_value >= 1000 and configuration_value <= 1999) order by LPAD(configuration_value,11,0)");
                    while (!
    $disp_sort_order->EOF) {
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_IMAGE') {
                        echo 
    $display_products_image;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_QUANTITY') {
                        echo 
    $display_products_quantity;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_BUY_NOW') {
                        echo 
    $display_products_button;
                      }

                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_NAME') {
                        echo 
    $display_products_name;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_MODEL') {
                        echo 
    $display_products_model;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_MANUFACTURER') {
                        echo 
    $display_products_manufacturers_name;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_PRICE') {
                        echo 
    $display_products_price;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_WEIGHT') {
                        echo 
    $display_products_weight;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_DATE_ADDED') {
                        echo 
    $display_products_date_added;
                      }
                      
    $disp_sort_order->MoveNext();
                    }
                  
    ?>
                </td>
                <td colspan="2" valign="top" class="main">
                  <?php
                    $disp_sort_order 
    $db->Execute("select configuration_key, configuration_value from " TABLE_CONFIGURATION " where configuration_group_id='" $group_id "' and (configuration_value >= 2000 and configuration_value <= 2999) order by LPAD(configuration_value,11,0)");
                    while (!
    $disp_sort_order->EOF) {
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_IMAGE') {
                        echo 
    $display_products_image;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_QUANTITY') {
                        echo 
    $display_products_quantity;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_BUY_NOW') {
                        echo 
    $display_products_button;
                      }

                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_NAME') {
                        echo 
    $display_products_name;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_MODEL') {
                        echo 
    $display_products_model;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_MANUFACTURER') {
                        echo 
    $display_products_manufacturers_name;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_PRICE') {
                        echo 
    $display_products_price;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_WEIGHT') {
                        echo 
    $display_products_weight;
                      }
                      if (
    $disp_sort_order->fields['configuration_key'] == 'PRODUCT_ALL_LIST_DATE_ADDED') {
                        echo 
    $display_products_date_added;
                      }
                      
    $disp_sort_order->MoveNext();
                    }
                  
    ?>
                </td>
              </tr>
    <?php if (PRODUCT_ALL_LIST_DESCRIPTION != 0) { ?>
              <tr class="<?php echo ((int)($row_counter/2)==($row_counter/2)) ? 'productListing-even' 'productListing-odd'?>">
                <td colspan="3" valign="top" class="main">
                  <?php
                    
    echo $display_products_description;
                  
    ?>
                </td>
              </tr>
    <?php ?>
              <tr>
                <td colspan="3"><hr /></td>
              </tr>
    <?php
          $products_all
    ->MoveNext();
        }
      } else {
    ?>
              <tr>
                <td class="main" colspan="2"><?php echo TEXT_NO_ALL_PRODUCTS?></td>
              </tr>
    <?php
      
    }
    ?>
    </table>
    Ah ha, so the one that actually builds the button and such is this one.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  3. #3
    Join Date
    Oct 2006
    Posts
    5,486
    Plugin Contributions
    12

    Default Re: Using one single listing template

    Let's peek at includes/modules/product_listing.php which takes care of category product listing:
    PHP Code:
    <?php
    /**
     * product_listing module
     *
     * @package modules
     * @copyright Copyright 2003-2006 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: product_listing.php 4655 2006-10-02 01:02:38Z ajeh $
     * UPDATED TO WORK WITH COLUMNAR PRODUCT LISTING For Zen Cart v1.3.6 - 10/25/2006
     */
    if (!defined('IS_ADMIN_FLAG')) {
      die(
    'Illegal Access');
    }
    // Column Layout Support originally added for Zen Cart v 1.1.4 by Eric Stamper - 02/14/2004
    // Upgraded to be compatible with Zen-cart v 1.2.0d by Rajeev Tandon - Aug 3, 2004
    // Column Layout Support (Grid Layout) upgraded for v1.3.0 compatibility DrByte 04/04/2006
    //
    if (!defined('PRODUCT_LISTING_LAYOUT_STYLE')) define('PRODUCT_LISTING_LAYOUT_STYLE','rows');
    if (!
    defined('PRODUCT_LISTING_COLUMNS_PER_ROW')) define('PRODUCT_LISTING_COLUMNS_PER_ROW',3);
    $row 0;
    $col 0;
    $list_box_contents = array();
    $title '';

    $max_results = (PRODUCT_LISTING_LAYOUT_STYLE=='columns' && PRODUCT_LISTING_COLUMNS_PER_ROW>0) ? (PRODUCT_LISTING_COLUMNS_PER_ROW * (int)(MAX_DISPLAY_PRODUCTS_LISTING/PRODUCT_LISTING_COLUMNS_PER_ROW)) : MAX_DISPLAY_PRODUCTS_LISTING;


    $show_submit zen_run_normal();
    $listing_split = new splitPageResults($listing_sql$max_results'p.products_id''page');
    $how_many 0;

    // Begin Row Layout Header
    if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') {        // For Column Layout (Grid Layout) add on module

      
    $list_box_contents[0] = array('params' => 'class="productListing-rowheading"');

      
    $zc_col_count_description 0;
      
    $lc_align '';
      for (
    $col=0$n=sizeof($column_list); $col<$n$col++) {
        switch (
    $column_list[$col]) {
          case 
    'PRODUCT_LIST_MODEL':
            
    $lc_text TABLE_HEADING_MODEL;
            
    $lc_align '';
            
    $zc_col_count_description++;
            break;
          case 
    'PRODUCT_LIST_NAME':
            
    $lc_text TABLE_HEADING_PRODUCTS;
            
    $lc_align '';
            
    $zc_col_count_description++;
            break;
          case 
    'PRODUCT_LIST_MANUFACTURER':
            
    $lc_text TABLE_HEADING_MANUFACTURER;
            
    $lc_align '';
            
    $zc_col_count_description++;
            break;
          case 
    'PRODUCT_LIST_PRICE':
            
    $lc_text TABLE_HEADING_PRICE;
            
    $lc_align 'right' . (PRODUCTS_LIST_PRICE_WIDTH '" width="' PRODUCTS_LIST_PRICE_WIDTH '');
            
    $zc_col_count_description++;
            break;
          case 
    'PRODUCT_LIST_QUANTITY':
            
    $lc_text TABLE_HEADING_QUANTITY;
            
    $lc_align 'right';
            
    $zc_col_count_description++;
            break;
          case 
    'PRODUCT_LIST_WEIGHT':
            
    $lc_text TABLE_HEADING_WEIGHT;
            
    $lc_align 'right';
            
    $zc_col_count_description++;
            break;
          case 
    'PRODUCT_LIST_IMAGE':
            
    $lc_text TABLE_HEADING_IMAGE;
            
    $lc_align 'center';
            
    $zc_col_count_description++;
            break;
        }

        if ( (
    $column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
          
    $lc_text zen_create_sort_heading($_GET['sort'], $col+1$lc_text);
        }

        
    $list_box_contents[0][$col] = array('align' => $lc_align,
                                            
    'params' => 'class="productListing-heading"',
                                            
    'text' => $lc_text );
      }

    // End Row Layout Header used in Column Layout (Grid Layout) add on module

    /////////////  HEADER ROW ABOVE /////////////////////////////////////////////////

    $num_products_count $listing_split->number_of_rows;

    if (
    $listing_split->number_of_rows 0) {
      
    $rows 0;
      
    // Used for Column Layout (Grid Layout) add on module
      
    $column 0;    
      if (
    PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
        if (
    $num_products_count PRODUCT_LISTING_COLUMNS_PER_ROW || PRODUCT_LISTING_COLUMNS_PER_ROW == ) {
          
    $col_width floor(100/$num_products_count) - 0.5;
        } else {
          
    $col_width floor(100/PRODUCT_LISTING_COLUMNS_PER_ROW) - 0.5;
        }
      }
      
    // Used for Column Layout (Grid Layout) add on module


      
    $listing $db->Execute($listing_split->sql_query);
      
    $extra_row 0;
      while (!
    $listing->EOF) {

        if (
    PRODUCT_LISTING_LAYOUT_STYLE == 'rows') { // Used in Column Layout (Grid Layout) Add on module
          
    $rows++;

          if (((
    $rows-$extra_row)/2) == floor(($rows-$extra_row)/2)) {
            
    $list_box_contents[$rows] = array('params' => 'class="productListing-even"');
          } else {
            
    $list_box_contents[$rows] = array('params' => 'class="productListing-odd"');
          }

          
    $cur_row sizeof($list_box_contents) - 1;
        }   
    // End of Conditional execution - only for row (regular style layout)

        
    $product_contents = array(); // Used For Column Layout (Grid Layout) Add on module

        
    for ($col=0$n=sizeof($column_list); $col<$n$col++) {
          
    $lc_align '';

          switch (
    $column_list[$col]) {
            case 
    'PRODUCT_LIST_MODEL':
              
    $lc_align '';
              
    $lc_text $listing->fields['products_model'];
              break;
            case 
    'PRODUCT_LIST_NAME':
              
    $lc_align '';
              if (isset(
    $_GET['manufacturers_id'])) {
                
    $lc_text '<h3 class="itemTitle"><a href="' zen_href_link(zen_get_info_page($listing->fields['products_id']), 'products_id=' $listing->fields['products_id']) . '">' $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
              } else {
                
    $lc_text '<h3 class="itemTitle"><a href="' zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 'cPath=' $_GET['cPath'] . '&' '') . 'products_id=' $listing->fields['products_id']) . '">' $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';
              }
              break;
            case 
    'PRODUCT_LIST_MANUFACTURER':
              
    $lc_align '';
              
    $lc_text '<a href="' zen_href_link(FILENAME_DEFAULT'manufacturers_id=' $listing->fields['manufacturers_id']) . '">' $listing->fields['manufacturers_name'] . '</a>';
              break;
            case 
    'PRODUCT_LIST_PRICE':
              
    $lc_price zen_get_products_display_price($listing->fields['products_id']) . '<br />';
              
    $lc_align 'right';
              
    $lc_text =  $lc_price;

              
    // more info in place of buy now
              
    $lc_button '';
              if (
    zen_has_product_attributes($listing->fields['products_id']) or PRODUCT_LIST_PRICE_BUY_NOW == '0') {
                
    $lc_button '<a href="' zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 'cPath=' $_GET['cPath'] . '&' '') . 'products_id=' $listing->fields['products_id']) . '">' MORE_INFO_TEXT '</a>';
              } else {
                if (
    PRODUCT_LISTING_MULTIPLE_ADD_TO_CART != 0) {
                if (
                    
    // not a hide qty box product
                    
    $listing->fields['products_qty_box_status'] != &&
                    
    // product type can be added to cart
                    
    zen_get_products_allow_add_to_cart($listing->fields['products_id']) != 'N'
                    
    &&
                    
    // product is not call for price
                    
    $listing->fields['product_is_call'] == 0
                    
    &&
                    
    // product is in stock or customers may add it to cart anyway
                    
    ($listing->fields['products_quantity'] > || SHOW_PRODUCTS_SOLD_OUT_IMAGE == 0) ) {
                        
    $how_many++;
                      }
                
    // hide quantity box
                
    if ($listing->fields['products_qty_box_status'] == 0) {
                  
    $lc_button '<a href="' zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' $listing->fields['products_id']) . '">' zen_image_button(BUTTON_IMAGE_BUY_NOWBUTTON_BUY_NOW_ALT'class="listingBuyNowButton"') . '</a>';
                } else {
                  
    $lc_button TEXT_PRODUCT_LISTING_MULTIPLE_ADD_TO_CART "<input type=\"text\" name=\"products_id[" $listing->fields['products_id'] . "]\" value=\"0\" size=\"4\" />";
                }
              } else {
    // qty box with add to cart button
                
    if (PRODUCT_LIST_PRICE_BUY_NOW == '2' && $listing->fields['products_qty_box_status'] != 0) {
                  
    $lc_buttonzen_draw_form('cart_quantity'zen_href_link(zen_get_info_page($listing->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' $listing->fields['products_id']), 'post''enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' zen_draw_hidden_field('products_id'$listing->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CARTBUTTON_IN_CART_ALT) . '</form>';
                } else {
                  
    $lc_button '<a href="' zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' $listing->fields['products_id']) . '">' zen_image_button(BUTTON_IMAGE_BUY_NOWBUTTON_BUY_NOW_ALT'class="listingBuyNowButton"') . '</a>';
                }
                }
              }
              
    $the_button $lc_button;
            
    $products_link '<a href="' zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 'cPath=' $_GET['cPath'] . '&' '') . 'products_id=' $listing->fields['products_id']) . '">' MORE_INFO_TEXT '</a>';
              
    $lc_text .= '<br />' zen_get_buy_now_button($listing->fields['products_id'], $the_button$products_link) . '<br />' zen_get_products_quantity_min_units_display($listing->fields['products_id']);
              
    $lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON '<br />' '') : '');

              break;
            case 
    'PRODUCT_LIST_QUANTITY':
              
    $lc_align 'right';
              
    $lc_text $listing->fields['products_quantity'];
              break;
            case 
    'PRODUCT_LIST_WEIGHT':
              
    $lc_align 'right';
              
    $lc_text $listing->fields['products_weight'];
              break;
            case 
    'PRODUCT_LIST_IMAGE':
              
    $lc_align 'center';
            if (
    $listing->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) {
              
    $lc_text '';
            } else {
              if (isset(
    $_GET['manufacturers_id'])) {
              
    $lc_text '<a href="' zen_href_link(zen_get_info_page($listing->fields['products_id']), 'products_id=' $listing->fields['products_id']) . '">' zen_image(DIR_WS_IMAGES $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTHIMAGE_PRODUCT_LISTING_HEIGHT'class="listingProductImage"') . '</a>';
              } else {
              
    $lc_text '<a href="' zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 'cPath=' $_GET['cPath'] . '&' '') . 'products_id=' $listing->fields['products_id']) . '">' zen_image(DIR_WS_IMAGES $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTHIMAGE_PRODUCT_LISTING_HEIGHT'class="listingProductImage"') . '</a>';
              }
            }
              break;
          }

          
    $product_contents[] = $lc_text// Used For Column Layout (Grid Layout) Option

          
    if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') {
            
    $list_box_contents[$rows][$col] = array('align' => $lc_align,
                                                    
    'params' => 'class="productListing-data"',
                                                    
    'text'  => $lc_text);
          }
        }

        
    // add description and match alternating colors
        //if (PRODUCT_LIST_DESCRIPTION > 0) {
        //  $rows++;
        //  if ($extra_row == 1) {
        //    $list_box_description = "productListing-data-description-even";
        //    $extra_row=0;
        //  } else {
        //    $list_box_description = "productListing-data-description-odd";
        //    $extra_row=1;
        //  }
        //  $list_box_contents[$rows][] = array('params' => 'class="' . $list_box_description . '" colspan="' . $zc_col_count_description . '"',
        //  'text' => zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION));
        //}

        // Following code will be executed only if Column Layout (Grid Layout) option is chosen
        
    if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
          
    $lc_text implode('<br />'$product_contents);
          
    $list_box_contents[$rows][$column] = array('params' => 'class="centerBoxContentsProducts centeredContent back"' ' ' 'style="width:' $col_width '%;"',
                                                     
    'text'  => $lc_text);
          
    $column ++;
          if (
    $column >= PRODUCT_LISTING_COLUMNS_PER_ROW) {
            
    $column 0;
            
    $rows ++;
          }
        }
        
    // End of Code fragment for Column Layout (Grid Layout) option in add on module
        
    $listing->MoveNext();
      }
      
    $error_categories false;
    } else {
      
    $list_box_contents = array();

      
    $list_box_contents[0] = array('params' => 'class="productListing-odd"');
      
    $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                      
    'text' => TEXT_NO_PRODUCTS);

      
    $error_categories true;
    }

    if ((
    $how_many and $show_submit == true and $listing_split->number_of_rows 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == or  PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 3) ) {
      
    $show_top_submit_button true;
    } else {
      
    $show_top_submit_button false;
    }
    if ((
    $how_many and $show_submit == true and $listing_split->number_of_rows 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART >= 2) ) {
      
    $show_bottom_submit_button true;
    } else {
      
    $show_bottom_submit_button false;
    }



      if (
    $how_many && PRODUCT_LISTING_MULTIPLE_ADD_TO_CART != and $show_submit == true and $listing_split->number_of_rows 0) {
      
    // bof: multiple products
        
    echo zen_draw_form('multiple_products_cart_quantity'zen_href_link(FILENAME_DEFAULTzen_get_all_get_params(array('action')) . 'action=multiple_products_add_product'), 'post''enctype="multipart/form-data"');
      }

    ?>
    Huhm, so doesnt this one do something very similar to tpl_modules_products_all_listing.php? Can we just include this one in all special/all/new listing instead? So 1 template for all? Yay
    But wait, this one put its query in $listing_sql, the other one puts that in $products_all_query_raw, grrr, but easy fix, lets do a bit hacking into the core code:
    I open includes/modules/pages/products_all/header_php.php and replace the whole thing with:

    PHP Code:
    <?php
    /**
     * products_all  header_php.php
     *
     * @package page
     * @copyright Copyright 2003-2006 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: header_php.php 4261 2006-08-25 04:35:20Z ajeh $
     */

      
    require(DIR_WS_MODULES zen_get_module_directory('require_languages.php'));

      
    $breadcrumb->add(NAVBAR_TITLE);
    // display order dropdown
      
    $order_by PRODUCT_ALL_LIST_SORT_DEFAULT;
      require(
    DIR_WS_MODULES zen_get_module_directory(FILENAME_LISTING_DISPLAY_ORDER));

      
    $products_all_array = array();

      
    $listing_sql "SELECT p.products_type, p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id,
                                        p.products_date_added, m.manufacturers_name, p.products_model, p.products_quantity, p.products_weight, p.product_is_call,
                                        p.product_is_always_free_shipping, p.products_qty_box_status
                                 FROM " 
    TABLE_PRODUCTS " p
                                 LEFT JOIN " 
    TABLE_MANUFACTURERS " m ON (p.manufacturers_id = m.manufacturers_id), " TABLE_PRODUCTS_DESCRIPTION " pd
                                 WHERE p.products_status = 1
                                 AND p.products_id = pd.products_id
                                 AND pd.language_id = :languageID " 
    $order_by;

      
    $listing_sql $db->bindVars($listing_sql':languageID'$_SESSION['languages_id'], 'integer');
     
    //check to see if we are in normal mode ... not showcase, not maintenance, etc
      
    $show_submit zen_run_normal();

    $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
      
    'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
      
    'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
      
    'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
      
    'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
      
    'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
      
    'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE);

      
    /*                         ,
      'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW);
      */
      
    asort($define_list);
      
    reset($define_list);
      
    $column_list = array();
      foreach (
    $define_list as $key => $value)
      {
        if (
    $value 0$column_list[] = $key;
      }
    ?>
    Notice how I keep the all listing query, but just change from $products_all_query_raw to $listing_sql, and then some minor changes to make it work? Basically you can do just the same for products_new and all other listings.
    Now lets move on to the last bit.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  4. #4
    Join Date
    Oct 2006
    Posts
    5,486
    Plugin Contributions
    12

    Default Re: Using one single listing template

    Edit your includes/templates/your_template/templates/tpl_products_all_default.php, replace the content by:

    PHP Code:
    <?php
    /**
     * Module Template
     *
     * @package templateSystem
     * @copyright Copyright 2003-2005 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: tpl_modules_product_listing.php 3241 2006-03-22 04:27:27Z ajeh $
     * UPDATED TO WORK WITH COLUMNAR PRODUCT LISTING 04/04/2006
     */

        
    require($template->get_template_dir('tpl_modules_product_listing.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_product_listing.php');
    ?>
    And that's it.
    This should work for most versions, only tested on 1.3.7 though. The reason I post such lengthy post, is for you to understand how it works, and then make changes on your own files, since you may use a different version and things can be slightly different. And, ALWAYS BACK UP, DO NOT TRY THIS ON A LIVE SITE FIRST.
    One more note, since we are now using a single product listing template, the layout can be controlled at Admin->configuration->Product Listing.

    You want to have your All Listing looks a bit different from the other ones? No, cant do that, well, the whole purpose of this process is to make things look exactly the same anyway rite?
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  5. #5
    Join Date
    Oct 2006
    Posts
    5,486
    Plugin Contributions
    12

    Default Re: Using one single listing template

    I forgot to add the product sorting there:
    PHP Code:
     <?php
    /**
     * Module Template
     *
     * @package templateSystem
     * @copyright Copyright 2003-2005 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: tpl_modules_product_listing.php 3241 2006-03-22 04:27:27Z ajeh $
     * UPDATED TO WORK WITH COLUMNAR PRODUCT LISTING 04/04/2006
     */
    require($template->get_template_dir('/tpl_modules_listing_display_order.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_listing_display_order.php');
        require(
    $template->get_template_dir('tpl_modules_product_listing.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_product_listing.php');
    ?>
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  6. #6
    Join Date
    Apr 2006
    Location
    Dark Side of the Moon
    Posts
    946
    Plugin Contributions
    1

    Default Re: Using one single listing template

    Hey!

    Nice post! Perhaps you'll compile the changes and make a download?

    I thought it strange myself that zencart needs to use a different layout sceme for EACH of the listing modules.

  7. #7
    Join Date
    Jun 2007
    Location
    Australia - Melbourne
    Posts
    310
    Plugin Contributions
    6

    Default Re: Using one single listing template

    Magical!

    Thanks a lot! That saved me a lot of time!
    The greatest pleasure in life is doing what people say you cannot do.

    Check on www.WebExtremeCustomiser.com for my modules (free contribution):
    AJAX Image Swapper
    AJAX Banner Swapper
    Fixed Navigation

  8. #8
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    21,829
    Plugin Contributions
    25

    Default Re: Using one single listing template

    Having the ability to customize the listing for each type is a good thing; the problem is that the featured/new/all listings are controlled by (I believe) an older kind of layout code, so they can't look the same as the product listing.

    The listings are planned to be standardized and improved in version 1.4.

  9. #9
    Join Date
    Oct 2006
    Posts
    5,486
    Plugin Contributions
    12

    Default Re: Using one single listing template

    With css over-ride, you can do lots of things without the need of using separated layout codes. Anyhow, this will save lots of time for most people, since most of us need only a single, consistent display throughout the site.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  10. #10
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    21,829
    Plugin Contributions
    25

    Default Re: Using one single listing template

    Yes, a full set of tags for handles would allow considerable modification to the layout for different listings. The things that would be difficult for CSS to achieve probably wouldn't make much sense to do anyway, as they would make listings radically different which is bad ergonomics...

 

 
Page 1 of 32 12311 ... LastLast

Similar Threads

  1. qty boxes missing in product listing page - cannot add multiples to cart?
    By SarahL in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 1 Feb 2008, 01:32 PM
  2. All Product Listing Page - Edit Template Question
    By thehighlandsgroup in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 29 Nov 2007, 04:37 AM
  3. making New Products Listing look like Category/Manufacturer Listing ??
    By simplifiedmedia in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 27 May 2006, 10:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •