1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_CatalogInventory_Model_Observer
35: {
36: 37: 38: 39: 40: 41: 42:
43: protected $_checkedProductsQty = array();
44:
45: 46: 47: 48: 49: 50:
51: protected $_checkedQuoteItems = array();
52:
53: protected $_itemsForReindex = array();
54:
55: 56: 57: 58: 59: 60:
61: protected $_stockItemsArray = array();
62:
63: 64: 65: 66: 67: 68:
69: public function addInventoryData($observer)
70: {
71: $product = $observer->getEvent()->getProduct();
72: if ($product instanceof Mage_Catalog_Model_Product) {
73: $productId = intval($product->getId());
74: if (!isset($this->_stockItemsArray[$productId])) {
75: $this->_stockItemsArray[$productId] = Mage::getModel('cataloginventory/stock_item');
76: }
77: $productStockItem = $this->_stockItemsArray[$productId];
78: $productStockItem->assignProduct($product);
79: }
80: return $this;
81: }
82:
83: 84: 85: 86: 87: 88:
89: public function removeInventoryData($observer)
90: {
91: $product = $observer->getEvent()->getProduct();
92: if (($product instanceof Mage_Catalog_Model_Product)
93: && $product->getId()
94: && isset($this->_stockItemsArray[$product->getId()])) {
95: unset($this->_stockItemsArray[$product->getId()]);
96: }
97: return $this;
98: }
99:
100: 101: 102: 103: 104: 105: 106:
107: public function addStockStatusToCollection($observer)
108: {
109: $productCollection = $observer->getEvent()->getCollection();
110: if ($productCollection->hasFlag('require_stock_items')) {
111: Mage::getModel('cataloginventory/stock')->addItemsToProducts($productCollection);
112: } else {
113: Mage::getModel('cataloginventory/stock_status')->addStockStatusToProducts($productCollection);
114: }
115: return $this;
116: }
117:
118: 119: 120: 121: 122: 123:
124: public function addInventoryDataToCollection($observer)
125: {
126: $productCollection = $observer->getEvent()->getProductCollection();
127: Mage::getModel('cataloginventory/stock')->addItemsToProducts($productCollection);
128: return $this;
129: }
130:
131: 132: 133: 134: 135: 136:
137: public function saveInventoryData($observer)
138: {
139: $product = $observer->getEvent()->getProduct();
140:
141: if (is_null($product->getStockData())) {
142: if ($product->getIsChangedWebsites() || $product->dataHasChangedFor('status')) {
143: Mage::getSingleton('cataloginventory/stock_status')
144: ->updateStatus($product->getId());
145: }
146: return $this;
147: }
148:
149: $item = $product->getStockItem();
150: if (!$item) {
151: $item = Mage::getModel('cataloginventory/stock_item');
152: }
153: $this->_prepareItemForSave($item, $product);
154: $item->save();
155: return $this;
156: }
157:
158: 159: 160: 161: 162: 163:
164: public function copyInventoryData($observer)
165: {
166:
167: $currentProduct = $observer->getEvent()->getCurrentProduct();
168:
169: $newProduct = $observer->getEvent()->getNewProduct();
170:
171: $newProduct->unsStockItem();
172: $stockData = array(
173: 'use_config_min_qty' => 1,
174: 'use_config_min_sale_qty' => 1,
175: 'use_config_max_sale_qty' => 1,
176: 'use_config_backorders' => 1,
177: 'use_config_notify_stock_qty'=> 1
178: );
179: if ($currentStockItem = $currentProduct->getStockItem()) {
180: $stockData += array(
181: 'use_config_enable_qty_inc' => $currentStockItem->getData('use_config_enable_qty_inc'),
182: 'enable_qty_increments' => $currentStockItem->getData('enable_qty_increments'),
183: 'use_config_qty_increments' => $currentStockItem->getData('use_config_qty_increments'),
184: 'qty_increments' => $currentStockItem->getData('qty_increments'),
185: );
186: }
187: $newProduct->setStockData($stockData);
188:
189: return $this;
190: }
191:
192: 193: 194: 195: 196: 197: 198:
199: protected function _prepareItemForSave($item, $product)
200: {
201: $item->addData($product->getStockData())
202: ->setProduct($product)
203: ->setProductId($product->getId())
204: ->setStockId($item->getStockId());
205: if (!is_null($product->getData('stock_data/min_qty'))
206: && is_null($product->getData('stock_data/use_config_min_qty'))) {
207: $item->setData('use_config_min_qty', false);
208: }
209: if (!is_null($product->getData('stock_data/min_sale_qty'))
210: && is_null($product->getData('stock_data/use_config_min_sale_qty'))) {
211: $item->setData('use_config_min_sale_qty', false);
212: }
213: if (!is_null($product->getData('stock_data/max_sale_qty'))
214: && is_null($product->getData('stock_data/use_config_max_sale_qty'))) {
215: $item->setData('use_config_max_sale_qty', false);
216: }
217: if (!is_null($product->getData('stock_data/backorders'))
218: && is_null($product->getData('stock_data/use_config_backorders'))) {
219: $item->setData('use_config_backorders', false);
220: }
221: if (!is_null($product->getData('stock_data/notify_stock_qty'))
222: && is_null($product->getData('stock_data/use_config_notify_stock_qty'))) {
223: $item->setData('use_config_notify_stock_qty', false);
224: }
225: $originalQty = $product->getData('stock_data/original_inventory_qty');
226: if (strlen($originalQty)>0) {
227: $item->setQtyCorrection($item->getQty()-$originalQty);
228: }
229: if (!is_null($product->getData('stock_data/enable_qty_increments'))
230: && is_null($product->getData('stock_data/use_config_enable_qty_inc'))) {
231: $item->setData('use_config_enable_qty_inc', false);
232: }
233: if (!is_null($product->getData('stock_data/qty_increments'))
234: && is_null($product->getData('stock_data/use_config_qty_increments'))) {
235: $item->setData('use_config_qty_increments', false);
236: }
237: return $this;
238:
239: }
240:
241: 242: 243: 244: 245: 246: 247:
248: protected function _removeErrorsFromQuoteAndItem($item, $code)
249: {
250: if ($item->getHasError()) {
251: $params = array(
252: 'origin' => 'cataloginventory',
253: 'code' => $code
254: );
255: $item->removeErrorInfosByParams($params);
256: }
257:
258: $quote = $item->getQuote();
259: $quoteItems = $quote->getItemsCollection();
260: $canRemoveErrorFromQuote = true;
261:
262: foreach ($quoteItems as $quoteItem) {
263: if ($quoteItem->getItemId() == $item->getItemId()) {
264: continue;
265: }
266:
267: $errorInfos = $quoteItem->getErrorInfos();
268: foreach ($errorInfos as $errorInfo) {
269: if ($errorInfo['code'] == $code) {
270: $canRemoveErrorFromQuote = false;
271: break;
272: }
273: }
274:
275: if (!$canRemoveErrorFromQuote) {
276: break;
277: }
278: }
279:
280: if ($quote->getHasError() && $canRemoveErrorFromQuote) {
281: $params = array(
282: 'origin' => 'cataloginventory',
283: 'code' => $code
284: );
285: $quote->removeErrorInfosByParams(null, $params);
286: }
287:
288: return $this;
289: }
290:
291: 292: 293: 294: 295: 296:
297: public function checkQuoteItemQty($observer)
298: {
299: $quoteItem = $observer->getEvent()->getItem();
300:
301: if (!$quoteItem || !$quoteItem->getProductId() || !$quoteItem->getQuote()
302: || $quoteItem->getQuote()->getIsSuperMode()) {
303: return $this;
304: }
305:
306: 307: 308:
309: $qty = $quoteItem->getQty();
310:
311: 312: 313:
314: if (($options = $quoteItem->getQtyOptions()) && $qty > 0) {
315: $qty = $quoteItem->getProduct()->getTypeInstance(true)->prepareQuoteItemQty($qty, $quoteItem->getProduct());
316: $quoteItem->setData('qty', $qty);
317:
318: $stockItem = $quoteItem->getProduct()->getStockItem();
319: if ($stockItem) {
320: $result = $stockItem->checkQtyIncrements($qty);
321: if ($result->getHasError()) {
322: $quoteItem->addErrorInfo(
323: 'cataloginventory',
324: Mage_CatalogInventory_Helper_Data::ERROR_QTY_INCREMENTS,
325: $result->getMessage()
326: );
327:
328: $quoteItem->getQuote()->addErrorInfo(
329: $result->getQuoteMessageIndex(),
330: 'cataloginventory',
331: Mage_CatalogInventory_Helper_Data::ERROR_QTY_INCREMENTS,
332: $result->getQuoteMessage()
333: );
334: } else {
335:
336: $this->_removeErrorsFromQuoteAndItem(
337: $quoteItem,
338: Mage_CatalogInventory_Helper_Data::ERROR_QTY_INCREMENTS
339: );
340: }
341: }
342:
343: foreach ($options as $option) {
344: $optionValue = $option->getValue();
345:
346: $optionQty = $qty * $optionValue;
347: $increaseOptionQty = ($quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty) * $optionValue;
348:
349: $stockItem = $option->getProduct()->getStockItem();
350:
351: if ($quoteItem->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
352: $stockItem->setProductName($quoteItem->getName());
353: }
354:
355:
356: if (!$stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) {
357: Mage::throwException(
358: Mage::helper('cataloginventory')->__('The stock item for Product in option is not valid.')
359: );
360: }
361:
362: 363: 364:
365: $stockItem->setIsChildItem(true);
366: 367: 368:
369: $stockItem->setSuppressCheckQtyIncrements(true);
370:
371: $qtyForCheck = $this->_getQuoteItemQtyForCheck(
372: $option->getProduct()->getId(),
373: $quoteItem->getId(),
374: $increaseOptionQty
375: );
376:
377: $result = $stockItem->checkQuoteItemQty($optionQty, $qtyForCheck, $optionValue);
378:
379: if (!is_null($result->getItemIsQtyDecimal())) {
380: $option->setIsQtyDecimal($result->getItemIsQtyDecimal());
381: }
382:
383: if ($result->getHasQtyOptionUpdate()) {
384: $option->setHasQtyOptionUpdate(true);
385: $quoteItem->updateQtyOption($option, $result->getOrigQty());
386: $option->setValue($result->getOrigQty());
387: 388: 389:
390: $quoteItem->setData('qty', intval($qty));
391: }
392: if (!is_null($result->getMessage())) {
393: $option->setMessage($result->getMessage());
394: $quoteItem->setMessage($result->getMessage());
395: }
396: if (!is_null($result->getItemBackorders())) {
397: $option->setBackorders($result->getItemBackorders());
398: }
399:
400: if ($result->getHasError()) {
401: $option->setHasError(true);
402:
403: $quoteItem->addErrorInfo(
404: 'cataloginventory',
405: Mage_CatalogInventory_Helper_Data::ERROR_QTY,
406: $result->getQuoteMessage()
407: );
408:
409: $quoteItem->getQuote()->addErrorInfo(
410: $result->getQuoteMessageIndex(),
411: 'cataloginventory',
412: Mage_CatalogInventory_Helper_Data::ERROR_QTY,
413: $result->getQuoteMessage()
414: );
415: } else {
416:
417: $this->_removeErrorsFromQuoteAndItem($quoteItem, Mage_CatalogInventory_Helper_Data::ERROR_QTY);
418: }
419:
420: $stockItem->unsIsChildItem();
421: }
422: } else {
423: $stockItem = $quoteItem->getProduct()->getStockItem();
424:
425: if (!$stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) {
426: Mage::throwException(Mage::helper('cataloginventory')->__('The stock item for Product is not valid.'));
427: }
428:
429: 430: 431:
432: if ($quoteItem->getParentItem()) {
433: $rowQty = $quoteItem->getParentItem()->getQty() * $qty;
434: 435: 436:
437: $qtyForCheck = $this->_getQuoteItemQtyForCheck(
438: $quoteItem->getProduct()->getId(),
439: $quoteItem->getId(),
440: 0
441: );
442: } else {
443: $increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty;
444: $rowQty = $qty;
445: $qtyForCheck = $this->_getQuoteItemQtyForCheck(
446: $quoteItem->getProduct()->getId(),
447: $quoteItem->getId(),
448: $increaseQty
449: );
450: }
451:
452: $productTypeCustomOption = $quoteItem->getProduct()->getCustomOption('product_type');
453: if (!is_null($productTypeCustomOption)) {
454:
455: if ($productTypeCustomOption->getValue() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) {
456: $stockItem->setIsChildItem(true);
457: }
458: }
459:
460: $result = $stockItem->checkQuoteItemQty($rowQty, $qtyForCheck, $qty);
461:
462: if ($stockItem->hasIsChildItem()) {
463: $stockItem->unsIsChildItem();
464: }
465:
466: if (!is_null($result->getItemIsQtyDecimal())) {
467: $quoteItem->setIsQtyDecimal($result->getItemIsQtyDecimal());
468: if ($quoteItem->getParentItem()) {
469: $quoteItem->getParentItem()->setIsQtyDecimal($result->getItemIsQtyDecimal());
470: }
471: }
472:
473: 474: 475: 476: 477:
478: if ($result->getHasQtyOptionUpdate()
479: && (!$quoteItem->getParentItem()
480: || $quoteItem->getParentItem()->getProduct()->getTypeInstance(true)
481: ->getForceChildItemQtyChanges($quoteItem->getParentItem()->getProduct())
482: )
483: ) {
484: $quoteItem->setData('qty', $result->getOrigQty());
485: }
486:
487: if (!is_null($result->getItemUseOldQty())) {
488: $quoteItem->setUseOldQty($result->getItemUseOldQty());
489: }
490: if (!is_null($result->getMessage())) {
491: $quoteItem->setMessage($result->getMessage());
492: if ($quoteItem->getParentItem()) {
493: $quoteItem->getParentItem()->setMessage($result->getMessage());
494: }
495: }
496:
497: if (!is_null($result->getItemBackorders())) {
498: $quoteItem->setBackorders($result->getItemBackorders());
499: }
500:
501: if ($result->getHasError()) {
502: $quoteItem->addErrorInfo(
503: 'cataloginventory',
504: Mage_CatalogInventory_Helper_Data::ERROR_QTY,
505: $result->getMessage()
506: );
507:
508: $quoteItem->getQuote()->addErrorInfo(
509: $result->getQuoteMessageIndex(),
510: 'cataloginventory',
511: Mage_CatalogInventory_Helper_Data::ERROR_QTY,
512: $result->getQuoteMessage()
513: );
514: } else {
515:
516: $this->_removeErrorsFromQuoteAndItem($quoteItem, Mage_CatalogInventory_Helper_Data::ERROR_QTY);
517: }
518: }
519:
520: return $this;
521: }
522:
523: 524: 525: 526: 527: 528: 529: 530:
531: protected function _getProductQtyForCheck($productId, $itemQty)
532: {
533: $qty = $itemQty;
534: if (isset($this->_checkedProductsQty[$productId])) {
535: $qty += $this->_checkedProductsQty[$productId];
536: }
537: $this->_checkedProductsQty[$productId] = $qty;
538: return $qty;
539: }
540:
541: 542: 543: 544: 545: 546: 547: 548: 549:
550: protected function _getQuoteItemQtyForCheck($productId, $quoteItemId, $itemQty)
551: {
552: $qty = $itemQty;
553: if (isset($this->_checkedQuoteItems[$productId]['qty']) &&
554: !in_array($quoteItemId, $this->_checkedQuoteItems[$productId]['items'])) {
555: $qty += $this->_checkedQuoteItems[$productId]['qty'];
556: }
557:
558: $this->_checkedQuoteItems[$productId]['qty'] = $qty;
559: $this->_checkedQuoteItems[$productId]['items'][] = $quoteItemId;
560:
561: return $qty;
562: }
563:
564: 565: 566: 567: 568: 569:
570: public function checkoutAllSubmitAfter(Varien_Event_Observer $observer)
571: {
572: $quote = $observer->getEvent()->getQuote();
573: if (!$quote->getInventoryProcessed()) {
574: $this->subtractQuoteInventory($observer);
575: $this->reindexQuoteInventory($observer);
576: }
577: return $this;
578: }
579:
580: 581: 582: 583: 584: 585: 586: 587:
588: public function subtractQuoteInventory(Varien_Event_Observer $observer)
589: {
590: $quote = $observer->getEvent()->getQuote();
591:
592:
593:
594: if ($quote->getInventoryProcessed()) {
595: return;
596: }
597: $items = $this->_getProductsQty($quote->getAllItems());
598:
599: 600: 601:
602: $this->_itemsForReindex = Mage::getSingleton('cataloginventory/stock')->registerProductsSale($items);
603:
604: $quote->setInventoryProcessed(true);
605: return $this;
606: }
607:
608: 609: 610: 611:
612: public function revertQuoteInventory($observer)
613: {
614: $quote = $observer->getEvent()->getQuote();
615: $items = $this->_getProductsQty($quote->getAllItems());
616: Mage::getSingleton('cataloginventory/stock')->revertProductsSale($items);
617:
618:
619: $quote->setInventoryProcessed(false);
620: }
621:
622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634:
635: protected function _addItemToQtyArray($quoteItem, &$items)
636: {
637: $productId = $quoteItem->getProductId();
638: if (!$productId)
639: return;
640: if (isset($items[$productId])) {
641: $items[$productId]['qty'] += $quoteItem->getTotalQty();
642: } else {
643: $stockItem = null;
644: if ($quoteItem->getProduct()) {
645: $stockItem = $quoteItem->getProduct()->getStockItem();
646: }
647: $items[$productId] = array(
648: 'item' => $stockItem,
649: 'qty' => $quoteItem->getTotalQty()
650: );
651: }
652: }
653:
654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665:
666: protected function _getProductsQty($relatedItems)
667: {
668: $items = array();
669: foreach ($relatedItems as $item) {
670: $productId = $item->getProductId();
671: if (!$productId) {
672: continue;
673: }
674: $children = $item->getChildrenItems();
675: if ($children) {
676: foreach ($children as $childItem) {
677: $this->_addItemToQtyArray($childItem, $items);
678: }
679: } else {
680: $this->_addItemToQtyArray($item, $items);
681: }
682: }
683: return $items;
684: }
685:
686: 687: 688: 689: 690:
691: public function reindexQuoteInventory($observer)
692: {
693:
694: $quote = $observer->getEvent()->getQuote();
695: $productIds = array();
696: foreach ($quote->getAllItems() as $item) {
697: $productIds[$item->getProductId()] = $item->getProductId();
698: $children = $item->getChildrenItems();
699: if ($children) {
700: foreach ($children as $childItem) {
701: $productIds[$childItem->getProductId()] = $childItem->getProductId();
702: }
703: }
704: }
705:
706: if( count($productIds)) {
707: Mage::getResourceSingleton('cataloginventory/indexer_stock')->reindexProducts($productIds);
708: }
709:
710:
711: $productIds = array();
712: foreach ($this->_itemsForReindex as $item) {
713: $item->save();
714: $productIds[] = $item->getProductId();
715: }
716: Mage::getResourceSingleton('catalog/product_indexer_price')->reindexProductIds($productIds);
717:
718: $this->_itemsForReindex = array();
719:
720: return $this;
721: }
722:
723: 724: 725: 726: 727:
728: public function refundOrderInventory($observer)
729: {
730:
731: $creditmemo = $observer->getEvent()->getCreditmemo();
732: $items = array();
733: foreach ($creditmemo->getAllItems() as $item) {
734:
735: $return = false;
736: if ($item->hasBackToStock()) {
737: if ($item->getBackToStock() && $item->getQty()) {
738: $return = true;
739: }
740: } elseif (Mage::helper('cataloginventory')->isAutoReturnEnabled()) {
741: $return = true;
742: }
743: if ($return) {
744: $parentOrderId = $item->getOrderItem()->getParentItemId();
745:
746: $parentItem = $parentOrderId ? $creditmemo->getItemByOrderId($parentOrderId) : false;
747: $qty = $parentItem ? ($parentItem->getQty() * $item->getQty()) : $item->getQty();
748: if (isset($items[$item->getProductId()])) {
749: $items[$item->getProductId()]['qty'] += $qty;
750: } else {
751: $items[$item->getProductId()] = array(
752: 'qty' => $qty,
753: 'item'=> null,
754: );
755: }
756: }
757: }
758: Mage::getSingleton('cataloginventory/stock')->revertProductsSale($items);
759: }
760:
761: 762: 763: 764: 765: 766:
767: public function cancelOrderItem($observer)
768: {
769: $item = $observer->getEvent()->getItem();
770:
771: $children = $item->getChildrenItems();
772: $qty = $item->getQtyOrdered() - max($item->getQtyShipped(), $item->getQtyInvoiced()) - $item->getQtyCanceled();
773:
774: if ($item->getId() && ($productId = $item->getProductId()) && empty($children) && $qty) {
775: Mage::getSingleton('cataloginventory/stock')->backItemQty($productId, $qty);
776: }
777:
778: return $this;
779: }
780:
781: 782: 783: 784: 785: 786:
787: public function updateItemsStockUponConfigChange($observer)
788: {
789: Mage::getResourceSingleton('cataloginventory/stock')->updateSetOutOfStock();
790: Mage::getResourceSingleton('cataloginventory/stock')->updateSetInStock();
791: Mage::getResourceSingleton('cataloginventory/stock')->updateLowStockDate();
792: return $this;
793: }
794:
795: 796: 797: 798: 799: 800:
801: public function productStatusUpdate(Varien_Event_Observer $observer)
802: {
803: $productId = $observer->getEvent()->getProductId();
804: Mage::getSingleton('cataloginventory/stock_status')
805: ->updateStatus($productId);
806: return $this;
807: }
808:
809: 810: 811: 812: 813: 814:
815: public function catalogProductWebsiteUpdate(Varien_Event_Observer $observer)
816: {
817: $websiteIds = $observer->getEvent()->getWebsiteIds();
818: $productIds = $observer->getEvent()->getProductIds();
819:
820: foreach ($websiteIds as $websiteId) {
821: foreach ($productIds as $productId) {
822: Mage::getSingleton('cataloginventory/stock_status')
823: ->updateStatus($productId, null, $websiteId);
824: }
825: }
826:
827: return $this;
828: }
829:
830: 831: 832: 833: 834: 835:
836: public function addStockStatusToPrepareIndexSelect(Varien_Event_Observer $observer)
837: {
838: $website = $observer->getEvent()->getWebsite();
839: $select = $observer->getEvent()->getSelect();
840:
841: Mage::getSingleton('cataloginventory/stock_status')
842: ->addStockStatusToSelect($select, $website);
843:
844: return $this;
845: }
846:
847: 848: 849: 850: 851: 852:
853: public function prepareCatalogProductIndexSelect(Varien_Event_Observer $observer)
854: {
855: $select = $observer->getEvent()->getSelect();
856: $entity = $observer->getEvent()->getEntityField();
857: $website = $observer->getEvent()->getWebsiteField();
858:
859: Mage::getSingleton('cataloginventory/stock_status')
860: ->prepareCatalogProductIndexSelect($select, $entity, $website);
861:
862: return $this;
863: }
864:
865: 866: 867: 868: 869: 870: 871: 872: 873:
874: public function lockOrderInventoryData($observer)
875: {
876: $order = $observer->getEvent()->getOrder();
877: $productIds = array();
878:
879: 880: 881:
882: if ($order->getId()) {
883: return $this;
884: }
885:
886: if ($order) {
887: foreach ($order->getAllItems() as $item) {
888: $productIds[] = $item->getProductId();
889: }
890: }
891:
892: if (!empty($productIds)) {
893: Mage::getSingleton('cataloginventory/stock')->lockProductItems($productIds);
894: }
895:
896: return $this;
897: }
898:
899: 900: 901: 902: 903: 904: 905:
906: public function createOrderItem($observer)
907: {
908: $item = $observer->getEvent()->getItem();
909: 910: 911:
912:
913: $children = $item->getChildrenItems();
914:
915: if (!$item->getId() && empty($children)) {
916: Mage::getSingleton('cataloginventory/stock')->registerItemSale($item);
917: }
918:
919: return $this;
920: }
921:
922: 923: 924: 925: 926: 927: 928:
929: public function refundOrderItem($observer)
930: {
931: $item = $observer->getEvent()->getCreditmemoItem();
932: if ($item->getId() && $item->getBackToStock() && ($productId = $item->getProductId())
933: && ($qty = $item->getQty())
934: ) {
935: Mage::getSingleton('cataloginventory/stock')->backItemQty($productId, $qty);
936: }
937: return $this;
938: }
939:
940: 941: 942: 943: 944:
945: public function reindexProductsMassAction($observer)
946: {
947: Mage::getSingleton('index/indexer')->indexEvents(
948: Mage_Catalog_Model_Product::ENTITY, Mage_Index_Model_Event::TYPE_MASS_ACTION
949: );
950: }
951: }
952: