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_Bundle_Adminhtml_Bundle_Product_EditController
  • Mage_Bundle_Adminhtml_Bundle_SelectionController
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Composite_Fieldset_Options_Type_Checkbox
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Composite_Fieldset_Options_Type_Multi
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Composite_Fieldset_Options_Type_Radio
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Composite_Fieldset_Options_Type_Select
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes_Extend
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes_Special
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option_Search
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option_Search_Grid
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option_Selection
  • Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tabs
  • Mage_Bundle_Block_Adminhtml_Sales_Order_Items_Renderer
  • Mage_Bundle_Block_Adminhtml_Sales_Order_View_Items_Renderer
  • Mage_Bundle_Block_Catalog_Product_List_Partof
  • Mage_Bundle_Block_Catalog_Product_Price
  • Mage_Bundle_Block_Catalog_Product_View
  • Mage_Bundle_Block_Catalog_Product_View_Type_Bundle
  • Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option
  • Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Checkbox
  • Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Multi
  • Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Radio
  • Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Select
  • Mage_Bundle_Block_Checkout_Cart_Item_Renderer
  • Mage_Bundle_Block_Sales_Order_Items_Renderer
  • Mage_Bundle_Helper_Catalog_Product_Configuration
  • Mage_Bundle_Helper_Data
  • Mage_Bundle_Model_CatalogIndex_Data_Bundle
  • Mage_Bundle_Model_Mysql4_Bundle
  • Mage_Bundle_Model_Mysql4_Indexer_Price
  • Mage_Bundle_Model_Mysql4_Indexer_Stock
  • Mage_Bundle_Model_Mysql4_Option
  • Mage_Bundle_Model_Mysql4_Option_Collection
  • Mage_Bundle_Model_Mysql4_Price_Index
  • Mage_Bundle_Model_Mysql4_Selection
  • Mage_Bundle_Model_Mysql4_Selection_Collection
  • Mage_Bundle_Model_Observer
  • Mage_Bundle_Model_Option
  • Mage_Bundle_Model_Price_Index
  • Mage_Bundle_Model_Product_Attribute_Source_Price_View
  • Mage_Bundle_Model_Product_Price
  • Mage_Bundle_Model_Product_Type
  • Mage_Bundle_Model_Resource_Bundle
  • Mage_Bundle_Model_Resource_Indexer_Price
  • Mage_Bundle_Model_Resource_Indexer_Stock
  • Mage_Bundle_Model_Resource_Option
  • Mage_Bundle_Model_Resource_Option_Collection
  • Mage_Bundle_Model_Resource_Price_Index
  • Mage_Bundle_Model_Resource_Selection
  • Mage_Bundle_Model_Resource_Selection_Collection
  • Mage_Bundle_Model_Sales_Order_Pdf_Items_Abstract
  • Mage_Bundle_Model_Sales_Order_Pdf_Items_Shipment
  • Mage_Bundle_Model_Selection
  • Mage_Bundle_Model_Source_Option_Selection_Price_Type
  • Mage_Bundle_Model_Source_Option_Type
  • 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_Bundle
 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: /**
 29:  * Bundle Selection Resource Model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Bundle
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Bundle_Model_Resource_Selection extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Define main table and id field
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->_init('bundle/selection', 'selection_id');
 44:     }
 45: 
 46:     /**
 47:      * Retrieve Price From index
 48:      *
 49:      * @param int $productId
 50:      * @param float $qty
 51:      * @param int $storeId
 52:      * @param int $groupId
 53:      * @return mixed
 54:      */
 55:     public function getPriceFromIndex($productId, $qty, $storeId, $groupId)
 56:     {
 57:         $adapter = $this->_getReadAdapter();
 58:         $select = clone $adapter->select();
 59:         $select->reset();
 60: 
 61:         $attrPriceId = Mage::getSingleton('eav/entity_attribute')
 62:             ->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'price');
 63:         $attrTierPriceId = Mage::getSingleton('eav/entity_attribute')
 64:             ->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'tier_price');
 65: 
 66:         $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
 67: 
 68:         $select->from(array("price_index" => $this->getTable('catalogindex/price')), array('price' => 'SUM(value)'))
 69:             ->where('entity_id = :product_id')
 70:             ->where('website_id = :website_id')
 71:             ->where('customer_group_id = :customer_group')
 72:             ->where('attribute_id = :price_attribute OR attribute_id = :tier_price_attribute')
 73:             ->where('qty <= :qty')
 74:             ->group('entity_id');
 75: 
 76:         $bind = array(
 77:             'product_id' => $productId,
 78:             'website_id' => $websiteId,
 79:             'customer_group' => $groupId,
 80:             'price_attribute' => $attrPriceId,
 81:             'tier_price_attribute' => $attrTierPriceId,
 82:             'qty'   => $qty
 83:         );
 84: 
 85:         $price = $adapter->fetchCol($select, $bind);
 86:         if (!empty($price)) {
 87:             return array_shift($price);
 88:         } else {
 89:             return 0;
 90:         }
 91:     }
 92: 
 93:     /**
 94:      * Retrieve Required children ids
 95:      * Return grouped array, ex array(
 96:      *   group => array(ids)
 97:      * )
 98:      *
 99:      * @param int $parentId
100:      * @param bool $required
101:      * @return array
102:      */
103:     public function getChildrenIds($parentId, $required = true)
104:     {
105:         $childrenIds = array();
106:         $notRequired = array();
107:         $adapter = $this->_getReadAdapter();
108:         $select = $adapter->select()
109:             ->from(
110:                 array('tbl_selection' => $this->getMainTable()),
111:                 array('product_id', 'parent_product_id', 'option_id')
112:             )
113:             ->join(
114:                 array('e' => $this->getTable('catalog/product')),
115:                 'e.entity_id = tbl_selection.product_id AND e.required_options=0',
116:                 array()
117:             )
118:             ->join(
119:                 array('tbl_option' => $this->getTable('bundle/option')),
120:                 'tbl_option.option_id = tbl_selection.option_id',
121:                 array('required')
122:             )
123:             ->where('tbl_selection.parent_product_id = :parent_id');
124:         foreach ($adapter->fetchAll($select, array('parent_id' => $parentId)) as $row) {
125:             if ($row['required']) {
126:                 $childrenIds[$row['option_id']][$row['product_id']] = $row['product_id'];
127:             } else {
128:                 $notRequired[$row['option_id']][$row['product_id']] = $row['product_id'];
129:             }
130:         }
131: 
132:         if (!$required) {
133:             $childrenIds = array_merge($childrenIds, $notRequired);
134:         } else {
135:             if (!$childrenIds) {
136:                 foreach ($notRequired as $groupedChildrenIds) {
137:                     foreach ($groupedChildrenIds as $childId) {
138:                         $childrenIds[0][$childId] = $childId;
139:                     }
140:                 }
141:             }
142:             if (!$childrenIds) {
143:                 $childrenIds = array(array());
144:             }
145:         }
146: 
147:         return $childrenIds;
148:     }
149: 
150:     /**
151:      * Retrieve array of related bundle product ids by selection product id(s)
152:      *
153:      * @param int|array $childId
154:      * @return array
155:      */
156:     public function getParentIdsByChild($childId)
157:     {
158:         $adapter = $this->_getReadAdapter();
159:         $select  = $adapter->select()
160:             ->distinct(true)
161:             ->from($this->getMainTable(), 'parent_product_id')
162:             ->where('product_id IN(?)', $childId);
163: 
164:         return $adapter->fetchCol($select);
165:     }
166: 
167:     /**
168:      * Save bundle item price per website
169:      *
170:      * @param Mage_Bundle_Model_Selection $item
171:      */
172:     public function saveSelectionPrice($item)
173:     {
174:         $write = $this->_getWriteAdapter();
175:         if ($item->getDefaultPriceScope()) {
176:             $write->delete($this->getTable('bundle/selection_price'),
177:                 array(
178:                     'selection_id = ?' => $item->getSelectionId(),
179:                     'website_id = ?'   => $item->getWebsiteId()
180:                 )
181:             );
182:         } else {
183:              $values = array(
184:                 'selection_id' => $item->getSelectionId(),
185:                 'website_id'   => $item->getWebsiteId(),
186:                 'selection_price_type' => $item->getSelectionPriceType(),
187:                 'selection_price_value' => $item->getSelectionPriceValue()
188:             );
189:             $write->insertOnDuplicate(
190:                 $this->getTable('bundle/selection_price'),
191:                 $values,
192:                 array('selection_price_type', 'selection_price_value')
193:             );
194:         }
195:     }
196: }
197: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0