function dc_ajax_add_cart_get_last_line_item_wrapper in Commerce Ajax Add to Cart 7.2
Returns the last line item that was added to cart.
Parameters
object $line_items_wrapper: Entity list wrapper of line items.
Return value
object The last line item.
1 call to dc_ajax_add_cart_get_last_line_item_wrapper()
- dc_ajax_add_cart_ajax_cart_form in ./
dc_ajax_add_cart.module - AJAX-ify the product add to cart.
File
- ./
dc_ajax_add_cart.module, line 893 - Ajax add to cart module.
Code
function dc_ajax_add_cart_get_last_line_item_wrapper($line_items_wrapper) {
$line_items = dc_ajax_add_cart_filter_commerce_line_item_by_commerce_product($line_items_wrapper
->value());
$changed = 0;
// By default it will return the last line item in the array.
$keys = array_keys($line_items);
$last_changed_key = end($keys);
foreach ($line_items as $key => $line_item) {
if ($line_item->changed >= $changed) {
$last_changed_key = $key;
$changed = $line_item->changed;
}
}
return $line_items[$last_changed_key];
}