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_Adminhtml
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: * Product inventory data
29: *
30: * @author Magento Core Team <core@magentocommerce.com>
31: */
32: class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Inventory extends Mage_Adminhtml_Block_Widget
33: {
34: public function __construct()
35: {
36: parent::__construct();
37: $this->setTemplate('catalog/product/tab/inventory.phtml');
38: }
39:
40: public function getBackordersOption()
41: {
42: if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
43: return Mage::getSingleton('cataloginventory/source_backorders')->toOptionArray();
44: }
45:
46: return array();
47: }
48:
49: /**
50: * Retrieve stock option array
51: *
52: * @return array
53: */
54: public function getStockOption()
55: {
56: if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
57: return Mage::getSingleton('cataloginventory/source_stock')->toOptionArray();
58: }
59:
60: return array();
61: }
62:
63: /**
64: * Return current product instance
65: *
66: * @return Mage_Catalog_Model_Product
67: */
68: public function getProduct()
69: {
70: return Mage::registry('product');
71: }
72:
73: /**
74: * Retrieve Catalog Inventory Stock Item Model
75: *
76: * @return Mage_CatalogInventory_Model_Stock_Item
77: */
78: public function getStockItem()
79: {
80: return $this->getProduct()->getStockItem();
81: }
82:
83: public function isConfigurable()
84: {
85: return $this->getProduct()->isConfigurable();
86: }
87:
88: public function getFieldValue($field)
89: {
90: if ($this->getStockItem()) {
91: return $this->getStockItem()->getDataUsingMethod($field);
92: }
93:
94: return Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_ITEM . $field);
95: }
96:
97: public function getConfigFieldValue($field)
98: {
99: if ($this->getStockItem()) {
100: if ($this->getStockItem()->getData('use_config_' . $field) == 0) {
101: return $this->getStockItem()->getData($field);
102: }
103: }
104:
105: return Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_ITEM . $field);
106: }
107:
108: public function getDefaultConfigValue($field)
109: {
110: return Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_ITEM . $field);
111: }
112:
113: /**
114: * Is readonly stock
115: *
116: * @return boolean
117: */
118: public function isReadonly()
119: {
120: return $this->getProduct()->getInventoryReadonly();
121: }
122:
123: public function isNew()
124: {
125: if ($this->getProduct()->getId()) {
126: return false;
127: }
128: return true;
129: }
130:
131: public function getFieldSuffix()
132: {
133: return 'product';
134: }
135:
136: /**
137: * Check Whether product type can have fractional quantity or not
138: *
139: * @return bool
140: */
141: public function canUseQtyDecimals()
142: {
143: return $this->getProduct()->getTypeInstance()->canUseQtyDecimals();
144: }
145:
146: /**
147: * Check if product type is virtual
148: *
149: * @return boolean
150: */
151: public function isVirtual()
152: {
153: return $this->getProduct()->getTypeInstance()->isVirtual();
154: }
155: }
156: