Without activating cart and checkout module it doesn't seem to be possible to calculate tax and pricing rules for present line items, as the commerce_cart_order_refresh function handles the necessary logic.

As this function hardly interacts with commerce_cart specific functionality it would be great if we could move the function to commerce_line_item (or commerce_order), to remove the dependencies and enable scenarios in which orders are solely created by the administrator.

The idea is also related to and discussed in #1645252: Allow administrators to trigger "checkout completed"

CommentFileSizeAuthor
#4 1918978-4.pricing_rules_button.patch2.02 KBrszrama
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rszrama’s picture

Title: Move commerce_cart_order_refresh from cart to line item module » Allow administrators to trigger price calculation on an order

Sure we don't have a feature request open for this already? Or was it just part of that issue? If not, retitling, because just moving that function probably isn't the solution.

archnode’s picture

I'm sorry, I wasn't aware of any other similar issues. I guess my main point (while implementing a custom line item type) is, that it would be useful to have a commerce_order centric function that updates the prices of the individual line items of an order.
Maybe it would be feasible to extend the hook_commerce_line_item_type_info() to specify a function that gets called when the price of a line item should be (re)calculated, as you could make the order refresh function more generic and move the product_reference specific stuff to the line_item_type implementation. If that sounds reasonable to you and I haven't missed any major points I could take a stab at a patch.

Exploratus’s picture

+1

rszrama’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
2.02 KB

Patch attached, implemented as a local action on the core order edit form for non-cart orders.

rszrama’s picture

Related patch in #1645252-8: Allow administrators to trigger "checkout completed" for invoking checkout completion.

rszrama’s picture

Status: Needs review » Fixed

Committed with an update function to disable the new feature on existing sites while leaving it enabled for new sites.

Commit: http://drupalcode.org/project/commerce.git/commitdiff/ff0bebd

Status: Fixed » Needs work

The last submitted patch, 4: 1918978-4.pricing_rules_button.patch, failed testing.

rszrama’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

rajmataj’s picture

Priority: Normal » Major
Status: Closed (fixed) » Active

I have to re-open this because ever since upgrading Drupal Commerce to the latest stable version, tax is no longer being calculated on the Add an Order page. Without this feature, my clients cannot process their orders which is causing major headaches and grief.

This used to work perfectly with http://drupal.org/project/commerce_checkout_admin but that module's page now says this is handled in Commerce Core. How?

Any help with this is highly appreciated. Thanks.

rszrama’s picture

Priority: Major » Normal
Status: Active » Closed (fixed)

I'm not sure what you mean. If you create an order with line items and addresses, save it, and then click the button to apply pricing rules to the order, it's going to calculate taxes just fine.

maxplus’s picture

Hi Ryan,
both raimataj and you are correct.

Before Commerce 1.9, an order in the cart state calculated its taxes automatic on a line item.
So I told my clients always to keep working in the Cart state until they are ready and at the final stage move the order to a complete or pending state.
Working like that always calculated taxes immediately.

Now in Commerce 1.9, there is a new button to apply the pricing rules manually and it works, but when using the order admin screen to create orders manually you always have to press this button else there is no tax calculated by default when adding a new line item. Also not when being the the cart state.

So for some kind of reason the "calculate the sell price of a product" is not running when creating line items using the order admin screen.

rajmataj’s picture

Thanks Maxplus,

What has happened for me is that I've had a Commerce Kickstart website for about a year now, and which has had regular updates as newer Kickstart versions have come out. To calculate taxes on the Add an Order page, I had to use the Commerce Checkout Admin which worked well and without any problems. Commerce Core as of version 1.9 was stated to incorporate these buttons, so after disabling Commerce Checkout Admin and updating to Commerce Core 1.9 that's part of Kickstart, the action buttons there do nothing to calculate tax.

