Magento – Quantity figure entered is being multiplied by itself at checkout

cartcheckoutquantity

(Further investigation showed that this bug was causing the quantity figure to be multiplied by itself which this question is updated with at the bottom as opposed to multipled by 10 as we initially thought when we raised this question).

Absolutely stumped on this one. Posting the quantity is multiplying the figure entered by 10 yet doesn't update the actual visible figure displayed in the field.

So if I updated the quantity on the checkout page from 10 to 50, Magento thinks that the quantity is 500 but still only shows 50. So this is resulting in lots of errors saying the product isn't available in the requested quantity… Therefore most customers cannot checkout.

Have spent an entire day testing this and trying to debug before I found this to be the problem.

I can't see any extensions overriding related functions or controllers. And the code for the qty input field and add to cart button appears to be the same as Magento's core. I've really got no idea where this is happening. It is multiplying by 10 every time, that figure doesn't vary.

We've also reverted to default theme and the same thing happens.

This is affecting both stores – I previously made a mistake in saying only store 2 was affected.

Please let me know any code you'd like to see or if you have any ideas to what might be causing this. Thanks in advance.

Edit 1: Adding sample / related code in use…

There is no checkout/cart overrides for the wholesale store so it falls back to what is in use for the retail (default) store.

/app/design/frontend/[package]/[theme]/template/checkout/cart.phtml

Quantity column:-

<th rowspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Qty') ?></th>

Is inside the form:-

<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">

In…

/app/design/frontend/[package]/[theme]/template/checkout/cart/item/default.phtml

The quantity field:-

<td class="a-center">
    <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="span1" maxlength="12" />
</td>

I don't see anything unusual with the above, further on from this, I think it will only use Magento core functions to update the quantity field? And we've just replaced the entire /app/code/core/Mage from a fresh download of Magento 1.7.

From a product view page, you can update the quantity and it successfully adds to cart, it is only once you view cart at /checkout/cart that Magento then decides to multiply the quantity field by 10.

What is affected:-

  • Both stores are affected.
  • Configurable products only (where associated products are added to cart).

Image of problem below…

cart qty error

Edit 2: Don't know if the stack trace gives anything of use?

2013-08-01T11:08:06+00:00 ERR (3): 
exception 'Mage_Core_Exception' with message 'Not all products are available in the requested quantity' in /var/www/vhosts/[domain]/httpdocs/app/Mage.php:594
Stack trace:
#0 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/CatalogInventory/Model/Stock.php(144): Mage::throwException('Not all product...')
#1 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/CatalogInventory/Model/Observer.php(602): Mage_CatalogInventory_Model_Stock->registerProductsSale(Array)
#2 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Core/Model/App.php(1338): Mage_CatalogInventory_Model_Observer->subtractQuoteInventory(Object(Varien_Event_Observer))
#3 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Fooman_AdvancedPromotions_Model_CatalogInventory_Observer), 'subtractQuoteIn...', Object(Varien_Event_Observer))
#4 /var/www/vhosts/[domain]/httpdocs/app/Mage.php(447): Mage_Core_Model_App->dispatchEvent('sales_model_ser...', Array)
#5 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Sales/Model/Service/Quote.php(187): Mage::dispatchEvent('sales_model_ser...', Array)
#6 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Sales/Model/Service/Quote.php(249): Mage_Sales_Model_Service_Quote->submitOrder()
#7 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Checkout/Model/Type/Onepage.php(774): Mage_Sales_Model_Service_Quote->submitAll()
#8 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Checkout/controllers/OnepageController.php(511): Mage_Checkout_Model_Type_Onepage->saveOrder()
#9 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Checkout_OnepageController->saveOrderAction()
#10 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('saveOrder')
#11 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#12 /var/www/vhosts/[domain]/httpdocs/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#13 /var/www/vhosts/[domain]/httpdocs/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#14 /var/www/vhosts/[domain]/httpdocs/wholesale/index.php(89): Mage::run('wholesale', 'store')
#15 {main}

Edit 3: Extending Mage_CatalogInventory_Model_Stock_Item

Please see this issue which could be related to the cause of this one. Reverting this change though does not make the problem go away. All sessions, cache etc cleared. This is driving us nuts.

Edit 4: Multiplied by itself not by 10…

Further investigation uncovers that the quantity figure is actually getting multipled by itself (as opposed to by 10 as originally claimed).

For example:-

  • entering 6 takes 36 off stock (6×6)
  • entering 10 takes 100 off stock as (10×10)
  • entering 3 takes 9 off stock as (3×3)

Illustrated below:-

Magento quantity field working

Magento quantity field not working

Magento stock levels that show that the above quantity orders should work

Quantity of 6 works, quantity of 7 doesn’t. 38 in stock. (6×6=36 below 38) works / (7×7=49 above 38) fails.

(Updated title of question to reflect new findings)…

Edit 5: We've also raised this as an issue at Magento's bug tracker

It definitely seems like a core Magento bug, we've exhausted every possible option and scenario having ripped the website to pieces and re-pieced it bit by bit, testing throughout the process. Issue just appears out of nowhere once the site is put together but remains if you revert back to default Magento core everything! (not got much hair left at the moment)… Link to issue in Magento Bug Tracker.

Edit 6: Customer Accounts / Shipping Methods

Issue seems very closely related to customer accounts and shipping methods. Will provide more issue when I have it…

Edit 7: This is now fixed, we've identified the bug – answer to follow shortly.

Best Answer

This sounds like a similar issue I had about a year ago.

The end result was the same as what you have: totals got doubled by qty (qty * qty)

The problem was tracked down to when customer address got added to the order object, it got added twice as delivery address. Thus the order object had 3 addresses:

  • 1 - Billing
  • 2 - Shipping
  • 3 - shipping (duplicate of #2)

I forget why this happened :( (I seem to recall an observer event doing something funky)

The same happened to the quote object (thus cart)

Since totals calculation hang directly off address objects, totals got doubled by qty.

An easy why to test if you are having the same issue, wipe out the sales_flat_order_address table, and enter checkout. Then check the table for address entries for your order. you should have 2 entries in there.

Additionally, since the issue is related to database entries, once the bug was fixed, it looked like the problem remained/was not fixed. It required removing the duplicates from the database for the problem to resolve for existing quote/order objects.

Related Topic