mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
test updates & working on calculating condition values based on orders
This commit is contained in:
+20
-6
@@ -16,7 +16,7 @@ class CartCondition
|
||||
/**
|
||||
* the parsed raw value of the condition
|
||||
*/
|
||||
public $parsedRawValue;
|
||||
public $parsedRawValue = 0;
|
||||
|
||||
/**
|
||||
* @param array $args (name, type, target, value)
|
||||
@@ -77,14 +77,20 @@ public function getAttributes()
|
||||
|
||||
/**
|
||||
* the value of this the condition
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
public function getValue(): int|float
|
||||
{
|
||||
return $this->args['value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of this condition
|
||||
*/
|
||||
public function setValue($value): void
|
||||
{
|
||||
$this->args['value'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order to apply this condition. If no argument order is applied we return 0 as
|
||||
* indicator that no assignment has been made
|
||||
@@ -123,9 +129,11 @@ public function applyCondition($totalOrSubTotalOrPrice)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCalculatedValue($totalOrSubTotalOrPrice)
|
||||
public function getCalculatedValue($totalOrSubTotalOrPrice = null): int|float
|
||||
{
|
||||
$this->apply($totalOrSubTotalOrPrice, $this->getValue());
|
||||
if ($totalOrSubTotalOrPrice) {
|
||||
$this->apply($totalOrSubTotalOrPrice, $this->getValue());
|
||||
}
|
||||
|
||||
return $this->parsedRawValue;
|
||||
}
|
||||
@@ -137,6 +145,12 @@ public function getCalculatedValue($totalOrSubTotalOrPrice)
|
||||
*/
|
||||
protected function apply($totalOrSubTotalOrPrice, $conditionValue)
|
||||
{
|
||||
if ($totalOrSubTotalOrPrice <= 0) {
|
||||
$this->parsedRawValue = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// if value has a percentage sign on it, we will get first
|
||||
// its percentage then we will evaluate again if the value
|
||||
// has a minus or plus sign so we can decide what to do with the
|
||||
|
||||
Reference in New Issue
Block a user