mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-22 23:25:23 +00:00
Updated readme
minor modifications
This commit is contained in:
26
src/Cart.php
26
src/Cart.php
@@ -45,6 +45,13 @@ class Cart
|
||||
*/
|
||||
private $discount = 0;
|
||||
|
||||
/**
|
||||
* Defines the discount percentage.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
private $taxRate = 0;
|
||||
|
||||
/**
|
||||
* Cart constructor.
|
||||
*
|
||||
@@ -55,6 +62,7 @@ class Cart
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->events = $events;
|
||||
$this->taxRate = config('cart.tax');
|
||||
|
||||
$this->instance(self::DEFAULT_INSTANCE);
|
||||
}
|
||||
@@ -392,6 +400,22 @@ class Cart
|
||||
$this->session->put($this->instance, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the global tax rate for the cart.
|
||||
* This will set the tax rate for all items.
|
||||
*
|
||||
* @param float $discount
|
||||
*/
|
||||
public function setGlobalTax(float $taxRate)
|
||||
{
|
||||
$this->taxRate = $taxRate;
|
||||
if ($this->content && $this->content->count()) {
|
||||
$this->content->each(function ($item, $key) {
|
||||
$item->setTaxRate($this->taxRate);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the discount rate for the cart item with the given rowId.
|
||||
*
|
||||
@@ -549,7 +573,7 @@ class Cart
|
||||
$cartItem->setQuantity($qty);
|
||||
}
|
||||
|
||||
$cartItem->setTaxRate(config('cart.tax'));
|
||||
$cartItem->setTaxRate($this->taxRate);
|
||||
$cartItem->setDiscountRate( $this->discount );
|
||||
|
||||
return $cartItem;
|
||||
|
||||
Reference in New Issue
Block a user