Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Attributes dependent on 1st choice?

Attributes dependent on 1st choice?

Locked

Views: 7,138

Results 1 to 20 of 23
This thread is locked. New replies are disabled.
21 Jan 2010, 8:14 AM
#1
graphic_content avatar

graphic_content

New Zenner

Join Date:
Nov 2008
Location:
Gex, France
Posts:
71
Plugin Contributions:
0

Attributes dependent on 1st choice?

Hi there,

I am currently building a site for a client who requires the attributes to display dependent on the first choice so for example if the customer selects tyre speed rating H then only the wheel sizes, tyres sizes etc display that are available for that speed rating.

I looked at dowloading 'improved Attributes' but once un zipped it only contains 1 file that allows you to make multiple choice for attributes but does not seem to offer the dependent choices that it states in it's description??

If someone can please help me out that would be great.

Thanks
Matt
https://www.graphiccontent.co.uk

21 Jan 2010, 8:26 AM
#2
misty avatar

misty

Inactive

Join Date:
Apr 2004
Location:
UK
Posts:
5,752
Plugin Contributions:
1

Re: Attributes dependent on 1st choice?

As far as an aware, currently zencart does not support dependant attributes.

21 Jan 2010, 8:37 AM
#3
graphic_content avatar

graphic_content

New Zenner

Join Date:
Nov 2008
Location:
Gex, France
Posts:
71
Plugin Contributions:
0

Re: Attributes dependent on 1st choice?

Hi Misty,

ahhh I just read the description of the 'Improved Attributes Controller' again and realised that in my excitment I read it wrong the first time haha! it refers only to the admin pages and not the store.

Damn that's a shame. If someone could write one that would be so useful. I had to build a site using Magento for someone last month and although I prefer using Zen Cart the filtered navigation on Magento is pretty damn good, it would be so useful if Zen Cart had this option.

If I was a PHP expert I'd have ago at it.

Misty can you think of anyway around this?

Thanks
Matt

21 Jan 2010, 8:42 AM
#4
misty avatar

misty

Inactive

Join Date:
Apr 2004
Location:
UK
Posts:
5,752
Plugin Contributions:
1

Re: Attributes dependent on 1st choice?

Misty can you think of anyway around this?
Post in Commercial Forum Section for zencart coder
to create what you require...

21 Jan 2010, 9:03 AM
#5
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Attributes dependent on 1st choice?

As far as I am aware, this is extremely difficult to achieve in the current structure of zencart - I have also inquired about this on several occasions.

There is some light at the end of the tunnel - while dependant attributes will not be an inherent feature in the new version (2.0), the architecture will more easily permit the development of a module that would support dependant attributes.

26 Jan 2010, 12:29 AM
#6
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: Attributes dependent on 1st choice?

It is possible to do using jQuery, and not that tough if you are familiar with that code. BUT it's not very flexible, kind of a workaround.

You would need to be sure you don't plan on changing products, attributes, or options too often. When your client wants to add options, you'll need to change the code.

3 Feb 2010, 5:52 PM
#7
snarlecp avatar

snarlecp

New Zenner

Join Date:
Feb 2010
Posts:
1
Plugin Contributions:
0

Re: Attributes dependent on 1st choice?

Hey Everyone,

I'm new to the forum. I am not an experienced Zen Cart Developer but I have been using it quite extensively as of late. I am using version 1.3.8p3, so currently up to date.

I currently have a client who has approximately 20 products but each product has both a size attribute, and a material attribute. Problem is that his pricing scheme is not stepped in any way (for example size +20 and material x +35 to the base price) that I can currently do this in an unmodified Zen Cart install.

After some playing with his pricing schema and Zen Cart's attributes I have set it up in such a way that it will work but it creates a small issue.

So currently I have placed all possible attributes into the system. and since I can't currently do dependent attributes I have setup each dropdown to correspond to a size and each dropdown to populate with materials priced for that size. See the image if my description doesn't make sense.

The problem with this method is a customer could select one from each attribute (dropdown), and it would charge them as if they ordered a number of separate products. Since each dropdown is in effect the product just a different size.

So my question to the forum is, How can I setup a simple work around that I can have one dropdown for size and it will then display the correct dropdown, I have setup already, for the products material. This would solve my problem and I think would defienetly look nicer than having 3 or more dropdowns for one product.

I browsed the forum for some time and found a lot of threads stating that it wasn't possible and so forth. But I found a response from jackie.taferner on this thread.

It is possible to do using jQuery, and not that tough if you are familiar with that code. BUT it's not very flexible, kind of a workaround.

You would need to be sure you don't plan on changing products, attributes, or options too often. When your client wants to add options, you'll need to change the code.

So how could I use jquery to do this, or javascript or even php, to do this. Where are the files that handle attributes, and how does the code for pulling and displaying attributes work? Also how does the attribute information get sent to the cart? and could I prevent the attributes that weren't selected from being sent to checkout.

Any help would be much appreciated.

5 Feb 2010, 12:36 AM
#8
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: Attributes dependent on 1st choice?

snarlecp,

Yes, this is possible using jquery. I must say first, that i cannot guarantee this will work. This is quite the workaround and will make your attributes/options NOT FLEXIBLE. When you want to change attributes, you'll have to do it in this code too.

And setting this up in the first place could be a LOT of work, depending on how many attributes you want to show/hide. Also, BACKUP BACKUP BACKUP!!! Dont do this on a live site. Work thru the code, make sure it works first before you implement it on a live site. That said, here we go! :smile:

The file that controls the display of the product page is includes/templates/TEMPLATENAME/templates/tpl_product_info_display.php

Find that file and put this code down at the bottom after everything else:

<script type="text/javascript">
function updateCustomPanel()
		{
		jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('HIDDEN_ATTRIBUTE_1'))").hide();
		jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('HIDDEN_ATTRIBUTE_2'))").hide();
		jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('HIDDEN_ATTRIBUTE_3'))").hide();
		jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('HIDDEN_ATTRIBUTE_4'))").hide();
		
		if (jQuery("option:contains('MAIN_SELECTION')").attr('selected')) {
			jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('HIDDEN_ATTRIBUTE_SHOWME'))").show();
			}
		if (jQuery("option:contains('MAIN_SELECTION')").attr('selected')) {
			jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('HIDDEN_ATTRIBUTE_SHOWME'))").show();
			}
		if (jQuery("option:contains('MAIN_SELECTION')").attr('selected')) {
			jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('HIDDEN_ATTRIBUTE_SHOWME'))").show();
			}
		if (jQuery("option:contains('MAIN_SELECTION')").attr('selected')) {
			jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('HIDDEN_ATTRIBUTE_SHOWME'))").show();
			}			
			else{}
		}
		jQuery("select:has(option:contains('Custom Size'))").change(updateCustomPanel);	
		jQuery(document).ready(updateCustomPanel);						
</script>

Now, first declare every attribute you would want to show/hide up in the first lines. To do this, replace HIDDEN_ATTRIBUTE_1, HIDDEN_ATTRIBUTE_2, etc. with the EXACT names of all the attribute NAMES you will want to hide & show. (of course, you need to setup these attributes in your admin first)

For example, you may want to hide "Pick A Material" and "Pick A Color" like so:

jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Pick A Material'))").hide();
jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Pick A Color'))").hide();

Now, you want to name the options and which attributes go with them. MAIN_SELECTION is where you would place the EXACT name of the attribute OPTION you want tied to the action of hiding & showing. HIDDEN_ATTRIBUTE_SHOWME is where you'll put the EXACT name of the attribute NAME you want to appear.

For example, you may have a main dropdown for size. When the customer selects "Medium" or "Small" you would want "Pick A Material" or "Pick A Color" to appear. You would put that in the code like so:

if (jQuery("option:contains('Medium')").attr('selected')) {
	jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Pick A Material'))").show();
	}
if (jQuery("option:contains('Small')").attr('selected')) {
	jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Pick A Color'))").show();
	}

Copy and paste additional lines of code as needed, until you've declared all of your attributes and the options to be hidden.

