hardevine / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
348 stars 120 forks source link

Specify taxrate in Cart::Add() #42

Closed sam-hsbu closed 2 years ago

sam-hsbu commented 3 years ago

Hello every one.

I would like to specify a taxrate in Cart::Add() like that :

Cart::add([
            'id' => $product->id, 
            'name' => $product->nom_produit, 
            'qty' => $request->qty, 
            'price' => $prix, 
            'taxrate' => 50
        ])

but it doesn't work.

I know we can specify the tax in the "config/cart.php" file but in this case I would like to specify directly in the Cart::Add().

I hope you can understand my request.

Thanks.

Regards.

sergomet commented 3 years ago

@sam-hsbu https://github.com/hardevine/LaravelShoppingcart#cartadd

sam-hsbu commented 3 years ago

@sergomet that's what I tried of course but it doesn't work :

You can optional pass different taxrates to the items.

Cart::add('293ad', 'Product 1', 1, 9.99, ['size' => 'large'], 20);

Shaka-60hp commented 2 years ago

Yes it doesnt work

Shaka-60hp commented 2 years ago

@sam-hsbu I solved it:

on /vendor/hardevine/shoppincart/src/Cart.php after line 485 I added this line:

$cartItem->setTaxRate($id['taxrate']);

hope it helps

nabeelyousafzai commented 2 years ago

i am new in laravel i use shopping cart package how to use this package i dont understand about the quick usage condition

timo75 commented 1 year ago

Why has this been closed? It's still not possible to submit the taxrate within an array in Cart:add($array);

srcKod commented 1 week ago

this should be fixed by modifying createCartItem method

on /vendor/hardevine/shoppincart/src/Cart.php line 470, 471

  $cartItem = CartItem::fromBuyable($id, $options ?: []); //previous $qty
  $cartItem->setQuantity($qty ?: 1); // previous $name

and the call should be like this to match add method signature in Cart.php

  Cart::add($product, null, $qty, null, $options, $taxrate);