Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_CatalogInventory_Block_Adminhtml_Form_Field_Customergroup
  • Mage_CatalogInventory_Block_Adminhtml_Form_Field_Minsaleqty
  • Mage_CatalogInventory_Block_Qtyincrements
  • Mage_CatalogInventory_Block_Stockqty_Abstract
  • Mage_CatalogInventory_Block_Stockqty_Composite
  • Mage_CatalogInventory_Block_Stockqty_Default
  • Mage_CatalogInventory_Block_Stockqty_Type_Configurable
  • Mage_CatalogInventory_Block_Stockqty_Type_Grouped
  • Mage_CatalogInventory_Helper_Data
  • Mage_CatalogInventory_Helper_Minsaleqty
  • Mage_CatalogInventory_Model_Api2_Stock_Item
  • Mage_CatalogInventory_Model_Api2_Stock_Item_Rest
  • Mage_CatalogInventory_Model_Api2_Stock_Item_Rest_Admin_V1
  • Mage_CatalogInventory_Model_Api2_Stock_Item_Validator_Item
  • Mage_CatalogInventory_Model_Indexer_Stock
  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock
  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Configurable
  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default
  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Grouped
  • Mage_CatalogInventory_Model_Mysql4_Stock
  • Mage_CatalogInventory_Model_Mysql4_Stock_Item
  • Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection
  • Mage_CatalogInventory_Model_Mysql4_Stock_Status
  • Mage_CatalogInventory_Model_Observer
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock_Configurable
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock_Grouped
  • Mage_CatalogInventory_Model_Resource_Stock
  • Mage_CatalogInventory_Model_Resource_Stock_Item
  • Mage_CatalogInventory_Model_Resource_Stock_Item_Collection
  • Mage_CatalogInventory_Model_Resource_Stock_Status
  • Mage_CatalogInventory_Model_Source_Backorders
  • Mage_CatalogInventory_Model_Source_Stock
  • Mage_CatalogInventory_Model_Stock
  • Mage_CatalogInventory_Model_Stock_Item
  • Mage_CatalogInventory_Model_Stock_Item_Api
  • Mage_CatalogInventory_Model_Stock_Item_Api_V2
  • Mage_CatalogInventory_Model_Stock_Status
  • Mage_CatalogInventory_Model_System_Config_Backend_Minqty
  • Mage_CatalogInventory_Model_System_Config_Backend_Minsaleqty
  • Mage_CatalogInventory_Model_System_Config_Backend_Qtyincrements