Now, keep in mind since this is all name-based, you'll need to have unique names for your attributes. So you can't have a "Pick A Material" for both "Small" and "Medium". Maybe you can name them "Pick A Material S" or "Pick A Material M". That's also why this is NOT flexible. If you want to change the names of any of your attributes or options, you'll need to get into this code and change it here too.

Maybe someday I'll work this into a mod and put it in the downloads section. Perhaps at that point I'll figure a way to tie it into the admin as well :blink:

But till then, hope this helps you out!

5 Feb 2010, 12:39 AM
#9
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: Attributes dependent on 1st choice?

If you're still looking for a way to do this, I've posted some code in this thread that should help you out:

http://www.zen-cart.com/forum/showthread.php?p=838839#post838839

Good luck :)

14 Jun 2010, 1:29 AM
#10
martin_75 avatar

martin_75

New Zenner

Join Date:
Jun 2010
Posts:
2
Plugin Contributions:
0

Re: Attributes dependent on 1st choice?

Has anyone managed to get the above code to work?

If so, or you know what may be wrong with the code, any help will be appreciated. I know it's just as likely and perhaps even more so that I am doing something wrong so I will try to explain as best I can.

My product page has 6 attributes, but unless the customer selects yes on attribute 4, I want the above code to help me hide attributes 5 & 6, attribute 4 has two options, Yes & No and attributes 5 & 6 have 10 options each.

Here is my code that I have based on the code above.

<script type="text/javascript">
function updateCustomPanel()
		{
		jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Game 2'))").hide();
		jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Game 3'))").hide();
		
		if (jQuery("option:contains('Yes')").attr('selected')) {
			jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Game 2'))").show();
			}
		if (jQuery("option:contains('Yes')").attr('selected')) {
			jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Game 3'))").show();
			}		
			else{}
		}
		jQuery("select:has(option:contains('Make it a bundle'))").change(updateCustomPanel);	
		jQuery(document).ready(updateCustomPanel);						
</script>

Unfortunately I don't have a live link to post yet.

Thank you in advance for any help given.

7 Jul 2010, 8:45 PM
#11
skinnyalbert avatar

skinnyalbert

New Zenner

Join Date:
Sep 2007
Posts:
30
Plugin Contributions:
0

Re: Attributes dependent on 1st choice?

Hi all,

I'm running into troubles with this as well. It doesn't seem that changing the main selector is launching the function. I have a simple situation where I'll want the same options on all pages dependent on a selection of Mens or Womens. I'm wondering if anyone has either gotten this specific code set up, or show / hide a specific attribute ID.

I have an idea I'm testing out as well, but will be digging into the files more than I'd like. If no response to this, I'll post my solution, if it works :)

7 Jul 2010, 8:50 PM
#12
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: Attributes dependent on 1st choice?

skinny albert,

why not create two sections of the website - one for men's stuff and one for women's? Seems pretty common in the clothing industry anyhow...

26 Jul 2010, 5:13 PM
#13
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: Attributes dependent on 1st choice?

Martin 75, sorry I missed your post earlier. A link to the page would be very helpful, but I'll do my best to troubleshoot without it. If I'm too late to help you out, hopefully this helps others.

You've got a "Yes" selection in two different "if" statements, should be combined. Also, option:contains should match in both places in the code. So calling "Yes" at top and "Make it a bundle" at the bottom is incorrect. (I think it's my mistake for not being clear in my earlier post)

I suggest to setup an attribute "Make it a Bundle?" and the options:
Yes please
No thanks

