Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature and fix #187

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "darryldecode/cart",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should don't do this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry

"name": "jrmessias/cart",
"description": "Laravel 5 Shopping cart",
"keywords": ["laravel", "shopping cart", "cart"],
"license": "MIT",
"authors": [
{
"name": "Darryl Fernandez",
"email": "[email protected]"
},
{
"name": "Junior Messias",
"email": "[email protected]"
}
],
"require": {
Expand Down
14 changes: 13 additions & 1 deletion src/Darryldecode/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public function getSubTotalWithoutConditions($formatted = true)
$cart = $this->getContent();

$sum = $cart->sum(function ($item) {
return $item->getPriceSum();
return $item->getPriceSum(false);
});

return Helpers::formatValue(floatval($sum), $formatted, $this->config);
Expand Down Expand Up @@ -647,6 +647,18 @@ public function getTotalQuantity()
return $count;
}

/**
* get total quantity of items individual in the cart
*
* @return int
*/
public function getTotalQuantityIndividual()
{
$items = $this->getContent();

return $items->count();
}

/**
* get the cart
*
Expand Down
33 changes: 31 additions & 2 deletions src/Darryldecode/Cart/ItemCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function __construct($items, $config)
*
* @return mixed|null
*/
public function getPriceSum()
public function getPriceSum($formatted = true)
{
return Helpers::formatValue($this->price * $this->quantity, $this->config['format_numbers'], $this->config);
return Helpers::formatValue($this->price * $this->quantity, $formatted, $this->config);

}

Expand Down Expand Up @@ -118,4 +118,33 @@ public function getPriceSumWithConditions($formatted = true)
{
return Helpers::formatValue($this->getPriceWithConditions(false) * $this->quantity, $formatted, $this->config);
}

/**
* get the sum of condition type
* @param string $type
* @param bool $multiple
* @param bool $formatted
* @return mixed|null
*/
public function getPriceOfCondition($type, $multiple = true, $formatted = true)
{
$zero = 0.00;
$quantity = ($multiple == true) ? $this->quantity : 1;

if ($this->hasConditions()) {
if (is_array($this->conditions)) {
foreach ($this->conditions as $condition) {
if ($condition->getType() == $type) {
$conditionValue = $condition->getValue() * $quantity;
}
}
} else {
$conditionValue = $this['conditions']->getValue() * $quantity;
}

return Helpers::formatValue($conditionValue, $formatted, $this->config);
}

return Helpers::formatValue($zero, $formatted, $this->config);
}
}