Mage_Adminhtml_Catalog_Product_Action_AttributeController Class Reference

Inheritance diagram for Mage_Adminhtml_Catalog_Product_Action_AttributeController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 editAction ()
 saveAction ()

Protected Member Functions

 _construct ()
 _validateProducts ()
 _getHelper ()
 _isAllowed ()


Detailed Description

Definition at line 35 of file AttributeController.php.


Member Function Documentation

_construct (  )  [protected]

Reimplemented from Mage_Core_Controller_Varien_Action.

Definition at line 38 of file AttributeController.php.

00039     {
00040         // Define module dependent translate
00041         $this->setUsedModuleName('Mage_Catalog');
00042     }

_getHelper (  )  [protected]

Rertive data manipulation helper

Returns:
Mage_Adminhtml_Helper_Catalog_Product_Edit_Action_Attribute

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 200 of file AttributeController.php.

00201     {
00202         return Mage::helper('adminhtml/catalog_product_edit_action_attribute');
00203     }

_isAllowed (  )  [protected]

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 205 of file AttributeController.php.

00206     {
00207         return Mage::getSingleton('admin/session')->isAllowed('catalog/update_attributes');
00208     }

_validateProducts (  )  [protected]

Validate selection of products for massupdate

Returns:
boolean

Definition at line 184 of file AttributeController.php.

00185     {
00186         if (!is_array($this->_getHelper()->getProductIds())) {
00187             $this->_getSession()->addError($this->__('Please select products for attributes update'));
00188             $this->_redirect('*/catalog_product/', array('_current'=>true));
00189             return false;
00190         }
00191 
00192         return true;
00193     }

editAction (  ) 

Definition at line 44 of file AttributeController.php.

00045     {
00046         if (!$this->_validateProducts()) {
00047             return;
00048         }
00049 
00050         $this->loadLayout();
00051         $this->renderLayout();
00052     }

saveAction (  ) 

Definition at line 54 of file AttributeController.php.

00055     {
00056         if (!$this->_validateProducts()) {
00057             return;
00058         }
00059 
00060         /* Collect Data */
00061         $inventoryData = $this->getRequest()->getParam('inventory', array());
00062         $attributesData = $this->getRequest()->getParam('attributes', array());
00063         $websiteRemoveData = $this->getRequest()->getParam('remove_website_ids', array());
00064         $websiteAddData = $this->getRequest()->getParam('add_website_ids', array());
00065 
00066         /* Prepare inventory data item options (use config settings) */
00067         foreach (Mage::helper('cataloginventory')->getConfigItemOptions() as $option) {
00068             if (isset($inventoryData[$option]) && !isset($inventoryData['use_config_' . $option])) {
00069                 $inventoryData['use_config_' . $option] = 0;
00070             }
00071         }
00072 
00073         try {
00074             if ($attributesData) {
00075                 $product = Mage::getModel('catalog/product');
00076                 if ($inventoryData) {
00077                     $stockItem = Mage::getModel('cataloginventory/stock_item');
00078                 }
00079                 foreach ($this->_getHelper()->getProductIds() as $productId) {
00080                     $product->setData(array());
00081                     $product->setStoreId($this->_getHelper()->getSelectedStoreId())
00082                         ->load($productId)
00083                         ->setIsMassupdate(true)
00084                         ->setExcludeUrlRewrite(true);
00085 
00086                     if (!$product->getId()) {
00087                         continue;
00088                     }
00089 
00090                     $product->addData($attributesData);
00091                     if ($inventoryData) {
00092                         $product->setStockData($inventoryData);
00093                     }
00094 
00095                     $dataChanged = false;
00096                     foreach ($attributesData as $k => $v) {
00097                         if ($product->dataHasChangedFor($k)) {
00098                             $dataChanged = true;
00099                         }
00100                     }
00101 
00102                     if ($dataChanged) {
00103                         $product->save();
00104                     }
00105                     elseif ($inventoryData) {
00106                         $stockItem->setData(array());
00107                         $stockItem->loadByProduct($productId)
00108                             ->setProductId($productId);
00109                         $stockDataChanged = false;
00110                         foreach ($inventoryData as $k => $v) {
00111                             $stockItem->setDataUsingMethod($k, $v);
00112                             if ($stockItem->dataHasChangedFor($k)) {
00113                                 $stockDataChanged = true;
00114                             }
00115                         }
00116                         if ($stockDataChanged) {
00117                             $stockItem->save();
00118                         }
00119                     }
00120                 }
00121             }
00122             elseif ($inventoryData) {
00123                 $stockItem = Mage::getModel('cataloginventory/stock_item');
00124 
00125                 foreach ($this->_getHelper()->getProductIds() as $productId) {
00126                     $stockItem->setData(array());
00127                     $stockItem->loadByProduct($productId)
00128                         ->setProductId($productId);
00129 
00130                     $stockDataChanged = false;
00131                     foreach ($inventoryData as $k => $v) {
00132                         $stockItem->setDataUsingMethod($k, $v);
00133                         if ($stockItem->dataHasChangedFor($k)) {
00134                             $stockDataChanged = true;
00135                         }
00136                     }
00137                     if ($stockDataChanged) {
00138                         $stockItem->save();
00139                     }
00140                 }
00141             }
00142 
00143             if ($websiteAddData || $websiteRemoveData) {
00144                 $productWebsite = Mage::getModel('catalog/product_website');
00145                 /* @var $productWebsite Mage_Catalog_Model_Product_Website */
00146 
00147                 if ($websiteRemoveData) {
00148                     $productWebsite->removeProducts($websiteRemoveData, $this->_getHelper()->getProductIds());
00149                 }
00150                 if ($websiteAddData) {
00151                     $productWebsite->addProducts($websiteAddData, $this->_getHelper()->getProductIds());
00152                 }
00153 
00154                 Mage::dispatchEvent(
00155                     'catalog_product_to_website_change',
00156                     array('products'=>$this->_getHelper()->getProductIds())
00157                 );
00158 
00159                 $this->_getSession()->addNotice(
00160                     $this->__('Please refresh "Catalog Rewrites" and "Layered Navigation Indices" in System -> <a href="%s">Cache Management</a>', $this->getUrl('adminhtml/system_cache'))
00161                 );
00162             }
00163 
00164             $this->_getSession()->addSuccess(
00165                 $this->__('Total of %d record(s) were successfully updated',
00166                 count($this->_getHelper()->getProductIds()))
00167             );
00168         }
00169         catch (Mage_Core_Exception $e) {
00170             $this->_getSession()->addError($e->getMessage());
00171         }
00172         catch (Exception $e) {
00173             $this->_getSession()->addException($e, $this->__('There was an error while updating product(s) attributes'));
00174         }
00175 
00176         $this->_redirect('*/catalog_product/', array('store'=>$this->_getHelper()->getSelectedStoreId()));
00177     }


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

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