Mage_Bundle_Model_Observer Class Reference

List of all members.

Public Member Functions

 prepareProductSave ($observer)
 appendUpsellProducts ($observer)
 appendBundleSelectionData ($observer)
 loadProductOptions ($observer)
 duplicateProduct ($observer)
 setAttributeTabBlock ($observer)
 catalogProductLoadAfter (Varien_Event_Observer $observer)
 catalogIndexPlainReindexAfter (Varien_Event_Observer $observer)


Detailed Description

Definition at line 34 of file Observer.php.


Member Function Documentation

appendBundleSelectionData ( observer  ) 

Append selection attributes to selection's order item

Parameters:
Varien_Object $observer
Returns:
Mage_Bundle_Model_Observer

Definition at line 123 of file Observer.php.

00124     {
00125         $orderItem = $observer->getEvent()->getOrderItem();
00126         $quoteItem = $observer->getEvent()->getItem();
00127 
00128         if ($attributes = $quoteItem->getProduct()->getCustomOption('bundle_selection_attributes')) {
00129             $productOptions = $orderItem->getProductOptions();
00130             $productOptions['bundle_selection_attributes'] = $attributes->getValue();
00131             $orderItem->setProductOptions($productOptions);
00132         }
00133 
00134         return $this;
00135     }

appendUpsellProducts ( observer  ) 

Append bundles in upsell list for current product

Parameters:
Varien_Object $observer
Returns:
Mage_Bundle_Model_Observer

Definition at line 76 of file Observer.php.

00077     {
00078         $product = $observer->getEvent()->getProduct();
00079 
00080         if ($product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
00081             return $this;
00082         }
00083 
00084         $collection = $observer->getEvent()->getCollection();
00085         $limit = $observer->getEvent()->getLimit();
00086 
00087         $bundles = Mage::getModel('catalog/product')->getResourceCollection()
00088             ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
00089             ->addStoreFilter()
00090             ->addMinimalPrice()
00091 
00092             ->joinTable('bundle/option', 'parent_id=entity_id', array('option_id' => 'option_id'))
00093             ->joinTable('bundle/selection', 'option_id=option_id', array('product_id' => 'product_id'), '{{table}}.product_id='.$product->getId());
00094 
00095         $ids = $collection->getAllIds();
00096         if (count($ids)) {
00097             $bundles->addIdFilter($ids, true);
00098         }
00099 
00100         Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($bundles);
00101         Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($bundles);
00102 
00103         $bundles->getSelect()->group('entity_id');
00104 
00105         if (isset($limit['bundle'])) {
00106             $bundles->setPageSize($limit['bundle']);
00107         }
00108         $bundles->load();
00109 
00110         foreach ($bundles->getItems() as $item) {
00111             $collection->addItem($item);
00112         }
00113 
00114         return $this;
00115     }

catalogIndexPlainReindexAfter ( Varien_Event_Observer observer  ) 

CatalogIndex Indexer after plain reindex process

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_Bundle_Model_Observer

Definition at line 259 of file Observer.php.

00260     {
00261         $products = $observer->getEvent()->getProducts();
00262         Mage::getSingleton('bundle/price_index')->reindex($products);
00263 
00264         return $this;
00265     }

catalogProductLoadAfter ( Varien_Event_Observer observer  ) 

Add price index to bundle product after load

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_Bundle_Model_Observer

Definition at line 242 of file Observer.php.

00243     {
00244         $product = $observer->getEvent()->getProduct();
00245         if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
00246             Mage::getSingleton('bundle/price_index')
00247                 ->addPriceIndexToProduct($product);
00248         }
00249 
00250         return $this;
00251     }

duplicateProduct ( observer  ) 

duplicating bundle options and selections

Parameters:
Varien_Object $observer
Returns:
Mage_Bundle_Model_Observer

Definition at line 169 of file Observer.php.

00170     {
00171         $product = $observer->getEvent()->getCurrentProduct();
00172 
00173         if ($product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
00174             //do nothing if not bundle
00175             return $this;
00176         }
00177 
00178         $newProduct = $observer->getEvent()->getNewProduct();
00179 
00180         $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
00181         $optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
00182         $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
00183             $product->getTypeInstance(true)->getOptionsIds($product),
00184             $product
00185         );
00186         $optionCollection->appendSelections($selectionCollection);
00187 
00188         $optionRawData = array();
00189         $selectionRawData = array();
00190 
00191         $i = 0;
00192         foreach ($optionCollection as $option) {
00193             $optionRawData[$i] = array(
00194                     'required' => $option->getData('required'),
00195                     'position' => $option->getData('position'),
00196                     'type' => $option->getData('type'),
00197                     'title' => $option->getData('title')?$option->getData('title'):$option->getData('default_title'),
00198                     'delete' => ''
00199                 );
00200             foreach ($option->getSelections() as $selection) {
00201                 $selectionRawData[$i][] = array(
00202                     'product_id' => $selection->getProductId(),
00203                     'position' => $selection->getPosition(),
00204                     'is_default' => $selection->getIsDefault(),
00205                     'selection_price_type' => $selection->getSelectionPriceType(),
00206                     'selection_price_value' => $selection->getSelectionPriceValue(),
00207                     'selection_qty' => $selection->getSelectionQty(),
00208                     'selection_can_change_qty' => $selection->getSelectionCanChangeQty(),
00209                     'delete' => ''
00210                 );
00211             }
00212             $i++;
00213         }
00214 
00215         $newProduct->setBundleOptionsData($optionRawData);
00216         $newProduct->setBundleSelectionsData($selectionRawData);
00217         return $this;
00218     }

loadProductOptions ( observer  ) 

loadding product options for products if there is one bundle in collection only for front end

Parameters:
Varien_Object $observer
Returns:
Mage_Bundle_Model_Observer

Definition at line 144 of file Observer.php.

00145     {
00146         $collection = $observer->getEvent()->getCollection();
00147         /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
00148         $hasBundle = false;
00149         foreach ($collection->getItems() as $item){
00150             if ($item->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
00151                 $hasBundle = true;
00152             }
00153         }
00154 
00155         if ($hasBundle) {
00156             Mage::getSingleton('bundle/price_index')
00157                 ->addPriceIndexToCollection($collection);
00158         }
00159 
00160         return $this;
00161     }

prepareProductSave ( observer  ) 

Setting Bundle Items Data to product for father processing

Parameters:
Varien_Object $observer
Returns:
Mage_Bundle_Model_Observer

Definition at line 42 of file Observer.php.

00043     {
00044         $request = $observer->getEvent()->getRequest();
00045         $product = $observer->getEvent()->getProduct();
00046 
00047         if (($items = $request->getPost('bundle_options')) && !$product->getCompositeReadonly()) {
00048             $product->setBundleOptionsData($items);
00049         }
00050 
00051         if (($selections = $request->getPost('bundle_selections')) && !$product->getCompositeReadonly()) {
00052             $product->setBundleSelectionsData($selections);
00053         }
00054 
00055         if ($product->getPriceType() == '0' && !$product->getOptionsReadonly()) {
00056             $product->setCanSaveCustomOptions(true);
00057             if ($customOptions = $product->getProductOptions()) {
00058                 foreach (array_keys($customOptions) as $key) {
00059                     $customOptions[$key]['is_delete'] = 1;
00060                 }
00061                 $product->setProductOptions($customOptions);
00062             }
00063         }
00064 
00065         $product->setCanSaveBundleSelections((bool)$request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly());
00066 
00067         return $this;
00068     }

setAttributeTabBlock ( observer  ) 

Setting attribute tab block for bundle

Parameters:
Varien_Object $observer
Returns:
Mage_Bundle_Model_Observer

Definition at line 226 of file Observer.php.

00227     {
00228         $product = $observer->getEvent()->getProduct();
00229         if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
00230             Mage::helper('adminhtml/catalog')
00231                 ->setAttributeTabBlock('bundle/adminhtml_catalog_product_edit_tab_attributes');
00232         }
00233         return $this;
00234     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:35 2009 for Magento by  doxygen 1.5.8