Mage_Adminhtml_Catalog_ProductController Class Reference

Inheritance diagram for Mage_Adminhtml_Catalog_ProductController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action Mage_Bundle_Product_EditController Mage_Downloadable_Product_EditController

List of all members.

Public Member Functions

 indexAction ()
 newAction ()
 editAction ()
 gridAction ()
 gridOnlyAction ()
 categoriesAction ()
 optionsAction ()
 relatedAction ()
 upsellAction ()
 crosssellAction ()
 superGroupAction ()
 superGroupGridOnlyAction ()
 reviewsAction ()
 superConfigAction ()
 bundlesAction ()
 validateAction ()
 categoriesJsonAction ()
 saveAction ()
 duplicateAction ()
 deleteAction ()
 tagGridAction ()
 alertsPriceGridAction ()
 alertsStockGridAction ()
 addCustomersToAlertQueueAction ()
 addAttributeAction ()
 createdAction ()
 massDeleteAction ()
 massStatusAction ()
 tagCustomerGridAction ()
 quickCreateAction ()

Protected Member Functions

 _construct ()
 _initProduct ()
 _createSerializerBlock ($inputName, Mage_Adminhtml_Block_Widget_Grid $gridBlock, $productsArray)
 _outputBlocks ()
 _initProductSave ()
 _decodeInput ($encoded)
 _isAllowed ()


Detailed Description

Definition at line 34 of file ProductController.php.


Member Function Documentation

_construct (  )  [protected]

Reimplemented from Mage_Core_Controller_Varien_Action.

Reimplemented in Mage_Bundle_Product_EditController, and Mage_Downloadable_Product_EditController.

Definition at line 36 of file ProductController.php.

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

_createSerializerBlock ( inputName,
Mage_Adminhtml_Block_Widget_Grid gridBlock,
productsArray 
) [protected]

Create serializer block for a grid

Parameters:
string $inputName
Mage_Adminhtml_Block_Widget_Grid $gridBlock
array $productsArray
Returns:
Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Ajax_Serializer

Definition at line 132 of file ProductController.php.

00133     {
00134         return $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_ajax_serializer')
00135             ->setGridBlock($gridBlock)
00136             ->setProducts($productsArray)
00137             ->setInputElementName($inputName)
00138         ;
00139     }

_decodeInput ( encoded  )  [protected]

Decode strings for linked products

Parameters:
string $encoded
Returns:
array

Definition at line 637 of file ProductController.php.

00638     {
00639         parse_str($encoded, $data);
00640         foreach($data as $key=>$value) {
00641             parse_str(base64_decode($value), $data[$key]);
00642         }
00643 
00644         return $data;
00645     }

_initProduct (  )  [protected]

Initialize product from request parameters

Returns:
Mage_Catalog_Model_Product

Definition at line 47 of file ProductController.php.

00048     {
00049         $productId  = (int) $this->getRequest()->getParam('id');
00050         $product    = Mage::getModel('catalog/product')
00051             ->setStoreId($this->getRequest()->getParam('store', 0));
00052 
00053         if (!$productId) {
00054             if ($setId = (int) $this->getRequest()->getParam('set')) {
00055                 $product->setAttributeSetId($setId);
00056             }
00057 
00058             if ($typeId = $this->getRequest()->getParam('type')) {
00059                 $product->setTypeId($typeId);
00060             }
00061         }
00062 
00063         if ($productId) {
00064             $product->load($productId);
00065         }
00066 
00067         $attributes = $this->getRequest()->getParam('attributes');
00068         if ($attributes && $product->isConfigurable() &&
00069             (!$productId || !$product->getTypeInstance()->getUsedProductAttributeIds())) {
00070             $product->getTypeInstance()->setUsedProductAttributeIds(
00071                 explode(",", base64_decode(urldecode($attributes)))
00072             );
00073         }
00074 
00075         // Init attribute label names for store selected in dropdown
00076         Mage_Catalog_Model_Resource_Eav_Attribute::initLabels($product->getStoreId());
00077 
00078         // Required attributes of simple product for configurable creation
00079         if ($this->getRequest()->getParam('popup')
00080             && $requiredAttributes = $this->getRequest()->getParam('required')) {
00081             $requiredAttributes = explode(",", $requiredAttributes);
00082             foreach ($product->getAttributes() as $attribute) {
00083                 if (in_array($attribute->getId(), $requiredAttributes)) {
00084                     $attribute->setIsRequired(1);
00085                 }
00086             }
00087         }
00088 
00089         if ($this->getRequest()->getParam('popup')
00090             && $this->getRequest()->getParam('product')
00091             && !is_array($this->getRequest()->getParam('product'))
00092             && $this->getRequest()->getParam('id', false) === false) {
00093 
00094             $configProduct = Mage::getModel('catalog/product')
00095                 ->setStoreId(0)
00096                 ->load($this->getRequest()->getParam('product'))
00097                 ->setTypeId($this->getRequest()->getParam('type'));
00098 
00099             /* @var $configProduct Mage_Catalog_Model_Product */
00100             $data = array();
00101             foreach ($configProduct->getTypeInstance()->getEditableAttributes() as $attribute) {
00102 
00103                 /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
00104                 if(!$attribute->getIsUnique()
00105                     && $attribute->getFrontend()->getInputType()!='gallery'
00106                     && $attribute->getAttributeCode() != 'required_options'
00107                     && $attribute->getAttributeCode() != 'has_options'
00108                     && $attribute->getAttributeCode() != $configProduct->getIdFieldName()) {
00109                     $data[$attribute->getAttributeCode()] = $configProduct->getData($attribute->getAttributeCode());
00110                 }
00111             }
00112 
00113             $product->addData($data)
00114                 ->setWebsiteIds($configProduct->getWebsiteIds());
00115         }
00116 
00117         $product->setData('_edit_mode', true);
00118 
00119         Mage::register('product', $product);
00120         Mage::register('current_product', $product);
00121         return $product;
00122     }

_initProductSave (  )  [protected]

Initialize product before saving

Websites

Check "Use Default Value" checkboxes values

Init product links data (related, upsell, crosssel)

Initialize product categories

Initialize data for configurable product

Initialize product options

Definition at line 443 of file ProductController.php.

00444     {
00445         $product    = $this->_initProduct();
00446         $productData = $this->getRequest()->getPost('product');
00447         if ($productData && !isset($productData['stock_data']['use_config_manage_stock'])) {
00448             $productData['stock_data']['use_config_manage_stock'] = 0;
00449         }
00450 
00451         /**
00452          * Websites
00453          */
00454         if (!isset($productData['website_ids'])) {
00455             $productData['website_ids'] = array();
00456         }
00457 
00458         $wasLockedMedia = false;
00459         if ($product->isLockedAttribute('media')) {
00460             $product->unlockAttribute('media');
00461             $wasLockedMedia = true;
00462         }
00463 
00464         $product->addData($productData);
00465 
00466         if ($wasLockedMedia) {
00467             $product->lockAttribute('media');
00468         }
00469 
00470         if (Mage::app()->isSingleStoreMode()) {
00471             $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
00472         }
00473         /**
00474          * Check "Use Default Value" checkboxes values
00475          */
00476         if ($useDefaults = $this->getRequest()->getPost('use_default')) {
00477             foreach ($useDefaults as $attributeCode) {
00478                 $product->setData($attributeCode, null);
00479             }
00480         }
00481 
00482         /**
00483          * Init product links data (related, upsell, crosssel)
00484          */
00485         $links = $this->getRequest()->getPost('links');
00486         if (isset($links['related']) && !$product->getRelatedReadonly()) {
00487             $product->setRelatedLinkData($this->_decodeInput($links['related']));
00488         }
00489         if (isset($links['upsell'])  && !$product->getUpsellReadonly()) {
00490             $product->setUpSellLinkData($this->_decodeInput($links['upsell']));
00491         }
00492         if (isset($links['crosssell'])  && !$product->getCrosssellReadonly()) {
00493             $product->setCrossSellLinkData($this->_decodeInput($links['crosssell']));
00494         }
00495         if (isset($links['grouped'])  && !$product->getGroupedReadonly()) {
00496             $product->setGroupedLinkData($this->_decodeInput($links['grouped']));
00497         }
00498 
00499         /**
00500          * Initialize product categories
00501          */
00502         $categoryIds = $this->getRequest()->getPost('category_ids');
00503         if (null !== $categoryIds) {
00504             if (empty($categoryIds)) {
00505                 $categoryIds = array();
00506             }
00507             $product->setCategoryIds($categoryIds);
00508         }
00509 
00510         /**
00511          * Initialize data for configurable product
00512          */
00513         if (($data = $this->getRequest()->getPost('configurable_products_data')) && !$product->getConfigurableReadonly()) {
00514             $product->setConfigurableProductsData(Zend_Json::decode($data));
00515         }
00516         if (($data = $this->getRequest()->getPost('configurable_attributes_data')) && !$product->getConfigurableReadonly()) {
00517             $product->setConfigurableAttributesData(Zend_Json::decode($data));
00518         }
00519 
00520         $product->setCanSaveConfigurableAttributes((bool)$this->getRequest()->getPost('affect_configurable_product_attributes') && !$product->getConfigurableReadonly());
00521 
00522         /**
00523          * Initialize product options
00524          */
00525         if (isset($productData['options']) && !$product->getOptionsReadonly()) {
00526             $product->setProductOptions($productData['options']);
00527         }
00528 
00529         $product->setCanSaveCustomOptions((bool)$this->getRequest()->getPost('affect_product_custom_options') && !$product->getOptionsReadonly());
00530 
00531         Mage::dispatchEvent('catalog_product_prepare_save', array('product' => $product, 'request' => $this->getRequest()));
00532 
00533         return $product;
00534     }

