Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.67k stars 1.73k forks source link

methods: subtotal & total #113

Closed reppair closed 8 years ago

reppair commented 8 years ago

Hello, first I want to say sorry if that isn't really an issue with the package it self and the case is that I am just doing something wrong or it is expected behavior. However I couldn't find better place to ask about it! I have my Product model associated with the Cart and I am using it in laravel5 project. Having that said here is my issue with the cart.. having one product in the cart (or more) when I update the product's price it gets reflected in the Cart, however the total() and the subtotal() still return the old data. With other words updating an product's price changes the $row->product->price but not the total(). I guess that it fetches the product's price from the model but the total() isn't being updated. May be this has a reason behind it, or I am missing a step like updating the Cart instance?

Please help me to get this right! :) thanks! Best Regards! Martin.

reppair commented 8 years ago

Update: well yes, $row->product->price returns the updated price of the product, but the $row it self isn't being updated at all.. Shouldn't it be updated as soon as the product price changes? Guess that also depends on the project requirements but in my case I expect the cart to get updated asap after the product's price changes. How can I accomplish this? drop the row and add a new one with the updated product? for each session that has this product in it's cart?

Crinsane commented 8 years ago

Okay, so basically you're saying you'd expect the prices in the cart to update when you update the price of a model in your database? First I really wonder why you would want this? Imagine going into a store, putting a 10 dollar usb-cable in your basket, giving it to the cashier and her charging you 100 dollars because someone conveniently changed the price while you were walking to the counter. ;) Wouldn't be to happy about that.

But apart from that, the 'link' between the cart and model is just for convenience, to quickly get to the model data from a cart row. It's not a real link in the sense that the cart pulls data from your database on each request. If you want to update the price in the cart, you can use the update() method.

reppair commented 8 years ago

I get it :+1: