[![enter image description here][1]][1] [![enter image description here][2]][2] I'm working with Magento 2.2.3. I want to get the current cart items I want to control the cart items of current logged user when FPC is enabled.

In category page, I've added extra add to cart buttons(+, -) on only mobile view. After I login and go to category page, if they click + button, the product is added.

But if I refresh the page, the qty is disappeared. As you can see at the below code, I'm checking the current cart lists and if a product is in current cart list, input field shows qty.

But if I enable FPC, its not showing. After I clear the FPC and reload the page again, it shows the qty. I think this is because I'm not working with customer data(private content)

To make this working fine even FPC is enabled, how should I do this? Can I assign customerData.get('cart') to $cartlist? So maybe javascript value into php value? I am so wondering how I can run this properly.


 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $cartlist = $objectManager->create('\Magento\Checkout\Model\Session')->getQuote(); ?>



foreach ($cartlist->getAllItems() as $item) {


$productQty= $item->getQty();


    $productIdarr[]=$productId; ?>

<input type="button" value="-" data-id="<?php echo $_item->getId() ?>" id="subs_<?php echo $_item->getId() ?>" class="btn btn-default pull-left qtyminus" />

<input type="number"


id="qty_<?php echo $_item->getId() ?>"



value="<?php echo $productQty; ?>"

title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty"


<?php }?>

<?php  }?>

  [1]: https://i.stack.imgur.com/GtokE.png
  [2]: https://i.stack.imgur.com/CX09G.png

Your Answer

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

Browse other questions tagged or ask your own question.