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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "darryldecode/cart",
"name": "karamelichkin/cart",
"description": "Laravel 5 Shopping cart",
"keywords": ["laravel", "shopping cart", "cart"],
"license": "MIT",
Expand Down
10 changes: 6 additions & 4 deletions src/Darryldecode/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,12 @@ public function getSubTotal($formatted = true)
});

// if there is no conditions, lets just return the sum
if (!$conditions->count()) return Helpers::formatValue(floatval($sum), $formatted, $this->config);
if (!$conditions->count()){
return Helpers::formatValue(Helpers::floatOrInt($sum), $formatted, $this->config);
}

// there are conditions, lets apply it
$newTotal = 0.00;
$newTotal = Helpers::floatOrInt(0.00);
$process = 0;

$conditions->each(function (CartCondition $cond) use ($sum, &$newTotal, &$process) {
Expand All @@ -608,7 +610,7 @@ public function getSubTotal($formatted = true)
$process++;
});

return Helpers::formatValue(floatval($newTotal), $formatted, $this->config);
return Helpers::formatValue(Helpers::floatOrInt($newTotal), $formatted, $this->config);
}

/**
Expand All @@ -620,7 +622,7 @@ public function getTotal()
{
$subTotal = $this->getSubTotal(false);

$newTotal = 0.00;
$newTotal = Helpers::floatOrInt(0.00);

$process = 0;

Expand Down
16 changes: 15 additions & 1 deletion src/Darryldecode/Cart/Helpers/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

class Helpers {


public static function floatOrInt($value)
{
if (config('shopping_cart.prices_in_int')) {
return intval($value);
} else {
return floatval($value);
}
}


/**
* normalize price
*
Expand All @@ -17,7 +28,10 @@ class Helpers {
*/
public static function normalizePrice($price)
{
return (is_string($price)) ? floatval($price) : $price;
if(config('shopping_cart.prices_in_int'))
{
return $price;
} else { return (is_string($price)) ? floatval($price) : $price; }
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Darryldecode/Cart/config/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [
'prices_in_int' => env('SHOPPING_PRICES_IN_INT', false),
/*
* ---------------------------------------------------------------
* formatting
Expand Down