I am using a module for rounding which adds rounding line item each time a product is added to cart. Currently this module expects that the last line item is a product which is false in this case. That results in incorrect / incomplete message displayed and couple of notices.

I think it should be changed to include only product type line items. Here is how I changed it for my use.

function dc_ajax_add_cart_get_last_line_item_wrapper($line_items_wrapper) {
  $product_types = commerce_product_types();
  foreach ($line_items_wrapper->value() as $line_item) {
    if (in_array($line_item->type, array_keys($product_types))) {
      $last_line_item = $line_item;
    }
  }
  return $last_line_item;
}

Comments

Neo13 created an issue. See original summary.

subhojit777’s picture

Status: Active » Postponed (maintainer needs more info)

Which module you are using for the rounding line item?

Neo13’s picture

Status: Postponed (maintainer needs more info) » Active
subhojit777’s picture

Assigned: Unassigned » subhojit777

  • subhojit777 committed 50f0a53 on 7.x-2.x authored by Neo13
    Issue #2913356 by Neo13, subhojit777: Do not expect that last line item...
subhojit777’s picture

Status: Active » Fixed
subhojit777’s picture

Thanks.

Status: Fixed » Closed (fixed)

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

ordermind’s picture

Oh, I'm so glad you fixed this. I also have a case where the last item is not always a product but I thought it would be too edge-case to be able to expect an official fix. Thanks!