Redirect to checkout does not happen with default settings

Created on 29 October 2024, 12 months ago

Problem/Motivation

I set up everything, added a skip cart rule with the defaults, starting from 0 EUR. I wanted to redirect to checkout every customer and anonymous customer after clicking Add to cart but the product page is shown with a message that a product was added to cart and redirect does not happen? Can't we set this behavior for every circumstances?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΈπŸ‡°Slovakia kaszarobert

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kaszarobert
  • Status changed to Postponed: needs info 10 months ago
  • 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

    1. 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.
    2. The ::save() handler of the CommerceCartSkipRuleForm 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".

    3. 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.

Production build 0.71.5 2024