public function onCoreBlockAbstractToHtmlBefore($observer) { $block = $observer->getBlock(); $massactionClass = Mage::getConfig()->getBlockClassName('adminhtml/widget_grid_massaction'); $productGridClass = Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_grid'); if ($massactionClass == get_class($block) && ($productGridClass == get_class($block->getParentBlock()) || in_array(get_class($block->getParentBlock()), $this->_irregularGridClasses))) { /*if ($massactionClass == get_class($block) // other way for checking && 'catalog_product' == $block->getRequest()->getControllerName()) {*/ $types = Mage::getStoreConfig('ampaction/general/commands'); if (!$types) { return $this; } $types = explode(',', $types); foreach ($types as $i => $type) { if (strlen($type) > 2) { $command = Amasty_Paction_Model_Command_Abstract::factory($type); $command->addAction($block); } else { // separator $block->addItem('ampaction_separator' . $i, array('label' => '---------------------', 'url' => '')); } } } return $this; }
/** * Executes the command * * @param array $ids product ids * @param int $storeId store id * @param string $val field value * @return string success message if any */ public function execute($ids, $storeId, $val) { parent::execute($ids, $storeId, $val); $hlp = Mage::helper('ampaction'); if (!preg_match('/^[+-][0-9]+(\\.[0-9]+)?%?$/', $val)) { throw new Exception($hlp->__('Please provide the difference as +12.5, -12.5, +12.5% or -12.5%')); } $sign = substr($val, 0, 1); $val = substr($val, 1); $percent = '%' == substr($val, -1, 1); if ($percent) { $val = substr($val, 0, -1); } $val = floatval($val); if ($val < 1.0E-5) { throw new Exception($hlp->__('Please provide a non empty difference')); } $attrCode = $this->_getAttrCode(); $this->_updateAttribute($attrCode, $ids, $storeId, array('sign' => $sign, 'val' => $val, 'percent' => $percent)); if (version_compare(Mage::getVersion(), '1.4.1.0') > 0) { $obj = new Varien_Object(); $obj->setData(array('product_ids' => array_unique($ids), 'attributes_data' => array($attrCode => true), 'store_id' => $storeId)); // register mass action indexer event Mage::getSingleton('index/indexer')->processEntityAction($obj, Mage_Catalog_Model_Product::ENTITY, Mage_Index_Model_Event::TYPE_MASS_ACTION); } $success = $hlp->__('Total of %d products(s) have been successfully updated', count($ids)); return $success; }
public function doAction() { $productIds = $this->getRequest()->getParam('product'); $val = trim($this->getRequest()->getParam('ampaction_value')); $commandType = trim($this->getRequest()->getParam('command')); $storeId = (int) $this->getRequest()->getParam('store', 0); $enhanced = $this->getRequest()->getParam('enhanced', 0); try { $command = Amasty_Paction_Model_Command_Abstract::factory($commandType); $success = $command->execute($productIds, $storeId, $val); if ($success) { $this->_getSession()->addSuccess($success); } // show non critical erroes to the user foreach ($command->getErrors() as $err) { $this->_getSession()->addError($err); } } catch (Exception $e) { $this->_getSession()->addError($this->__('Error: %s', $e->getMessage())); } if ($enhanced) { $this->_redirect('enhancedgrid/catalog_product/index', array('store' => $storeId)); } else { $this->_redirect('adminhtml/catalog_product/index', array('store' => $storeId)); } return $this; }
/** * Returns value field options for the mass actions block * * @param string $title field title * @return array */ protected function _getValueField($title) { $field = parent::_getValueField($title); $field = $field; // prvents Zend Studio validation error $field['ampaction_value']['type'] = 'select'; $field['ampaction_value']['values'] = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())->load()->toOptionHash(); return $field; }
/** * Returns value field options for the mass actions block * * @param string $title field title * @return array */ protected function _getValueField($title) { $field = parent::_getValueField($title); $storeId = (int) Mage::app()->getRequest()->getParam('store', 0); if (Mage::getStoreConfig('ampaction/general/categories', $storeId)) { $rootId = Mage::app()->getStore($storeId)->getRootCategoryId(); $field['ampaction_value']['label'] = Mage::helper('ampaction')->__('Category'); $field['ampaction_value']['type'] = 'select'; $field['ampaction_value']['values'] = $this->getTree($rootId); } return $field; }
public function handleAmProductGridMassaction($observer) { $grid = $observer->getGrid(); $types = array('', 'addcategory', 'removecategory', '', 'modifyprice', 'modifyspecial', 'addspecial', '', 'relate', 'upsell', 'crosssell', '', 'copyoptions', 'copyattr', 'copyimg', '', 'changeattributeset', '', 'delete'); foreach ($types as $i => $type) { if ($type) { $command = Amasty_Paction_Model_Command_Abstract::factory($type); $command->addAction($grid); } else { // separator $grid->getMassactionBlock()->addItem('ampaction_separator' . $i, array('label' => '---------------------', 'url' => '')); } } return $this; }
public function toOptionArray() { $options = array(); // magento wants at least one option to be selected $options[] = array('value' => '', 'label' => ''); $types = array('', 'addcategory', 'removecategory', 'replacecategory', '', 'modifycost', 'modifyprice', 'modifyspecial', 'addspecial', 'addprice', 'addspecialbycost', '', 'relate', 'upsell', 'crosssell', '', 'unrelate', 'unupsell', 'uncrosssell', '', 'copyoptions', 'copyattr', 'copyimg', 'removeimg', '', 'changeattributeset', '', 'delete', ''); foreach ($types as $i => $type) { if ($type) { $command = Amasty_Paction_Model_Command_Abstract::factory($type); $options[] = array('value' => $type, 'label' => Mage::helper('ampaction')->__($command->getLabel())); } else { $options[] = array('value' => $i, 'label' => '---------------------'); } } return $options; }
/** * Executes the command * * @param array $ids product ids * @param int $storeId store id * @param string $val field value * @return string success message if any */ public function execute($ids, $storeId, $val) { $success = parent::execute($ids, $storeId, $val); $hlp = Mage::helper('ampaction'); $srcId = intVal($val); $collection = $this->_getCollection($val); if (!count($collection)) { throw new Exception($hlp->__('Please provide a product with custom options')); } $options = array(); $countOptions = $collection->getSize(); foreach ($collection as $option) { $options[] = $this->_convertToArray($option); } $num = 0; foreach ($ids as $id) { if ($srcId == $id) { continue; } try { $product = Mage::getModel('catalog/product'); /* @var Mage_Catalog_Model_Product */ $product->reset()->load($id)->setIsMassupdate(true)->setExcludeUrlRewrite(true); // set new $product->setProductOptions($options); $product->setCanSaveCustomOptions(!$product->getOptionsReadonly()); // delete old $option = $product->getOptionInstance(); $optionsCollection = $this->_getCollection($id); $optionsCollection->walk('delete'); $option->unsetOptions(); $product->save(); $product->reset()->load($srcId); $option = $product->getOptionInstance(); $option->getResource()->duplicate($option, $srcId, $id); $this->_clean($id, $countOptions); ++$num; } catch (Exception $e) { $this->_errors[] = $hlp->__('Can not copy the options to the product ID=%d, the error is: %s', $id, $e->getMessage()); } } if ($num) { $success = $hlp->__('Total of %d products(s) have been successfully updated.', $num); } return $success; }
/** * Executes the command * * @param array $ids product ids * @param int $storeId store id * @param string $val field value * @return string success message if any */ public function execute($ids, $storeId, $val) { $success = parent::execute($ids, $storeId, $val); $hlp = Mage::helper('ampaction'); $fromId = intVal(trim($val)); if (!$fromId) { throw new Exception($hlp->__('Please provide a valid product ID')); } if (in_array($fromId, $ids)) { throw new Exception($hlp->__('Please remove source product from the selected products')); } $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($fromId); if (!$product->getId()) { throw new Exception($hlp->__('Please provide a valid product ID')); } // check attributes $codes = Mage::getStoreConfig('ampaction/general/attr'); if (!$codes) { throw new Exception($hlp->__('Please set attribute codes in the module configuration')); } $config = array(); $codes = explode(',', $codes); foreach ($codes as $code) { $code = trim($code); $attribute = Mage::getModel('catalog/product')->getResource()->getAttribute($code); if (!$attribute || !$attribute->getId()) { throw new Exception($hlp->__('There is no product attribute with code `%s`, please compare values in the module configuration with catalog > attibutes > manage attributes section.', $code)); } if ($attribute->getIsUnique()) { throw new Exception($hlp->__('Attribute `%s` is unique and can not be copied. Please remove the code in the module configuration.', $code)); } $type = $attribute->getBackendType(); if ('static' == $type) { throw new Exception($hlp->__('Attribute `%s` is static and can not be copied. Please remove the code in the module configuration.', $code)); } if (!isset($config[$type])) { $config[$type] = array(); } $config[$type][] = $attribute->getId(); } // we do not use store id as it is global action $this->_copyData($fromId, $ids, $config); $success = $hlp->__('Attributes have been successfully copied.'); return $success; }
/** * Executes the command * * @param array $ids product ids * @param int $storeId store id * @param string $val field value * @return string success message if any */ public function execute($ids, $storeId, $val) { $success = parent::execute($ids, $storeId, $val); $hlp = Mage::helper('ampaction'); $mainId = intVal(trim($val)); if (!$mainId) { throw new Exception($hlp->__('Please provide a valid product ID')); } $num = 0; if ($this->isTwoWay()) { foreach ($ids as $id) { $num += $this->_createNewLink($mainId, $id); $num += $this->_createNewLink($id, $mainId); } } elseif ($this->isMultiWay()) { $ids[] = $mainId; foreach ($ids as $id) { foreach ($ids as $id2) { if ($id == $id2) { continue; } $num += $this->_createNewLink($id, $id2); } } } else { // default one-way relation foreach ($ids as $id) { $num += $this->_createNewLink($mainId, $id); } } if ($num) { if (1 == $num) { $success = $hlp->__('Product association has been successfully added.'); } else { $success = $hlp->__(' %d product associations have been successfully added.', $num); } } return $success; }
/** * Executes the command * * @param array $ids product ids * @param int $storeId store id * @param string $val field value * @return string success message if any */ public function execute($ids, $storeId, $val) { $success = parent::execute($ids, $storeId, $val); $hlp = Mage::helper('ampaction'); $fromId = intVal(trim($val)); if (!$fromId) { throw new Exception($hlp->__('Please provide a valid product ID')); } if (in_array($fromId, $ids)) { throw new Exception($hlp->__('Please remove source product from the selected products')); } $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($fromId); if (!$product->getId()) { throw new Exception($hlp->__('Please provide a valid product ID')); } // we do not use store id as it is a global action; $attribute = $product->getResource()->getAttribute('media_gallery'); foreach ($ids as $id) { $this->_copyData($attribute->getId(), $fromId, $id, $product); } $success = $hlp->__('Images and labels have been successfully copied.'); return $success; }
public function __construct($type) { parent::__construct($type); $this->_label = 'Remove Relations'; }
/** * Returns value field options for the mass actions block * * @param string $title field title * @return array */ protected function _getValueField($title) { if ($this->isMultiWay()) { $title = $title; // prevents Zend Studio validtaion error return null; } else { return parent::_getValueField($title); } }
public function __construct($type) { parent::__construct($type); $this->_label = 'Fast Delete'; }