简体   繁体   中英

Shopping Cart Multiple atribute products

I've create a solid multiple product shopping cart some long time ago, and now i've decided to add multiple attributes to products (such as size, color...).

My database is something like this:

Products: id ...

attributes id name (color/size) value (blue/grey/XXL) ...

Product_attributes id atribute_id product_id

I've added the atribute inputs on single product page, in a such way (it's working)

if(the product has atributes on product_attributes table){
   while(there's product_attributes id){
        echo <select name=".$name.">
        while(there's atributes equal to product_attributes){
             echo <option value=".$id.">$value</option>
        }
        echo </select>
   }
}
<input type="number" name="qtd"> //quantity input
<input type="hidden" name="product_id" value="$product_id">
<input type="hidden" name="action" value="add">
<input submit>

And on the cart.php, i've the following script

if(isset($_POST['action']) && $_POST['action'] == 'add'){
    $product= $_POST['product_id'];
    $qty= $_POST['qtd'];

    if(!empty($_SESSION['cart'][$product])){
        $qty= $qty+ $_SESSION['cart'][$product];

    }
    $_SESSION['cart'][$product] = $qty;
    header('location: cart');
}

how can i adapt this script to the new atribute input i have, knowing that: not all products has atributes; the product can have one or infinite atributes; saving the product in different arrays due to qty of them and depending of his atributes (ex: Prod: 1, color: blue, Size: L Qty: 2 | Prod: 1, Color: Black, Size: l, Qty: 1)

Could anyone help me with this dilema? I love your kindness ;)

I give you only the idea create two tables :

one for attribute's type

attribute

id-name-value

1-size-42

2-taglia-xxl

then a table with the associations with the properties and the products

associations

id-product-attribute

autoincrement-1(for example id 1 product 1)- 2(attribute)

the product with that id has taglia xxl and if add any row will has other attributes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM