0

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 '17 at 9:52
  • yes. I use this to show minicart. But question is about how to mark last added product in minicart? – Serhii Ziukov May 24 '17 at 11:13
0

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;
}  

$productID=$this->_checkoutSession->getLastAddedProductId(true);
echo $productID."<br>";  
  • This doesn't work if I add again product that already is in cart, it will get wrong product by getLastAddedProductId. – Serhii Ziukov May 26 '17 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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