_isAllowed (  )  [protected]

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 895 of file ProductController.php.

00896     {
00897         return Mage::getSingleton('admin/session')->isAllowed('catalog/products');
00898     }

_outputBlocks (  )  [protected]

Output specified blocks as a text list

Definition at line 144 of file ProductController.php.

00145     {
00146         $blocks = func_get_args();
00147         $output = $this->getLayout()->createBlock('adminhtml/text_list');
00148         foreach ($blocks as $block) {
00149             $output->insert($block, '', true);
00150         }
00151         $this->getResponse()->setBody($output->toHtml());
00152     }

addAttributeAction (  ) 

Definition at line 711 of file ProductController.php.

00712     {
00713         $this->_getSession()->addNotice(Mage::helper('catalog')->__('Please click on Close Window button if it won\'t be closed automatically'));
00714         $this->loadLayout('popup');
00715         $this->_initProduct();
00716         $this->_addContent(
00717             $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_new_product_created')
00718         );
00719         $this->renderLayout();
00720     }

addCustomersToAlertQueueAction (  ) 

Definition at line 687 of file ProductController.php.

00688     {
00689         $alerts = Mage::getSingleton('customeralert/config')->getAlerts();;
00690         $block = $this->getLayout()
00691             ->createBlock('adminhtml/messages', 'messages');
00692         $collection = $block
00693             ->getMessageCollection();
00694         foreach ($alerts as $key=>$val) {
00695             try {
00696                 if(Mage::getSingleton('customeralert/config')->getAlertByType($key)
00697                     ->setParamValues($this->getRequest()->getParams())
00698                     ->addCustomersToAlertQueue())
00699                 {
00700                     $collection->addMessage(Mage::getModel('core/message')->success($this->__('Customers for alert %s was successfuly added to queue', Mage::getSingleton('customeralert/config')->getTitleByType($key))));
00701                 }
00702             } catch (Exception $e) {
00703                 $collection->addMessage(Mage::getModel('core/message')->error($this->__('Error while adding customers for %s alert. Message: %s',Mage::getSingleton('customeralert/config')->getTitleByType($key),$e->getMessage())));
00704                 continue;
00705             }
00706         }
00707         print $block->getGroupedHtml();
00708         return $this;
00709     }

alertsPriceGridAction (  ) 

Definition at line 673 of file ProductController.php.

00674     {
00675         $this->getResponse()->setBody(
00676             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_alerts_price')->toHtml()
00677         );
00678     }

alertsStockGridAction (  ) 

