Zen Cart Logo
Forums / General Questions / my solution of dependent attributes & need help from you

my solution of dependent attributes & need help from you

Views: 592

Results 1 to 2 of 2
24 Nov 2012, 6:44 AM
#1
mybiz9999 avatar

mybiz9999

Zen Follower

Join Date:
Jul 2010
Posts:
143
Plugin Contributions:
0

my solution of dependent attributes & need help from you

Definition of dependent attributes

Example: A dress has two attributes, the color and size

Color: blue, red, purple

Size: S, M, L, XL

There are 12 option combinations including ‘Blue S’, ‘blue M,’…. ‘purple XL’ etc.
In reality, some combinations are not available, such as when the ‘purple XL’ is out of stock.

So there is a requirement like this, When the ‘purple’ is selected, the option of ‘XL’ becomes disabled. And When the ‘XL’ is selected, the option of ‘purple’ becomes disabled.

We call this ‘rule of dependent attribute’ or ‘rules’ as abbreviation below.

Below is an image to illustrate this requirement.

Attachment 11513

**
Features of rule of dependent attribute for apparel products
**
1: Each product has its own rule of dependent attributes, i.e, the rule of dependent attributes is product-specific.
2: The rule of dependent attributes is created in an ERP warehouse system. And the rule of dependent attributes changes on the daily basis.

**
Solutions to realize rule of dependent attributes in Zen cart**

Obviously Zen cart itself has no such function. There are two methods to realize it.

Solution 1: Add a new table to store the ‘rules’ and load the ‘rules’ when product is displayed.
This is very complicated, much programming work needed.

Solution 2: Use the javascript to realize the ‘rules’ ,and add the javascript to Product description field.
This is quite easy to do, an typical javascript is shown below.

Attachment 11512

New issue and my questions

But there is an efficiency issue for solution 2. As I have said ‘the rule of dependent attributes changes on the daily basis’, which results a daily update work on all products’ Description field where the javascript to realize ‘rules’ is stored. That would affect the online store very much.

I am thinking about using a new field rather than product Description field to store the javascript of ‘rules’, in that case, only this new field is frequently updated rather than the product Description field.

There are also two possible solutions when thinking using a new field to store javascript.

1: add a new field to Product_Description table.

Or

2: use a existing field in Product_Description table.
The only possible field is product_url field. First change it to Text type from VarChar type.

Therefore here are my questions
**

Which solution do you recommend? What are the advantages and disadvantages of them?

If add a new field to Product_Description table, how to acquire its value at tpl_product_display.php?

Is there a potential risk to add a new field to Product_Description?

Thank you so much in advance.

**

24 Nov 2012, 5:37 PM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: my solution of dependent attributes & need help from you

Repurposing an existing field will obviously disable it for its original use, so would not be a good general-purpose approach. It would work fine for a single store that will never use the particular field. I recommend creating a new field, as that will be suitable for all stores, and there are a lot that will want to use this feature if it is developed and released.

I think a field that holds an array of relationship values (pairs of attribute ids and the kind of dependency between them) rather than specific js code would be more maintainable. You would then put the script in a jscript_attributes.js file placed to load on product info pages, and grab whatever relationship parameters are present and apply them.

There is at least one mod in Plugins for creating new product fields and using them, which you could use as a guide for that part.