2

I am trying to find out how I could manually add the product model to each title in the category product listing in zencart, rather than having the model number appear in its own column.

It appears that any instance of using:

$listing->fields['products_model']

in the "product_listing.php" file will only work when the parameters in the admin are sent to true. This is fine, however I then get two instances of the product model. One with the variable in it's own column (which I don't want), and one wherever else I put the variable.

Here is the section I am referring to, you will notice that a case is set up for the model to have its own column, however I want to place it before the title instead under the product list name case and eliminate the column.

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 = '';
         $lc_text = '<h3 class="itemTitle"><a href="'.zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id'] > 0) ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3>

Is there a way I can reference the model number and place in the title for each row while bypassing the parameter set in the administration?

Any help would be greatly appreciated.

boisvert
  • 3,444
  • 2
  • 25
  • 50
cclark413
  • 426
  • 2
  • 13
  • Perhaps an easier way of putting it: Is there a convenient way to override a parameter set on a variable so that it displays regardless of what the parameter is set at? – cclark413 Apr 09 '13 at 16:21

2 Answers2

1

I would just append the product model number ($listing->fields['products_model']) to the product title:

case 'PRODUCT_LIST_NAME':
    $lc_align = '';
    $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id'] > 0) ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '[' . $listing->fields['products_model'] . ']' . '</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;

Remember to then turn off the Model Number column in the Zen Cart Admin.

I haven't tested this in Zen Cart - hope it helps.

kerrin
  • 2,998
  • 1
  • 20
  • 32
  • Hey again Kerrin. This only works if you have the model column turned on in the Admin. Therefore, you end up with the model number in the title AND the column (which I don't want). If it's not, it just shows the brackets you encased the code in.Any ideas of how to disable the column from being created all together? – cclark413 Jun 18 '13 at 16:17
  • Let me have a play in my demo Zen Cart and then I can put a **tested** solution here :) – kerrin Jun 20 '13 at 01:49
1

After some time, I have figured out the answer to my own question. It was actually much easier than I thought. Hopefully, this will help others who may have wanted to do the same thing.

Go to "includes/index_filters/default_filter.php:

From what I can tell, this is where all the queries are made for the "Product Listing" module to display lists for both a specific category or manufacturer. By default, the current queries do not include "p.products_model". Simply add the column identifier in each query (4 total locations: category, category:all, manufacturer, manufacturer:all).

Example:

// We are asked to show only specific category
  $listing_sql = "select " . $select_column_list . " p.products_id, p.products_model, p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
  from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " .
  TABLE_PRODUCTS_DESCRIPTION . " pd, " .
  TABLE_MANUFACTURERS . " m, " .
  TABLE_PRODUCTS_TO_CATEGORIES . " p2c
  where p.products_status = 1
    and p.manufacturers_id = m.manufacturers_id
    and m.manufacturers_id = '" . (int)$_GET['filter_id'] . "'
    and p.products_id = p2c.products_id
    and pd.products_id = p2c.products_id
    and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
    and p2c.categories_id = '" . (int)$current_category_id . "'" .
    $alpha_sort;
}

From there, you will be able to call the product model code "$listing->fields['products_model']" anywhere you would like, without the parameter in the admin back-end interrupting it from showing. In my case, it I included it directly under the product name in the "product_listing.php" file in modules.

Example:

$lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id'] > 0) ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div id=\"listing_model\">Item Code: ' .$listing->fields['products_model'] . '</div>

Hope this helps someone. Why they made you originally have a whole column for the product model is beyond me, as both "Listing New" and "Listing All" both show it in the same column as the title and description.

cclark413
  • 426
  • 2
  • 13