Fixed issues with testing criteria of cart rule conditions
This commit is contained in:
parent
ea185aad7b
commit
90c229442d
|
|
@ -2,23 +2,21 @@
|
|||
|
||||
namespace Webkul\Discount\Actions;
|
||||
|
||||
class BuyAGetB
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
use Webkul\Discount\Actions\Action;
|
||||
|
||||
class BuyAGetB extends Action
|
||||
{
|
||||
public function calculate($rule, $item, $cart)
|
||||
{
|
||||
//calculate discount amount
|
||||
$action_type = $rule->action_type; // action type used
|
||||
$disc_threshold = $rule->disc_threshold; // atleast quantity by default 1 --> may be omitted in near future
|
||||
$disc_threshold = $rule->disc_threshold; // atleast quantity by default 1
|
||||
$disc_amount = $rule->disc_amount; // value of discount
|
||||
$disc_quantity = $rule->disc_quantity; //max quantity allowed to be discounted
|
||||
|
||||
$amountDiscounted = 0;
|
||||
$leastWorthItem = $this->leastWorthItem();
|
||||
$realQty = $leastWorthItem['quantity'];
|
||||
|
||||
$realQty = $item['quantity'];
|
||||
|
||||
if ($cart->items_qty >= $disc_threshold) {
|
||||
$amountDiscounted = $disc_amount;
|
||||
|
|
@ -27,8 +25,8 @@ class BuyAGetB
|
|||
$amountDiscounted = $amountDiscounted * $disc_quantity;
|
||||
}
|
||||
|
||||
if ($amountDiscounted > $leastWorthItem['price']) {
|
||||
$amountDiscounted = $leastWorthItem['price'];
|
||||
if ($amountDiscounted > $item['price']) {
|
||||
$amountDiscounted = $item['price'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,6 @@ use Webkul\Discount\Actions\Action;
|
|||
|
||||
class FixedAmount extends Action
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function calculate($rule, $item, $cart)
|
||||
{
|
||||
//calculate discount amount
|
||||
|
|
|
|||
|
|
@ -114,7 +114,6 @@ class CouponAbleRule extends Discount
|
|||
*/
|
||||
public function remove()
|
||||
{
|
||||
dd('removing coupon');
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$existingRule = $this->cartRuleCart->findWhere([
|
||||
|
|
|
|||
|
|
@ -299,7 +299,8 @@ abstract class Discount
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function testIfAllConditionAreTrue($conditions, $cart) {
|
||||
protected function testIfAllConditionAreTrue($conditions, $cart)
|
||||
{
|
||||
array_pop($conditions);
|
||||
|
||||
$shipping_address = $cart->getShippingAddressAttribute() ?? '';
|
||||
|
|
@ -320,9 +321,7 @@ abstract class Discount
|
|||
$total_weight = $total_weight + $item->base_total_weight;
|
||||
}
|
||||
|
||||
$test_mode = config('pricerules.test_mode.0');
|
||||
$test_conditions = config('pricerules.cart.conditions');
|
||||
$result = 1;
|
||||
$result = true;
|
||||
|
||||
foreach ($conditions as $condition) {
|
||||
$actual_value = ${$condition->attribute};
|
||||
|
|
@ -332,43 +331,43 @@ abstract class Discount
|
|||
if ($condition->type == 'numeric' || $condition->type == 'string' || $condition->type == 'text') {
|
||||
if ($test_condition == '=') {
|
||||
if ($actual_value != $test_value) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '>=') {
|
||||
if (! ($actual_value >= $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '<=') {
|
||||
if (! ($actual_value <= $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '>') {
|
||||
if (! ($actual_value > $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '<') {
|
||||
if (! ($actual_value < $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '{}') {
|
||||
if (! str_contains($actual_value, $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '!{}') {
|
||||
if (str_contains($actual_value, $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -388,7 +387,7 @@ abstract class Discount
|
|||
protected function testIfAnyConditionIsTrue($conditions, $cart) {
|
||||
array_pop($conditions);
|
||||
|
||||
$result = true;
|
||||
$result = false;
|
||||
|
||||
$shipping_address = $cart->getShippingAddressAttribute() ?? '';
|
||||
|
||||
|
|
@ -415,44 +414,44 @@ abstract class Discount
|
|||
|
||||
if ($condition->type == 'numeric' || $condition->type == 'string' || $condition->type == 'text') {
|
||||
if ($test_condition == '=') {
|
||||
if ($actual_value != $test_value) {
|
||||
$result = false;
|
||||
if ($actual_value == $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '>=') {
|
||||
if (! ($actual_value >= $test_value)) {
|
||||
$result = false;
|
||||
if ($actual_value >= $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '<=') {
|
||||
if (! ($actual_value <= $test_value)) {
|
||||
$result = false;
|
||||
if ($actual_value <= $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '>') {
|
||||
if (! ($actual_value > $test_value)) {
|
||||
$result = false;
|
||||
if ($actual_value > $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '<') {
|
||||
if (! ($actual_value < $test_value)) {
|
||||
$result = false;
|
||||
if ($actual_value < $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '{}') {
|
||||
if (! str_contains($actual_value, $test_value)) {
|
||||
$result = false;
|
||||
if (str_contains($actual_value, $test_value)) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '!{}') {
|
||||
if (str_contains($actual_value, $test_value)) {
|
||||
$result = false;
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue