cancel
Showing results for 
Search instead for 
Did you mean: 

Magento Add to cart qty greater than stock total

Magento Add to cart qty greater than stock total

Hello all,

 

I've been having a problem with my 'add to cart' button and therefore my checkout.

 

If a customer tries to add more of a product than the current stock level to the cart, it simply lets them do it.

I've got the inventory set to 'Do not allow backorders', 'Reduce stock when order is placed', and use Finale Inventory to manage stock levels.

 

 

This is the code,

                    <p><strong><?php if($onSale):?>
                        <p class="on-sale-tag">
                            <?php if($saleText):?>
                                <?php echo $saleText;?>
                            <?php else:?>
                                Save $<?php echo number_format($valueSaved, 2);?>
                            <?php endif;?>
                        </p>
                    <?php endif;?>
                    <?php if ($_product->isSaleable() && $this->hasOptions()):?>
                        <div class="configurable-options">
                            <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
                        </div>
                    <?php elseif ($_product->isAvailable()): ?>
                        <div class="prod__add-to">
                            <?php echo $this->getChildHtml('addtocart'); ?>
                        </div>
                    <?php endif;?>
                    <?php else:?>
                        <div class="prod__add-to">
                        </div>
                    <?php endif;?></strong></p>

I'd like for it to somehow check if the amount being added to the cart is greater than the amount in stock, and if so not add it.

 

 

if 'qty added' <= 'qty in stock' then 'addtocart'

else do nothing/error message.

 

If there is a better way to do this, or anyone knows why it is happening, that would also be great. (I think it must be an extension, but I have no idea which).

 

 

Thank you for your time,

Jacob

3 REPLIES 3

Re: Magento Add to cart qty greater than stock total

Hi Jacob,
Magento default shows below error whe you add to cart qty greater than stocl level

"The requested quantity for product is not available."


its comes from below file path:- app/code/core/Mage/CatalogInventory/Model/Stock/Item.php
refer link:-http://www.demacmedia.com/magento-commerce/mini-tutorial-how-to-set-ordered-quantity-to-quantity-on-...

Re: Magento Add to cart qty greater than stock total

I tried switching out the code suggested by that article, it didn't seem to do anything even after clearing both caches.

Is there something I would need to do to cause the code to start working?(as in waiting or indexing)

 

Otherwise, the code that is already in 'app/code/core/Mage/CatalogInventory/Model/Stock/Item.php' isn't showing a message when I add too many of something, despite the code being what the article said it should have been.

 

Is it possible my Magento is having trouble pulling qty?

Re: Magento Add to cart qty greater than stock total

Are you editing core code directly or creating local overrides?

-Kris
4x Certified, Blogger @ xgento.com