I have below array and I want to simplify array to add my logic to check product qty
The array is as below:-
$conditions = Array
(
[type] => MagentoSalesRuleModelRuleConditionCombine
[attribute] =>
[operator] =>
[value] => 1
[is_value_processed] =>
[aggregator] => all
[conditions] => Array
(
[0] => Array
(
[type] => MagentoSalesRuleModelRuleConditionProductFound
[attribute] =>
[operator] =>
[value] => 1
[is_value_processed] =>
[aggregator] => all
[conditions] => Array
(
[0] => Array
(
[type] => MagentoSalesRuleModelRuleConditionProduct
[attribute] => category_ids
[operator] => ==
[value] => 5
[is_value_processed] =>
)
[1] => Array
(
[type] => MagentoSalesRuleModelRuleConditionProduct
[attribute] => category_factor
[operator] => ==
[value] => 13
[is_value_processed] =>
)
)
)
[1] => Array
(
[type] => MagentlyCustomerRuleModelRuleConditionCustomer
[attribute] => product_qty
[operator] => >=
[value] => 99
[is_value_processed] =>
)
)
)
I want to check attribute
operator
and value
like below :
if(product_qty >= 99){
//do your stuff
}
Please help me to simplify this array to add my condition to check the product qty for some purpose.
3
Answers
If I correct understanding of your question.
You can use array indexes like this:
this code checks when
attribute
is equal toproduct_qty
andvalue
of this item is more than equal 99. condition is true.I think you better create a function that has the array as input.
it will do a for each like ttrasn mentioned:
But ad if $condition is an array, recursive call the same function with that array.
You don’t have easy way to perform a comparison with the operator stored in a value, so you need to write the function yourself. A simple
switch
can do the job :To evaluate you whole conditions, you can use recursion :
Here is a skeleton :