php - 如何在 laravel moltin 购物车中添加多个具有不同尺寸的相同 ID 的产品?

标签 php mysql laravel laravel-4 moltin

我正在尝试使用 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购物车包裹,但看着 code看起来它使用 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'
    )
));

关于php - 如何在 laravel moltin 购物车中添加多个具有不同尺寸的相同 ID 的产品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27879255/

相关文章:

php - 跨表的唯一标识符

laravel - Vagrant 失败与Laravel : 'The SSH command responded with a non-zero exit status'

php - 无法从 laravel 中的 session 获取 $id

PHP 解析错误 : syntax error, 意外 T_OBJECT_OPERATOR

PHP:从路径中获取最后一个目录名称

php - Phalcon - 语法错误,意外标记 AS,接近 ' a,UNSIGNED ) AS intHours

mysql - RoleProvider .NET 2 - 从 MS Access 转换为 MySQL

laravel - 流明本地化

php - 可选的正则表达式模式不产生任何值

php - 在另一个文件中携带 $id 变量