1

I'm using commerce checkout redirect module in my commerce site, but in the same time I enabled email verification to register, so the user is redirected to user profile page after he log in.
I want to automatically redirect him to checkout page, I created a rule 'when the user logged in - if order is a cart - then redirect to checkout'.
It always redirect the user even if the cart is empty.
What condition I should add to my rule to do that?

I tested a new condition suggested by Channel Islander, it's not working also in my site :

My new rule:

{ "rules_redirect_to_checkout_after_login" : {
"LABEL" : "redirect to checkout after login",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "checkout", "morad" ],
"REQUIRES" : [ "commerce_rules_extra", "rules" ],
"ON" : { "user_login" : [] },
"IF" : [
  { "commerce_rules_extra_compare_line_item_count" : {
      "order" : [ "site:current-cart-order" ],
      "operator" : "\u003E=",
      "value" : "1"
    }
  }
],
"DO" : [ { "redirect" : { "url" : "[site:url]\/checkout" } } ]

} }

Log when user log in

Information de débogage de Rules :
" Reacting on event L'utilisateur s'est connecté.
0 ms Reacting on event L'utilisateur s'est connecté.
12.51 ms Evaluating conditions of rule redirect admins to dashboard after login. [edit]
13.394 ms The condition user_has_role evaluated to FALSE [edit]
13.403 ms AND evaluated to FALSE.
13.433 ms Evaluating conditions of rule redirect to checkout after login. [edit]
" Reacting on event Calcul du prix de vente d'un produit.
0 ms Reacting on event Calcul du prix de vente d'un produit.
0.245 ms Evaluating conditions of rule Calculer les taxes : Sales tax. [edit]
0.254 ms AND evaluated to TRUE.
" Rule Calculer les taxes : Sales tax fires. [edit]
0 ms Rule Calculer les taxes : Sales tax fires.
0.112 ms Evaluating the action commerce_tax_calculate_by_type. [edit]
1.159 ms Rule Calculer les taxes : Sales tax has fired.
1.478 ms Evaluating conditions of rule Calculer les taxes : VAT. [edit]
1.484 ms AND evaluated to TRUE.
" Rule Calculer les taxes : VAT fires. [edit]
0 ms Rule Calculer les taxes : VAT fires.
0.079 ms Evaluating the action commerce_tax_calculate_by_type. [edit]
" Executing rule Calculer TVA Maroc 10%. [edit]
0 ms Executing rule Calculer TVA Maroc 10%.
0.179 ms Evaluating conditions of rule Calculer TVA Maroc 10%. [edit]
0.188 ms AND evaluated to TRUE.
" Rule Calculer TVA Maroc 10% fires. [edit]
0 ms Rule Calculer TVA Maroc 10% fires.
0.094 ms Evaluating the action commerce_tax_rate_apply. [edit]
0.686 ms Added the provided variable applied_tax of type commerce_price [edit]
0.703 ms Rule Calculer TVA Maroc 10% has fired.
0.931 ms Finished executing of rule Calculer TVA Maroc 10%.
2.55 ms Rule Calculer les taxes : VAT has fired.
4.065 ms Evaluating conditions of rule add ka par options price. [edit]
5.286 ms The condition entity_has_field evaluated to TRUE [edit]
5.294 ms AND evaluated to TRUE.
" Rule add ka par options price fires. [edit]
0 ms Rule add ka par options price fires.
2.376 ms Looping over the list items of commerce-line-item:field-options [edit]
4.179 ms Evaluating the action commerce_line_item_unit_price_add. [edit]
6.962 ms Evaluating the action commerce_line_item_unit_price_add. [edit]
8.387 ms Evaluating the action commerce_line_item_unit_price_add. [edit]
8.746 ms Rule add ka par options price has fired.
14.085 ms Evaluating conditions of rule add ku pro options price. [edit]
14.208 ms The condition entity_has_field evaluated to FALSE [edit]
14.215 ms AND evaluated to FALSE.
14.283 ms Evaluating conditions of rule Annuler le prix pour les produits désactivés dans le panier. [edit]
16.268 ms The condition data_is_empty evaluated to FALSE [edit]
16.403 ms The condition entity_has_field evaluated to TRUE [edit]
16.963 ms The condition data_is evaluated to FALSE [edit]
16.97 ms AND evaluated to FALSE.
16.99 ms Finished reacting on event Calcul du prix de vente d'un produit.
51.739 ms The condition commerce_rules_extra_compare_line_item_count evaluated to FALSE [edit]
51.746 ms AND evaluated to FALSE.
51.76 ms Finished reacting on event L'utilisateur s'est connecté.

1

Install and use Commerce Rules Extra and use the condition "Total quantity of product line items in the cart".

  • thank you @Channel, I tested it in simplytest.me it work good, but it doesn't work in my site, I think there is a rule prevent it. – learner123 Jan 30 '15 at 14:52
  • Have you enabled Rules debug log? Post the output of the log after your test user logs in. Post the rule here, and we'll take a look. Go to admin/config/workflow/rules and click the export link next to your rule. – Channel Islander Jan 30 '15 at 19:41
  • I did, check the log above please – learner123 Jan 31 '15 at 9:49
  • If you could explain your workflow in detail that would help. I am the maintainer of CRE. Assuming you need all customers that purchase products to have account. If this is what you need. Then a way to approach this is to allow anonymous checkout and create an account if one does not exist. I run an eCommerce site that sells digital downloads so I have a complex checkout process that I am able to handle customer registrations without a painful experience for the user. – Brady Jan 31 '15 at 10:07
  • @murad there sure are a lot of rules in there! I suggest temporarily disabling all your custom pricing, tax and checkout rules, to test whether the rule above actually works. Try it with just the default Commerce rules and a product in the cart, and then add each of your rules back in one at a time until you find the one that is causing this one to not fire. It's impossible to see what is the problem with so many conditions being evaluated. – Channel Islander Jan 31 '15 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.