mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Further codestyle changes
This commit is contained in:
@@ -22,16 +22,17 @@ trait CanBeBought
|
|||||||
*/
|
*/
|
||||||
public function getBuyableDescription($options = null)
|
public function getBuyableDescription($options = null)
|
||||||
{
|
{
|
||||||
if(property_exists($this, 'name'))
|
if(property_exists($this, 'name')) {
|
||||||
return $this->name;
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
if(property_exists($this, 'title'))
|
if(property_exists($this, 'title')) {
|
||||||
return $this->title;
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
if(property_exists($this, 'description'))
|
if(property_exists($this, 'description')) {
|
||||||
return $this->description;
|
return $this->description;
|
||||||
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,9 +42,9 @@ trait CanBeBought
|
|||||||
*/
|
*/
|
||||||
public function getBuyablePrice($options = null)
|
public function getBuyablePrice($options = null)
|
||||||
{
|
{
|
||||||
if(property_exists($this, 'price'))
|
if(property_exists($this, 'price')) {
|
||||||
return $this->price;
|
return $this->price;
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,8 +54,10 @@ trait CanBeBought
|
|||||||
*/
|
*/
|
||||||
public function getBuyableWeight($options = null)
|
public function getBuyableWeight($options = null)
|
||||||
{
|
{
|
||||||
if(property_exists($this, 'weight'))
|
if(property_exists($this, 'weight')) {
|
||||||
return $this->weight;
|
return $this->weight;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
81
src/Cart.php
81
src/Cart.php
@@ -5,9 +5,9 @@ namespace Gloudemans\Shoppingcart;
|
|||||||
use Closure;
|
use Closure;
|
||||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||||
use Gloudemans\Shoppingcart\Contracts\InstanceIdentifier;
|
use Gloudemans\Shoppingcart\Contracts\InstanceIdentifier;
|
||||||
use Gloudemans\Shoppingcart\Exceptions\UnknownModelException;
|
|
||||||
use Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException;
|
|
||||||
use Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException;
|
use Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException;
|
||||||
|
use Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException;
|
||||||
|
use Gloudemans\Shoppingcart\Exceptions\UnknownModelException;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Illuminate\Database\DatabaseManager;
|
use Illuminate\Database\DatabaseManager;
|
||||||
use Illuminate\Session\SessionManager;
|
use Illuminate\Session\SessionManager;
|
||||||
@@ -106,6 +106,7 @@ class Cart
|
|||||||
* @param int|float $qty
|
* @param int|float $qty
|
||||||
* @param float $price
|
* @param float $price
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return \Gloudemans\Shoppingcart\CartItem
|
* @return \Gloudemans\Shoppingcart\CartItem
|
||||||
*/
|
*/
|
||||||
public function add($id, $name = null, $qty = null, $price = null, array $options = [])
|
public function add($id, $name = null, $qty = null, $price = null, array $options = [])
|
||||||
@@ -117,6 +118,7 @@ class Cart
|
|||||||
}
|
}
|
||||||
|
|
||||||
$cartItem = $this->createCartItem($id, $name, $qty, $price, $options);
|
$cartItem = $this->createCartItem($id, $name, $qty, $price, $options);
|
||||||
|
|
||||||
return $this->addCartItem($cartItem);
|
return $this->addCartItem($cartItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,11 +134,11 @@ class Cart
|
|||||||
public function addCartItem($item, $keepDiscount = false, $keepTax = false)
|
public function addCartItem($item, $keepDiscount = false, $keepTax = false)
|
||||||
{
|
{
|
||||||
if (!$keepDiscount) {
|
if (!$keepDiscount) {
|
||||||
$item->setDiscountRate( $this->discount );
|
$item->setDiscountRate($this->discount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$keepTax) {
|
if (!$keepTax) {
|
||||||
$item->setTaxRate( $this->taxRate );
|
$item->setTaxRate($this->taxRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $this->getContent();
|
$content = $this->getContent();
|
||||||
@@ -173,15 +175,13 @@ class Cart
|
|||||||
} else {
|
} else {
|
||||||
$cartItem->qty = $qty;
|
$cartItem->qty = $qty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$content = $this->getContent();
|
$content = $this->getContent();
|
||||||
|
|
||||||
if ($rowId !== $cartItem->rowId) {
|
if ($rowId !== $cartItem->rowId) {
|
||||||
$content->pull($rowId);
|
$content->pull($rowId);
|
||||||
|
|
||||||
if ($content->has($cartItem->rowId))
|
if ($content->has($cartItem->rowId)) {
|
||||||
{
|
|
||||||
$existingCartItem = $this->get($cartItem->rowId);
|
$existingCartItem = $this->get($cartItem->rowId);
|
||||||
$cartItem->setQuantity($existingCartItem->qty + $cartItem->qty);
|
$cartItem->setQuantity($existingCartItem->qty + $cartItem->qty);
|
||||||
}
|
}
|
||||||
@@ -190,8 +190,7 @@ class Cart
|
|||||||
if ($cartItem->qty <= 0) {
|
if ($cartItem->qty <= 0) {
|
||||||
$this->remove($cartItem->rowId);
|
$this->remove($cartItem->rowId);
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$content->put($cartItem->rowId, $cartItem);
|
$content->put($cartItem->rowId, $cartItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +205,7 @@ class Cart
|
|||||||
* Remove the cart item with the given rowId from the cart.
|
* Remove the cart item with the given rowId from the cart.
|
||||||
*
|
*
|
||||||
* @param string $rowId
|
* @param string $rowId
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function remove($rowId)
|
public function remove($rowId)
|
||||||
@@ -225,14 +225,16 @@ class Cart
|
|||||||
* Get a cart item from the cart by its rowId.
|
* Get a cart item from the cart by its rowId.
|
||||||
*
|
*
|
||||||
* @param string $rowId
|
* @param string $rowId
|
||||||
|
*
|
||||||
* @return \Gloudemans\Shoppingcart\CartItem
|
* @return \Gloudemans\Shoppingcart\CartItem
|
||||||
*/
|
*/
|
||||||
public function get($rowId)
|
public function get($rowId)
|
||||||
{
|
{
|
||||||
$content = $this->getContent();
|
$content = $this->getContent();
|
||||||
|
|
||||||
if ( ! $content->has($rowId))
|
if ( ! $content->has($rowId)) {
|
||||||
throw new InvalidRowIDException("The cart does not contain rowId {$rowId}.");
|
throw new InvalidRowIDException("The cart does not contain rowId {$rowId}.");
|
||||||
|
}
|
||||||
|
|
||||||
return $content->get($rowId);
|
return $content->get($rowId);
|
||||||
}
|
}
|
||||||
@@ -254,8 +256,10 @@ class Cart
|
|||||||
*/
|
*/
|
||||||
public function content()
|
public function content()
|
||||||
{
|
{
|
||||||
if (is_null($this->session->get($this->instance)))
|
if (is_null($this->session->get($this->instance))) {
|
||||||
return new Collection([]);
|
return new Collection([]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->session->get($this->instance);
|
return $this->session->get($this->instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,6 +301,7 @@ class Cart
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -322,6 +327,7 @@ class Cart
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -347,6 +353,7 @@ class Cart
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -372,6 +379,7 @@ class Cart
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function discount($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function discount($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -397,6 +405,7 @@ class Cart
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function initial($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function initial($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -422,6 +431,7 @@ class Cart
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function weight($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function weight($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -433,6 +443,7 @@ class Cart
|
|||||||
* Search the cart content for a cart item matching the given search closure.
|
* Search the cart content for a cart item matching the given search closure.
|
||||||
*
|
*
|
||||||
* @param \Closure $search
|
* @param \Closure $search
|
||||||
|
*
|
||||||
* @return \Illuminate\Support\Collection
|
* @return \Illuminate\Support\Collection
|
||||||
*/
|
*/
|
||||||
public function search(Closure $search)
|
public function search(Closure $search)
|
||||||
@@ -445,12 +456,14 @@ class Cart
|
|||||||
*
|
*
|
||||||
* @param string $rowId
|
* @param string $rowId
|
||||||
* @param mixed $model
|
* @param mixed $model
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function associate($rowId, $model)
|
public function associate($rowId, $model)
|
||||||
{
|
{
|
||||||
if(is_string($model) && ! class_exists($model))
|
if(is_string($model) && ! class_exists($model)) {
|
||||||
throw new UnknownModelException("The supplied model {$model} does not exist.");
|
throw new UnknownModelException("The supplied model {$model} does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
$cartItem = $this->get($rowId);
|
$cartItem = $this->get($rowId);
|
||||||
|
|
||||||
@@ -468,6 +481,7 @@ class Cart
|
|||||||
*
|
*
|
||||||
* @param string $rowId
|
* @param string $rowId
|
||||||
* @param int|float $taxRate
|
* @param int|float $taxRate
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setTax($rowId, $taxRate)
|
public function setTax($rowId, $taxRate)
|
||||||
@@ -494,8 +508,7 @@ class Cart
|
|||||||
$this->taxRate = $taxRate;
|
$this->taxRate = $taxRate;
|
||||||
|
|
||||||
$content = $this->getContent();
|
$content = $this->getContent();
|
||||||
if ($content && $content->count())
|
if ($content && $content->count()) {
|
||||||
{
|
|
||||||
$content->each(function ($item, $key) {
|
$content->each(function ($item, $key) {
|
||||||
$item->setTaxRate($this->taxRate);
|
$item->setTaxRate($this->taxRate);
|
||||||
});
|
});
|
||||||
@@ -507,6 +520,7 @@ class Cart
|
|||||||
*
|
*
|
||||||
* @param string $rowId
|
* @param string $rowId
|
||||||
* @param int|float $taxRate
|
* @param int|float $taxRate
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setDiscount($rowId, $discount)
|
public function setDiscount($rowId, $discount)
|
||||||
@@ -527,14 +541,15 @@ class Cart
|
|||||||
* This will set the discount for all cart items.
|
* This will set the discount for all cart items.
|
||||||
*
|
*
|
||||||
* @param float $discount
|
* @param float $discount
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setGlobalDiscount($discount)
|
public function setGlobalDiscount($discount)
|
||||||
{
|
{
|
||||||
$this->discount = $discount;
|
$this->discount = $discount;
|
||||||
|
|
||||||
$content = $this->getContent();
|
$content = $this->getContent();
|
||||||
if ($content && $content->count())
|
if ($content && $content->count()) {
|
||||||
{
|
|
||||||
$content->each(function ($item, $key) {
|
$content->each(function ($item, $key) {
|
||||||
$item->setDiscountRate($this->discount);
|
$item->setDiscountRate($this->discount);
|
||||||
});
|
});
|
||||||
@@ -545,22 +560,25 @@ class Cart
|
|||||||
* Store an the current instance of the cart.
|
* Store an the current instance of the cart.
|
||||||
*
|
*
|
||||||
* @param mixed $identifier
|
* @param mixed $identifier
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function store($identifier)
|
public function store($identifier)
|
||||||
{
|
{
|
||||||
$content = $this->getContent();
|
$content = $this->getContent();
|
||||||
|
|
||||||
if ($identifier instanceof InstanceIdentifier)
|
if ($identifier instanceof InstanceIdentifier) {
|
||||||
$identifier = $identifier->getInstanceIdentifier();
|
$identifier = $identifier->getInstanceIdentifier();
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->storedCartWithIdentifierExists($identifier))
|
if ($this->storedCartWithIdentifierExists($identifier)) {
|
||||||
throw new CartAlreadyStoredException("A cart with identifier {$identifier} was already stored.");
|
throw new CartAlreadyStoredException("A cart with identifier {$identifier} was already stored.");
|
||||||
|
}
|
||||||
|
|
||||||
$this->getConnection()->table($this->getTableName())->insert([
|
$this->getConnection()->table($this->getTableName())->insert([
|
||||||
'identifier' => $identifier,
|
'identifier' => $identifier,
|
||||||
'instance' => $this->currentInstance(),
|
'instance' => $this->currentInstance(),
|
||||||
'content' => serialize($content)
|
'content' => serialize($content),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->events->fire('cart.stored');
|
$this->events->fire('cart.stored');
|
||||||
@@ -570,15 +588,18 @@ class Cart
|
|||||||
* Restore the cart with the given identifier.
|
* Restore the cart with the given identifier.
|
||||||
*
|
*
|
||||||
* @param mixed $identifier
|
* @param mixed $identifier
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function restore($identifier)
|
public function restore($identifier)
|
||||||
{
|
{
|
||||||
if ($identifier instanceof InstanceIdentifier)
|
if ($identifier instanceof InstanceIdentifier) {
|
||||||
$identifier = $identifier->getInstanceIdentifier();
|
$identifier = $identifier->getInstanceIdentifier();
|
||||||
|
}
|
||||||
|
|
||||||
if( ! $this->storedCartWithIdentifierExists($identifier))
|
if( ! $this->storedCartWithIdentifierExists($identifier)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$stored = $this->getConnection()->table($this->getTableName())
|
$stored = $this->getConnection()->table($this->getTableName())
|
||||||
->where('identifier', $identifier)->first();
|
->where('identifier', $identifier)->first();
|
||||||
@@ -591,8 +612,9 @@ class Cart
|
|||||||
|
|
||||||
$content = $this->getContent();
|
$content = $this->getContent();
|
||||||
|
|
||||||
foreach ($storedContent as $cartItem)
|
foreach ($storedContent as $cartItem) {
|
||||||
$content->put($cartItem->rowId, $cartItem);
|
$content->put($cartItem->rowId, $cartItem);
|
||||||
|
}
|
||||||
|
|
||||||
$this->events->fire('cart.restored');
|
$this->events->fire('cart.restored');
|
||||||
|
|
||||||
@@ -624,8 +646,9 @@ class Cart
|
|||||||
|
|
||||||
$storedContent = unserialize($stored->content);
|
$storedContent = unserialize($stored->content);
|
||||||
|
|
||||||
foreach ($storedContent as $cartItem)
|
foreach ($storedContent as $cartItem) {
|
||||||
$this->addCartItem($cartItem, $keepDiscount, $keepTax);
|
$this->addCartItem($cartItem, $keepDiscount, $keepTax);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -639,7 +662,7 @@ class Cart
|
|||||||
*/
|
*/
|
||||||
public function __get($attribute)
|
public function __get($attribute)
|
||||||
{
|
{
|
||||||
switch($attribute) {
|
switch ($attribute) {
|
||||||
case 'total':
|
case 'total':
|
||||||
return $this->total();
|
return $this->total();
|
||||||
case 'tax':
|
case 'tax':
|
||||||
@@ -661,7 +684,7 @@ class Cart
|
|||||||
if ($this->session->has($this->instance)) {
|
if ($this->session->has($this->instance)) {
|
||||||
return $this->session->get($this->instance);
|
return $this->session->get($this->instance);
|
||||||
}
|
}
|
||||||
return new Collection;
|
return new Collection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -761,15 +784,15 @@ class Cart
|
|||||||
*/
|
*/
|
||||||
private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator)
|
private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator)
|
||||||
{
|
{
|
||||||
if(is_null($decimals)) {
|
if (is_null($decimals)) {
|
||||||
$decimals = config('cart.format.decimals', 2);
|
$decimals = config('cart.format.decimals', 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_null($decimalPoint)) {
|
if (is_null($decimalPoint)) {
|
||||||
$decimalPoint = config('cart.format.decimal_point', '.');
|
$decimalPoint = config('cart.format.decimal_point', '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_null($thousandSeperator)) {
|
if (is_null($thousandSeperator)) {
|
||||||
$thousandSeperator = config('cart.format.thousand_separator', ',');
|
$thousandSeperator = config('cart.format.thousand_separator', ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace Gloudemans\Shoppingcart;
|
namespace Gloudemans\Shoppingcart;
|
||||||
|
|
||||||
use Illuminate\Contracts\Support\Arrayable;
|
|
||||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||||
|
use Illuminate\Contracts\Support\Arrayable;
|
||||||
use Illuminate\Contracts\Support\Jsonable;
|
use Illuminate\Contracts\Support\Jsonable;
|
||||||
|
|
||||||
class CartItem implements Arrayable, Jsonable
|
class CartItem implements Arrayable, Jsonable
|
||||||
@@ -88,22 +88,22 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
*/
|
*/
|
||||||
public function __construct($id, $name, $price, $weight = 0, array $options = [])
|
public function __construct($id, $name, $price, $weight = 0, array $options = [])
|
||||||
{
|
{
|
||||||
if(empty($id)) {
|
if (empty($id)) {
|
||||||
throw new \InvalidArgumentException('Please supply a valid identifier.');
|
throw new \InvalidArgumentException('Please supply a valid identifier.');
|
||||||
}
|
}
|
||||||
if(empty($name)) {
|
if (empty($name)) {
|
||||||
throw new \InvalidArgumentException('Please supply a valid name.');
|
throw new \InvalidArgumentException('Please supply a valid name.');
|
||||||
}
|
}
|
||||||
if(strlen($price) < 0 || ! is_numeric($price)) {
|
if (strlen($price) < 0 || ! is_numeric($price)) {
|
||||||
throw new \InvalidArgumentException('Please supply a valid price.');
|
throw new \InvalidArgumentException('Please supply a valid price.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->price = floatval($price);
|
$this->price = floatval($price);
|
||||||
$this->weight = floatval($weight);
|
$this->weight = floatval($weight);
|
||||||
$this->options = new CartItemOptions($options);
|
$this->options = new CartItemOptions($options);
|
||||||
$this->rowId = $this->generateRowId($id, $options);
|
$this->rowId = $this->generateRowId($id, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,6 +112,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function weight($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function weight($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -125,6 +126,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function price($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function price($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -138,6 +140,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function priceTarget($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function priceTarget($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -151,6 +154,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function priceTax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function priceTax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -160,11 +164,12 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the formatted subtotal.
|
* Returns the formatted subtotal.
|
||||||
* Subtotal is price for whole CartItem without TAX
|
* Subtotal is price for whole CartItem without TAX.
|
||||||
*
|
*
|
||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -174,11 +179,12 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the formatted total.
|
* Returns the formatted total.
|
||||||
* Total is price for whole CartItem with TAX
|
* Total is price for whole CartItem with TAX.
|
||||||
*
|
*
|
||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -192,6 +198,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -205,6 +212,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function taxTotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function taxTotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -218,6 +226,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function discount($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function discount($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -231,6 +240,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function discountTotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
public function discountTotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||||
@@ -255,6 +265,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* Update the cart item from a Buyable.
|
* Update the cart item from a Buyable.
|
||||||
*
|
*
|
||||||
* @param \Gloudemans\Shoppingcart\Contracts\Buyable $item
|
* @param \Gloudemans\Shoppingcart\Contracts\Buyable $item
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function updateFromBuyable(Buyable $item)
|
public function updateFromBuyable(Buyable $item)
|
||||||
@@ -269,6 +280,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* Update the cart item from an array.
|
* Update the cart item from an array.
|
||||||
*
|
*
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function updateFromArray(array $attributes)
|
public function updateFromArray(array $attributes)
|
||||||
@@ -288,6 +300,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* Associate the cart item with the given model.
|
* Associate the cart item with the given model.
|
||||||
*
|
*
|
||||||
* @param mixed $model
|
* @param mixed $model
|
||||||
|
*
|
||||||
* @return \Gloudemans\Shoppingcart\CartItem
|
* @return \Gloudemans\Shoppingcart\CartItem
|
||||||
*/
|
*/
|
||||||
public function associate($model)
|
public function associate($model)
|
||||||
@@ -301,6 +314,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* Set the tax rate.
|
* Set the tax rate.
|
||||||
*
|
*
|
||||||
* @param int|float $taxRate
|
* @param int|float $taxRate
|
||||||
|
*
|
||||||
* @return \Gloudemans\Shoppingcart\CartItem
|
* @return \Gloudemans\Shoppingcart\CartItem
|
||||||
*/
|
*/
|
||||||
public function setTaxRate($taxRate)
|
public function setTaxRate($taxRate)
|
||||||
@@ -314,6 +328,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* Set the discount rate.
|
* Set the discount rate.
|
||||||
*
|
*
|
||||||
* @param int|float $discountRate
|
* @param int|float $discountRate
|
||||||
|
*
|
||||||
* @return \Gloudemans\Shoppingcart\CartItem
|
* @return \Gloudemans\Shoppingcart\CartItem
|
||||||
*/
|
*/
|
||||||
public function setDiscountRate($discountRate)
|
public function setDiscountRate($discountRate)
|
||||||
@@ -327,6 +342,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* Get an attribute from the cart item or get the associated model.
|
* Get an attribute from the cart item or get the associated model.
|
||||||
*
|
*
|
||||||
* @param string $attribute
|
* @param string $attribute
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function __get($attribute)
|
public function __get($attribute)
|
||||||
@@ -371,6 +387,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
*
|
*
|
||||||
* @param \Gloudemans\Shoppingcart\Contracts\Buyable $item
|
* @param \Gloudemans\Shoppingcart\Contracts\Buyable $item
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return \Gloudemans\Shoppingcart\CartItem
|
* @return \Gloudemans\Shoppingcart\CartItem
|
||||||
*/
|
*/
|
||||||
public static function fromBuyable(Buyable $item, array $options = [])
|
public static function fromBuyable(Buyable $item, array $options = [])
|
||||||
@@ -382,6 +399,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* Create a new instance from the given array.
|
* Create a new instance from the given array.
|
||||||
*
|
*
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return \Gloudemans\Shoppingcart\CartItem
|
* @return \Gloudemans\Shoppingcart\CartItem
|
||||||
*/
|
*/
|
||||||
public static function fromArray(array $attributes)
|
public static function fromArray(array $attributes)
|
||||||
@@ -398,6 +416,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param float $price
|
* @param float $price
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return \Gloudemans\Shoppingcart\CartItem
|
* @return \Gloudemans\Shoppingcart\CartItem
|
||||||
*/
|
*/
|
||||||
public static function fromAttributes($id, $name, $price, $weight, array $options = [])
|
public static function fromAttributes($id, $name, $price, $weight, array $options = [])
|
||||||
@@ -410,6 +429,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
*
|
*
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function generateRowId($id, array $options)
|
protected function generateRowId($id, array $options)
|
||||||
@@ -444,6 +464,7 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* Convert the object to its JSON representation.
|
* Convert the object to its JSON representation.
|
||||||
*
|
*
|
||||||
* @param int $options
|
* @param int $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function toJson($options = 0)
|
public function toJson($options = 0)
|
||||||
@@ -458,18 +479,22 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
* @param int $decimals
|
* @param int $decimals
|
||||||
* @param string $decimalPoint
|
* @param string $decimalPoint
|
||||||
* @param string $thousandSeperator
|
* @param string $thousandSeperator
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator)
|
private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator)
|
||||||
{
|
{
|
||||||
if (is_null($decimals))
|
if (is_null($decimals)) {
|
||||||
$decimals = config('cart.format.decimals', 2);
|
$decimals = config('cart.format.decimals', 2);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_null($decimalPoint))
|
if (is_null($decimalPoint)) {
|
||||||
$decimalPoint = config('cart.format.decimal_point', '.');
|
$decimalPoint = config('cart.format.decimal_point', '.');
|
||||||
|
}
|
||||||
|
|
||||||
if (is_null($thousandSeperator))
|
if (is_null($thousandSeperator)) {
|
||||||
$thousandSeperator = config('cart.format.thousand_separator', ',');
|
$thousandSeperator = config('cart.format.thousand_separator', ',');
|
||||||
|
}
|
||||||
|
|
||||||
return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
|
return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user