I have no custom modules on the site, so everything has been kept tidy and yet after updating, I've lost this ability to have taxes calculated on the Add an Order page, while at the same time, it works fine for a front-end user going through a normal check-out process. So, it appears something has gone awry for the updating process of Commerce Kickstart.

Ryan, if there is any other info I can provide, or if you'd like access to the live site, please let me know. I've seen other posts on Stackexchange regarding the same question so I can't be the only person experiencing this.

Thanks.

rszrama’s picture

@maxplus Yeah, that's working as designed. The problem is it's still a strange combination of "front end pricing" vs. "administrator pricing." I'm not happy with it, but basically if you use the form to apply pricing rules, it's going to disrupt any custom pricing you've applied to an order. We need a better solution, but at the moment it's the best we have. : (

maxplus’s picture

@rajmataj
I'm sure you just have to enable the new buttons to be able to apply the pricing rules: please visit "admin/commerce/config/order" and check this checkbox:
=> "Enable the local action link on order edit forms to apply pricing rules"
Only now you will see the new button at the top of your order edit screen when the order is NOT in the shopping cart state anymore
(Even if enabled the link will not appear on shopping cart order edit forms.)

You could also enable the second checkbox on the "admin/commerce/config/order":
=> "Enable the local action link on order edit forms to simulate checkout completion"
Sometimes this is also handy if you want to send mails to the client or other rules that had to be fired during the checkout progress.

@rszrama
Are you saying that even a store administrator should better work in some kind of "admin frontend version" to administer orders or manually create new orders for clients?
If working in the frontend is better for all the pricing Rules and other stuff, maybe I should create some kind of frontend order admin pages.
It could make more sense because also for stock management, creating orders in the order admin screen is also not a good thing I think.
Also when using for example the Registration module in combination of Commerce for an event registration system, there is no admin backend way to properly administer these registrations in combination with there line items...
So going more the frontend way for an administrator could indeed solve some issues at the moment...

rajmataj’s picture

Thanks for the feedback but both [blue] buttons are indeed activated but unfortunately do not calculate the tax. This has essentially prevented the store from being able to create any manual orders - resulting in a lot of frustration for the store managers.

Iceabenezer’s picture

Does anyone know how to check the "run pricing rules when this order is saved" value as TRUE by default? Every time my staff creates an order on the admin side, they have to remember to check this, and there's no harm that I can see in having it always checked for my use case. Thanks in advance!

marcus178’s picture

The Apply pricing rules button works fine, but there really needs to be a way to this using rules as it seems an unnecessary process to have to remember to click the button. The same goes for checkout completion.

If rules were available you'd have the option to have manual button or to automate it using rules depending on your needs.

rszrama’s picture

The philosophy of Commerce 1.x is you can easily create those rules yourself. I don't think there's a generic rules based solution I'd want to put into core.

marcus178’s picture

Would you have to code your own rules then? As I think the issue most people have is there isn't a condition for admin created orders nor is there an action to trigger the pricing rules. From my understanding pricing rules only work with the status set to shopping cart.

Iceabenezer’s picture

This is exactly the problem. Pricing rules actions only get triggered when the status is shopping cart. Admin only rules are easy enough to make, but if I'm saving existing orders or making new ones that are not shopping carts, the current pricing rule will not fire.

Iceabenezer’s picture

Any thoughts about this one? Still waiting to be able to use this as a default selection. Thanks!

calbasi’s picture

I've used "Apply pricing rules" button and it apply VAT tax and a simple product discount created with Commerce Discount module. But what if my discount just apply some users, with a "user custom field" set to a value (for example: "40% b2b discount").
Rules selectors use "current cart user", not "order owner". And "order owner" selectors let select "by role", but not "custom fields".
I suppose I can assign a role depending of user custom field, but it's not my best desired approach (using roles just for this)

calbasi’s picture

I'm soory, I think I get it using rules "entity has field", and, there, selector:
commerce-line-item:order:owner
After it, I use "data comparison":
"commerce-line-item:order:owner:my_custom_field"