After product is added to cart, I want to open minicart and mark it with some styles. I found http://magento.stackexchange.com/questions/141507/magento-2-open-minicart-when-item-is-added how to open it. But dont know how to get last added.

  • Did u try this: magento.stackexchange.com/questions/123329/… (pinicio's answer)...This works on the last item added to cart, ie) recently added item will pop up. i tried its working
    – Sushivam
    May 24, 2017 at 9:52
  • yes. I use this to show minicart. But question is about how to mark last added product in minicart? May 24, 2017 at 11:13

1 Answer 1


I havent tried it out, just to give you a picture. you can try this out in your block:

This is to get the last product item added to cart.

public function __construct(
    \Magento\Checkout\Model\Session $checkoutSession,
    array $data = []
 ) {
    $this->_checkoutSession = $checkoutSession;

echo $productID."<br>";  
  • This doesn't work if I add again product that already is in cart, it will get wrong product by getLastAddedProductId. May 26, 2017 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.