I have a controller, from where I can send cart quantity. And I used ajax call to fetch data

], function($){
        url: "/mycart/cartcount",
        type: "POST",
        data: "",
        success: function (res) {

My question is, how can I get cart quantity in my controller?

  • As per as,your code, you do not send any parameters controller then how you get Cart Qty and Cart Item
    – Amit Bera
    Mar 1, 2019 at 7:39

1 Answer 1


You can't simply update the qty field in the quote_item table because there is lots of constrains that has.

  1. Validate requested qty exist or not?
  2. Is the product is In-Stock or not?
  3. Is the product enabled or not and so?

and yes you can update the quantity field in quote table.

Try this, add this in your controller and you need to get item_id and qty to update the specific field.

 namespace Vendor\Module\Controller\Index;                                
 class Save extends \Magento\Framework\App\Action\Action                      
  public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Quote\Api\CartRepositoryInterface $quote,
    array $data = []
  ) {
    $this->quoteRepository = $quote;
    parent::__construct($context, $data);
 public function execute()
    $item_id = '6';
    $qty = '10';
    $quote = $this->quoteRepository->getById($item_id);
    foreach ($quote->getItems() as $quoteItem) {
    return true;

Hope this will help you :)


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.