Definition at line 680 of file ProductController.php.

00681     {
00682         $this->getResponse()->setBody(
00683             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_alerts_stock')->toHtml()
00684         );
00685     }

bundlesAction (  ) 

Deprecated since 1.2

Definition at line 384 of file ProductController.php.

00385     {
00386         $product = $this->_initProduct();
00387         $this->getResponse()->setBody(
00388             $this->getLayout()->createBlock('bundle/adminhtml_catalog_product_edit_tab_bundle', 'admin.product.bundle.items')
00389                 ->setProductId($product->getId())
00390                 ->toHtml()
00391         );
00392     }

categoriesAction (  ) 

Get categories fieldset block

Definition at line 256 of file ProductController.php.

00257     {
00258         $this->_initProduct();
00259 
00260         $this->getResponse()->setBody(
00261             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_categories')->toHtml()
00262         );
00263     }

categoriesJsonAction (  ) 

Definition at line 536 of file ProductController.php.

00537     {
00538         $product = $this->_initProduct();
00539 
00540 
00541 
00542         $this->getResponse()->setBody(
00543             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_categories')
00544                 ->getCategoryChildrenJson($this->getRequest()->getParam('category'))
00545         );
00546     }

createdAction (  ) 

Definition at line 722 of file ProductController.php.

00723     {
00724         $this->_getSession()->addNotice(Mage::helper('catalog')->__('Please click on Close Window button if it won\'t be closed automatically'));
00725         $this->loadLayout('popup');
00726         $this->_addContent(
00727             $this->getLayout()->createBlock('adminhtml/catalog_product_created')
00728         );
00729         $this->renderLayout();
00730     }

crosssellAction (  ) 

Get crosssell products grid and serializer block

Definition at line 311 of file ProductController.php.

00312     {
00313         $this->_initProduct();
00314 
00315         $gridBlock = $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_crosssell')
00316             ->setGridUrl($this->getUrl('*/*/gridOnly', array('_current' => true, 'gridOnlyBlock' => 'crosssell')))
00317         ;
00318         $serializerBlock = $this->_createSerializerBlock('links[crosssell]', $gridBlock, Mage::registry('product')->getCrossSellProducts());
00319 
00320         $this->_outputBlocks($gridBlock, $serializerBlock);
00321     }

deleteAction (  ) 

Definition at line 647 of file ProductController.php.

00648     {
00649         if ($id = $this->getRequest()->getParam('id')) {
00650             $product = Mage::getModel('catalog/product')
00651                 ->load($id);
00652             $sku = $product->getSku();
00653             try {
00654                 $product->delete();
00655                 $this->_getSession()->addSuccess($this->__('Product deleted'));
00656             }
00657             catch (Exception $e) {
00658                 $this->_getSession()->addError($e->getMessage());
00659             }
00660         }
00661         $this->getResponse()->setRedirect($this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store'))));
00662     }

duplicateAction (  ) 

Create product duplicate

Definition at line 616 of file ProductController.php.

00617     {
00618         $productId = (int) $this->getRequest()->getParam('id');
00619         $product = Mage::getModel('catalog/product')->load($productId);
00620         try {
00621             $newProduct = $product->duplicate();
00622             $this->_getSession()->addSuccess($this->__('Product duplicated'));
00623             $this->_redirect('*/*/edit', array('_current'=>true, 'id'=>$newProduct->getId()));
00624         }
00625         catch (Exception $e){
00626             $this->_getSession()->addError($e->getMessage());
00627             $this->_redirect('*/*/edit', array('_current'=>true));
00628         }
00629     }

editAction (  ) 

Product edit form

Definition at line 197 of file ProductController.php.

00198     {
00199         $product = $this->_initProduct();
00200         Mage::dispatchEvent('catalog_product_edit_action', array('product' => $product));
00201 
00202         $_additionalLayoutPart = '';
00203         if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
00204             && !($product->getTypeInstance()->getUsedProductAttributeIds()))
00205         {
00206             $_additionalLayoutPart = '_new';
00207         }
00208 
00209         $this->loadLayout(array(
00210             'default',
00211             strtolower($this->getFullActionName()),
00212             'adminhtml_catalog_product_'.$product->getTypeId() . $_additionalLayoutPart
00213         ));
00214 
00215         $this->_setActiveMenu('catalog/products');
00216 
00217         if (!Mage::app()->isSingleStoreMode() && ($switchBlock = $this->getLayout()->getBlock('store_switcher'))) {
00218             $switchBlock->setDefaultStoreName($this->__('Default Values'))
00219                 ->setWebsiteIds($product->getWebsiteIds())
00220                 ->setSwitchUrl($this->getUrl('*/*/*', array('_current'=>true, 'active_tab'=>null, 'tab' => null, 'store'=>null)));
00221         }
00222 
00223         $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
00224 
00225         $this->renderLayout();
00226     }

gridAction (  ) 

Product grid for AJAX request

Definition at line 231 of file ProductController.php.

00232     {
00233         $this->loadLayout();
00234         $this->getResponse()->setBody(
00235             $this->getLayout()->createBlock('adminhtml/catalog_product_grid')->toHtml()
00236         );
00237     }

gridOnlyAction (  ) 

Get specified tab grid

Definition at line 242 of file ProductController.php.

00243     {
00244         $this->_initProduct();
00245         $this->loadLayout();
00246         $this->getResponse()->setBody(
00247             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_' . $this->getRequest()->getParam('gridOnlyBlock'))
00248                 ->toHtml()
00249         );
00250     }

indexAction (  ) 

Product list page

Definition at line 157 of file ProductController.php.

00158     {
00159         $this->loadLayout();
00160         $this->_setActiveMenu('catalog/products');
00161         $this->renderLayout();
00162     }

massDeleteAction (  ) 

Definition at line 732 of file ProductController.php.

00733     {
00734         $productIds = $this->getRequest()->getParam('product');
00735         if (!is_array($productIds)) {
00736             $this->_getSession()->addError($this->__('Please select product(s)'));
00737         }
00738         else {
00739             try {
00740                 foreach ($productIds as $productId) {
00741                     $product = Mage::getSingleton('catalog/product')->load($productId);
00742                     Mage::dispatchEvent('catalog_controller_product_delete', array('product' => $product));
00743                     $product->delete();
00744                 }
00745                 $this->_getSession()->addSuccess(
00746                     $this->__('Total of %d record(s) were successfully deleted', count($productIds))
00747                 );
00748             } catch (Exception $e) {
00749                 $this->_getSession()->addError($e->getMessage());
00750             }
00751         }
00752         $this->_redirect('*/*/index');
00753     }

massStatusAction (  ) 

Definition at line 755 of file ProductController.php.

00756     {
00757         $productIds = (array)$this->getRequest()->getParam('product');
00758         $storeId    = (int)$this->getRequest()->getParam('store', 0);
00759         $status     = (int)$this->getRequest()->getParam('status');
00760 
00761         $statusModel = Mage::getModel('catalog/product_status');
00762 
00763         try {
00764             foreach ($productIds as $productId) {
00765                 $statusModel->updateProductStatus($productId, $storeId, $status);
00766             }
00767             $this->_getSession()->addSuccess(
00768                 $this->__('Total of %d record(s) were successfully updated', count($productIds))
00769             );
00770         }
00771         catch (Mage_Core_Model_Exception $e) {
00772             $this->_getSession()->addError($e->getMessage());
00773         }
00774         catch (Exception $e) {
00775             $this->_getSession()->addException($e, $this->__('There was an error while updating product(s) status'));
00776         }
00777 
00778         $this->_redirect('*/*/', array('store'=> $storeId));
00779     }

newAction (  ) 

Create new product page

Definition at line 167 of file ProductController.php.

00168     {
00169         $product = $this->_initProduct();
00170 
00171         Mage::dispatchEvent('catalog_product_new_action', array('product' => $product));
00172 
00173         if ($this->getRequest()->getParam('popup')) {
00174             $this->loadLayout('popup');
00175         } else {
00176             $_additionalLayoutPart = '';
00177             if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
00178                 && !($product->getTypeInstance()->getUsedProductAttributeIds()))
00179             {
00180                 $_additionalLayoutPart = '_new';
00181             }
00182             $this->loadLayout(array(
00183                 'default',
00184                 strtolower($this->getFullActionName()),
00185                 'adminhtml_catalog_product_'.$product->getTypeId() . $_additionalLayoutPart
00186             ));
00187             $this->_setActiveMenu('catalog/products');
00188         }
00189 
00190         $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
00191         $this->renderLayout();
00192     }

