LaravelShoppingcart icon indicating copy to clipboard operation
LaravelShoppingcart copied to clipboard

change item quantity with priced addon

Open Malebestia opened this issue 3 years ago • 0 comments

if, in the cart, I change the quantity of an item that has an addon, the single price is not updated correctly because the price of the addon is not considered in the calculation. Have you already thought about it?

I suggest these changes: in CartiItem.php:

`public function __get($attribute) {
    //......
    if ('totalPriceAddons' == $attribute) {
        if (! $this->options->has('addons')) {
            return 0;
        }
    //.....
    if ('total' === $attribute) {
        return $this->qty * ($this->priceTax + $this->totalPriceAddons);
    }
}`

in Cart.php:

`public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null) {
    $content = $this->getContent();
    $total = $content->reduce(function ($total, CartItem $cartItem) {
        //return $total + ($cartItem->qty * $cartItem->priceTax);
        return $total + ($cartItem->total);
    }, 0);
    return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
}`

Malebestia avatar Nov 30 '21 11:11 Malebestia