Make sure your other attributes do not have the same option name "Yes please" (it has to be unique to that attribute, or the code can't tell the difference).

With those changes, see if this code works:

<script type="text/javascript">
function updateCustomPanel()
		{
		jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Game 2'))").hide();
		jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Game 3'))").hide();
		
		if (jQuery("option:contains('Yes please')").attr('selected')) {
			jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Game 2'))").show();
			jQuery("div.wrapperAttribsOptions:has(label.attribsInput:contains('Game 3'))").show();
			}		
			else{}
		}
		jQuery("select:has(option:contains('Yes please'))").change(updateCustomPanel);	
		jQuery(document).ready(updateCustomPanel);						
</script>
26 Oct 2010, 9:34 PM
#14
ogrelink avatar

ogrelink

New Zenner

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

Re: Attributes dependent on 1st choice?

Hi Jackie,

Do you know how to make the attribute that is hidden to not appearing in the checkout page and the receipt after the purchase?

I have two main attributes that user can select. The second attribute is actually three attributes with same name and I just hide or show each one when user select the first attribute.

The structure is as follow

Type1AttributeSelect
|_ Size1 - price 1.0
|_ Size2 - price 2.0
|_ Size3 - price 3.0

Type2AttributeSelect
|_ Size1 - price 1.1
|_ Size2 - price 2.1
|_ Size3 - price 3.1

Type3AttributeSelect
|_ Size1 - price 1.2
|_ Size2 - price 2.2
|_ Size3 - price 3.2

It works well in the product page and shopping cart page because I can remove them using javascript. However, I don't have any clue as how to remove the other Sizes in the receipt sent to the customer's email. Any ideas?

Thanks

27 Oct 2010, 12:05 AM
#15
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: Attributes dependent on 1st choice?

Hmmm, that's a tough one. I honestly can't say how you could hide some and not others.

Like you said, in the browser javascript works great. But on email notifications and invoices it would be much trickier.

I'd say perhaps to play with the wording on the existing attributes, to try and make it read better on the invoice.

Or perhaps there's a way to have it display only the attribute value, but not the name.

I wish I could be better help!

28 Oct 2010, 4:54 PM
#16
ogrelink avatar

ogrelink

New Zenner

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

Re: Attributes dependent on 1st choice?

Fix it! :) just adding simple if statement in the order.php to not list the attribute if the value selected is not what user select.

I actually set a unique hidden value for each sizes and hide them by using the hidden value. I used the hidden value in the if statement to remove them from the order email.

Btw, there is another problem and I wonder if you know the workaround for it. I am trying the jQuery you mentioned in the post to hide a value inside a dropdown (my hidden value) and it works well for firefox. However when I open it in Google Chrome, the hidden value is not hidden! Do you see the same problem in Chrome with your code and happen to have a fix for it? :)

Thanks

28 Oct 2010, 5:02 PM
#17
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: Attributes dependent on 1st choice?

Really well that's fantastic!

Would you mind emailing me the files you changed? I plan to build this into a plugin and it would be a great feature to be able to show/hide on email and invoice.

If you provide a link to your site I can have a look in Chrome. My first thought is that if the same Jquery works in chrome for the attributes, then it should work on the dropdowns too.

Perhaps check the variables and make sure they're pointing to the correct objects (it gets complicated the further they're nested)

28 Oct 2010, 5:25 PM
#18
ogrelink avatar

ogrelink

New Zenner

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

Re: Attributes dependent on 1st choice?

Basically what I want to hide is th <option> inside <select> tag.

Here is the link of the site btw

http://sumaqrugs.com/index.php?main_page=product_info&cPath=1&products_id=48

and you can see that the "Select Value" is hidden in FireFox but not GChrome.
Sure, I can send you the edited file. It's hard-coded though so might not be some help for your plugin. I don't have access to the file at the moment though. I'll get it to you later.

Thanks

28 Oct 2010, 5:40 PM
#19
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: Attributes dependent on 1st choice?

Nice site, looks good!

Pardon me for asking, but what's the reason for hiding the Select Value option? It seems to me that it's not planned to appear for any reason (as 3x5 is the default). You could remove it from the options in Zen Cart admin.

And your hard-coded file will help - in fact, my plugin is mostly going to be hard-coded anyhow.

28 Oct 2010, 5:51 PM
#20
ogrelink avatar

ogrelink

New Zenner

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

Re: Attributes dependent on 1st choice?

It's because I need to use the same attribute name "Product Size" for all three attributes. If you have a slow internet connection, you should notice that there are actually three "Product Size" attributes :smile:. I hide each one based on the product Type that user select. Reason being is that each type will have different price for different size and I don't know a better way to implement it since zencart does not support dependent pricing :dontgetit.

So, I need a unique identifier to hide the attributes and that unique value happen to be "Select Value" (notice the dots next to it :P) which appear to be a problem for Google Chrome :(

Thanks for the compliment on the site btw :)