optionsAction (  ) 

Get options fieldset block

Definition at line 269 of file ProductController.php.

00270     {
00271         $this->_initProduct();
00272 
00273         $this->getResponse()->setBody(
00274             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_options', 'admin.product.options')->toHtml()
00275         );
00276     }

quickCreateAction (  ) 

Definition at line 790 of file ProductController.php.

00791     {
00792         $result = array();
00793 
00794         /* @var $configurableProduct Mage_Catalog_Model_Product */
00795         $configurableProduct = Mage::getModel('catalog/product')
00796             ->setStoreId(0)
00797             ->load($this->getRequest()->getParam('product'));
00798 
00799         if (!$configurableProduct->isConfigurable()) {
00800             // If invalid parent product
00801             $this->_redirect('*/*/');
00802             return;
00803         }
00804 
00805         /* @var $product Mage_Catalog_Model_Product */
00806 
00807         $product = Mage::getModel('catalog/product')
00808             ->setStoreId(0)
00809             ->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)
00810             ->setAttributeSetId($configurableProduct->getAttributeSetId());
00811 
00812 
00813         foreach ($product->getTypeInstance()->getEditableAttributes() as $attribute) {
00814             if ($attribute->getIsUnique()
00815                 || $attribute->getFrontend()->getInputType() == 'gallery'
00816                 || $attribute->getFrontend()->getInputType() == 'media_image'
00817                 || !$attribute->getIsVisible()) {
00818                 continue;
00819             }
00820 
00821             $product->setData(
00822                 $attribute->getAttributeCode(),
00823                 $configurableProduct->getData($attribute->getAttributeCode())
00824             );
00825         }
00826 
00827         $product->addData($this->getRequest()->getParam('simple_product', array()));
00828         $product->setWebsiteIds($configurableProduct->getWebsiteIds());
00829 
00830         $autogenerateOptions = array();
00831         $result['attributes'] = array();
00832 
00833         foreach ($configurableProduct->getTypeInstance()->getConfigurableAttributes() as $attribute) {
00834             $value = $product->getAttributeText($attribute->getProductAttribute()->getAttributeCode());
00835             $autogenerateOptions[] = $value;
00836             $result['attributes'][] = array(
00837                 'label'         => $value,
00838                 'value_index'   => $product->getData($attribute->getProductAttribute()->getAttributeCode()),
00839                 'attribute_id'  => $attribute->getProductAttribute()->getId()
00840             );
00841         }
00842 
00843         if ($product->getNameAutogenerate()) {
00844             $product->setName($configurableProduct->getName() . '-' . implode('-', $autogenerateOptions));
00845         }
00846 
00847         if ($product->getSkuAutogenerate()) {
00848             $product->setSku($configurableProduct->getSku() . '-' . implode('-', $autogenerateOptions));
00849         }
00850 
00851         if (is_array($product->getPricing())) {
00852            $result['pricing'] = $product->getPricing();
00853            $additionalPrice = 0;
00854            foreach ($product->getPricing() as $pricing) {
00855                if (empty($pricing['value'])) {
00856                    continue;
00857                }
00858 
00859                if (!empty($pricing['is_percent'])) {
00860                    $pricing['value'] = ($pricing['value']/100)*$product->getPrice();
00861                }
00862 
00863                $additionalPrice += $pricing['value'];
00864            }
00865 
00866            $product->setPrice($product->getPrice() + $additionalPrice);
00867            $product->unsPricing();
00868         }
00869 
00870         try {
00871             $product->validate();
00872             $product->save();
00873             $result['product_id'] = $product->getId();
00874             $this->_getSession()->addSuccess(Mage::helper('catalog')->__('Product was successfully created.'));
00875             $this->_initLayoutMessages('adminhtml/session');
00876             $result['messages']  = $this->getLayout()->getMessagesBlock()->getGroupedHtml();
00877         } catch (Mage_Core_Exception $e) {
00878             $result['error'] = array(
00879                 'message' =>  $e->getMessage(),
00880                 'fields'  => array(
00881                     'sku'  =>  $product->getSku()
00882                 )
00883             );
00884 
00885         } catch (Exception $e) {
00886             Mage::logException($e);
00887             $result['error'] = array(
00888                 'message'   =>  $this->__('Product saving error. ') . $e->getMessage()
00889              );
00890         }
00891 
00892         $this->getResponse()->setBody(Zend_Json::encode($result));
00893     }

