Not sure if I should post this here or in the Inline Entity Form.

When creating an order through the admin order interface, the Inline Entity Form works great for adding line items with extra fields attached (in our case, adding a child's name and birthday to a class registration). The problem I'm having is that when we edit an order line item with Inline Entity Form enabled and change the price (for example, to manually add a discount before completing a pre-authed credit card payment), the order total isn't getting updated. It updates the price on the edit screen, but not the order view or payment pages.

So for now I have to enable Inline Entity Form when creating an order, but disable it if I have to edit the price of a line item. I'm not sure where to start to fix this. I know it was happening before in an earlier version of Commerce (http://drupal.org/node/1124414), but I don't have the skill to apply the same changes to make the Inline Entity Form editing work.

Any pointers or help would be appreciated!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rszrama’s picture

Project: Commerce Core » Inline Entity Form
Component: Price » Code

I'd say it should go in IEF, though saving an order should cause the order total to be recalculated. The thing is that order total calculation depends on the summation of all line item total price components, not just the addition of price field amount columns as a direct edit would perform. This means IEF needs to be able to create a price component inside these line items when a price is adjusted to reflect the difference or else recalculate the price component arrays from scratch whenever saving with a manually edited price.

mariagwyn’s picture

I will test whatever version you guys decide on, and think will continue to receive support. Just let me know what you need from me. I can test, but I am not a coder.

mariagwyn’s picture

I am using Using Commerce 7.x-1.3, Customizable Products 7.x-1.0-beta1, inline entity 7.x-1.0-beta3 (I can move to dev if that helps testing).

On the user order form, everything works fine. On the admin-entered order form, I have the following problems:

1. The price for the sku is not entered automatically. This is an inconvenience, but for some of the site members, this will be a source of great frustration (low tech users).
2. The form does not calculate the price AT ALL. So, even if I manually enter amounts, which show in unit price and the line-item total, the final total is not calculated at all. This is true for both new orders and edited orders. Note that this is true if I edit or create a new order, and it remains true even after I save the order: https://skitch.com/mariagwyn/efkmg/orders-the-orthodox-theological-socie.... Note this screenshot is of an order that was newly created, saved, edited, and saved. Neither price seems to be totaled.

My site will have at least half of its orders added by a treasurer, so I am eager to help with a solution, though my abilities are limited to testing and breaking things.

Maria

cjgriffin’s picture

Hi Maria,

The price not updating issue on order creation is due to Commerce, not Inline Entity Form. If you want to update the prices on order creation, you have to set the order status to one the has 'cart' => TRUE. Try editing an order and change the status to 'Shopping cart' and save the order. It should fire the product pricing rules and update the prices. For our workflow I created (through code) and order status ('Admin order') with 'cart' => TRUE that I set the order status to when an admin creates a new order (I do it with Rules because Commerce defaults to Pending when an order is created by an admin and I couldn't seem to override it). This is still one area where Commerce is a little clunky compared to Ubercart IMHO.

When you edit an order with Inline Entity Form disabled and change the price of a line item, the order total will be updated. Unfortunately when you change the price of a line item with Inline Entity Form enabled, it doesn't update the order total.

fago’s picture

Project: Inline Entity Form » Commerce Core
Component: Code » Order

I'm not sure how that should be covered by IEF, it's not up to IEF to know where it gets used. Instead I guess the order module should care about possibly needed order total recalculations if a line item of the order gets its price changed.

Moving back to Drupal Commerce queue for re-consideration.

rszrama’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

Honestly, I'm not sure what the issue is here I guess. My first impulse was to move it to IEF because that module does make special accommodation for line items that I assumed could be interfering with the normal order total calculation process. Additionally, I don't experience any issues adding line items and adjusting their prices on the create order form without IEF. I just added a $10 product to a new order, changed it to $17, and saved the order. Voila, my order total was $17.

The issue with cart based recalculation seems like a red herring to me.

Perhaps we can get a recap of what the base problem is and how to reproduce it. If reproducing it isn't possible without IEF, then we should move this back to its queue. And I need to know if you're talking about manual adjustments of line item prices or expecting pricing rules to fire (which do depend on the cart statuses).

cjgriffin’s picture

Category: support » bug
Status: Postponed (maintainer needs more info) » Active

This issue has nothing to do with pricing rules firing, but with manual adjustment of line item prices. I was just trying to help Maria with that (completely) separate issue.

Recap:
In order to create line items with customizable fields through the back-end by an admin (telephone order, in-person order), Inline Entity Form needs to be enabled (and the line-item reference field on the order needs to be set to use it). On order creation, everything works... prices are calculated properly.

When adjusting the price of a line item with Inline Entity Form when editing an order, the order total doesn't get re-calculated. The price changes on the line-item on the edit screen, but on the view or payment screen the total doesn't get updated to the changed value. Like Ryan mentioned, this works when editing the price of a line item without using Inline Entity Form; the order total gets updated properly. But with Inline Entity Form, it doesn't.

I've been playing around with the Commerce Kickstart beta and noticed that this also applies to discount line items. Without Inline Entity Form, you can add a fixed-amount discount to an order and the order total is updated to reflect the discount. With Inline Entity Form, the order total isn't updated to reflect the discount.

To reproduce:
Go to "admin/commerce/config/order/fields/commerce_line_items/widget-type" and change the widget to Inline entity form (from Line item manager).
Edit an order. Click Edit on a line item in the order, change the unit price of the line item, and save the line item. Save the order. View the order. The order total will be the same as it was before the edit, and won't reflect the updated line-item price.

I hope this clears things up!

rszrama’s picture

Project: Commerce Core » Inline Entity Form
Component: Order » Code

Moving this to IEF's queue, then. I suppose we'll need to determine why the order total isn't being recalculated on save, but that only seems possible if you're editing the line item via the inline form and not saving the order form itself. In that case, I'm not sure why the line item data would be changing. Maybe it's a cart / horse thing - perhaps the order is being saved first and then the line items are being saved for some reason.

mariagwyn’s picture

cjgriffin, sorry for the silence, I got distracted by other projects.

Just so you know, I am a very novice commerce user, this is my first commerce site. I seem to be stuck between rock and, well, ...you get it. Here is the situation:

I have a product, 'membership' that gives registrants the option of selecting a journal subscription. It is just a radio field. It works fine when a user creates the order, etc. However, many members will send in their order via snail mail. So, an admin must enter the order on the site. Here are the problems:

IF the widget is LINE ITEM MANAGER:
The sku is entered, the price is correctly entered
BUT no option to choose the subscription. This is a problem.

IF the widget is IEF,
Able to choose subscription as a part of adding a line item.
BUT price is not calculated correctly. Note that this is NOT the result cgriffin describes in his recap. It is not a problem just with editing prices, but creating the order in the first place.

My preference is to use IEF since, if I understand correctly, it is IEF that will be maintained. So, cgriffin, can you share the rule you created to 'trick' commerce into think that admin orders are 'cart' orders? I get the idea, but I have no idea where to begin actually construction such a rule.

Thanks,
Maria

cjgriffin’s picture

Hi Maria,

I've changed from using a rule to set the status to using a sandbox module that adds a checkbox to run the product pricing rules when creating an order: http://drupal.org/sandbox/klausi/1645238.

To make it easier for our site admins (so they wouldn't have to remember to check the checkbox each time they create an order), I added a hook_form_alter function to a custom module to make the checkboxes checked by default on order creation:

  function my_module_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
      case 'commerce_order_ui_order_form':
        if ($form['order_history']['created']['#value'] == '') {
          $form['order_status']['complete']['#default_value'] = 1;
          $form['order_status']['pricing']['#default_value'] = 1;
        }
      break;
    }
  }

Hope this helps!

Chris

cjgriffin’s picture

Hi Ryan,

I've managed to rebase the unit price of line items that are edited, but I'm still having trouble getting the total to update. Do you have any hints / ideas where I should look in order to figure this out? I thought that rebasing the line items might solve the issue, but it seems to be only a piece of the puzzle.

Thanks!

Chris

jpstrikesback’s picture

The http://drupal.org/project/commerce_checkout_admin module (was a sandbox now full fledged) sorts this for now in my scenario. Thanks Chris!!

JulienF’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc1

Hello Everyone,

I experienced the same issue when usuing this widget (awesome widget by the way).

And I just updated to the latest version (1.0 rc1) with the hope of seeing it solved, with no luck. I dove into the code and found the problem.

It is in the hook_field_attach_submit where the line items are being saved that the pb occur.

Starting Line 1115

foreach ($values['entities'] as $item) {
        if ($item['needs_save']) {
          $controller->save($item['entity'], $context);
        }
        $entity_ids[] = array($values['settings']['column'] => entity_id($entity_type, $item['entity']));
      }

You simply need to add a call to the commerce_line_item_rebase_unit_price($item); just before the $controller->save(...) one

Of course this will make the module "un-update-able" and it would be great if this fix (after review and eventual optimization) could be added to the module.

Thanks

cjgriffin’s picture

Version: 7.x-1.0-rc1 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
692 bytes

Yay, Julien is smarter than me!
I've created a patch incorporating his fix. I also added a check to make sure the line item belongs to a commerce order (not sure if the fix would effect other entity types).

JulienF’s picture

:) Thanks Chris,

