简体   繁体   English

Codeigniter购物车类-产品选项的额外价格

[英]Codeigniter Cart Class - additional price for product options

Is it possible to add price values to product options in the Codeigniter Cart Class. 是否可以在Codeigniter购物车类的产品选项中添加价格值。 For example: T-shirt price is $10.00, but the XXL size is an extra $2.00. 例如:T恤价格为$ 10.00,但XXL尺寸额外为$ 2.00。

$data = array(
           'id'      => 'abc',
           'qty'     => 1,
           'price'   => 10.00,
           'name'    => 'T-Shirt',
           'options' => array('Size' => 'XXL') // Where would you add $2.00 for XXL?
        );

$this->cart->insert($data);

From looking at the cart class, it looks like the only way to do what you're asking is to incorporate the options price into the price that is passed to CodeIgniter's cart class. 从查看购物车类看,似乎您要执行的唯一方法是将期权价格纳入传递给CodeIgniter的购物车类的价格中。 So you'd pass the array you provided in your example, with $data['price'] set to 12.00 (10.00 plus the 2.00 for XXL) 因此,您将传递示例中提供的数组,并将$ data ['price']设置为12.00(10.00加上XXL的2.00)

My understanding of CI's cart class is that it's only there to provide the basic session handling information for a shopping cart. 我对CI的购物车类的理解是,它仅用于提供购物车的基本会话处理信息。 Things like product options with their own pricing would need to be built on top of it in your own code. 产品定价等具有自己定价的事物需要在您自己的代码的基础上构建。

Yep, you should "merge" the product with the option price and put the package with the total, new price into your cart. 是的,您应该将产品与选择的价格“合并”起来,然后将包含新价格的包装放入购物车。 That's probably the only way that I can come up with if you want to be able to use CI:s prebuilt features of cart total etc. 如果您希望能够使用CI:s cart total等的预构建功能,那可能是我提出的唯一方法。

That's one of the reasons why we built our own cart and order management system apart from CI's original one. 这就是为什么我们建立自己的购物车和订单管理系统而不是CI最初的原因之一。

The better way imho is to extend or rebuild CI's cart Class in order to inject product and options straight from db results. imho更好的方法是扩展或重建CI的cart类,以便直接从数据库结果中注入产品和选项。 This way you can always track down how the price was calculated : from ericofsac's answer, why it is priced at 12 not 10 and how much the option was charged at sale's time. 这样,您始终可以跟踪价格的计算方法:从ericofsac的答案,为什么定价为12而不是10,以及在出售时收取了多少期权费。

You can also ease implementation of recording interfaces from your cart data to your order, but that's another point. 您还可以简化从购物车数据到订单的记录界面的实现,但这是另一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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