Results 1 to 2 of 2
  1. #1
    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:
    Code:
            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.

  2. #2
    Join Date
    May 2006
    Posts
    4
    Plugin Contributions
    0

    Idea or Suggestion Re: Add attributes dropdowns to products listings

    Okay it's done! 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):

    Code:
    //          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:

    Code:
    $column_list[2] = $column_list[1];
    $column_list[1] = "PRODUCT_LIST_ATTRIBUTES";
    1.3 Line 83 (approx.), I added a 'case' to the switch:

    Code:
        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:

    Code:
            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:

    Code:
              $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:

    Code:
                      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";
    					}
    4. /includes/languages/english/index.php:

    4.1 I added a definition for the attributes row heading:

    Code:
      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.

 

 

Similar Threads

  1. Attributes dropdowns all showing in cart
    By delia in forum General Questions
    Replies: 1
    Last Post: 13 Oct 2011, 02:20 PM
  2. Products Listings Price, add to cart & Name Spacing
    By hcd888 in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 17 Mar 2011, 01:36 AM
  3. Add attributes dropdowns to products listings
    By onlyjf77 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 17 Oct 2009, 01:50 AM
  4. Dynamic Dropdowns For Stock By Attributes
    By Craig Robbo in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 19 Jan 2009, 07:24 AM
  5. question about attributes and dropdowns
    By AvieLF in forum General Questions
    Replies: 3
    Last Post: 24 Sep 2006, 06:52 AM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR