簡體   English   中英

如何在laravel moltin購物車中添加多個同一個ID且具有不同尺寸的商品?

[英]How to Add more than one products of same id with different sizes in laravel moltin cart?

我正在嘗試使用Moltin購物車添加不止一種具有相同ID但尺寸不同的產品。 這里的問題是,如果我試圖將不同尺寸的同一產品添加到購物車中,它只會增加數量而不是附加數量。 我用谷歌搜索了一個解決方案,但是我發現發生這種情況是因為將相同的ID傳遞給Cart::insert()方法。

購物車插入方法是:

Cart::insert(array(
    'id' => $product->id,
    'name' => $product->title,
    'price' => $product->price,
    'dimension'=>null,
    'unit'=>$product->unit,
    'quantity' => $quantity,
    'image' => $product->image,
    'tax' =>$product->taxvalue,
    'taxtype'=>$product->tax,
    'pincode' =>$pincode,
    'shippingfee'=>Session::get('shippingfee'),
    'retailerId' =>$retailerIdfromProductId
));  

如果尺寸不為空,我想附加一個新產品。 我該怎么做呢?

我從未使用過Moltin購物車包,但是看它看起來像是使用id字段和options數組字段的組合來構建商品標識符的代碼 因此,如果id相同,但options不同,則應在購物車中插入兩個不同的項目。

你能做這樣的事情:

// first item with no dimension
Cart::insert(array(
    'id' => $product->id,
    'name' => $product->title,
    'price' => $product->price,
    'unit' => $product->unit,
    'quantity' => $quantity,
    'image' => $product->image,
    'tax' => $product->taxvalue,
    'taxtype' => $product->tax,
    'pincode' => $pincode,
    'shippingfee' => Session::get('shippingfee'),
    'retailerId' => $retailerIdfromProductId,
    'options' => array(
        'dimension' => null
    )
));

// second item with 'M' dimension
Cart::insert(array(
    'id' => $product->id,
    'name' => $product->title,
    'price' => $product->price,
    'unit' => $product->unit,
    'quantity' => $quantity,
    'image' => $product->image,
    'tax' => $product->taxvalue,
    'taxtype' => $product->tax,
    'pincode' => $pincode,
    'shippingfee' => Session::get('shippingfee'),
    'retailerId' => $retailerIdfromProductId,
    'options' => array(
        'dimension' => 'M'
    )
));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM