At checkout is it possible to retrieve the pricing components for individual line items? For instance I am looking for the list price, discount amounts (if any), what taxes were applied (if any), and the final price. Looking at the order object I have those components for the order as a whole, but not for the individual line items.

Many thanks!

Comments

rszrama’s picture

Status: Active » Fixed

The components for the individual items would be in each line item's "Total" price field data array. The "Order total" field on the order is simply calculated by summing up all these "Total" fields.

fp’s picture

@Beanjammin:

I think you are saying that you want the line items per product. If so, I think you can access them this way:

function hook_commerce_cart_order_refresh($order_wrapper) {              
  $data = $order_wrapper->getIterator()->current()->value();             
}  
beanjammin’s picture

Thank-you both for your quick response. I will post back after I have tried this out.

beanjammin’s picture

Status: Fixed » Active

There must be something I am missing, explaining poorly, or perhaps I am trying to access the order information incorrectly.

I am looking for details on the individual items in the order after payment has gone through. For instance, I would like to know how many of each item there are, the amounts of any discounts per item, the amounts of any taxes per item, and the list price per item. The purpose is to update a POS system used for inventory management and accounting.

I am using hook_commerce_payment_order_paid_in_full($transaction) and looking at $transaction I see what follows below, which is for a cart with 3 items in it, of which one has the quantity set to 3 and the other two have a quantity of 1. There is a discount on all items and varying tax rates. Based on rszrama's response I was expecting more information in the commerce_line_items array. I have searched the commerce api for a function that would either load the order as a whole or the individual line items, but have not found what I am after.

From my reading it seems that hook_commerce_cart_order_refresh (mentioned in #2) is for refreshing the information in the cart, not for accessing the details of the line items.

Pointers in the right direction would be much appreciated.

stdClass Object
(
    [order_number] => 12
    [revision_id] => 73
    [revision_uid] => 4
    [mail] => me@here.com
    [status] => checkout_review
    [log] => Customer continued to the next checkout page via a submit button.
    [revision_timestamp] => 1332369616
    [revision_hostname] => 127.0.0.1
    [data] => Array
        (
            [payment_method] => commerce_payment_example|commerce_payment_commerce_payment_example
            [commerce_payment_example] => Array
                (
                    [name] => asdf
                )

        )

    [order_id] => 12
    [type] => commerce_order
    [uid] => 4
    [created] => 1332369467
    [changed] => 1332369616
    [hostname] => 127.0.0.1
    [commerce_line_items] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [line_item_id] => 24
                        )

                    [1] => Array
                        (
                            [line_item_id] => 25
                        )

                    [2] => Array
                        (
                            [line_item_id] => 26
                        )

                )

        )

    [commerce_order_total] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [amount] => 6246
                            [currency_code] => CAD
                            [data] => Array
                                (
                                    [components] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [name] => base_price
                                                    [price] => Array
                                                        (
                                                            [amount] => 7349
                                                            [currency_code] => CAD
                                                            [data] => Array
                                                                (
                                                                )

                                                        )

                                                    [included] => 1
                                                )

                                            [1] => Array
                                                (
                                                    [name] => tax|gst
                                                    [price] => Array
                                                        (
                                                            [amount] => 367.45
                                                            [currency_code] => CAD
                                                            [data] => Array
                                                                (
                                                                    [tax_rate] => Array
                                                                        (
                                                                            [name] => gst
                                                                            [display_title] => 5% Tax
                                                                            [description] => 
                                                                            [rate] => 0.05
                                                                            [type] => sales_tax
                                                                            [rules_component] => commerce_tax_rate_gst
                                                                            [default_rules_component] => 1
                                                                            [price_component] => tax|gst
                                                                            [calculation_callback] => commerce_tax_rate_calculate
                                                                            [module] => commerce_tax_ui
                                                                            [title] => 5% Tax
                                                                            [admin_list] => 1
                                                                        )

                                                                )

                                                        )

                                                    [included] => 
                                                )

                                            [2] => Array
                                                (
                                                    [name] => discount
                                                    [price] => Array
                                                        (
                                                            [amount] => -1470
                                                            [currency_code] => CAD
                                                            [data] => Array
                                                                (
                                                                )

                                                        )

                                                    [included] => 1
                                                )

                                        )

                                )

                        )

                )

        )

    [commerce_customer_billing] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [profile_id] => 8
                        )

                )

        )

    [rdf_mapping] => Array
        (
        )

)
beanjammin’s picture

Title: Price components for individual line items? » [SOLVED] Price components for individual line items?

Of course the "D'oh!" moment came mere minutes after posting the above.

It seems the details shown in $transaction are from the commerce_order entity and to get the line item details you need to load the commerce_line_item entity. The following loads the line item details for the first line item in the order above:

$line_item_details = entity_load('commerce_line_item', array(24));

Thanks for your time rszrama and fp!

beanjammin’s picture

Status: Active » Fixed

And now marked as fixed...

Status: Fixed » Closed (fixed)

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