Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / product listing: combine and output labels before combined data values

product listing: combine and output labels before combined data values

Locked

Views: 821

Results 1 to 1 of 1
This thread is locked. New replies are disabled.
29 Jun 2008, 9:47 PM
#1
molywerks avatar

molywerks

Zen Follower

Join Date:
Aug 2006
Posts:
136
Plugin Contributions:
0

product listing: combine and output labels before combined data values

Any PHP inspectors out there?

Background. I need help with tpl_modules_products_new_listing.php where I am successfully using two custom data fields, model name and style. Note that a style value does not necessarily exist but a model name always does. Thus, I am trying to output and display covering the two possible conditions:

  1. model name | style » iPod | Shuffle
  2. model » Zune
    Note the absence of a style label in the second. This is my trouble, preventing its output when there is no style value.

Question. How do I rework the functioning tpl_modules code shown in purple below so that it outputs labels and data to cover the above two possible conditions?

What works. Figuring out the HTML is easy as is getting the custom data fields to output in display with their labels, but the trouble I am having is the conditional combine and output. Also, I do not mind if a solution involves the code shown in green below which is in the <td>table</td> areas toward the bottom of the modules template file. And yes the configuration table and admin panel are set properly to display the new configuration table rows: PRODUCT_NEW_LIST_STYLE_LABEL, PRODUCT_NEW_LIST_MODEL_NAME and PRODUCT_NEW_LIST_STYLE.

What doesn't. What I've tried is a zen_products_lookup with an if empty statement shown in blue below but my PHP skills are in early beta. Obviously. IOW, I can copy and paste and sometimes manipulate it to get it to do what I want but original coding from scratch is out of the question for me at this stage. I may need examples pointing out where I am going wrong.

Lastly, I will add PRODUCT_NEW_LIST_MODEL_NAME_LABEL components if necessary once I understand how to get the STYLE label working properly.

Functioning code
if (PRODUCT_NEW_LIST_MODEL_NAME != '0' and zen_get_show_product_switch($products_new->fields['products_id'], 'custom_model_name')) {
$display_products_model_name = TEXT_PRODUCTS_MODEL_NAME . $products_new->fields['custom_model_name'] . str_repeat('<br clear="all" />', substr(PRODUCT_NEW_LIST_MODEL_NAME, 3, 1));
} else {
$display_products_model_name = '';
}
if (PRODUCT_NEW_LIST_STYLE != '0' and zen_get_show_product_switch($products_new->fields['products_id'], 'custom_style')) {
$display_products_style = '<br />' . TEXT_PRODUCTS_STYLE . $products_new->fields['custom_style'] . TEXT_STYLE . str_repeat('<br clear="all" />', substr(PRODUCT_NEW_LIST_STYLE, 3, 1));
} else {
$display_products_style = '';
}


Table area code
if ($disp_sort_order->fields['configuration_key'] == 'PRODUCT_NEW_LIST_MODEL_NAME') {
echo $display_products_model_name;
}
if ($disp_sort_order->fields['configuration_key'] == 'PRODUCT_NEW_LIST_STYLE') {
echo $display_products_style;
}
if ($disp_sort_order->fields['configuration_key'] == 'PRODUCT_NEW_LIST_STYLE_LABEL') {
echo $display_products_style_label;
}


Failing code
if (PRODUCT_NEW_LIST_STYLE_LABEL != '0') {
zen_get_info_page($products_new->fields['products_id']);
zen_products_lookup($product['id'], 'custom_style');
if (empty($products_new->fields['custom_style'])) {
$display_products_style_label = '';
} else {
$display_products_style_label = zen_products_lookup($product['id'], 'details_size') . '<span style="text-transform:uppercase; font-size:0.8em">size </span>';
}
} else {
$display_products_style_label = '';
}