Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / One product, multible sizes

One product, multible sizes

Views: 948

Results 1 to 8 of 8
11 Mar 2010, 7:15 PM
#1
halollet avatar

halollet

New Zenner

Join Date:
Mar 2010
Posts:
66
Plugin Contributions:
0

One product, multible sizes

Hello all. :D

I just got my Zencart up and running so I have the most recent release.

What I'm trying to do is get my products set up properly.

I'm selling clothing. So I have a red shirt that comes in small, medium, and large. But I have limited quantities of each. Once I'm out of one size, that's it.

I don't want to make 3 different products for each size with the same image, that's silly.

So how do I get it so that my Option Value with the dropdown to say :
Small (3 left)
Medium (5 left)
Large (1 left)

or something along those lines. Even if I can't have the (#left) I would like to have the size automatically remove itself so I don't have customers buying something that I no longer have.

Thanks! :cool:

p.s. I'm a video game programmer by trade and php is very readable to me and so you can get all technical with me and stuff! :P

12 Mar 2010, 2:02 AM
#3
halollet avatar

halollet

New Zenner

Join Date:
Mar 2010
Posts:
66
Plugin Contributions:
0

Re: One product, multible sizes

Dude you are a cake of awesome with booyeah frosting!

:clap:

12 Mar 2010, 7:50 PM
#4
halollet avatar

halollet

New Zenner

Join Date:
Mar 2010
Posts:
66
Plugin Contributions:
0

Re: One product, multible sizes

Problem;

When I run out of a size, it doesn't hide that size from the drop down menu. It just gives a back order thing to the shopping cart.

I can't have this since I have no backorder products at all.

So how can I hide the size when stock = 0?

30 Mar 2010, 4:28 PM
#5
jage avatar

jage

New Zenner

Join Date:
Mar 2010
Posts:
5
Plugin Contributions:
0

Re: One product, multible sizes

I just finished hacking mine. I am not advising this but it works for my site and I can't find/wait for a better answer. Use at your own risk!

I'm using ZC 1.3.8 and Stock By Attributes 1.4.9. This is for a dropdown menu with one attribute. I am not sure if this SQL is relevant to anything else.

In the file includes/modules/attributes.php around line 76 you should find this:

                $sql = "select    pov.products_options_values_id,
                        pov.products_options_values_name,
                        pa.*
              from      " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov
              where     pa.products_id = '" . (int)$_GET['products_id'] . "'
              and       pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
              and       pa.options_values_id = pov.products_options_values_id
              and       pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
                $order_by;

I replaced it with this:

$sql = "select    pov.products_options_values_id,
	pov.products_options_values_name,
	pa.*
	from      " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov
,products_with_attributes_stock ps
	where     pa.products_id = '" . (int)$_GET['products_id'] . "'
	and       pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
	and       pa.options_values_id = pov.products_options_values_id
AND pa.products_attributes_id = ps.stock_attributes
AND pa.products_id = ps.products_id
AND ps.quantity > 0
	and       pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
	$order_by;

The funky indent is so you can see which lines I added.

Note that I did not use a variable name for the products_with_attributes_stock. What this does is when the attributes are selected it does not include any with Quantity 0 or less. Since this result is used to build the dropdown menu items that are out of stock never show up.

Again, this is pretty specific, but hopefully will help you solve your problem.

30 Mar 2010, 5:04 PM
#6
jage avatar

jage

New Zenner

Join Date:
Mar 2010
Posts:
5
Plugin Contributions:
0

Re: One product, multible sizes

Well I've discovered that SQL code only works for my first item. :censored:

I think the idea is correct, just the manner in which the attributes by item are being returned is opaque to me, so I need to rework the SQL so I understand it (and can join on stock).

30 Mar 2010, 7:19 PM
#7
kjconnects avatar

kjconnects

New Zenner

Join Date:
Aug 2008
Posts:
11
Plugin Contributions:
0

Re: One product, multible sizes

jage:

Well I've discovered that SQL code only works for my first item. :censored:

I think the idea is correct, just the manner in which the attributes by item are being returned is opaque to me, so I need to rework the SQL so I understand it (and can join on stock).

If you're only looking to affect the drop-down box, you will need to find this line of code in attributes.php:

$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";

Before you modify it, I recommend you place it in an override folder, i.e., /includes/modules/[YOU TEMPLATE]/attributes.php, and edit that file.

Notice that it uses a function called zen_draw_pull_down_menu(). That can be found in html_output.php in the functions folder. You'll need to either create a new function and modify it in html_output, or copy that function down to attributes.php and modify it. Basically, what I did was check to see for read-only or quantity, and stated that selection was [out of stock] in the drop-down box. There is CSS you need to add if you want to grey it out. You can see it in action at:

http://www.randylion.com/index.php?main_page=product_info&cPath=36&products_id=142

You could remove that selection by modifying the function. If you wanted to do this for radio buttons, that is elsewhere in attributes.php.

Hope that points you in the right direction...

31 Mar 2010, 1:06 AM
#8
jage avatar

jage

New Zenner

Join Date:
Mar 2010
Posts:
5
Plugin Contributions:
0

Re: One product, multible sizes

Yes my intention is not to get people off on the wrong track! I can't figure out how products_with_attributes_stock.stock_attributes can be related to products_attributes.options_values_id so I created a new column in products_with_attributes_stock called products_attributes_lookup_id and hand populated it.

Again, I'm not saying this is a GOOD solution and I don't really understand a lot of the zen_cart coding choices but this is what got my single attribute drop down with stock working for the time being.

$sql = 'SELECT
			pov.products_options_values_id,
			pov.products_options_values_name,
			pa.*
		FROM
			products_attributes pa
		JOIN products_options_values pov ON
			pa.options_values_id = pov.products_options_values_id
		JOIN products_with_attributes_stock ps ON
			(pa.options_values_id = ps.products_attributes_lookup_id
				AND
			pa.products_id = ps.products_id)
		WHERE
			pa.products_id = ' . (int)$_GET['products_id'] .'
			AND pa.options_id = ' . (int)$products_options_names->fields['products_options_id'] . '
			AND pov.language_id = ' . (int)$_SESSION['languages_id'] . '
		' . $order_by;