Reputation: 67
I want to make an if else in filterArgs
(in Model) as follow:
public $filterArgs = array(
array('name' => 'to', 'type' => 'value' => 'Product.regular_price' ),
);
I want the field to change base on the condition.
if sale = 1, field is promo_price, else field is regular_price
I already try below code (but unsuccessful):
'field'=> 'Product.sale' => 1 ? 'Product.promo_price >=' : 'Product.regular_price >='
Can someone please help me. Thanks alot in advance!
Upvotes: 0
Views: 718
Reputation: 9398
I would create a virtualField in my Product Model
$virtualFields = array
(
'my_price' => 'IF(Product.sale = 1, Product.promo_price, Product.regular_price)';
)
public $filterArgs = array
(
'my_price' => array('type' => 'value'),
);
Upvotes: 1