OK, as of a day or two ago, one of my Commerce sites has started to apply no VAT to orders.

Symptoms:

  • VAT is applied correctly on Product display pages, and on the Basket page.
  • VAT is not applied at all on the Checkout Page, or after that in the checkout process.
  • If I add an empty coupon code to the order, the page refreshes and VAT is added correctly!

Stepping through the code with a debugger I just get hopelessly lost. I can't see the wood for the trees, there are so many function and method calls! I've learnt that you have to clear the cache too, otherwise the price field is simply loaded from cache, and not calculated from the base price plus taxes.

There aren't any errors reported in Drupal watchdog nor Apache logs.

Looking at the database, when I view the order's Basket, the line item commerce_unit_price_amount in the field_data_commerce_unit_price table includes VAT, and the commerce_unit_price_data includes all the VAT details.

But just going to the Checkout page causes the line item price to lose VAT, both in the price_amount and in the price_data.

Then refreshing the order by adding an empty discount coupon code adds in VAT to the display and to the line item data in the database.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

adwuk’s picture

Have you recently upgraded Rules? There is a problem with product pricing rules that breaks with v2.8 Rules, so a few people have downgraded to v2.7. Might be related.

fonant’s picture

I've added a "price formatted with components" field to the cart contents View, to see what's going on.

Here's the checkout on first page load:

Only local images are allowed.

Note how VAT is missing from the line item (although it included VAT in the Basket) but is being added OK for the shipping charge.

Here's the same page just after I've added an empty coupon code to refresh the order:

Before

fonant’s picture

fonant’s picture

Title: VAT appears on Basket page but not for basket contents on Checkout page » Product pricing rules (e.g. VAT) fail with Rules 7.x-2.8

Updated issue title.

rszrama’s picture

Title: Product pricing rules (e.g. VAT) fail with Rules 7.x-2.8 » Product pricing rules fail with Rules 7.x-2.8 [patch Rules or downgrade to 2.7]
Version: 7.x-1.10 » 7.x-1.x-dev
Category: Bug report » Support request
Priority: Critical » Major

Bummer. Well, this isn't a bug in Commerce itself - Rules made a change and the unintended consequence is that it breaks common functionality in Drupal Commerce. Not the first time. : P

Let's leave this open so people can be directed to the patch and see how the Rules maintainers respond.

#2403851-9: Drupal Commerce is broken with Rules 7.x-2.8

Channel Islander’s picture

I am having difficulties fixing this problem.

My issue does not involve pricing rules, but does appear to be caused by the bug in Rules 1.28 which causes Rules to get invoked too soon. In my case, Rules is reacting on the event "Select available payment methods for an order" right at the beginning, before checkout, when first adding a product to the cart. (The same error occurs all the way through checkout with basically every event being reacted to, no matter where you are.)

So I followed the advice and downgraded Rules to 1.27. But the problem hasn't been fixed!

What I did:

  • Manually replaced the sites/all/modules/contrib/rules directory with the one for 1.27
  • Ran update.php
  • Cleared all caches
  • Rebuilt the Rules cache numerous times
  • Manually deleted the rows in the cache_rules table in the DB

But still the "Select available payment methods for an order" event is reacted to when first adding a product to the cart, and again on Checkout:Review.

When _should_ the "Select available payment methods for an order" event get reacted to?

fonant’s picture

"Select available payment methods for an order" is fired when you reach the checkout page containing the payment method selector. Typically this is after the Shipping page, and just before the Review page.

Channel Islander’s picture

FileSize
86.63 KB

@fonant, that's what I thought, but haven't found the canonical list. IMO it could have a clearer name. It's not clear whether the event is when the selection options are loaded or when the user selects one of them.

If it is the former, as I assume it is, a better name would be "Display available payment options for an order."

In any case there's no way "Select available payment methods for an order" should be reacted to upon adding a product to the cart, amiright?

event evaluation too early

fonant’s picture

