Created
November 21, 2016 10:30
-
-
Save schmengler/fe4048c309d9b7e0704ce38a0f0adc67 to your computer and use it in GitHub Desktop.
Magento1 Stock Model Rewrite to add events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add events to observe stock qty change | |
* | |
* @author Fabian Schmengler | |
* | |
*/ | |
class SGH_ShippingExpress_Model_CatalogInventory_Stock | |
extends Mage_CatalogInventory_Model_Stock | |
{ | |
const EVENT_CORRECT_STOCK_ITEMS_QTY_BEFORE = 'cataloginventory_stock_item_correct_qty_before'; | |
const EVENT_CORRECT_STOCK_ITEMS_QTY_AFTER = 'cataloginventory_stock_item_correct_qty_after'; | |
/** | |
* (non-PHPdoc) | |
* @see Mage_CatalogInventory_Model_Stock::registerProductsSale() | |
*/ | |
public function registerProductsSale($items) | |
{ | |
Mage::dispatchEvent(self::EVENT_CORRECT_STOCK_ITEMS_QTY_BEFORE, array( | |
'stock' => $this, | |
'items_obj' => (object)array('items' => &$items), | |
'operator' => '+' | |
)); | |
$result = parent::registerProductsSale($items); | |
Mage::dispatchEvent(self::EVENT_CORRECT_STOCK_ITEMS_QTY_AFTER, array( | |
'stock' => $this, | |
'items' => $items, | |
'fullsave_items' => $result, | |
'operator' => '+' | |
)); | |
return $result; | |
} | |
/** | |
* (non-PHPdoc) | |
* @see Mage_CatalogInventory_Model_Stock::revertProductsSale() | |
*/ | |
public function revertProductsSale($items) | |
{ | |
Mage::dispatchEvent(self::EVENT_CORRECT_STOCK_ITEMS_QTY_BEFORE, array( | |
'stock' => $this, | |
'items_obj' => (object)array('items' => &$items), | |
'operator' => '-' | |
)); | |
$result = parent::revertProductsSale($items); | |
Mage::dispatchEvent(self::EVENT_CORRECT_STOCK_ITEMS_QTY_BEFORE, array( | |
'stock' => $this, | |
'items' => $items, | |
'fullsave_items' => $result, | |
'operator' => '-' | |
)); | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment