问题
If you have a seller accounts at amazon or ever happened to look at their product upload form, I am sure you must have noticed that for each product type you wish to upload they have a slightly different form.
If you want to sell Table Fans, you are presented with this form
and in case you wish to sell shirts, this is what is presented you.
both forms are different yet do the same thing, i.e. upload products (which has some common and few specific attributes)
What intrigues me about this design is the thought that the end user, a layman, wouldn't be expected to understand jargon like product attributes or its use. You give him a product specific upload form and he will fill it up as necessary.
Looking at a few other carts, take for instance opencart
opencart has one form for all product types and if you need to add a few extra attributes it lays the onus on you (the end user) to first understand what attributes are then work as needed.
(this is opencart's add attributes as needed)
I like the way amazon (and a few other ecommerce site, I believe ebay too does as amazon) worked this up.
I wish to replicate this for my project but honestly speaking I have never seen this before. I do not even understand what do you call this. I tried searching google for "form based on product type" and could not find anything to help me.
Can you please let me know how amazon or ebay do this.
回答1:
There are many different ways of implementing this. In general, you probably won't be able to do something this complicated with HTML and Javascript alone, you'll need a database and some sort of scripting language like PHP or Ruby on your server to dynamically generate the pages.
It's not clear to me what languages you'd want to use, so I'll give a general description:
On the back-end, in a database I'd create a table for the general product. This table would have a field for product type. Then I would create additional tables for the specific product types, and have these tables store all the additional fields, and the primary key referencing the entry in the main, general product table. I would then create a table for product type, which has the product ID's used in the field in the general product table, and a second field referencing the name of the table in the database that stores this type of product.
The code that is all in common between all types of products, I would have reference the general product table. I would then allow the user to specify the product type, and when this is clicked, send the user to a new page, which would run a script. The script would query the database to retrieve the table name for that data type, and then query the database for a description of additional fields specific to that data type, and display an appropriate form, dynamically generated based on what the database returns.
来源:https://stackoverflow.com/questions/44739567/form-based-on-product-types