bumbummen99 / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
501 stars 228 forks source link

Zero count #198

Closed foRsxs closed 1 year ago

foRsxs commented 1 year ago

Hi, why set quantity can't set 0 ? For example we have products which can be sell with pieces, but counting with box (like pharmacy products) So sometimes main qty is zero but in options we have pieces.

Have any chance to apply this if I send PR?

` public function setQuantity($qty) { if (!isset($qty) || !is_numeric($qty)) { throw new \InvalidArgumentException("Please supply a valid quantity."); }

    $this->qty = $qty;
}`
anayarojo commented 1 year ago

Hi @foRsxs,

We shouldn't set qty to 0 because of this affects other values including priceTotal, discountTotal, total, etc.

Please take a look at calculator class https://github.com/bumbummen99/LaravelShoppingcart/blob/master/src/Calculation/DefaultCalculator.php#L24

foRsxs commented 1 year ago

Hi @foRsxs,

We shouldn't set qty to 0 because of this affects other values including priceTotal, discountTotal, total, etc.

Please take a look at calculator class https://github.com/bumbummen99/LaravelShoppingcart/blob/master/src/Calculation/DefaultCalculator.php#L24

Everything working good in Calculator, except priceTarget (divisionByZero) In PR I can add fix in calculator for check empty qty for priceTarget case 'priceTarget': return !empty($cartItem->qty) ? round(($cartItem->priceTotal - $cartItem->discountTotal) / $cartItem->qty, $decimals) : 0;

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days