Interfaces

  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Interface
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock_Interface
  • Overview
  • Package
  • Class
  • Tree
  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:  * MinSaleQty value manipulation helper
 29:  */
 30: class Mage_CatalogInventory_Helper_Minsaleqty
 31: {
 32:     /**
 33:      * Retrieve fixed qty value
 34:      *
 35:      * @param mixed $qty
 36:      * @return float|null
 37:      */
 38:     protected function _fixQty($qty)
 39:     {
 40:         return (!empty($qty) ? (float)$qty : null);
 41:     }
 42: 
 43:     /**
 44:      * Generate a storable representation of a value
 45:      *
 46:      * @param mixed $value
 47:      * @return string
 48:      */
 49:     protected function _serializeValue($value)
 50:     {
 51:         if (is_numeric($value)) {
 52:             $data = (float)$value;
 53:             return (string)$data;
 54:         } else if (is_array($value)) {
 55:             $data = array();
 56:             foreach ($value as $groupId => $qty) {
 57:                 if (!array_key_exists($groupId, $data)) {
 58:                     $data[$groupId] = $this->_fixQty($qty);
 59:                 }
 60:             }
 61:             if (count($data) == 1 && array_key_exists(Mage_Customer_Model_Group::CUST_GROUP_ALL, $data)) {
 62:                 return (string)$data[Mage_Customer_Model_Group::CUST_GROUP_ALL];
 63:             }
 64:             return serialize($data);
 65:         } else {
 66:             return '';
 67:         }
 68:     }
 69: 
 70:     /**
 71:      * Create a value from a storable representation
 72:      *
 73:      * @param mixed $value
 74:      * @return array
 75:      */
 76:     protected function _unserializeValue($value)
 77:     {
 78:         if (is_numeric($value)) {
 79:             return array(
 80:                 Mage_Customer_Model_Group::CUST_GROUP_ALL => $this->_fixQty($value)
 81:             );
 82:         } else if (is_string($value) && !empty($value)) {
 83:             return unserialize($value);
 84:         } else {
 85:             return array();
 86:         }
 87:     }
 88: 
 89:     /**
 90:      * Check whether value is in form retrieved by _encodeArrayFieldValue()
 91:      *
 92:      * @param mixed
 93:      * @return bool
 94:      */
 95:     protected function _isEncodedArrayFieldValue($value)
 96:     {
 97:         if (!is_array($value)) {
 98:             return false;
 99:         }
100:         unset($value['__empty']);
101:         foreach ($value as $_id => $row) {
102:             if (!is_array($row) || !array_key_exists('customer_group_id', $row) || !array_key_exists('min_sale_qty', $row)) {
103:                 return false;
104:             }
105:         }
106:         return true;
107:     }
108: 
109:     /**
110:      * Encode value to be used in Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
111:      *
112:      * @param array
113:      * @return array
114:      */
115:     protected function _encodeArrayFieldValue(array $value)
116:     {
117:         $result = array();
118:         foreach ($value as $groupId => $qty) {
119:             $_id = Mage::helper('core')->uniqHash('_');
120:             $result[$_id] = array(
121:                 'customer_group_id' => $groupId,
122:                 'min_sale_qty' => $this->_fixQty($qty),
123:             );
124:         }
125:         return $result;
126:     }
127: 
128:     /**
129:      * Decode value from used in Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
130:      *
131:      * @param array
132:      * @return array
133:      */
134:     protected function _decodeArrayFieldValue(array $value)
135:     {
136:         $result = array();
137:         unset($value['__empty']);
138:         foreach ($value as $_id => $row) {
139:             if (!is_array($row) || !array_key_exists('customer_group_id', $row) || !array_key_exists('min_sale_qty', $row)) {
140:                 continue;
141:             }
142:             $groupId = $row['customer_group_id'];
143:             $qty = $this->_fixQty($row['min_sale_qty']);
144:             $result[$groupId] = $qty;
145:         }
146:         return $result;
147:     }
148: 
149:     /**
150:      * Retrieve min_sale_qty value from config
151:      *
152:      * @param int $customerGroupId
153:      * @param mixed $store
154:      * @return float|null
155:      */
156:     public function getConfigValue($customerGroupId, $store = null)
157:     {
158:         $value = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MIN_SALE_QTY, $store);
159:         $value = $this->_unserializeValue($value);
160:         if ($this->_isEncodedArrayFieldValue($value)) {
161:             $value = $this->_decodeArrayFieldValue($value);
162:         }
163:         $result = null;
164:         foreach ($value as $groupId => $qty) {
165:             if ($groupId == $customerGroupId) {
166:                 $result = $qty;
167:                 break;
168:             } else if ($groupId == Mage_Customer_Model_Group::CUST_GROUP_ALL) {
169:                 $result = $qty;
170:             }
171:         }
172:         return $this->_fixQty($result);
173:     }
174: 
175:     /**
176:      * Make value readable by Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
177:      *
178:      * @param mixed $value
179:      * @return array
180:      */
181:     public function makeArrayFieldValue($value)
182:     {
183:         $value = $this->_unserializeValue($value);
184:         if (!$this->_isEncodedArrayFieldValue($value)) {
185:             $value = $this->_encodeArrayFieldValue($value);
186:         }
187:         return $value;
188:     }
189: 
190:     /**
191:      * Make value ready for store
192:      *
193:      * @param mixed $value
194:      * @return string
195:      */
196:     public function makeStorableArrayFieldValue($value)
197:     {
198:         if ($this->_isEncodedArrayFieldValue($value)) {
199:             $value = $this->_decodeArrayFieldValue($value);
200:         }
201:         $value = $this->_serializeValue($value);
202:         return $value;
203:     }
204: }
205: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0