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:  * Bundle Products Observer
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Bundle
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Bundle_Model_Observer
 35: {
 36:     /**
 37:      * Setting Bundle Items Data to product for father processing
 38:      *
 39:      * @param Varien_Object $observer
 40:      * @return Mage_Bundle_Model_Observer
 41:      */
 42:     public function prepareProductSave($observer)
 43:     {
 44:         $request = $observer->getEvent()->getRequest();
 45:         $product = $observer->getEvent()->getProduct();
 46: 
 47:         if (($items = $request->getPost('bundle_options')) && !$product->getCompositeReadonly()) {
 48:             $product->setBundleOptionsData($items);
 49:         }
 50: 
 51:         if (($selections = $request->getPost('bundle_selections')) && !$product->getCompositeReadonly()) {
 52:             $product->setBundleSelectionsData($selections);
 53:         }
 54: 
 55:         if ($product->getPriceType() == '0' && !$product->getOptionsReadonly()) {
 56:             $product->setCanSaveCustomOptions(true);
 57:             if ($customOptions = $product->getProductOptions()) {
 58:                 foreach (array_keys($customOptions) as $key) {
 59:                     $customOptions[$key]['is_delete'] = 1;
 60:                 }
 61:                 $product->setProductOptions($customOptions);
 62:             }
 63:         }
 64: 
 65:         $product->setCanSaveBundleSelections(
 66:             (bool)$request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly()
 67:         );
 68: 
 69:         return $this;
 70:     }
 71: 
 72:     /**
 73:      * Append bundles in upsell list for current product
 74:      *
 75:      * @param Varien_Object $observer
 76:      * @return Mage_Bundle_Model_Observer
 77:      */
 78:     public function appendUpsellProducts($observer)
 79:     {
 80:         /* @var $product Mage_Catalog_Model_Product */
 81:         $product = $observer->getEvent()->getProduct();
 82: 
 83:         /**
 84:          * Check is current product type is allowed for bundle selection product type
 85:          */
 86:         if (!in_array($product->getTypeId(), Mage::helper('bundle')->getAllowedSelectionTypes())) {
 87:             return $this;
 88:         }
 89: 
 90:         /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection */
 91:         $collection = $observer->getEvent()->getCollection();
 92:         $limit      = $observer->getEvent()->getLimit();
 93:         if (is_array($limit)) {
 94:             if (isset($limit['upsell'])) {
 95:                 $limit = $limit['upsell'];
 96:             } else {
 97:                 $limit = 0;
 98:             }
 99:         }
100: 
101:         /* @var $resource Mage_Bundle_Model_Mysql4_Selection */
102:         $resource   = Mage::getResourceSingleton('bundle/selection');
103: 
104:         $productIds = array_keys($collection->getItems());
105:         if (!is_null($limit) && $limit <= count($productIds)) {
106:             return $this;
107:         }
108: 
109:         // retrieve bundle product ids
110:         $bundleIds  = $resource->getParentIdsByChild($product->getId());
111:         // exclude up-sell product ids
112:         $bundleIds  = array_diff($bundleIds, $productIds);
113: 
114:         if (!$bundleIds) {
115:             return $this;
116:         }
117: 
118:         /* @var $bundleCollection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
119:         $bundleCollection = $product->getCollection()
120:             ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
121:             ->addStoreFilter()
122:             ->addMinimalPrice()
123:             ->addFinalPrice()
124:             ->addTaxPercents();
125: 
126:         Mage::getSingleton('catalog/product_visibility')
127:             ->addVisibleInCatalogFilterToCollection($bundleCollection);
128: 
129:         if (!is_null($limit)) {
130:             $bundleCollection->setPageSize($limit);
131:         }
132:         $bundleCollection->addFieldToFilter('entity_id', array('in' => $bundleIds))
133:             ->setFlag('do_not_use_category_id', true);
134: 
135:         if ($collection instanceof Varien_Data_Collection) {
136:             foreach ($bundleCollection as $item) {
137:                 $collection->addItem($item);
138:             }
139:         } elseif ($collection instanceof Varien_Object) {
140:             $items = $collection->getItems();
141:             foreach ($bundleCollection as $item) {
142:                 $items[$item->getEntityId()] = $item;
143:             }
144:             $collection->setItems($items);
145:         }
146: 
147:         return $this;
148:     }
149: 
150:     /**
151:      * Append selection attributes to selection's order item
152:      *
153:      * @param Varien_Object $observer
154:      * @return Mage_Bundle_Model_Observer
155:      */
156:     public function appendBundleSelectionData($observer)
157:     {
158:         $orderItem = $observer->getEvent()->getOrderItem();
159:         $quoteItem = $observer->getEvent()->getItem();
160: 
161:         if ($attributes = $quoteItem->getProduct()->getCustomOption('bundle_selection_attributes')) {
162:             $productOptions = $orderItem->getProductOptions();
163:             $productOptions['bundle_selection_attributes'] = $attributes->getValue();
164:             $orderItem->setProductOptions($productOptions);
165:         }
166: 
167:         return $this;
168:     }
169: 
170:     /**
171:      * Add price index data for catalog product collection
172:      * only for front end
173:      *
174:      * @param Varien_Event_Observer $observer
175:      * @return Mage_Bundle_Model_Observer
176:      */
177:     public function loadProductOptions($observer)
178:     {
179:         $collection = $observer->getEvent()->getCollection();
180:         /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
181:         $collection->addPriceData();
182: 
183:         return $this;
184:     }
185: 
186:     /**
187:      * duplicating bundle options and selections
188:      *
189:      * @param Varien_Object $observer
190:      * @return Mage_Bundle_Model_Observer
191:      */
192:     public function duplicateProduct($observer)
193:     {
194:         $product = $observer->getEvent()->getCurrentProduct();
195: 
196:         if ($product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
197:             //do nothing if not bundle
198:             return $this;
199:         }
200: 
201:         $newProduct = $observer->getEvent()->getNewProduct();
202: 
203:         $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
204:         $optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
205:         $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
206:             $product->getTypeInstance(true)->getOptionsIds($product),
207:             $product
208:         );
209:         $optionCollection->appendSelections($selectionCollection);
210: 
211:         $optionRawData = array();
212:         $selectionRawData = array();
213: 
214:         $i = 0;
215:         foreach ($optionCollection as $option) {
216:             $optionRawData[$i] = array(
217:                     'required' => $option->getData('required'),
218:                     'position' => $option->getData('position'),
219:                     'type' => $option->getData('type'),
220:                     'title' => $option->getData('title')?$option->getData('title'):$option->getData('default_title'),
221:                     'delete' => ''
222:                 );
223:             foreach ($option->getSelections() as $selection) {
224:                 $selectionRawData[$i][] = array(
225:                     'product_id' => $selection->getProductId(),
226:                     'position' => $selection->getPosition(),
227:                     'is_default' => $selection->getIsDefault(),
228:                     'selection_price_type' => $selection->getSelectionPriceType(),
229:                     'selection_price_value' => $selection->getSelectionPriceValue(),
230:                     'selection_qty' => $selection->getSelectionQty(),
231:                     'selection_can_change_qty' => $selection->getSelectionCanChangeQty(),
232:                     'delete' => ''
233:                 );
234:             }
235:             $i++;
236:         }
237: 
238:         $newProduct->setBundleOptionsData($optionRawData);
239:         $newProduct->setBundleSelectionsData($selectionRawData);
240:         return $this;
241:     }
242: 
243:     /**
244:      * Setting attribute tab block for bundle
245:      *
246:      * @param Varien_Object $observer
247:      * @return Mage_Bundle_Model_Observer
248:      */
249:     public function setAttributeTabBlock($observer)
250:     {
251:         $product = $observer->getEvent()->getProduct();
252:         if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
253:             Mage::helper('adminhtml/catalog')
254:                 ->setAttributeTabBlock('bundle/adminhtml_catalog_product_edit_tab_attributes');
255:         }
256:         return $this;
257:     }
258: 
259:     /**
260:      * Initialize product options renderer with bundle specific params
261:      *
262:      * @param Varien_Event_Observer $observer
263:      * @return Mage_Bundle_Model_Observer
264:      */
265:     public function initOptionRenderer(Varien_Event_Observer $observer)
266:     {
267:         $block = $observer->getBlock();
268:         $block->addOptionsRenderCfg('bundle', 'bundle/catalog_product_configuration');
269:         return $this;
270:     }
271: 
272:     /**
273:      * Add price index to bundle product after load
274:      *
275:      * @deprecated since 1.4.0.0
276:      *
277:      * @param Varien_Event_Observer $observer
278:      * @return Mage_Bundle_Model_Observer
279:      */
280:     public function catalogProductLoadAfter(Varien_Event_Observer $observer)
281:     {
282:         $product = $observer->getEvent()->getProduct();
283:         if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
284:             Mage::getSingleton('bundle/price_index')
285:                 ->addPriceIndexToProduct($product);
286:         }
287: 
288:         return $this;
289:     }
290: 
291:     /**
292:      * CatalogIndex Indexer after plain reindex process
293:      *
294:      * @deprecated since 1.4.0.0
295:      * @see Mage_Bundle_Model_Mysql4_Indexer_Price
296:      *
297:      * @param Varien_Event_Observer $observer
298:      * @return Mage_Bundle_Model_Observer
299:      */
300:     public function catalogIndexPlainReindexAfter(Varien_Event_Observer $observer)
301:     {
302:         $products = $observer->getEvent()->getProducts();
303:         Mage::getSingleton('bundle/price_index')->reindex($products);
304: 
305:         return $this;
306:     }
307: }
308: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0