mysql - Adding product attributes -
while listing product in catalog every product has few general attributes mrp, price, sku, product description etc etc, applicable all.
but there few attributes product specific, example, t-shirts can have color , size, laptops have memory, resolution, processor speed, mobile phones can have memory, camera resolution, , operating system.
each of above attributes in example product specific , important.
taking cue out of opencart ecommerce, believe, replicated database few changes (to suit needs) , here is.
products

the idea record product information/attribute (which applicable described in first paragraph) product table in product table.

attributes

then comes attributes table store attributename eg, resolution, memory, color, size, processor speed etc etc

product_attribute

this table save productid of product table, attributeid of attributes table , value of attribute attributevalue eg . resolution = 15000pixels(attributevalue), memory = 500gb (attributevalue), color = blue (attributevalue).

up till have 3 tables records need displayed on product detail page this

opencart, if not mistaken, uses left join statement combine product, attribute , product_attribute display product on product detail pages , need do.
how use left join statement display product, attribute , product_attribute display products , attributes? please note there can few products needs no attribute.
unfortunately, going full recursion left join 1 of things sql not at. in fact, i'm pretty sure impossible, @ least in standard sql.
a decent alternative use simple inheritance having main "products table" base class, , extending other different tables types (such "cell phone" or "t-shirt"). extension, in case, can performed having different new tables , have of them have foreign key products table.
then if don't have way distinguish type of product in product table, add "kind" or "type" attribute , in application perform left join based on attribute, needed.
Comments
Post a Comment