I actually needed this functionnality hard and I have to comply with specific performance constraints.

By the way, I would gladly help on improving some parts of this module. For instance I would need to output multiple entity types for a same field (line_items field with different line item types: Products, shipping, bundle products etc...) and I would like to have different tables for each entity type with their own custom header fields. For now the fastest way I thought about for this is to put all the fields definition in the defaultFields() controller method and then perform conditionnal outputs in the theme function. Probably not the cleanest way to go but time isn't my friend on that one... Shall I go ahead and work on this alone ?

bojanz’s picture

I'm not sure what you mean, JulienF.
The line items example you gave is about showing different bundles (which we already support), not different entity types.
But if you're showing different bundles (or even entity types), then you must have one common header for all of them, no?

JulienF’s picture

Hello Bojanz,

Actually right now I have the following line item types:
- Single Product
- Shipping
- Bundle Product

All have custom fields and I want to add some of those fields in the table header to show some more info than the regular ones.

For instance
- On the single product I would like to show the following added fields: - Cost, -Dimensions, -Color, etc...
- On the Shipping I would like to show the following: -Cost

I don't mind having a Dimension and color field in the header of the table with empty fields for the shipping line items.

Right now, if I add the "Dimensions" field in the defaultField method, I get an error whenever I have an order with a Shipping Line item as this field doesn't exist for this specific bundle.

bojanz’s picture

Status: Needs review » Fixed
cjgriffin’s picture

Thanks for putting it in the right spot, bojanz! And thanks for the module!

Status: Fixed » Closed (fixed)

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