Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Add attributes dropdowns to products listings

Add attributes dropdowns to products listings

Locked

Views: 7,476

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
10 May 2006, 8:59 AM
#1
antz avatar

antz

New Zenner

Join Date:
May 2006
Posts:
4
Plugin Contributions:
0

Add attributes dropdowns to products listings

Hi all,

I'm currently trying to modify the products listing. Appart product name, price and quantity wanted, I also want to display dropdowns for each product attributes. When pressing "Add selected products to cart", I want to add the products selected with their attributes choice.

Here is a screenshot of the listing I'm working on:

I succeeded in displaying good attributes. I modified some little things in /catalog/includes/modules/product_listing.php and I added this piece of code at line +-180:

        case 'PRODUCT_LIST_ATTRIBUTES':
        	$lc_align = 'center';

			if (zen_has_product_attributes($listing->fields['products_id']))
			{
				$_GET['products_id'] = $listing->fields['products_id'];
	
				require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_ATTRIBUTES));
	
				/**
				* display the product atributes
				*/
				for($i=0;$i<sizeof($options_name);$i++)
				{
					$lc_text = '<div id="productAttributes">';
					$lc_text .= $options_name[$i];
					$lc_text .= $options_menu[$i];
					$lc_text .= '</div>';
				}
			}
			else
			{
				$lc_text = '';
			}
		break;

So it correctly displays attributes for each product. But when I press "Add selected products to cart", it doesn't remember my attributes choices. So I have to change the way the form is processing.

Does anybody knows how to do that?

PS: my HTML editor has bugged, I can't open it right now. When it is back, I'll try to see what the form is doing and I'll add more information to my topic.

11 May 2006, 9:07 AM
#2
antz avatar

antz

New Zenner

Join Date:
May 2006
Posts:
4
Plugin Contributions:
0

Re: Add attributes dropdowns to products listings

Okay it's done! :yes: Here is what has to be done for displaying attributes on the products listing and adapting the form process (for Zen Cart 1.3). This is not perfect but it will work for the shop I'm working on.

1. /catalog/includes/modules/product_listing.php:

1.1 Line 27 (approx.), I commented the last checks done to see if the product has attributes (and on my shop, all products have thier product_type as n°3):

//          if (zen_has_product_attributes($chk_attributes->fields['products_id']) < 1 and $chk_attributes->fields['products_type'] != 3) {
            $how_many++;
//          }

1.2 Line 42 (approx.), I added an item to the $column_list array:

$column_list[2] = $column_list[1];
$column_list[1] = "PRODUCT_LIST_ATTRIBUTES";

1.3 Line 83 (approx.), I added a 'case' to the switch:

    case 'PRODUCT_LIST_ATTRIBUTES':
    $lc_text = TABLE_HEADING_ATTRIBUTES;
    $lc_align = 'left';
    $zc_col_count_description++;
    break;

1.4 Line 182 (approx.), I added a 'case' to the second switch:

        case 'PRODUCT_LIST_ATTRIBUTES':
        	$lc_align = 'center';

			if (zen_has_product_attributes($listing->fields['products_id']))
			{
				$_GET['products_id'] = $listing->fields['products_id'];
				$productsListing = true;
	
				require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_ATTRIBUTES));
	
				/**
				* display the product attributes
				*/
				for($i = 0; $i < sizeof($options_name); $i++)
				{
					$lc_text = '<div id="productAttributes">';
					$lc_text .= $options_name[$i];
					$lc_text .= $options_menu[$i];
					$lc_text .= '</div>';
				}
			}
			else
			{
				$lc_text = '';
			}
		break;

2. /catalog/includes/classes/shopping_cart.php:

2.1 Line 1674 (approx.), I added a line to check for attributes and I added the third parameter to the add_cart() call:

          $real_ids = isset($_POST['attrib'][$prodId]) ? $_POST['attrib'][$prodId] : "";
          $this->add_cart($prodId, $this->get_quantity($prodId)+($new_qty), $real_ids);

3. /catalog/includes/modules/attributes.php:

3.1 Line 574 (approx.), I changed the way the HTML is generated when it is for a products listing:

                  if ($show_attributes_qty_prices_icon == 'true') {
                    $options_name[] = ATTRIBUTES_QTY_PRICE_SYMBOL . $products_options_names->fields['products_options_name'];
                  } else if (!$productsListing) {
                    $options_name[] = '<label class="attribsSelect" for="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '">' . $products_options_names->fields['products_options_name'] . '</label>';
                  } else {
                    $options_name[] = '<label class="attribsSelect" for="attrib[' . $_GET['products_id'] . '][' . $products_options_names->fields['products_options_id'] . ']">' . $products_options_names->fields['products_options_name'] . '</label>';
					}


					if (!$productsListing)
					{
                  $options_menu[] = zen_draw_pull_down_menu('id[' . $products_options_names->fields['products_options_id'] . ']', $products_options_array, $selected_attribute, 'id="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '"') . "\n";
					}
					else
					{
                  $options_menu[] = zen_draw_pull_down_menu('attrib['. $_GET['products_id'] .'][' . $products_options_names->fields['products_options_id'] . ']', $products_options_array, $selected_attribute, '') . "\n";
					}
  1. /includes/languages/english/index.php:

4.1 I added a definition for the attributes row heading:

  define('TABLE_HEADING_ATTRIBUTES', 'Attributes');

I think that's all. I know it's not perfect, some checks missing. But this is for a small shop and it will work with our products. If anybody can improve it, answers appreciated. :thumbsup: