mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-22 15:15:27 +00:00
Adjusted for global discount
Fixed tests for Laravel 5.7
This commit is contained in:
19
src/Cart.php
19
src/Cart.php
@@ -37,6 +37,13 @@ class Cart
|
||||
*/
|
||||
private $instance;
|
||||
|
||||
/**
|
||||
* Defines the discount percentage.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
private $discount;
|
||||
|
||||
/**
|
||||
* Cart constructor.
|
||||
*
|
||||
@@ -47,6 +54,7 @@ class Cart
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->events = $events;
|
||||
$this->discount = 0;
|
||||
|
||||
$this->instance(self::DEFAULT_INSTANCE);
|
||||
}
|
||||
@@ -340,6 +348,16 @@ class Cart
|
||||
$this->session->put($this->instance, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the global discount percentage for the cart
|
||||
*
|
||||
* @param float $discount
|
||||
*/
|
||||
public function setDiscount(float $discount)
|
||||
{
|
||||
$this->discount = $discount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an the current instance of the cart.
|
||||
*
|
||||
@@ -462,6 +480,7 @@ class Cart
|
||||
}
|
||||
|
||||
$cartItem->setTaxRate(config('cart.tax'));
|
||||
$cartItem->setDiscountRate( $this->discount );
|
||||
|
||||
return $cartItem;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user