- Issue created by @kaszarobert
- Status changed to Postponed: needs info
10 months ago 11:35am 5 January 2025 Hi, if you could paste the configuration for the skip rule you created? As described that should have worked.
I've identified multiple issues in the code that cause this
- There are two "price" fields on the rule config form (
CommerceCartSkipRuleForm
);$form['conditions']['price']
AND$form['order_values']['price']
.
As the$form
does not set'#tree' => TRUE
, both form fields map to the same form state key and the latter field value ends up overwriting the former field value. - The
::save()
handler of theCommerceCartSkipRuleForm
similarly doesn't distinguish between the two input values; the same form input value is incorrectly used twice here:
$rule->set('conditions', [ // ... 'price' => $form_state->getValue('price'), // ... ]); $rule->set('order_values', [ // ... 'price' => $form_state->getValue('price'), // ... ]);
Hence the field that actually determines the "price" used for rule evaluation is the one in "order values" instead of "conditions".
- In the function
commerce_cart_skip_can_skip()
, a conditional comparison is made depending on whether a price was specified in the rule:
if (isset($rule->get('conditions')['price']) && !empty($rule->get('conditions')['price']) && $productVariation->getPrice()) { $conditions['price'] = $productVariation->getPrice() ->getNumber() == $rule->get('conditions')['price']['number']; }
However, because the price widget always requires a currency code to be set even if no price is entered, the currency code of the price field will always be saved, and hence
$rule->get('conditions')['price']
will never be empty. This results in redundant price check that can cause a false negative rule evaluation.
- There are two "price" fields on the rule config form (