Because the line_items were concatenated,
the last added item doesn't have to be the item the message was shown.
So I chose to take the last changed item instead. Because I did not use git on the machine, here is the src code from line 880 following in dc_ajax_add_cart.module:
/**
* Returns the last line item that was changed to cart.
*
* @param object $line_items_wrapper
* Entity list wrapper of line items.
*
* @return object
* The last line item.
*/
function dc_ajax_add_cart_get_last_line_item_wrapper($line_items_wrapper) {
$result = $line_items_wrapper->value();
$changed = 0;
foreach ($result as $key => $value) {
if($value->changed > $changed){
$last_changed_key = $key;
$changed = $value->changed;
}
}
return $result[$last_changed_key];
}
Comments
Comment #2
maen commentedComment #3
subhojit777The logic to get the last line item is nice. But I would like to replicate the problem on my end. What do you mean by Because the line_items were concatenated?
Comment #4
subhojit777Comment #5
maen commentedI use Commerce Customizable Products to have line item fields in the product form. When I add the exact same product multiple times to cart they were gathered in 1 line item. So I do not see the last added product, instead I see the last product which was added with a different price.
For example:
I buy 1 white shirt -> 3 $. -> correct display.
I buy 1 black shirt -> 4 $. -> correct display.
I buy 1 white shirt-> 3 $. -> shows the black shirt in the pop-up display. -> wrong!
That's it.
The db table "commerce_line_item" sets the quantity from 1 to 2.
Comment #6
stockticker commentedGot a similar issue, when ajax pop-up message showed wrong items (not that products, where 'add to cart' button was pressed on).
However, piece of code, that maen provided - worked like a charm.
Many thanks!
Comment #7
subhojit777Comment #9
subhojit777