phpcart icon indicating copy to clipboard operation
phpcart copied to clipboard

Missing method

Open projct1 opened this issue 9 years ago • 5 comments

I have to calculate total sum for each item $item->quantity * $item->price...

projct1 avatar Sep 02 '15 18:09 projct1

I agree on this one, it would be an easy method to create and would simplify the templates a lot.

fhusquinet avatar Feb 10 '16 17:02 fhusquinet

@fhusquinet, @rorc is this a good approach to add the total in each item. For example:

use Anam\Phpcart\Cart;

$cart = new Cart();

$cart->add([
    'id'       => 1001,
    'name'     => 'Skinny Jeans',
    'quantity' => 2,
    'price'    => 90
]);

$cart->get(1001);
// This will return item with total
[
   'id'       => 1001,
    'name'     => 'Skinny Jeans',
    'quantity' => 2,
    'price'    => 90,
    'total' => 180
]

anam-hossain avatar Feb 13 '16 09:02 anam-hossain

@anam-hossain If the total is updated at the same time the quantity is then that sure would be a great approach.

fhusquinet avatar Feb 13 '16 09:02 fhusquinet

@fhusquinet Total will be updated during adding and updating an item.

Do you think this will conflict with user content? i mean they can not add total to their own.

anam-hossain avatar Feb 13 '16 10:02 anam-hossain

@anam-hossain I hadn't considered that... A simple $item->getTotal() since the user currently sets every value of an item himself. Although I wouldn't mind it myself, this might indeed throw of some users.

fhusquinet avatar Feb 13 '16 10:02 fhusquinet