Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/Darryldecode/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,17 +788,17 @@ 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.
if (($item[$key] - $value) > 0) {
$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;
Expand All @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Darryldecode/Cart/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

'thousands_sep' => env('SHOPPING_THOUSANDS_SEP', ','),

'dec_quantity' => env('SHOPPING_ALLOW_DECIMAL_QUANTITY', false),

/*
* ---------------------------------------------------------------
* persistence
Expand All @@ -33,4 +35,4 @@
* the configuration for cart events
*/
'events' => null,
];
];