Vote up!
Vote down!

Custom Line Item Loses commerce_unit_price and commerce_total

I'm working on commerce_layaway and running into an issue with my custom line_items. I've been using the commerce_shipping module as a base to work from.

I've added a new checkout page and pane. The current sequence of events is - Review cart, Shipping/Billing Information, Select Layaway option, Select Shipping option, Credit card information, Review, submit transaction.

When I select the layaway option I want to use, the commerce_line_item of type 'layaway' is created and has the commerce_unit_price and commerce_total price. At this point the line_item has been saved (which is why we have the commerce_total price on the line item). Moving on to the next step.

During the submission of the shipping pane form the following error occurs.

EntityMetadataWrapperException: Unable to get the data property currency_code
as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue()
(line 442 of /var/aegir/platforms/commerce-7.x-1.3/profiles/worxco/modules/

This occurs because when the commerce_order_calculate_total($order) function is called it loads up the order_wrapper and loops through each line item. It gets the pricing of the commerce_total and for some reason when it gets to my custom commerce_line_item of type 'layaway' the commerce_total and commerce_unit_price and no longer there. So the error from above is thrown because the currency_code can not be retrieved from the non-existing commerce_total.

Is there something special I'm supposed to do in order to retrieve my commerce_unit_price and commerce_total for my line_item? I've debugged the code and don't see where the shipping is loading extra data and yet it still has it's commerce_unit_price and commerce_total.

Asked by: fatguylaughing
on January 10, 2014

1 Answer

Vote up!
Vote down!

The implementation of hook_commerce_line_item_type_info() fixes this issue. Each custom line_item needs to be created via this hook. This will add the two fields commerce_unit_price and commerce_total to the line_item.

Answer by: fatguylaughing
Posted: Jan 13, 2014