extend cart rule validation with search in cart item additional
This commit is contained in:
parent
88ce2bd320
commit
f53a6fba16
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
|
||||
<?php
|
||||
|
||||
return [
|
||||
'save' => 'حفظ',
|
||||
'create' => 'خلق',
|
||||
|
|
@ -1010,6 +1009,7 @@ return [
|
|||
'choose-condition-to-add' => 'اختر شرط لإضافته',
|
||||
'cart-attribute' => 'سمة سلة التسوق',
|
||||
'subtotal' => 'المجموع الفرعي',
|
||||
'additional' => 'Additional Information',
|
||||
'total-items-qty' => 'إجمالي كمية العناصر',
|
||||
'total-weight' => 'الوزن الكلي',
|
||||
'payment-method' => 'طريقة الدفع او السداد',
|
||||
|
|
|
|||
|
|
@ -1010,6 +1010,7 @@ return [
|
|||
'choose-condition-to-add' => 'Choose a condition to add',
|
||||
'cart-attribute' => 'Cart Attribute',
|
||||
'subtotal' => 'Subtotal',
|
||||
'additional' => 'Additional Information',
|
||||
'total-items-qty' => 'Total Items Qty',
|
||||
'total-weight' => 'Total Weight',
|
||||
'payment-method' => 'Payment Method',
|
||||
|
|
|
|||
|
|
@ -1010,6 +1010,7 @@ return [
|
|||
'choose-condition-to-add' => 'شرطی را برای اضافه کردن انتخاب کنید',
|
||||
'cart-attribute' => 'ویژگی سبد خرید',
|
||||
'subtotal' => 'فرعی',
|
||||
'additional' => 'Additional Information',
|
||||
'total-items-qty' => 'تعداد کل موارد',
|
||||
'total-weight' => 'وزن کل',
|
||||
'payment-method' => 'روش پرداخت',
|
||||
|
|
|
|||
|
|
@ -1010,6 +1010,7 @@ return [
|
|||
'choose-condition-to-add' => 'Conditie toevoegen',
|
||||
'cart-attribute' => 'Winkelwagenattribuut',
|
||||
'subtotal' => 'Subtotaal',
|
||||
'additional' => 'Additional Information',
|
||||
'total-items-qty' => 'Totaal aantal artikelen',
|
||||
'total-weight' => 'Totale gewicht',
|
||||
'payment-method' => 'Betaalmethode',
|
||||
|
|
|
|||
|
|
@ -1010,6 +1010,7 @@ return [
|
|||
'choose-condition-to-add' => 'Escolha uma condição para adicionar',
|
||||
'cart-attribute' => 'Atributo do carrinho',
|
||||
'subtotal' => 'Subtotal',
|
||||
'additional' => 'Additional Information',
|
||||
'total-items-qty' => 'Quantidade total de itens',
|
||||
'total-weight' => 'Peso total',
|
||||
'payment-method' => 'Forma de pagamento',
|
||||
|
|
|
|||
|
|
@ -272,6 +272,10 @@ class CartRuleRepository extends Repository
|
|||
'key' => 'cart_item|base_total',
|
||||
'type' => 'price',
|
||||
'label' => trans('admin::app.promotions.cart-rules.subtotal'),
|
||||
], [
|
||||
'key' => 'cart_item|additional',
|
||||
'type' => 'text',
|
||||
'label' => trans('admin::app.promotions.cart-rules.additional'),
|
||||
]
|
||||
]
|
||||
], [
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class Validator
|
|||
if ($entity instanceof \Webkul\Checkout\Contracts\Cart && strpos($condition['attribute'], 'cart|') === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$totalConditionCount++;
|
||||
|
||||
if ($rule->condition_type == 1) {
|
||||
|
|
@ -99,7 +99,7 @@ class Validator
|
|||
$value = $entity->product
|
||||
? $entity->product->categories()->pluck('id')->toArray()
|
||||
: $entity->categories()->pluck('id')->toArray();
|
||||
|
||||
|
||||
return $value;
|
||||
} else {
|
||||
$value = $entity->product
|
||||
|
|
@ -109,7 +109,7 @@ class Validator
|
|||
if (! in_array($condition['attribute_type'], ['multiselect', 'checkbox'])) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
return $value ? explode(',', $value) : [];
|
||||
}
|
||||
}
|
||||
|
|
@ -236,9 +236,9 @@ class Validator
|
|||
$result = ! empty(array_intersect($condition['value'], $attributeValue));
|
||||
} else {
|
||||
if (is_array($attributeValue)) {
|
||||
$result = in_array($condition['value'], $attributeValue);
|
||||
$result = self::validateArrayValues($attributeValue, $condition['value']);
|
||||
} else {
|
||||
$result = (strpos($attributeValue, $condition['value']) !== false) ? true : false;
|
||||
$result = strpos($attributeValue, $condition['value']) !== false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -251,4 +251,28 @@ class Validator
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the condition value against a multi dimensional array recursively
|
||||
*
|
||||
* @param array $attributeValue
|
||||
* @param string $conditionValue
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function validateArrayValues(array $attributeValue, string $conditionValue): bool
|
||||
{
|
||||
$result = in_array($conditionValue, $attributeValue, true);
|
||||
if ($result === false) {
|
||||
foreach ($attributeValue as $subValue) {
|
||||
if (is_array($subValue)) {
|
||||
$result = self::validateArrayValues($subValue, $conditionValue);
|
||||
if ($result === true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue