00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Controller_Action
00035 {
00036 protected function _construct()
00037 {
00038
00039 $this->setUsedModuleName('Mage_Catalog');
00040 }
00041
00042
00043
00044
00045
00046
00047 protected function _initProduct()
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
00076 Mage_Catalog_Model_Resource_Eav_Attribute::initLabels($product->getStoreId());
00077
00078
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
00100 $data = array();
00101 foreach ($configProduct->getTypeInstance()->getEditableAttributes() as $attribute) {
00102
00103
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 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 protected function _createSerializerBlock($inputName, Mage_Adminhtml_Block_Widget_Grid $gridBlock, $productsArray)
00133 {
00134 return $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_ajax_serializer')
00135 ->setGridBlock($gridBlock)
00136 ->setProducts($productsArray)
00137 ->setInputElementName($inputName)
00138 ;
00139 }
00140
00141
00142
00143
00144 protected function _outputBlocks()
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 }
00153
00154
00155
00156
00157 public function indexAction()
00158 {
00159 $this->loadLayout();
00160 $this->_setActiveMenu('catalog/products');
00161 $this->renderLayout();
00162 }
00163
00164
00165
00166
00167 public function newAction()
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 }
00193
00194
00195
00196
00197 public function editAction()
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 }
00227
00228
00229
00230
00231 public function gridAction()
00232 {
00233 $this->loadLayout();
00234 $this->getResponse()->setBody(
00235 $this->getLayout()->createBlock('adminhtml/catalog_product_grid')->toHtml()
00236 );
00237 }
00238
00239
00240
00241
00242 public function gridOnlyAction()
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 }
00251
00252
00253
00254
00255
00256 public function categoriesAction()
00257 {
00258 $this->_initProduct();
00259
00260 $this->getResponse()->setBody(
00261 $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_categories')->toHtml()
00262 );
00263 }
00264
00265
00266
00267
00268
00269 public function optionsAction()
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 }
00277
00278
00279
00280
00281 public function relatedAction()
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 }
00292
00293
00294
00295
00296 public function upsellAction()
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 }
00307
00308
00309
00310
00311 public function crosssellAction()
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 }
00322
00323
00324
00325
00326 public function superGroupAction()
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 }
00340
00341
00342
00343
00344
00345 public function superGroupGridOnlyAction()
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 }
00355
00356
00357
00358
00359
00360 public function reviewsAction()
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 }
00371
00372 public function superConfigAction()
00373 {
00374 $this->_initProduct();
00375 $this->getResponse()->setBody(
00376 $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_super_config_grid')->toHtml()
00377 );
00378 }
00379
00380
00381
00382
00383
00384 public function bundlesAction()
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 }
00393
00394
00395
00396
00397
00398 public function validateAction()
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 }
00439
00440
00441
00442
00443 protected function _initProductSave()
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
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
00475
00476 if ($useDefaults = $this->getRequest()->getPost('use_default')) {
00477 foreach ($useDefaults as $attributeCode) {
00478 $product->setData($attributeCode, null);
00479 }
00480 }
00481
00482
00483
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
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
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
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 }
00535
00536 public function categoriesJsonAction()
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 }
00547
00548
00549
00550
00551 public function saveAction()
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
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
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 }
00612
00613
00614
00615
00616 public function duplicateAction()
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 }
00630
00631
00632
00633
00634
00635
00636
00637 protected function _decodeInput($encoded)
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 }
00646
00647 public function deleteAction()
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 }
00663
00664 public function tagGridAction()
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 }
00672
00673 public function alertsPriceGridAction()
00674 {
00675 $this->getResponse()->setBody(
00676 $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_alerts_price')->toHtml()
00677 );
00678 }
00679
00680 public function alertsStockGridAction()
00681 {
00682 $this->getResponse()->setBody(
00683 $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_alerts_stock')->toHtml()
00684 );
00685 }
00686
00687 public function addCustomersToAlertQueueAction()
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 }
00710
00711 public function addAttributeAction()
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 }
00721
00722 public function createdAction()
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 }
00731
00732 public function massDeleteAction()
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 }
00754
00755 public function massStatusAction()
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 }
00780
00781 public function tagCustomerGridAction()
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 }
00789
00790 public function quickCreateAction()
00791 {
00792 $result = array();
00793
00794
00795 $configurableProduct = Mage::getModel('catalog/product')
00796 ->setStoreId(0)
00797 ->load($this->getRequest()->getParam('product'));
00798
00799 if (!$configurableProduct->isConfigurable()) {
00800
00801 $this->_redirect('*/*/');
00802 return;
00803 }
00804
00805
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 }
00894
00895 protected function _isAllowed()
00896 {
00897 return Mage::getSingleton('admin/session')->isAllowed('catalog/products');
00898 }
00899
00900 }