The event is triggered when the payment methods that are available for an order are gathered for display. So the "Select" is meant in terms of Commerce selecting, not the customer. I do see the confusion if you think of "Select" in terms of the customer's actions.

"Gather available payment methods for an order" would be most logical, although "Display" would work too since the display of the options is what triggers the rule that gathers the options.

The "Select available payment methods for an order" shouldn't fire for the Cart page, no, unless you've added the payment options widget to the Cart page somehow.

Looks like the "Calculating the sell price of a product" is firing too often for you as well, there's only one product in the cart that would need its price to be calculated.

Channel Islander’s picture

FileSize
60.15 KB

@fonant, Thank you for your reply. It's amazing how a throw-away comment by someone who knows, can be just the clue one needs. You said

unless you've added the payment options widget to the Cart page somehow

. . .

I was so hopeful because, yes, I did find a stray widget in the Cart on my test server, a leftover from a failed experiment with Product Attributes :

Missing handler

However, I removed it, cleared the cache and the error remains the same. Argh.

Additionally, the same error occurs on a different server that never had Product Attributes or Product Options modules installed. The thing the two servers have in common, that a third, which is not having the error, does not, is to have had Rules 1.28 installed (and then downgraded).

Can you help me track this down?

How can I make sure my Shopping Cart view is the default?

Is there any way to further debug the Rules calls, and identify what is calling them, or why they are getting called?

fonant’s picture

@Channel Islander - product attributes won't have any effect. The only thing that I can think of that would cause the "Select available payment methods for an order" event to occur is if you had the "Payment" checkout pane on the Cart page, which is unlikely. It's normally on the "Review" page.

Sorry, I don't have time to help you track this down.

You could make sure you have all the default settings by disabling and uninstalling all your Commerce modules, but that would also delete all Commerce data as well as settings, so no good if the site has already been used.

Channel Islander’s picture

@fonant, I disabled all my Rules and added them back one by one.

Solved!

I discovered the cause was that I had both Paypal Express Checkout and Paypal WPP enabled.

This causes the Paypal checkout button to not be displayed until the normal payment method selection, but the code causes the Event "Select available payment methods for an order" to be evaluated at Paypal EC's normal place in checkout, which is to say, at the beginning, in the cart. Because the button wasn't displaying, I didn't suspect it.

Seems like it should be documented somewhere. I'll post in the Paypal EC and WPP issue threads. Thanks for your help.

sierkje’s picture

zterry95’s picture

Fixed by upgrade rules to 7.x-2.x-dev.
a lot time spend on dig the code and explain to client:(

rszrama’s picture

@zterry95 Understood, it's a frustrating part of depending on other contribs. We do try to communicate this sort of information in the header of our release notes, though, so I'd start there in the future.

roball’s picture

Rules 7.x-2.9 has just been released: "This release fixes an incompatibility of Rules 2.8 with Drupal commerce".

Can anybody confirm that it is fine to update from Rules 2.7 to 2.9, and Commerce continues to work fine?

mmtt’s picture

I'v done a fresh install of commerce, commerce_custom_product and rules-7.x-2.7. As josh i created somthink like "Customizable Product with Drupal Commerce: Pizza Store". Even i created the necessary rules to add the custom fees to the amount. But the price will not change in the cart.

Is there maybe something else to know beside the downgrading rules to get it to work?

bojanz’s picture

Title: Product pricing rules fail with Rules 7.x-2.8 [patch Rules or downgrade to 2.7] » Product pricing rules fail with Rules 7.x-2.8 [use Rules 2.7 or 2.9]
Status: Active » Fixed

Rules 2.9 was released, fixing the regression.

roball’s picture

Title: Product pricing rules fail with Rules 7.x-2.8 [use Rules 2.7 or 2.9] » Product pricing rules fail with Rules 7.x-2.8 [use Rules 2.9]
Version: 7.x-1.x-dev » 7.x-1.11

I just confirm that Rules 7.x-2.9 is working perfectly fine with Drupal commerce.

ShaneOnABike’s picture

I can also confirm that what a HUGE relief lordy!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.