relatedAction (  ) 

Get related products grid and serializer block

Definition at line 281 of file ProductController.php.

00282     {
00283         $this->_initProduct();
00284 
00285         $gridBlock = $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_related')
00286             ->setGridUrl($this->getUrl('*/*/gridOnly', array('_current' => true, 'gridOnlyBlock' => 'related')))
00287         ;
00288         $serializerBlock = $this->_createSerializerBlock('links[related]', $gridBlock, Mage::registry('product')->getRelatedProducts());
00289 
00290         $this->_outputBlocks($gridBlock, $serializerBlock);
00291     }

reviewsAction (  ) 

Get product reviews grid

Definition at line 360 of file ProductController.php.

00361     {
00362         $this->_initProduct();
00363 
00364         $this->getResponse()->setBody(
00365             $this->getLayout()->createBlock('adminhtml/review_grid', 'admin.product.reviews')
00366                 ->setProductId(Mage::registry('product')->getId())
00367                 ->setUseAjax(true)
00368                 ->toHtml()
00369         );
00370     }

saveAction (  ) 

Save product action

Do copying data to stores

Definition at line 551 of file ProductController.php.

00552     {
00553         $storeId        = $this->getRequest()->getParam('store');
00554         $redirectBack   = $this->getRequest()->getParam('back', false);
00555         $productId      = $this->getRequest()->getParam('id');
00556         $isEdit         = (int)($this->getRequest()->getParam('id') != null);
00557 
00558         $data = $this->getRequest()->getPost();
00559         if ($data) {
00560             if (!isset($data['product']['stock_data']['use_config_manage_stock'])) {
00561                 $data['product']['stock_data']['use_config_manage_stock'] = 0;
00562             }
00563             $product = $this->_initProductSave();
00564 
00565             try {
00566                 $product->save();
00567                 $productId = $product->getId();
00568 
00569                 /**
00570                  * Do copying data to stores
00571                  */
00572                 if (isset($data['copy_to_stores'])) {
00573                     foreach ($data['copy_to_stores'] as $storeTo=>$storeFrom) {
00574                         $newProduct = Mage::getModel('catalog/product')
00575                             ->setStoreId($storeFrom)
00576                             ->load($productId)
00577                             ->setStoreId($storeTo)
00578                             ->save();
00579                     }
00580                 }
00581                 $this->_getSession()->addSuccess($this->__('Product was successfully saved.'));
00582             }
00583             catch (Mage_Core_Exception $e) {
00584                 $this->_getSession()->addError($e->getMessage())
00585                     ->setProductData($data);
00586                 $redirectBack = true;
00587             }
00588             catch (Exception $e) {
00589 //                $this->_getSession()->addException($e, $this->__('Product saving error.'));
00590                 $this->_getSession()->addException($e, $e->getMessage());
00591                 $redirectBack = true;
00592             }
00593         }
00594 
00595         if ($redirectBack) {
00596             $this->_redirect('*/*/edit', array(
00597                 'id'    => $productId,
00598                 '_current'=>true
00599             ));
00600         }
00601         else if($this->getRequest()->getParam('popup')) {
00602             $this->_redirect('*/*/created', array(
00603                 '_current'   => true,
00604                 'id'         => $productId,
00605                 'edit'       => $isEdit
00606             ));
00607         }
00608         else {
00609             $this->_redirect('*/*/', array('store'=>$storeId));
00610         }
00611     }

superConfigAction (  ) 

