1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_CatalogInventory
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Catalo
29: */
30: class Mage_CatalogInventory_Helper_Data extends Mage_Core_Helper_Abstract
31: {
32: const XML_PATH_SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock';
33: const XML_PATH_ITEM_AUTO_RETURN = 'cataloginventory/item_options/auto_return';
34:
35: /**
36: * Error codes, that Catalog Inventory module can set to quote or quote items
37: */
38: const ERROR_QTY = 1;
39: const ERROR_QTY_INCREMENTS = 2;
40:
41: /**
42: * All product types registry in scope of quantity availability
43: *
44: * @var array
45: */
46: protected static $_isQtyTypeIds;
47:
48: /**
49: * Check if quantity defined for specified product type
50: *
51: * @param string $productTypeId
52: * @return bool
53: */
54: public function isQty($productTypeId)
55: {
56: $this->getIsQtyTypeIds();
57: if (!isset(self::$_isQtyTypeIds[$productTypeId])) {
58: return false;
59: }
60: return self::$_isQtyTypeIds[$productTypeId];
61: }
62:
63: /**
64: * Get all registered product type ids and if quantity is defined for them
65: *
66: * @param bool $filter
67: * @return array
68: */
69: public function getIsQtyTypeIds($filter = null)
70: {
71: if (null === self::$_isQtyTypeIds) {
72: self::$_isQtyTypeIds = array();
73: $productTypesXml = Mage::getConfig()->getNode('global/catalog/product/type');
74: foreach ($productTypesXml->children() as $typeId => $configXml) {
75: self::$_isQtyTypeIds[$typeId] = (bool)$configXml->is_qty;
76: }
77: }
78: if (null === $filter) {
79: return self::$_isQtyTypeIds;
80: }
81: $result = self::$_isQtyTypeIds;
82: foreach ($result as $key => $value) {
83: if ($value !== $filter) {
84: unset($result[$key]);
85: }
86: }
87: return $result;
88: }
89:
90: /**
91: * Retrieve inventory item options (used in config)
92: *
93: * @return array
94: */
95: public function getConfigItemOptions()
96: {
97: return array(
98: 'min_qty',
99: 'backorders',
100: 'min_sale_qty',
101: 'max_sale_qty',
102: 'notify_stock_qty',
103: 'manage_stock',
104: 'enable_qty_increments',
105: 'qty_increments',
106: 'is_decimal_divided',
107: );
108: }
109:
110: /**
111: * Display out of stock products option
112: *
113: * @return bool
114: */
115: public function isShowOutOfStock()
116: {
117: return Mage::getStoreConfigFlag(self::XML_PATH_SHOW_OUT_OF_STOCK);
118: }
119:
120: /**
121: * Check if creditmemo items auto return option is enabled
122: * @return bool
123: */
124: public function isAutoReturnEnabled()
125: {
126: return Mage::getStoreConfigFlag(self::XML_PATH_ITEM_AUTO_RETURN);
127: }
128: }
129: