diff --git a/src/Darryldecode/Cart/Cart.php b/src/Darryldecode/Cart/Cart.php index b582dca..781f361 100644 --- a/src/Darryldecode/Cart/Cart.php +++ b/src/Darryldecode/Cart/Cart.php @@ -788,7 +788,7 @@ protected function itemHasConditions($item) protected function updateQuantityRelative($item, $key, $value) { if (preg_match('/\-/', $value) == 1) { - $value = (int)str_replace('-', '', $value); + $value = ($this->config['dec_quantity']) ? (float)str_replace('-', '', $value) : (int)str_replace('-', '', $value); // we will not allowed to reduced quantity to 0, so if the given value // would result to item quantity of 0, we will not do it. @@ -796,9 +796,9 @@ protected function updateQuantityRelative($item, $key, $value) $item[$key] -= $value; } } elseif (preg_match('/\+/', $value) == 1) { - $item[$key] += (int)str_replace('+', '', $value); + $item[$key] += ($this->config['dec_quantity']) ? (float)str_replace('+', '', $value) : (int)str_replace('+', '', $value); } else { - $item[$key] += (int)$value; + $item[$key] += ($this->config['dec_quantity']) ? (float)$value : (int)$value; } return $item; @@ -814,8 +814,7 @@ protected function updateQuantityRelative($item, $key, $value) */ protected function updateQuantityNotRelative($item, $key, $value) { - $item[$key] = (int)$value; - + $item[$key] = ($this->config['dec_quantity']) ? (float)$value : (int)$value; return $item; } diff --git a/src/Darryldecode/Cart/config/config.php b/src/Darryldecode/Cart/config/config.php index 985b250..8d93671 100644 --- a/src/Darryldecode/Cart/config/config.php +++ b/src/Darryldecode/Cart/config/config.php @@ -16,6 +16,8 @@ 'thousands_sep' => env('SHOPPING_THOUSANDS_SEP', ','), + 'dec_quantity' => env('SHOPPING_ALLOW_DECIMAL_QUANTITY', false), + /* * --------------------------------------------------------------- * persistence @@ -33,4 +35,4 @@ * the configuration for cart events */ 'events' => null, -]; \ No newline at end of file +];