Definition at line 372 of file ProductController.php.

00373     {
00374         $this->_initProduct();
00375         $this->getResponse()->setBody(
00376             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_super_config_grid')->toHtml()
00377         );
00378     }

superGroupAction (  ) 

Get associated grouped products grid and serializer block

Definition at line 326 of file ProductController.php.

00327     {
00328         $this->_initProduct();
00329 
00330         $gridBlock = $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_super_group')
00331             ->setProductId(Mage::registry('product')->getId())
00332             ->setGridUrl($this->getUrl('*/*/superGroupGridOnly', array('_current' => true)))
00333         ;
00334         $serializerBlock = $this->_createSerializerBlock('links[grouped]', $gridBlock, Mage::registry('product')->getTypeInstance()->getAssociatedProducts())
00335             ->setIsEntityId(true)
00336         ;
00337 
00338         $this->_outputBlocks($gridBlock, $serializerBlock);
00339     }

superGroupGridOnlyAction (  ) 

Get associated grouped products grid

Definition at line 345 of file ProductController.php.

00346     {
00347         $this->_initProduct();
00348 
00349         $this->getResponse()->setBody(
00350             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_super_group')
00351                 ->setProductId(Mage::registry('product')->getId())
00352                 ->toHtml()
00353         );
00354     }

tagCustomerGridAction (  ) 

Definition at line 781 of file ProductController.php.

00782     {
00783         $this->getResponse()->setBody(
00784             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_tag_customer', 'admin.product.tags.customers')
00785                 ->setProductId($this->getRequest()->getParam('id'))
00786                 ->toHtml()
00787         );
00788     }

tagGridAction (  ) 

Definition at line 664 of file ProductController.php.

00665     {
00666         $this->getResponse()->setBody(
00667             $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_tag', 'admin.product.tags')
00668                 ->setProductId($this->getRequest()->getParam('id'))
00669                 ->toHtml()
00670         );
00671     }

upsellAction (  ) 

Get upsell products grid and serializer block

Definition at line 296 of file ProductController.php.

00297     {
00298         $this->_initProduct();
00299 
00300         $gridBlock = $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_upsell')
00301             ->setGridUrl($this->getUrl('*/*/gridOnly', array('_current' => true, 'gridOnlyBlock' => 'upsell')))
00302         ;
00303         $serializerBlock = $this->_createSerializerBlock('links[upsell]', $gridBlock, Mage::registry('product')->getUpsellProducts());
00304 
00305         $this->_outputBlocks($gridBlock, $serializerBlock);
00306     }

validateAction (  ) 

Validate product

Definition at line 398 of file ProductController.php.

00399     {
00400         $response = new Varien_Object();
00401         $response->setError(false);
00402 
00403         try {
00404             $productData = $this->getRequest()->getPost('product');
00405             if ($productData && !isset($productData['stock_data']['use_config_manage_stock'])) {
00406                 $productData['stock_data']['use_config_manage_stock'] = 0;
00407             }
00408             $product = Mage::getModel('catalog/product');
00409             if ($storeId = $this->getRequest()->getParam('store_id')) {
00410                 $product->setStoreId($storeId);
00411             }
00412             if ($setId = $this->getRequest()->getParam('set')) {
00413                 $product->setAttributeSetId($setId);
00414             }
00415             if ($typeId = $this->getRequest()->getParam('type')) {
00416                 $product->setTypeId($typeId);
00417             }
00418             if ($productId = $this->getRequest()->getParam('id')) {
00419                 $product->load($productId);
00420             }
00421             $product
00422                 ->addData($productData)
00423                 ->validate();
00424         }
00425         catch (Mage_Eav_Model_Entity_Attribute_Exception $e) {
00426             $response->setError(true);
00427             $response->setAttribute($e->getAttributeCode());
00428             $response->setMessage($e->getMessage());
00429         }
00430         catch (Exception $e) {
00431             $this->_getSession()->addError($e->getMessage());
00432             $this->_initLayoutMessages('adminhtml/session');
00433             $response->setError(true);
00434             $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
00435         }
00436 
00437         $this->getResponse()->setBody($response->toJson());
00438     }


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

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