The code can be complicated ...
So ... I spent some of the afternoon messing around with this and think I have a pretty good solution, with a little help from Rainbow and the work he did on this awhile back ...
Now for the fun customizations ...
1 You need to add a new setting to the Configuration ... Product Listing ...
Code:
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES
('Display Product Quantity Discount', 'PRODUCT_LIST_QUANTITY_DISCOUNT', '4', 'Do you want to display the Product Quantity Discounts?', 8, 3, '2013-11-10 13:34:21', '2013-10-18 14:26:01', NULL, NULL);
2 New file:
/includes/languages/english/extra_definitions/extra_qty_discounts_listing.php
Code:
<?php
/**
** Messages used by product_listing fr Discount quantities
*/
define('TABLE_HEADING_QUANTITY_DISCOUNT', 'Quantity Discounts');
3 Customize:
/includes/modules/pages/index/main_template_vars.php
Code:
// create column list
$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_QUANTITY_DISCOUNT' => PRODUCT_LIST_QUANTITY_DISCOUNT
);
/includes/modules/your_template_dir/product_listing.php
Code:
case 'PRODUCT_LIST_MANUFACTURER':
$lc_text = TABLE_HEADING_MANUFACTURER;
$lc_align = '';
$zc_col_count_description++;
break;
case 'PRODUCT_LIST_QUANTITY_DISCOUNT':
$lc_text = TABLE_HEADING_QUANTITY_DISCOUNT;
$lc_align = '';
$zc_col_count_description++;
break;
case 'PRODUCT_LIST_PRICE':
Code:
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_QUANTITY_DISCOUNT':
// The following lines are taken for Ajeh's code in this forum thread
$products_discount_type = zen_products_lookup($listing->fields['products_id'], $what_field = 'products_discount_type');
$columns ++;
$products_id_current = (int)$listing->fields['products_id'];
$quantityDiscounts = array();
$products_discount_type_from = zen_products_lookup($listing->fields['products_id'], $what_field = 'products_discount_type_from');
require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_PRODUCTS_QUANTITY_DISCOUNTS));
// The following lines are my long & heavy but seemingly functional code, I've adapted it from tpl_modules_products_quantity_discounts as I couldn't get the foreach statement to work here
for ($i=1, $m=$products_discounts_query->RecordCount(); $i<=$m; $i++) {
$discount_level_n = 'discount_level_' . $i;
$$discount_level_n = $quantityDiscounts[$i-1];
}
if ($products_discount_type != 0) {
// I've adapted the following table style from my custom tpl_modules_product_quantity_discounts, I've made it more vertical to make it fit better, if you want the original horizontal layout you can find the code in tpl_modules_product_quantity_discounts
//NB the TEXT_HEADER below is for ACTUAL PRICE DISCOUNTS it could be replaced with the alternatives: TEXT_HEADER_DISCOUNT_PRICES_AMOUNT_OFF or TEXT_HEADER_DISCOUNT_PRICES_PERCENTAGE.
$lc_text = '<table style="margin-top: 0.3em; margin-left: 1em; margin-right: 1em; margin-bottom: 1.5em; border:1px solid #94d9f8" cellspacing="0" cellpadding="3">
<tr style="background: #ECF8FD; font-weight: bold">
<td colspan="2" align="center">'. TABLE_HEADING_QUANTITY_DISCOUNT . '</font></td> </tr>';
$lc_text .= '<tr><td align="left">' . $show_qty . '</td><td>' . $currencies->display_price($show_price, zen_get_tax_rate($products_tax_class_id)) . '</td></tr>';
for ($i=1, $m=$products_discounts_query->RecordCount(); $i<=$m; $i++) {
$discount_level_n = 'discount_level_' . $i;
//$lc_text .= '$discount_level_n: ' . $discount_level_n . ' $$discount_level_n[show_qty]:' . $$discount_level_n['show_qty'] . '<br>';
//echo '$$discount_level_n: ' . var_dump($$discount_level_n) . ' $$discount_level_n[show_qty]:' . ${$discount_level_n}['show_qty'] . '<br>';
$lc_text .= '<tr><td align="left">' . ${$discount_level_n}['show_qty'] . '</td><td>' . $currencies->display_price(${$discount_level_n}['discounted_price'], zen_get_tax_rate($products_tax_class_id)) . '</td></tr>';
}
$lc_text .= '</table>';
} else {
$lc_text ='';
}
break;
case 'PRODUCT_LIST_PRICE':
And to make things look better, I like to have the Product Description under all of the columns, so I change the code for the products_description ...
Code:
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><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>';
$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>';
break;
and at the bottom, you will see the commented code:
Code:
// 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));
//}
$listing->MoveNext();
Remove all of the comment marks // and that will display the description beneath the columns ...
Now you try it and see if it comes out right for you ...
Bookmarks