Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:49:33+00:00 2026-06-14T08:49:33+00:00

I am trying to remove just one qty from my cart rather than all,

  • 0

I am trying to remove just one qty from my cart rather than all, but to no avail.

Can anybody help?

Here is the code I have got so far…

require_once 'app/Mage.php';
Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");

$yourProId = $_POST['prodID'];
$qty = 1;

foreach (Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item) {
    if ($yourProId == $item->getProductId()) {
        Mage::getSingleton('checkout/cart')->removeItem($item->getId())->save();
    }
}

UPDATE: Here is the code that works, thanks to R.S. for this!

$yourProId = $_POST['prodID']; 
$qty=1; 

$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item) {
if ($item->getProduct()->getId() == $yourProId) {
    $qty = $item->getQty() - 1; // check if greater then 0 or set it to what you want
    if($qty == 0) {
        Mage::getSingleton('checkout/cart')->removeItem($item->getId());    
    } else {
            $item->setQty($qty);
        }
        $cartHelper->getCart()->save();
        break;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:49:34+00:00Added an answer on June 14, 2026 at 8:49 am

    Try

    $cartHelper = Mage::helper('checkout/cart');
    $items = $cartHelper->getCart()->getItems();
    foreach ($items as $item) {
        if ($item->getProduct()->getId() == $yourProId) {
            if( $item->getQty() == 1 ){
                $cartHelper->getCart()->removeItem($item->getItemId())->save();
            }
            else if($item->getQty() > 1){
                $item->setQty($item->getQty() - 1)
                $cartHelper->getCart()->save();
            }
            break;
        }
    }
    

    Take a look @ /app/code/core/Mage/Checkout/controllers/CartController.php

    See http://www.magentocommerce.com/boards/viewthread/30113/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to remove nodes from an XML file. Using just one XSLT
I'm trying to remove wiki formatting from some text so it can be parsed.
I am trying to remove all references to a table from a Crystal XI
i'm trying to remove a child node from an xml. my script is working..but
In FluentAssertions I can use the AllProperties.But(obj => obj.property_I_do_not_want) to remove specific properties from
I am trying to remove an object from an array, but for some reason
I am trying to remove the actual box of a checkbox field, and just
I am trying to add/remove UILabels to a ScrollView. The adding takes place just
I'm trying to remove scrollbar from my facebook app. I tried js solution, that
I'm trying to remove a specific graph object from the zedgraph, is it possible....?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.