Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Canceling orders after item quantity hits 0 doesn’t work properly, status won’t change back? 
 
MageParts
Guru
 
Avatar
Total Posts:  415
Joined:  2007-11-18
 

Yo, I’ve tried to order some stuffs with paypal in a test shop I’m setting up for a client. After placing one order I tried to remove it, went great except for the fact that the items in the order didn’t seem to return to the stock. Is there some option I will have to fill in or is this a bugg that I’ll have to fix?

 
Magento Community Magento Community
Magento Community
Magento Community
 
7th SENSE new media GmbH
Jr. Member
 
Avatar
Total Posts:  25
Joined:  2008-04-03
Reutlingen, Germany
 

Hi,

have you finsh the order process and canceld the new order in the backend?

i have noticed an other problem with paypal standard. in the order process, i canceld the paypal billing and went back to the shop (still with my items in there). when i take a look at the backend, there is a new order with paypal. can you reproduce it?

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageParts
Guru
 
Avatar
Total Posts:  415
Joined:  2007-11-18
 

hehe, I just noticed that this problem also occours when you order with any other payment method, just tested ordering with flat rate and then canceling the order. Same issue, the items are infact returned to the stock, but they are set to “Not in stock” when the quantity hits 0. The status is not being changed back to “In stock” after an order has been cancelled. I’ll try to fix it and post an updated version of the core file incase no one has a better solution for this problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageParts
Guru
 
Avatar
Total Posts:  415
Joined:  2007-11-18
 

@7thSENSE.DE, I will to reproduce the error you mentioned later, I’ll take care of the stock issue first.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageParts
Guru
 
Avatar
Total Posts:  415
Joined:  2007-11-18
 

SOLVED

Finally solved this after a couple of hours rasberry

File: app/code/core/Mage/CatalogInventroy/Model/Stock.php

Change the following function (round line 105) from

public function backItemQty($productId$qty)
    
{
        $stockItem 
Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
        if (
$stockItem->getId()) {
            $stockItem
->addQty($qty)
                ->
save();
         
}
        
return $this;
    
}

to

public function backItemQty($productId$qty)
    
{
        $stockItem 
Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
        if (
$stockItem->getId()) {
            $stockItem
->addQty($qty)
                ->
save();
                
            
$product Mage::getModel('catalog/product');
            
$read $product->getResource()->getWriteConnection();
            
$read->query'UPDATE cataloginventory_stock_item SET `is_in_stock` = 1 WHERE `product_id` = '.$stockItem->getId() ); 
        
}
        
return $this;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

sorry, cant see any differences smile!

Cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michae1
Enthusiast
 
Total Posts:  826
Joined:  2007-08-31
 

It depends on what Magento version you have.
1.1 has a separate configuration setting “Set Items’ Status to be In Stock When Order is Cancelled” and the following code:

app/code/core/Mage/CatalogInventory/Model/Stock/Item.php:

class Mage_CatalogInventory_Model_Stock_Item extends Mage_Core_Model_Abstract
{
...
    const 
XML_PATH_CAN_BACK_IN_STOCK    'cataloginventory/options/can_back_in_stock';
...
    public function 
getCanBackInStock()
    
{
        
return Mage::getStoreConfigFlag(self::XML_PATH_CAN_BACK_IN_STOCK);
    
}
....
}

app/code/core/Mage/CatalogInventory/Model/Stock.php:

class Mage_CatalogInventory_Model_Stock extends Mage_Core_Model_Abstract
{
...
    public function 
backItemQty($productId$qty)
    
{
        $stockItem 
Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
        if (
$stockItem->getId()) {
            $stockItem
->addQty($qty);
            
/**
             * get back in stock (when order is canceled or whatever else)
             */
            
if ($stockItem->getCanBackInStock() && $stockItem->getQty() > $stockItem->getMinQty()) {
                $stockItem
->setIsInStock(true);
            
}
            $stockItem
->save();
        
}
        
return $this;
    
}
...
}

app/code/core/Mage/CatalogInventory/etc/system.xml:

<can_back_in_stock translate="label">
    <
label>Set Items' Status to be In Stock When Order is Cancelled</label>
    <frontend_type>select</frontend_type>
    <source_model>adminhtml/system_config_source_yesno</source_model>
    <sort_order>2</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</can_back_in_stock>
 
Magento Community Magento Community
Magento Community
Magento Community
 
evL
Member
 
Total Posts:  32
Joined:  2008-04-23
 

Damnnnn thanks for the fix!

Was trying to do the same thing, but that code is cleaner smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top