test updates & working on calculating condition values based on orders

This commit is contained in:
Joel Male
2024-08-15 17:21:19 +10:00
parent 77fa8601b9
commit 85ae0c30c5
10 changed files with 1758 additions and 972 deletions
+20 -6
View File
@@ -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