diff --git a/app/Mage.php b/app/Mage.php index 6702f50c6a..68be8b1bd8 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -130,13 +130,32 @@ final class Mage static private $_isInstalled; /** - * Retrieve current Magento version + * Gets the current Magento version string + * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/ * * @return string */ public static function getVersion() { - return '1.4.0.0-alpha1'; + return '1.4.0.0-alpha2'; + } + + /** + * Gets the detailed Magento version information + * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/ + * + * @return array + */ + public static function getVersionInfo() + { + return array( + 'major' => '1', + 'minor' => '4', + 'revision' => '0', + 'patch' => '0', + 'stability' => 'alpha', + 'number' => '2', + ); } /** @@ -312,7 +331,7 @@ public static function getStoreConfig($path, $store = null) public static function getStoreConfigFlag($path, $store = null) { $flag = strtolower(self::getStoreConfig($path, $store)); - if (!empty($flag) && 'false'!==$flag && '0'!==$flag) { + if (!empty($flag) && 'false' !== $flag) { return true; } else { return false; @@ -665,8 +684,11 @@ public static function log($message, $level = null, $file = '') if (!self::getConfig()) { return; } - if (!self::getStoreConfig('dev/log/active')) { - return; + + if (!self::$_isDeveloperMode) { + if (!self::getStoreConfig('dev/log/active')) { + return; + } } static $loggers = array(); @@ -768,6 +790,9 @@ public static function printException(Exception $e, $extra = '') !empty($extra) ? $extra . "\n\n" : '' . $e->getMessage(), $e->getTraceAsString() ); + if (isset($_SERVER) && isset($_SERVER['REQUEST_URI'])) { + $reportData[] = $_SERVER['REQUEST_URI']; + } $reportData = serialize($reportData); file_put_contents($reportFile, $reportData); diff --git a/app/code/core/Mage/Admin/Model/Config.php b/app/code/core/Mage/Admin/Model/Config.php index 8681c43321..088f72a1e8 100644 --- a/app/code/core/Mage/Admin/Model/Config.php +++ b/app/code/core/Mage/Admin/Model/Config.php @@ -34,11 +34,46 @@ */ class Mage_Admin_Model_Config extends Varien_Simplexml_Config { + /** + * adminhtml.xml merged config + * + * @var Varien_Simplexml_Config + */ + protected $_adminhtmlConfig; + + /** + * Load config from merged adminhtml.xml files + */ public function __construct() { parent::__construct(); - #$this->_elementClass = 'Mage_Core_Model_Config_Element'; - #$this->loadFile(Mage::getModuleDir('etc', 'Mage_Admin').DS.'admin.xml'); + $this->setCacheId('adminhtml_acl_menu_config'); + /* @var $adminhtmlConfig Varien_Simplexml_Config */ + $adminhtmlConfig = Mage::app()->loadCache($this->getCacheId()); + if ($adminhtmlConfig) { + $this->_adminhtmlConfig = new Varien_Simplexml_Config($adminhtmlConfig); + } else { + $adminhtmlConfig = new Varien_Simplexml_Config; + $adminhtmlConfig->loadString(''); + Mage::getConfig()->loadModulesConfiguration('adminhtml.xml', $adminhtmlConfig); + $this->_adminhtmlConfig = $adminhtmlConfig; + + // support back compatibility with base config + $aclConfig = Mage::getConfig()->getNode('adminhtml/acl'); + if ($aclConfig) { + $adminhtmlConfig->getNode()->extendChild($aclConfig, true); + } + + $menuConfig = Mage::getConfig()->getNode('adminhtml/menu'); + if ($menuConfig) { + $adminhtmlConfig->getNode()->extendChild($menuConfig, true); + } + + if (Mage::app()->useCache('config')) { + Mage::app()->saveCache($adminhtmlConfig->getXmlString(), $this->getCacheId(), + array(Mage_Core_Model_Config::CACHE_TAG)); + } + } } /** @@ -52,7 +87,7 @@ public function __construct() public function loadAclResources(Mage_Admin_Model_Acl $acl, $resource=null, $parentName=null) { if (is_null($resource)) { - $resource = Mage::getConfig()->getNode("adminhtml/acl/resources"); + $resource = $this->getAdminhtmlConfig()->getNode("acl/resources"); $resourceName = null; } else { $resourceName = (is_null($parentName) ? '' : $parentName.'/').$resource->getName(); @@ -121,4 +156,13 @@ public function getAclPrivilegeSet($name='') return false; } + /** + * Retrieve xml config + * + * @return Varien_Simplexml_Config + */ + public function getAdminhtmlConfig() + { + return $this->_adminhtmlConfig; + } } \ No newline at end of file diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Rules.php b/app/code/core/Mage/Admin/Model/Mysql4/Rules.php index 257dde77b3..b3fa0a20ba 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Rules.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Rules.php @@ -30,38 +30,47 @@ protected function _construct() { $this->_init('admin/rule', 'rule_id'); } - public function saveRel(Mage_Admin_Model_Rules $rule) { - $this->_getWriteAdapter()->beginTransaction(); - + /** + * Save ACL resources + * + * @param Mage_Admin_Model_Rules $rule + */ + public function saveRel(Mage_Admin_Model_Rules $rule) + { try { + $this->_getWriteAdapter()->beginTransaction(); $roleId = $rule->getRoleId(); $this->_getWriteAdapter()->delete($this->getMainTable(), "role_id = {$roleId}"); - $masterResources = Mage::getModel('admin/roles')->getResourcesList2D(); - $masterAdmin = false; - if ( $postedResources = $rule->getResources() ) { - foreach ($masterResources as $index => $resName) { - if ( !$masterAdmin ) { - $permission = ( in_array($resName, $postedResources) )? 'allow' : 'deny'; - $this->_getWriteAdapter()->insert($this->getMainTable(), array( - 'role_type' => 'G', - 'resource_id' => trim($resName, '/'), - 'privileges' => '', # FIXME !!! - 'assert_id' => 0, - 'role_id' => $roleId, - 'permission' => $permission - )); - } - if ( $resName == 'all' && $permission == 'allow' ) { - $masterAdmin = true; + $postedResources = $rule->getResources(); + if ($postedResources) { + $row = array( + 'role_type' => 'G', + 'resource_id' => 'all', + 'privileges' => '', // not used yet + 'assert_id' => 0, + 'role_id' => $roleId, + 'permission' => 'allow' + ); + + // If all was selected save it only and nothing else. + if ($postedResources === array('all')) { + $this->_getWriteAdapter()->insert($this->getMainTable(), $row); + } else { + foreach (Mage::getModel('admin/roles')->getResourcesList2D() as $index => $resName) { + $row['permission'] = (in_array($resName, $postedResources) ? 'allow' : 'deny'); + $row['resource_id'] = trim($resName, '/'); + $this->_getWriteAdapter()->insert($this->getMainTable(), $row); } } } $this->_getWriteAdapter()->commit(); } catch (Mage_Core_Exception $e) { + $this->_getWriteAdapter()->rollBack(); throw $e; } catch (Exception $e){ $this->_getWriteAdapter()->rollBack(); + Mage::logException($e); } } } diff --git a/app/code/core/Mage/Admin/Model/Roles.php b/app/code/core/Mage/Admin/Model/Roles.php index 1902ee42f9..fe49529e22 100644 --- a/app/code/core/Mage/Admin/Model/Roles.php +++ b/app/code/core/Mage/Admin/Model/Roles.php @@ -71,7 +71,7 @@ protected function _buildResourcesArray(Varien_Simplexml_Element $resource=null, { static $result; if (is_null($resource)) { - $resource = Mage::getConfig()->getNode('adminhtml/acl/resources'); + $resource = Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode('acl/resources'); $resourceName = null; $level = -1; } else { @@ -89,12 +89,6 @@ protected function _buildResourcesArray(Varien_Simplexml_Element $resource=null, $resource->addAttribute("module_c", $module); } - //if (!(string)$resource->title) { - // return array(); - //} - - //$resource->title = Mage::helper($module)->__((string)$resource->title); - if ( is_null($represent2Darray) ) { $result[$resourceName]['name'] = Mage::helper($module)->__((string)$resource->title); $result[$resourceName]['level'] = $level; diff --git a/app/code/core/Mage/Admin/Model/User.php b/app/code/core/Mage/Admin/Model/User.php index aee3ccb533..8c6407f349 100644 --- a/app/code/core/Mage/Admin/Model/User.php +++ b/app/code/core/Mage/Admin/Model/User.php @@ -56,13 +56,12 @@ protected function _construct() } /** - * Save user + * Processing data before model save * * @return Mage_Admin_Model_User */ - public function save() + protected function _beforeSave() { - $this->_beforeSave(); $data = array( 'firstname' => $this->getFirstname(), 'lastname' => $this->getLastname(), @@ -85,8 +84,7 @@ public function save() if ($this->getNewPassword()) { $data['password'] = $this->_getEncodedPassword($this->getNewPassword()); - } - elseif ($this->getPassword()) { + } elseif ($this->getPassword()) { $data['new_password'] = $this->getPassword(); } @@ -95,9 +93,8 @@ public function save() } $this->addData($data); - $this->_getResource()->save($this); - $this->_afterSave(); - return $this; + + return parent::_beforeSave(); } /** @@ -115,17 +112,6 @@ public function saveExtra($data) return $this; } - /** - * Delete user - * - * @return Mage_Admin_Model_User - */ - public function delete() - { - $this->_getResource()->delete($this); - return $this; - } - /** * Save user roles * @@ -323,7 +309,7 @@ protected function _getEncodedPassword($pwd) public function findFirstAvailableMenu($parent=null, $path='', $level=0) { if ($parent == null) { - $parent = Mage::getConfig()->getNode('adminhtml/menu'); + $parent = Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode('menu'); } foreach ($parent->children() as $childName=>$child) { $aclResource = 'admin/' . $path . $childName; @@ -372,8 +358,9 @@ public function getStartupPageUrl() $startupPage = Mage::getStoreConfig(self::XML_PATH_STARTUP_PAGE); $aclResource = 'admin/' . $startupPage; if (Mage::getSingleton('admin/session')->isAllowed($aclResource)) { - $nodePath = 'adminhtml/menu/' . join('/children/', explode('/', $startupPage)) . '/action'; - if ($url = Mage::getConfig()->getNode($nodePath)) { + $nodePath = 'menu/' . join('/children/', explode('/', $startupPage)) . '/action'; + $url = Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode($nodePath); + if ($url) { return $url; } } diff --git a/app/code/core/Mage/Admin/etc/config.xml b/app/code/core/Mage/Admin/etc/config.xml index 2a7e371ce3..686d5b1291 100644 --- a/app/code/core/Mage/Admin/etc/config.xml +++ b/app/code/core/Mage/Admin/etc/config.xml @@ -54,16 +54,7 @@ Mage_Admin - - core_setup - - - core_write - - - core_read - Mage_Admin_Block diff --git a/app/code/core/Mage/AdminNotification/Model/Observer.php b/app/code/core/Mage/AdminNotification/Model/Observer.php index fb56f37380..fdfac46446 100644 --- a/app/code/core/Mage/AdminNotification/Model/Observer.php +++ b/app/code/core/Mage/AdminNotification/Model/Observer.php @@ -41,9 +41,15 @@ class Mage_AdminNotification_Model_Observer */ public function preDispatch(Varien_Event_Observer $observer) { - $feedModel = Mage::getModel('adminnotification/feed'); - /* @var $feedModel Mage_AdminNotification_Model_Feed */ - $feedModel->checkUpdate(); + if (Mage::getSingleton('admin/session')->isLoggedIn()) { + + $feedModel = Mage::getModel('adminnotification/feed'); + /* @var $feedModel Mage_AdminNotification_Model_Feed */ + + $feedModel->checkUpdate(); + + } + } } \ No newline at end of file diff --git a/app/code/core/Mage/AdminNotification/etc/adminhtml.xml b/app/code/core/Mage/AdminNotification/etc/adminhtml.xml new file mode 100644 index 0000000000..28a4dd0812 --- /dev/null +++ b/app/code/core/Mage/AdminNotification/etc/adminhtml.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Notifications + 10 + + + Show Toolbar + 10 + + + Show List + 20 + + + Mark as read + 30 + + + Remove + 40 + + + + + + + + + + + + + + Notifications + adminhtml/notification + 15 + + + + + diff --git a/app/code/core/Mage/AdminNotification/etc/config.xml b/app/code/core/Mage/AdminNotification/etc/config.xml index b5673be53d..62404ad191 100644 --- a/app/code/core/Mage/AdminNotification/etc/config.xml +++ b/app/code/core/Mage/AdminNotification/etc/config.xml @@ -57,20 +57,7 @@ Mage_AdminNotification - - core_setup - - - - core_setup - - - - - core_setup - - @@ -80,51 +67,6 @@ - - - - - - - - Notifications - 10 - - - Show Toolbar - 10 - - - Show List - 20 - - - Mark as read - 30 - - - Remove - 40 - - - - - - - - - - - - - - Notifications - adminhtml/notification - 15 - - - - @@ -138,7 +80,6 @@ - singleton adminnotification/observer preDispatch diff --git a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php index 54f186078e..b02f24424c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php @@ -94,7 +94,7 @@ protected function _prepareForm() 'label' => Mage::helper('adminhtml')->__('New Api Key'), 'id' => 'new_pass', 'title' => Mage::helper('adminhtml')->__('New Api Key'), - 'class' => 'input-text validate-admin-password', + 'class' => 'input-text validate-password', )); $fieldset->addField('confirmation', 'password', array( @@ -110,7 +110,7 @@ protected function _prepareForm() 'label' => Mage::helper('adminhtml')->__('Api Key'), 'id' => 'customer_pass', 'title' => Mage::helper('adminhtml')->__('Api Key'), - 'class' => 'input-text required-entry validate-admin-password', + 'class' => 'input-text required-entry validate-password', 'required' => true, )); $fieldset->addField('confirmation', 'password', array( diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit/Form.php index c79ba06c52..5b608bf301 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit/Form.php @@ -145,6 +145,9 @@ public function getAdditionalButtonsHtml() */ public function addAdditionalButton($alias, $config) { + if (isset($config['name'])) { + $config['element_name'] = $config['name']; + } $this->setChild($alias . '_button', $this->getLayout()->createBlock('adminhtml/widget_button')->addData($config)); $this->_additionalButtons[$alias] = $alias . '_button'; diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Widget/Chooser.php new file mode 100644 index 0000000000..cea17d37bb --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Widget/Chooser.php @@ -0,0 +1,173 @@ + + */ +class Mage_Adminhtml_Block_Catalog_Category_Widget_Chooser extends Mage_Adminhtml_Block_Catalog_Category_Tree +{ + protected $_selectedCategories = array(); + + /** + * Block construction + * Defines tree template and init tree params + */ + public function __construct() + { + parent::__construct(); + $this->setTemplate('catalog/category/widget/tree.phtml'); + $this->_withProductCount = false; + } + + /** + * Setter + * + * @param array $selectedCategories + * @return Mage_Adminhtml_Block_Catalog_Category_Widget_Chooser + */ + public function setSelectedCategories($selectedCategories) + { + $this->_selectedCategories = $selectedCategories; + return $this; + } + + /** + * Getter + * + * @return array + */ + public function getSelectedCategories() + { + return $this->_selectedCategories; + } + + /** + * Prepare chooser element HTML + * + * @param Varien_Data_Form_Element_Abstract $element Form Element + * @return Varien_Data_Form_Element_Abstract + */ + public function prepareElementHtml(Varien_Data_Form_Element_Abstract $element) + { + $uniqId = $element->getId() . md5(microtime()); + $sourceUrl = $this->getUrl('*/catalog_category_widget/chooser', array('uniq_id' => $uniqId, 'use_massaction' => false)); + + $chooser = $this->getLayout()->createBlock('adminhtml/cms_widget_chooser') + ->setElement($element) + ->setTranslationHelper($this->getTranslationHelper()) + ->setConfig($this->getConfig()) + ->setFieldsetId($this->getFieldsetId()) + ->setSourceUrl($sourceUrl) + ->setUniqId($uniqId); + + if ($element->getValue()) { + $value = explode('/', $element->getValue()); + $categoryId = isset($value[1]) ? $value[1] : false; + if ($categoryId) { + $label = Mage::getSingleton('catalog/category')->load($categoryId)->getName(); + $chooser->setLabel($label); + } + } + + $element->setData('after_element_html', $chooser->toHtml()); + return $element; + } + + /** + * Category Tree node onClick listener js function + * + * @return string + */ + public function getNodeClickListener() + { + if ($this->getData('node_click_listener')) { + return $this->getData('node_click_listener'); + } + if ($this->getUseMassaction()) { + $js = ' + function (node, e) { + node.ui.toggleCheck(true); + } + '; + } else { + $chooserJsObject = $this->getId(); + $js = ' + function (node, e) { + '.$chooserJsObject.'.setElementValue("category/" + node.attributes.id); + '.$chooserJsObject.'.setElementLabel(node.text); + '.$chooserJsObject.'.close(); + } + '; + } + return $js; + } + + /** + * Get JSON of a tree node or an associative array + * + * @param Varien_Data_Tree_Node|array $node + * @param int $level + * @return string + */ + protected function _getNodeJson($node, $level = 0) + { + $item = parent::_getNodeJson($node, $level); + if (in_array($node->getId(), $this->getSelectedCategories())) { + $item['checked'] = true; + } + $item['is_anchor'] = (int)$node->getIsAnchor(); + $item['url_key'] = $node->getData('url_key'); + return $item; + } + + /** + * Adds some extra params to categories collection + * + * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection + */ + public function getCategoryCollection() + { + return parent::getCategoryCollection()->addAttributeToSelect('url_key')->addAttributeToSelect('is_anchor'); + } + + /** + * Tree JSON source URL + * + * @return string + */ + public function getLoadTreeUrl($expanded=null) + { + return $this->getUrl('*/catalog_category_widget/categoriesJson', array( + '_current'=>true, + 'uniq_id' => $this->getId(), + 'use_massaction' => $this->getUseMassaction() + )); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php index 180b6f3b1c..a0edfb0af7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php @@ -97,7 +97,7 @@ public function canDisplayUseDefault() public function usedDefault() { $devaultValue = $this->getDataObject()->getAttributeDefaultValue($this->getAttribute()->getAttributeCode()); - return is_null($devaultValue); + return $devaultValue === false; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php index 8526e7d60b..c8edeaf5f4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php @@ -30,70 +30,45 @@ * * @category Mage * @package Mage_Adminhtml - * @author Magento Core Team + * @author Magento Core Team */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main extends Mage_Adminhtml_Block_Widget_Form +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract { - + /** + * Adding product form elements for editing attribute + * + * @return Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main + */ protected function _prepareForm() { - $model = Mage::registry('entity_attribute'); - - $form = new Varien_Data_Form(array( - 'id' => 'edit_form', - 'action' => $this->getData('action'), - 'method' => 'post' - )); - - $disableAttributeFields = array( - 'sku' => array( - 'is_global', - 'is_unique', - ), - 'url_key' => array( - 'is_unique', - ), - 'status' => array( - 'is_configurable', - 'is_filterable', - 'is_filterable_in_search' - ), - 'visibility' => array( - 'is_configurable', - 'is_filterable', - 'is_filterable_in_search' - ), - ); - - $fieldset = $form->addFieldset('base_fieldset', - array('legend'=>Mage::helper('catalog')->__('Attribute Properties')) - ); - if ($model->getAttributeId()) { - $fieldset->addField('attribute_id', 'hidden', array( - 'name' => 'attribute_id', - )); - } - - $this->_addElementTypes($fieldset); - - $yesno = array( + parent::_prepareForm(); + $attributeObject = $this->getAttributeObject(); + /* @var $form Varien_Data_Form */ + $form = $this->getForm(); + /* @var $fieldset Varien_Data_Form_Element_Fieldset */ + $fieldset = $form->getElement('base_fieldset'); + + $frontendInputElm = $form->getElement('frontend_input'); + $additionalTypes = array( array( - 'value' => 0, - 'label' => Mage::helper('catalog')->__('No') + 'value' => 'price', + 'label' => Mage::helper('catalog')->__('Price') ), array( - 'value' => 1, - 'label' => Mage::helper('catalog')->__('Yes') - )); + 'value' => 'media_image', + 'label' => Mage::helper('catalog')->__('Media Image') + ) + ); + if ($attributeObject->getFrontendInput() == 'gallery') { + $inputTypes[] = array( + 'value' => 'gallery', + 'label' => Mage::helper('catalog')->__('Gallery') + ); + } + $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); + $frontendInputElm->setValues($frontendInputValues); - $fieldset->addField('attribute_code', 'text', array( - 'name' => 'attribute_code', - 'label' => Mage::helper('catalog')->__('Attribute Code'), - 'title' => Mage::helper('catalog')->__('Attribute Code'), - 'note' => Mage::helper('catalog')->__('For internal use. Must be unique with no spaces'), - 'class' => 'validate-code', - 'required' => true, - )); + $yesnoSource = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(); $scopes = array( Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'), @@ -101,7 +76,7 @@ protected function _prepareForm() Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'), ); - if ($model->getAttributeCode() == 'status' || $model->getAttributeCode() == 'tax_class_id') { + if ($attributeObject->getAttributeCode() == 'status' || $attributeObject->getAttributeCode() == 'tax_class_id') { unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]); } @@ -111,165 +86,7 @@ protected function _prepareForm() 'title' => Mage::helper('catalog')->__('Scope'), 'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'), 'values'=> $scopes - )); - - $inputTypes = array( - array( - 'value' => 'text', - 'label' => Mage::helper('catalog')->__('Text Field') - ), - array( - 'value' => 'textarea', - 'label' => Mage::helper('catalog')->__('Text Area') - ), - array( - 'value' => 'date', - 'label' => Mage::helper('catalog')->__('Date') - ), - array( - 'value' => 'boolean', - 'label' => Mage::helper('catalog')->__('Yes/No') - ), - array( - 'value' => 'multiselect', - 'label' => Mage::helper('catalog')->__('Multiple Select') - ), - array( - 'value' => 'select', - 'label' => Mage::helper('catalog')->__('Dropdown') - ), - array( - 'value' => 'price', - 'label' => Mage::helper('catalog')->__('Price') - ), - array( - 'value' => 'media_image', - 'label' => Mage::helper('catalog')->__('Media Image') - ), - ); - - if ($model->getFrontendInput() == 'gallery') { - $inputTypes[] = array( - 'value' => 'gallery', - 'label' => Mage::helper('catalog')->__('Gallery') - ); - } - - $response = new Varien_Object(); - $response->setTypes(array()); - Mage::dispatchEvent('adminhtml_product_attribute_types', array('response'=>$response)); - - $_disabledTypes = array(); - $_hiddenFields = array(); - foreach ($response->getTypes() as $type) { - $inputTypes[] = $type; - if (isset($type['hide_fields'])) { - $_hiddenFields[$type['value']] = $type['hide_fields']; - } - if (isset($type['disabled_types'])) { - $_disabledTypes[$type['value']] = $type['disabled_types']; - } - } - Mage::register('attribute_type_hidden_fields', $_hiddenFields); - Mage::register('attribute_type_disabled_types', $_disabledTypes); - - - $fieldset->addField('frontend_input', 'select', array( - 'name' => 'frontend_input', - 'label' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), - 'title' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), - 'value' => 'text', - 'values'=> $inputTypes - )); - - $fieldset->addField('default_value_text', 'text', array( - 'name' => 'default_value_text', - 'label' => Mage::helper('catalog')->__('Default value'), - 'title' => Mage::helper('catalog')->__('Default value'), - 'value' => $model->getDefaultValue(), - )); - - $fieldset->addField('default_value_yesno', 'select', array( - 'name' => 'default_value_yesno', - 'label' => Mage::helper('catalog')->__('Default value'), - 'title' => Mage::helper('catalog')->__('Default value'), - 'values' => $yesno, - 'value' => $model->getDefaultValue(), - )); - - $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); - $fieldset->addField('default_value_date', 'date', array( - 'name' => 'default_value_date', - 'label' => Mage::helper('catalog')->__('Default value'), - 'title' => Mage::helper('catalog')->__('Default value'), - 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'value' => $model->getDefaultValue(), - 'format' => $dateFormatIso - )); - - $fieldset->addField('default_value_textarea', 'textarea', array( - 'name' => 'default_value_textarea', - 'label' => Mage::helper('catalog')->__('Default value'), - 'title' => Mage::helper('catalog')->__('Default value'), - 'value' => $model->getDefaultValue(), - )); - - $fieldset->addField('is_unique', 'select', array( - 'name' => 'is_unique', - 'label' => Mage::helper('catalog')->__('Unique Value'), - 'title' => Mage::helper('catalog')->__('Unique Value (not shared with other products)'), - 'note' => Mage::helper('catalog')->__('Not shared with other products'), - 'values' => $yesno, - )); - - $fieldset->addField('is_required', 'select', array( - 'name' => 'is_required', - 'label' => Mage::helper('catalog')->__('Values Required'), - 'title' => Mage::helper('catalog')->__('Values Required'), - 'values' => $yesno, - )); - - $fieldset->addField('frontend_class', 'select', array( - 'name' => 'frontend_class', - 'label' => Mage::helper('catalog')->__('Input Validation for Store Owner'), - 'title' => Mage::helper('catalog')->__('Input Validation for Store Owner'), - 'values'=> array( - array( - 'value' => '', - 'label' => Mage::helper('catalog')->__('None') - ), - array( - 'value' => 'validate-number', - 'label' => Mage::helper('catalog')->__('Decimal Number') - ), - array( - 'value' => 'validate-digits', - 'label' => Mage::helper('catalog')->__('Integer Number') - ), - array( - 'value' => 'validate-email', - 'label' => Mage::helper('catalog')->__('Email') - ), - array( - 'value' => 'validate-url', - 'label' => Mage::helper('catalog')->__('Url') - ), - array( - 'value' => 'validate-alpha', - 'label' => Mage::helper('catalog')->__('Letters') - ), - array( - 'value' => 'validate-alphanum', - 'label' => Mage::helper('catalog')->__('Letters(a-zA-Z) or Numbers(0-9)') - ), - ) - )); -/* - $fieldset->addField('use_in_super_product', 'select', array( - 'name' => 'use_in_super_product', - 'label' => Mage::helper('catalog')->__('Apply To Configurable/Grouped Product'), - 'values' => $yesno, - )); */ + ), 'attribute_code'); $fieldset->addField('apply_to', 'apply', array( 'name' => 'apply_to[]', @@ -280,15 +97,13 @@ protected function _prepareForm() 'custom' => Mage::helper('catalog')->__('Selected Product Types') ), 'required' => true - )); + ), 'frontend_class'); $fieldset->addField('is_configurable', 'select', array( 'name' => 'is_configurable', 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'), - 'values' => $yesno, - )); - // ----- - + 'values' => $yesnoSource, + ), 'apply_to'); // frontend properties fieldset $fieldset = $form->addFieldset('front_fieldset', array('legend'=>Mage::helper('catalog')->__('Frontend Properties'))); @@ -297,24 +112,23 @@ protected function _prepareForm() 'name' => 'is_searchable', 'label' => Mage::helper('catalog')->__('Use in quick search'), 'title' => Mage::helper('catalog')->__('Use in quick search'), - 'values' => $yesno, + 'values' => $yesnoSource, )); $fieldset->addField('is_visible_in_advanced_search', 'select', array( 'name' => 'is_visible_in_advanced_search', 'label' => Mage::helper('catalog')->__('Use in advanced search'), 'title' => Mage::helper('catalog')->__('Use in advanced search'), - 'values' => $yesno, + 'values' => $yesnoSource, )); $fieldset->addField('is_comparable', 'select', array( 'name' => 'is_comparable', 'label' => Mage::helper('catalog')->__('Comparable on Front-end'), 'title' => Mage::helper('catalog')->__('Comparable on Front-end'), - 'values' => $yesno, + 'values' => $yesnoSource, )); - $fieldset->addField('is_filterable', 'select', array( 'name' => 'is_filterable', 'label' => Mage::helper('catalog')->__("Use In Layered Navigation"), @@ -332,14 +146,14 @@ protected function _prepareForm() 'label' => Mage::helper('catalog')->__("Use In Search Results Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), - 'values' => $yesno, + 'values' => $yesnoSource, )); $fieldset->addField('is_used_for_price_rules', 'select', array( 'name' => 'is_used_for_price_rules', 'label' => Mage::helper('catalog')->__('Use for Price Rule Conditions'), 'title' => Mage::helper('catalog')->__('Use for Price Rule Conditions'), - 'values' => $yesno, + 'values' => $yesnoSource, )); $fieldset->addField('position', 'text', array( @@ -354,9 +168,9 @@ protected function _prepareForm() 'name' => 'is_html_allowed_on_front', 'label' => Mage::helper('catalog')->__('Allow HTML-tags on Front-end'), 'title' => Mage::helper('catalog')->__('Allow HTML-tags on Front-end'), - 'values' => $yesno, + 'values' => $yesnoSource, )); - if (!$model->getId()) { + if (!$attributeObject->getId()) { $htmlAllowed->setValue(1); } @@ -364,7 +178,7 @@ protected function _prepareForm() 'name' => 'is_visible_on_front', 'label' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), 'title' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), - 'values' => $yesno, + 'values' => $yesnoSource, )); $fieldset->addField('used_in_product_listing', 'select', array( @@ -372,52 +186,54 @@ protected function _prepareForm() 'label' => Mage::helper('catalog')->__('Used in product listing'), 'title' => Mage::helper('catalog')->__('Used in product listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), - 'values' => $yesno, + 'values' => $yesnoSource, )); $fieldset->addField('used_for_sort_by', 'select', array( 'name' => 'used_for_sort_by', 'label' => Mage::helper('catalog')->__('Used for sorting in product listing'), 'title' => Mage::helper('catalog')->__('Used for sorting in product listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), - 'values' => $yesno, + 'values' => $yesnoSource, )); - if ($model->getId()) { - $form->getElement('attribute_code')->setDisabled(1); - $form->getElement('frontend_input')->setDisabled(1); - - if (isset($disableAttributeFields[$model->getAttributeCode()])) { - foreach ($disableAttributeFields[$model->getAttributeCode()] as $field) { - $form->getElement($field)->setDisabled(1); - $form->getElement($field)->setReadonly(1); - } - } - } - if (!$model->getIsUserDefined() && $model->getId()) { - $form->getElement('is_unique')->setDisabled(1); - } - - $form->addValues($model->getData()); - $form->getElement('apply_to')->setSize(5); - if ($applyTo = $model->getApplyTo()) { + if ($applyTo = $attributeObject->getApplyTo()) { $applyTo = is_array($applyTo) ? $applyTo : explode(',', $applyTo); $form->getElement('apply_to')->setValue($applyTo); } else { $form->getElement('apply_to')->addClass('no-display ignore-validate'); } - $this->setForm($form); + $response = new Varien_Object(); + $response->setTypes(array()); + Mage::dispatchEvent('adminhtml_product_attribute_types', array('response'=>$response)); + $_disabledTypes = array(); + $_hiddenFields = array(); + foreach ($response->getTypes() as $type) { + $inputTypes[] = $type; + if (isset($type['hide_fields'])) { + $_hiddenFields[$type['value']] = $type['hide_fields']; + } + if (isset($type['disabled_types'])) { + $_disabledTypes[$type['value']] = $type['disabled_types']; + } + } + Mage::register('attribute_type_hidden_fields', $_hiddenFields); + Mage::register('attribute_type_disabled_types', $_disabledTypes); - return parent::_prepareForm(); + return $this; } + /** + * Retrieve additional element types for product attributes + * + * @return array + */ protected function _getAdditionalElementTypes() { return array( 'apply' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_apply') ); } - } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Options.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Options.php index 0e3d17b042..637333b377 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Options.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Options.php @@ -31,155 +31,6 @@ * @package Mage_Adminhtml * @author Magento Core Team */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options extends Mage_Adminhtml_Block_Widget +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract { - - public function __construct() - { - parent::__construct(); - $this->setTemplate('catalog/product/attribute/options.phtml'); - } - - protected function _prepareLayout() - { - $this->setChild('delete_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( - 'label' => Mage::helper('catalog')->__('Delete'), - 'class' => 'delete delete-option' - ))); - - $this->setChild('add_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( - 'label' => Mage::helper('catalog')->__('Add Option'), - 'class' => 'add', - 'id' => 'add_new_option_button' - ))); - return parent::_prepareLayout(); - } - - public function getDeleteButtonHtml() - { - return $this->getChildHtml('delete_button'); - } - - public function getAddNewButtonHtml() - { - return $this->getChildHtml('add_button'); - } - - public function getStores() - { - $stores = $this->getData('stores'); - if (is_null($stores)) { - $stores = Mage::getModel('core/store') - ->getResourceCollection() - ->setLoadDefault(true) - ->load(); - $this->setData('stores', $stores); - } - return $stores; - } - - public function getOptionValues() - { - $attributeType = $this->getAttributeObject()->getFrontendInput(); - $defaultValues = $this->getAttributeObject()->getDefaultValue(); - if ($attributeType == 'select' || $attributeType == 'multiselect') { - $defaultValues = explode(',', $defaultValues); - } else { - $defaultValues = array(); - } - - switch ($attributeType) { - case 'select': - $inputType = 'radio'; - break; - case 'multiselect': - $inputType = 'checkbox'; - break; - default: - $inputType = ''; - break; - } - - $values = $this->getData('option_values'); - if (is_null($values)) { - $values = array(); - $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection') - ->setAttributeFilter($this->getAttributeObject()->getId()) - ->setPositionOrder('desc', true) - ->load(); - - foreach ($optionCollection as $option) { - $value = array(); - if (in_array($option->getId(), $defaultValues)) { - $value['checked'] = 'checked="checked"'; - } else { - $value['checked'] = ''; - } - - $value['intype'] = $inputType; - $value['id'] = $option->getId(); - $value['sort_order'] = $option->getSortOrder(); - foreach ($this->getStores() as $store) { - $storeValues = $this->getStoreOptionValues($store->getId()); - if (isset($storeValues[$option->getId()])) { - $value['store'.$store->getId()] = htmlspecialchars($storeValues[$option->getId()]); - } - else { - $value['store'.$store->getId()] = ''; - } - } - $values[] = new Varien_Object($value); - } - $this->setData('option_values', $values); - } - - return $values; - } - - public function getLabelValues() - { - $values = array(); - $values[0] = $this->getAttributeObject()->getFrontend()->getLabel(); - // it can be array and cause bug - $frontendLabel = $this->getAttributeObject()->getFrontend()->getLabel(); - if (is_array($frontendLabel)) { - $frontendLabel = array_shift($frontendLabel); - } - $translations = Mage::getModel('core/translate_string') - ->load(Mage_Catalog_Model_Entity_Attribute::MODULE_NAME.Mage_Core_Model_Translate::SCOPE_SEPARATOR.$frontendLabel) - ->getStoreTranslations(); - foreach ($this->getStores() as $store) { - if ($store->getId() != 0) { - $values[$store->getId()] = isset($translations[$store->getId()]) ? $translations[$store->getId()] : ''; - } - } - return $values; - } - - public function getStoreOptionValues($storeId) - { - $values = $this->getData('store_option_values_'.$storeId); - if (is_null($values)) { - $values = array(); - $valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection') - ->setAttributeFilter($this->getAttributeObject()->getId()) - ->setStoreFilter($storeId, false) - ->load(); - foreach ($valuesCollection as $item) { - $values[$item->getId()] = $item->getValue(); - } - $this->setData('store_option_values_'.$storeId, $values); - } - return $values; - } - - public function getAttributeObject() - { - return Mage::registry('entity_attribute'); - } - } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php index 6b7a39d803..2137742cc2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php @@ -29,54 +29,34 @@ * * @category Mage * @package Mage_Adminhtml - * @author Magento Core Team + * @author Magento Core Team */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Grid extends Mage_Adminhtml_Block_Widget_Grid +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Grid extends Mage_Eav_Block_Adminhtml_Attribute_Grid_Abstract { - - public function __construct() - { - parent::__construct(); - $this->setId('attributeGrid'); - $this->setDefaultSort('attribute_code'); - $this->setDefaultDir('ASC'); - } - + /** + * Prepare product attributes grid collection object + * + * @return Mage_Adminhtml_Block_Catalog_Product_Attribute_Grid + */ protected function _prepareCollection() { - $collection = Mage::getResourceModel('eav/entity_attribute_collection') - ->setEntityTypeFilter( Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId() ) + $collection = Mage::getResourceModel('catalog/product_attribute_collection') ->addVisibleFilter(); $this->setCollection($collection); return parent::_prepareCollection(); } + /** + * Prepare product attributes grid columns + * + * @return Mage_Adminhtml_Block_Catalog_Product_Attribute_Grid + */ protected function _prepareColumns() { - /* - $this->addColumn('attribute_id', array( - 'header'=>Mage::helper('catalog')->__('ID'), - 'align'=>'right', - 'sortable'=>true, - 'width' => '50px', - 'index'=>'attribute_id' - )); - */ - - $this->addColumn('attribute_code', array( - 'header'=>Mage::helper('catalog')->__('Attribute Code'), - 'sortable'=>true, - 'index'=>'attribute_code' - )); + parent::_prepareColumns(); - $this->addColumn('frontend_label', array( - 'header'=>Mage::helper('catalog')->__('Attribute Label'), - 'sortable'=>true, - 'index'=>'frontend_label' - )); - - $this->addColumn('is_visible', array( + $this->addColumnAfter('is_visible', array( 'header'=>Mage::helper('catalog')->__('Visible'), 'sortable'=>true, 'index'=>'is_visible_on_front', @@ -86,9 +66,9 @@ protected function _prepareColumns() '0' => Mage::helper('catalog')->__('No'), ), 'align' => 'center', - )); + ), 'frontend_label'); - $this->addColumn('is_global', array( + $this->addColumnAfter('is_global', array( 'header'=>Mage::helper('catalog')->__('Scope'), 'sortable'=>true, 'index'=>'is_global', @@ -99,31 +79,7 @@ protected function _prepareColumns() Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'), ), 'align' => 'center', - )); - - $this->addColumn('is_required', array( - 'header'=>Mage::helper('catalog')->__('Required'), - 'sortable'=>true, - 'index'=>'is_required', - 'type' => 'options', - 'options' => array( - '1' => Mage::helper('catalog')->__('Yes'), - '0' => Mage::helper('catalog')->__('No'), - ), - 'align' => 'center', - )); - - $this->addColumn('is_user_defined', array( - 'header'=>Mage::helper('catalog')->__('System'), - 'sortable'=>true, - 'index'=>'is_user_defined', - 'type' => 'options', - 'align' => 'center', - 'options' => array( - '0' => Mage::helper('catalog')->__('Yes'), // intended reverted use - '1' => Mage::helper('catalog')->__('No'), // intended reverted use - ), - )); + ), 'is_visible'); $this->addColumn('is_searchable', array( 'header'=>Mage::helper('catalog')->__('Searchable'), @@ -135,9 +91,9 @@ protected function _prepareColumns() '0' => Mage::helper('catalog')->__('No'), ), 'align' => 'center', - )); + ), 'is_user_defined'); - $this->addColumn('is_filterable', array( + $this->addColumnAfter('is_filterable', array( 'header'=>Mage::helper('catalog')->__('Use In Layered Navigation'), 'sortable'=>true, 'index'=>'is_filterable', @@ -148,9 +104,9 @@ protected function _prepareColumns() '0' => Mage::helper('catalog')->__('No'), ), 'align' => 'center', - )); + ), 'is_searchable'); - $this->addColumn('is_comparable', array( + $this->addColumnAfter('is_comparable', array( 'header'=>Mage::helper('catalog')->__('Comparable'), 'sortable'=>true, 'index'=>'is_comparable', @@ -160,14 +116,8 @@ protected function _prepareColumns() '0' => Mage::helper('catalog')->__('No'), ), 'align' => 'center', - )); - - return parent::_prepareColumns(); - } + ), 'is_filterable'); - public function getRowUrl($row) - { - return $this->getUrl('*/*/edit', array('attribute_id' => $row->getAttributeId())); + return $this; } - } \ No newline at end of file diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php index bca0c3bbcb..91a083cd99 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php @@ -187,8 +187,7 @@ public function getGroupTreeJson() $item['allowDrop'] = true; $item['allowDrag'] = true; - $nodeChildren = Mage::getModel('eav/entity_attribute') - ->getResourceCollection() + $nodeChildren = Mage::getResourceModel('catalog/product_attribute_collection') ->setAttributeGroupFilter($node->getId()) ->addVisibleFilter() ->checkConfigurableProducts() @@ -207,7 +206,7 @@ public function getGroupTreeJson() 'leaf' => true, 'is_user_defined' => $child->getIsUserDefined(), 'is_configurable' => (int)in_array($child->getAttributeId(), $configurable), - 'entity_id' => $child->getEntityId() + 'entity_id' => $child->getEntityAttributeId() ); $item['children'][] = $attr; @@ -230,8 +229,7 @@ public function getAttributeTreeJson() $items = array(); $setId = $this->_getSetId(); - $collection = Mage::getModel('eav/entity_attribute') - ->getResourceCollection() + $collection = Mage::getResourceModel('catalog/product_attribute_collection') ->setAttributeSetFilter($setId) ->load(); @@ -241,9 +239,7 @@ public function getAttributeTreeJson() $attributesIds[] = $item->getAttributeId(); } - $attributes = Mage::getModel('eav/entity_attribute') - ->getResourceCollection() - ->setEntityTypeFilter(Mage::registry('entityType')) + $attributes = Mage::getResourceModel('catalog/product_attribute_collection') ->setAttributesExcludeFilter($attributesIds) ->addVisibleFilter() ->load(); diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php index ea29de7b9e..c5678f1440 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php @@ -43,7 +43,7 @@ protected function _prepareForm() ->load($this->getRequest()->getParam('id')); $form = new Varien_Data_Form(); - $fieldset = $form->addFieldset('set_name', array('legend'=>__('Edit Set Name'))); + $fieldset = $form->addFieldset('set_name', array('legend'=> Mage::helper('catalog')->__('Edit Set Name'))); $fieldset->addField('attribute_set_name', 'text', array( 'label' => Mage::helper('catalog')->__('Name
(For internal use)'), diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Ajax/Serializer.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Ajax/Serializer.php index 7200b4bbd8..3a48bb52ac 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Ajax/Serializer.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Ajax/Serializer.php @@ -52,4 +52,20 @@ public function getProductsJSON() } return $result ? Zend_Json_Encoder::encode($result) : '{}'; } + + /** + * Initialize grid block under the "Related Products", "Up-sells", "Cross-sells" sections + * + * @param string $blockName + * @param string $getProductFunction + * @param string $inputName + */ + public function initSerializerBlock($blockName, $getProductFunction, $inputName) + { + if ($block = $this->getLayout()->getBlock($blockName)) { + $this->setGridBlock($block) + ->setProducts(Mage::registry('current_product')->$getProductFunction()) + ->setInputElementName($inputName); + } + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php index bf7d8330ed..08e8578211 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php @@ -33,6 +33,10 @@ */ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Crosssell extends Mage_Adminhtml_Block_Widget_Grid { + /** + * Set grid params + * + */ public function __construct() { parent::__construct(); @@ -54,6 +58,12 @@ protected function _getProduct() return Mage::registry('current_product'); } + /** + * Add filter + * + * @param object $column + * @return Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Crosssell + */ protected function _addColumnFilterToCollection($column) { // Set custom filter for in product flag @@ -64,19 +74,22 @@ protected function _addColumnFilterToCollection($column) } if ($column->getFilter()->getValue()) { $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds)); - } - else { + } else { if($productIds) { $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds)); } } - } - else { + } else { parent::_addColumnFilterToCollection($column); } return $this; } + /** + * Prepare collection + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ protected function _prepareCollection() { $collection = Mage::getModel('catalog/product_link')->useCrossSellLinks() @@ -107,37 +120,42 @@ public function isReadonly() return $this->_getProduct()->getCrosssellReadonly(); } + /** + * Add columns to grid + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ protected function _prepareColumns() { if (!$this->isReadonly()) { $this->addColumn('in_products', array( - 'header_css_class' => 'a-center', - 'type' => 'checkbox', - 'name' => 'in_products', - 'values' => $this->_getSelectedProducts(), - 'align' => 'center', - 'index' => 'entity_id' + 'header_css_class' => 'a-center', + 'type' => 'checkbox', + 'name' => 'in_products', + 'values' => $this->_getSelectedProducts(), + 'align' => 'center', + 'index' => 'entity_id' )); } $this->addColumn('entity_id', array( 'header' => Mage::helper('catalog')->__('ID'), 'sortable' => true, - 'width' => '60px', + 'width' => 60, 'index' => 'entity_id' )); + $this->addColumn('name', array( 'header' => Mage::helper('catalog')->__('Name'), 'index' => 'name' )); - $this->addColumn('type', - array( - 'header'=> Mage::helper('catalog')->__('Type'), - 'width' => '100px', - 'index' => 'type_id', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(), + $this->addColumn('type', array( + 'header' => Mage::helper('catalog')->__('Type'), + 'width' => 100, + 'index' => 'type_id', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(), )); $sets = Mage::getResourceModel('eav/entity_attribute_set_collection') @@ -145,73 +163,89 @@ protected function _prepareColumns() ->load() ->toOptionHash(); - $this->addColumn('set_name', - array( - 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'), - 'width' => '130px', - 'index' => 'attribute_set_id', - 'type' => 'options', - 'options' => $sets, + $this->addColumn('set_name', array( + 'header' => Mage::helper('catalog')->__('Attrib. Set Name'), + 'width' => 130, + 'index' => 'attribute_set_id', + 'type' => 'options', + 'options' => $sets, )); - $this->addColumn('status', - array( - 'header'=> Mage::helper('catalog')->__('Status'), - 'width' => '90px', - 'index' => 'status', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(), + $this->addColumn('status', array( + 'header' => Mage::helper('catalog')->__('Status'), + 'width' => 90, + 'index' => 'status', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(), )); - $this->addColumn('visibility', - array( - 'header'=> Mage::helper('catalog')->__('Visibility'), - 'width' => '90px', - 'index' => 'visibility', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(), + $this->addColumn('visibility', array( + 'header' => Mage::helper('catalog')->__('Visibility'), + 'width' => 90, + 'index' => 'visibility', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(), )); $this->addColumn('sku', array( 'header' => Mage::helper('catalog')->__('SKU'), - 'width' => '80px', + 'width' => 80, 'index' => 'sku' )); + $this->addColumn('price', array( - 'header' => Mage::helper('catalog')->__('Price'), - 'type' => 'currency', + 'header' => Mage::helper('catalog')->__('Price'), + 'type' => 'currency', 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE), - 'index' => 'price' + 'index' => 'price' )); $this->addColumn('position', array( - 'header' => Mage::helper('catalog')->__('Position'), - 'name' => 'position', - 'width' => '60px', - 'type' => 'number', - 'validate_class' => 'validate-number', - 'index' => 'position', - 'editable' => !$this->isReadonly(), - 'edit_only' => !$this->_getProduct()->getId() + 'header' => Mage::helper('catalog')->__('Position'), + 'name' => 'position', + 'width' => 60, + 'type' => 'number', + 'validate_class' => 'validate-number', + 'index' => 'position', + 'editable' => !$this->isReadonly(), + 'edit_only' => !$this->_getProduct()->getId() )); - - return parent::_prepareColumns(); } + /** + * Rerieve grid URL + * + * @return string + */ public function getGridUrl() { - return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/crosssell', array('_current'=>true)); + return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/crosssellGrid', array('_current'=>true)); } + /** + * Retrieve selected crosssell products + * + * @return array + */ protected function _getSelectedProducts() { - $products = $this->getRequest()->getPost('products', null); + $products = $this->getProductsCrossSell(); if (!is_array($products)) { - $products = $this->_getProduct()->getCrossSellProductIds(); + $products = $this->getSelectedCrossSellProducts(); } return $products; } + + /** + * Retrieve crosssell products + * + * @return array + */ + public function getSelectedCrossSellProducts() + { + return Mage::registry('current_product')->getCrossSellProductIds(); + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php index bdf569c05f..63c23c3bc8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php @@ -38,9 +38,6 @@ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option extends Mage_ protected $_productInstance; - protected $_name = 'product[options]'; - protected $_id = 'product_option'; - protected $_values; protected $_itemCount = 1; @@ -86,14 +83,24 @@ public function setProduct($product) return $this; } + /** + * Retrieve options field name prefix + * + * @return string + */ public function getFieldName() { - return $this->_name; + return 'product[options]'; } + /** + * Retrieve options field id prefix + * + * @return string + */ public function getFieldId() { - return $this->_id; + return 'product_option'; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Abstract.php index 3fb72af344..2d38dffe35 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Abstract.php @@ -44,10 +44,12 @@ protected function _prepareLayout() 'id' => 'product_option_{{option_id}}_price_type', 'class' => 'select product-option-price-type' )) - ->setName('product[options][{{option_id}}][price_type]') - ->setOptions(Mage::getSingleton('adminhtml/system_config_source_product_options_price')->toOptionArray()) ); + $this->getChild('option_price_type')->setName('product[options][{{option_id}}][price_type]') + ->setOptions(Mage::getSingleton('adminhtml/system_config_source_product_options_price') + ->toOptionArray()); + return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Tier.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Tier.php index 10f9199c1d..654f4d8c54 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Tier.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Tier.php @@ -25,154 +25,273 @@ */ /** - * Adminhtml tier pricing item renderer + * Adminhtml tier price item renderer * * @category Mage * @package Mage_Adminhtml - * @author Magento Core Team + * @author Magento Core Team */ -class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Tier extends Mage_Adminhtml_Block_Widget implements Varien_Data_Form_Element_Renderer_Interface +class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Tier + extends Mage_Adminhtml_Block_Widget + implements Varien_Data_Form_Element_Renderer_Interface { + /** + * Form element instance + * + * @var Varien_Data_Form_Element + */ + protected $_element; + + /** + * Customer Groups cache + * + * @var array + */ + protected $_customerGroups; - protected $_element = null; - protected $_customerGroups = null; - protected $_websites = null; + /** + * Websites cache + * + * @var array + */ + protected $_websites; + /** + * Define tier price template file + * + */ public function __construct() { $this->setTemplate('catalog/product/edit/price/tier.phtml'); } + /** + * Retrieve current edit product instance + * + * @return Mage_Catalog_Model_Product + */ public function getProduct() { return Mage::registry('product'); } + /** + * Render HTML + * + * @param Varien_Data_Form_Element_Abstract $element + * @return string + */ public function render(Varien_Data_Form_Element_Abstract $element) { $this->setElement($element); return $this->toHtml(); } + /** + * Set form element instance + * + * @param Varien_Data_Form_Element_Abstract $element + * @return Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Tier + */ public function setElement(Varien_Data_Form_Element_Abstract $element) { $this->_element = $element; return $this; } + /** + * Retrieve form element instance + * + * @return Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Tier + */ public function getElement() { return $this->_element; } + /** + * Prepare Tier Price values + * + * @return array + */ public function getValues() { - $values =array(); - $data = $this->getElement()->getValue(); + $values = array(); + $data = $this->getElement()->getValue(); if (is_array($data)) { usort($data, array($this, '_sortTierPrices')); $values = $data; } + + foreach ($values as &$v) { + $v['readonly'] = $v['website_id'] == 0 && $this->isShowWebsiteColumn() && !$this->isAllowChangeWebsite(); + } + return $values; } + /** + * Sort tier price values callback method + * + * @param array $a + * @param array $b + * @return int + */ protected function _sortTierPrices($a, $b) { - if ($a['website_id']!=$b['website_id']) { - return $a['website_id']<$b['website_id'] ? -1 : 1; + if ($a['website_id'] != $b['website_id']) { + return $a['website_id'] < $b['website_id'] ? -1 : 1; } - if ($a['cust_group']!=$b['cust_group']) { - return $this->getCustomerGroups($a['cust_group'])<$this->getCustomerGroups($b['cust_group']) ? -1 : 1; + if ($a['cust_group'] != $b['cust_group']) { + return $this->getCustomerGroups($a['cust_group']) < $this->getCustomerGroups($b['cust_group']) ? -1 : 1; } - if ($a['price_qty']!=$b['price_qty']) { - return $a['price_qty']<$b['price_qty'] ? -1 : 1; + if ($a['price_qty'] != $b['price_qty']) { + return $a['price_qty'] < $b['price_qty'] ? -1 : 1; } + return 0; } - public function getCustomerGroups($groupId=null) + /** + * Retrieve allowed customer groups + * + * @param int $groupId return name by customer group id + * @return array|string + */ + public function getCustomerGroups($groupId = null) { - if (!$this->_customerGroups) { - $collection = Mage::getModel('customer/group')->getCollection() - ->load(); + if (is_null($this->_customerGroups)) { + $collection = Mage::getModel('customer/group')->getCollection(); $this->_customerGroups = array( - Mage_Customer_Model_Group::CUST_GROUP_ALL => Mage::helper('catalog')->__('ALL GROUPS'), + Mage_Customer_Model_Group::CUST_GROUP_ALL => Mage::helper('catalog')->__('ALL GROUPS') ); - foreach ($collection->getIterator() as $item) { + + foreach ($collection as $item) { + /* @var $item Mage_Customer_Model_Group */ $this->_customerGroups[$item->getId()] = $item->getCustomerGroupCode(); } } - return is_null($groupId) ? $this->_customerGroups : - (isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : null); + + if (!is_null($groupId)) { + return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : null; + } + + return $this->_customerGroups; } + /** + * Retrieve count of websites + * + * @return int + */ public function getWebsiteCount() { return count($this->getWebsites()); } + /** + * Show Website column and switcher for tier price table + * + * @return bool + */ public function isMultiWebsites() { return !Mage::app()->isSingleStoreMode(); } + /** + * Retrieve allowed for edit websites + * + * @return array + */ public function getWebsites() { if (!is_null($this->_websites)) { return $this->_websites; } - $websites = array(); - $websites[0] = array( - 'name' => $this->__('All Websites'), - 'currency' => Mage::app()->getBaseCurrencyCode() + + $this->_websites = array( + 0 => array( + 'name' => Mage::helper('catalog')->__('All Websites'), + 'currency' => Mage::app()->getBaseCurrencyCode() + ) ); - if (Mage::app()->isSingleStoreMode() || $this->getElement()->getEntityAttribute()->isScopeGlobal()) { - return $websites; - } - elseif ($storeId = $this->getProduct()->getStoreId()) { - $website = Mage::app()->getStore($storeId)->getWebsite(); - $websites[$website->getId()] = array( + + if (!$this->isScopeGlobal() && $this->getProduct()->getStoreId()) { + /* @var $website Mage_Core_Model_Website */ + $website = Mage::app()->getStore($this->getProduct()->getStoreId())->getWebsite(); + + $this->_websites[$website->getId()] = array( 'name' => $website->getName(), - 'currency' => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE), - ); - } - else { - $websites[0] = array( - 'name' => $this->__('All Websites'), - 'currency' => Mage::app()->getBaseCurrencyCode() + 'currency' => $website->getBaseCurrencyCode() ); - foreach (Mage::app()->getWebsites() as $website) { - if (!in_array($website->getId(), $this->getProduct()->getWebsiteIds())) { + } else if (!$this->isScopeGlobal()) { + $websites = Mage::app()->getWebsites(false); + $productWebsiteIds = $this->getProduct()->getWebsiteIds(); + foreach ($websites as $website) { + /* @var $website Mage_Core_Model_Website */ + if (!in_array($website->getId(), $productWebsiteIds)) { continue; } - $websites[$website->getId()] = array( + $this->_websites[$website->getId()] = array( 'name' => $website->getName(), - 'currency' => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE), + 'currency' => $website->getBaseCurrencyCode() ); } } - $this->_websites = $websites; + return $this->_websites; } + /** + * Retrieve default value for customer group + * + * @return int + */ public function getDefaultCustomerGroup() { return Mage_Customer_Model_Group::CUST_GROUP_ALL; } + /** + * Retrieve default value for website + * + * @return int + */ + public function getDefaultWebsite() + { + if ($this->isShowWebsiteColumn() && !$this->isAllowChangeWebsite()) { + return Mage::app()->getStore($this->getProduct()->getStoreId())->getWebsiteId(); + } + return 0; + } + + /** + * Prepare global layout + * Add "Add tier" button to layout + * + * @return Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Tier + */ protected function _prepareLayout() { - $this->setChild('add_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( - 'label' => Mage::helper('catalog')->__('Add Tier'), - 'onclick' => 'tierPriceControl.addItem()', - 'class' => 'add' - ))); + $button = $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData(array( + 'label' => Mage::helper('catalog')->__('Add Tier'), + 'onclick' => 'return tierPriceControl.addItem()', + 'class' => 'add' + )); + $button->setName('add_tier_price_item_button'); + + $this->setChild('add_button', $button); return parent::_prepareLayout(); } + /** + * Retrieve Add Tier Price Item button HTML + * + * @return string + */ public function getAddButtonHtml() { return $this->getChildHtml('add_button'); @@ -193,4 +312,52 @@ public function getPriceColumnHeader($default) return $default; } } -} \ No newline at end of file + + /** + * Retrieve Tier Price entity attribute + * + * @return Mage_Catalog_Model_Resource_Eav_Attribute + */ + public function getAttribute() + { + return $this->getElement()->getEntityAttribute(); + } + + /** + * Check tier price attribute scope is global + * + * @return bool + */ + public function isScopeGlobal() + { + return $this->getAttribute()->isScopeGlobal(); + } + + /** + * Show tier prices grid website column + * + * @return bool + */ + public function isShowWebsiteColumn() + { + if ($this->isScopeGlobal()) { + return false; + } else if (Mage::app()->isSingleStoreMode()) { + return false; + } + return true; + } + + /** + * Check is allow change website value for combination + * + * @return bool + */ + public function isAllowChangeWebsite() + { + if (!$this->isShowWebsiteColumn() || $this->getProduct()->getStoreId()) { + return false; + } + return true; + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php index 5f957300ea..50d351ad84 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php @@ -33,6 +33,10 @@ */ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Related extends Mage_Adminhtml_Block_Widget_Grid { + /** + * Set grid params + * + */ public function __construct() { parent::__construct(); @@ -54,6 +58,12 @@ protected function _getProduct() return Mage::registry('current_product'); } + /** + * Add filter + * + * @param object $column + * @return Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Related + */ protected function _addColumnFilterToCollection($column) { // Set custom filter for in product flag @@ -64,19 +74,22 @@ protected function _addColumnFilterToCollection($column) } if ($column->getFilter()->getValue()) { $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds)); - } - else { + } else { if($productIds) { $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds)); } } - } - else { + } else { parent::_addColumnFilterToCollection($column); } return $this; } + /** + * Prepare collection + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ protected function _prepareCollection() { $collection = Mage::getModel('catalog/product_link')->useRelatedLinks() @@ -106,24 +119,28 @@ public function isReadonly() return $this->_getProduct()->getRelatedReadonly(); } - + /** + * Add columns to grid + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ protected function _prepareColumns() { if (!$this->isReadonly()) { $this->addColumn('in_products', array( - 'header_css_class' => 'a-center', - 'type' => 'checkbox', - 'name' => 'in_products', - 'values' => $this->_getSelectedProducts(), - 'align' => 'center', - 'index' => 'entity_id' + 'header_css_class' => 'a-center', + 'type' => 'checkbox', + 'name' => 'in_products', + 'values' => $this->_getSelectedProducts(), + 'align' => 'center', + 'index' => 'entity_id' )); } $this->addColumn('entity_id', array( 'header' => Mage::helper('catalog')->__('ID'), 'sortable' => true, - 'width' => '60px', + 'width' => 60, 'index' => 'entity_id' )); $this->addColumn('name', array( @@ -131,13 +148,12 @@ protected function _prepareColumns() 'index' => 'name' )); - $this->addColumn('type', - array( - 'header'=> Mage::helper('catalog')->__('Type'), - 'width' => '100px', - 'index' => 'type_id', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(), + $this->addColumn('type', array( + 'header' => Mage::helper('catalog')->__('Type'), + 'width' => 100, + 'index' => 'type_id', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(), )); $sets = Mage::getResourceModel('eav/entity_attribute_set_collection') @@ -145,81 +161,88 @@ protected function _prepareColumns() ->load() ->toOptionHash(); - $this->addColumn('set_name', - array( - 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'), - 'width' => '130px', - 'index' => 'attribute_set_id', - 'type' => 'options', - 'options' => $sets, + $this->addColumn('set_name', array( + 'header' => Mage::helper('catalog')->__('Attrib. Set Name'), + 'width' => 130, + 'index' => 'attribute_set_id', + 'type' => 'options', + 'options' => $sets, )); - $this->addColumn('status', - array( - 'header'=> Mage::helper('catalog')->__('Status'), - 'width' => '90px', - 'index' => 'status', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(), + $this->addColumn('status', array( + 'header' => Mage::helper('catalog')->__('Status'), + 'width' => 90, + 'index' => 'status', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(), )); - $this->addColumn('visibility', - array( - 'header'=> Mage::helper('catalog')->__('Visibility'), - 'width' => '90px', - 'index' => 'visibility', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(), + $this->addColumn('visibility', array( + 'header' => Mage::helper('catalog')->__('Visibility'), + 'width' => 90, + 'index' => 'visibility', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(), )); $this->addColumn('sku', array( 'header' => Mage::helper('catalog')->__('SKU'), - 'width' => '80px', + 'width' => 80, 'index' => 'sku' )); + $this->addColumn('price', array( - 'header' => Mage::helper('catalog')->__('Price'), - 'type' => 'currency', + 'header' => Mage::helper('catalog')->__('Price'), + 'type' => 'currency', 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE), - 'index' => 'price' + 'index' => 'price' )); - /*$this->addColumn('qty', array( - 'header' => Mage::helper('catalog')->__('Default Qty'), - 'name' => 'qty', - 'align' => 'center', - 'type' => 'number', - 'validate_class' => 'validate-number', - 'index' => 'qty', - 'width' => '60px', - 'editable' => true - ));*/ - $this->addColumn('position', array( - 'header' => Mage::helper('catalog')->__('Position'), - 'name' => 'position', - 'type' => 'number', - 'validate_class' => 'validate-number', - 'index' => 'position', - 'width' => '60px', - 'editable' => !$this->isReadonly(), - 'edit_only' => !$this->_getProduct()->getId() + 'header' => Mage::helper('catalog')->__('Position'), + 'name' => 'position', + 'type' => 'number', + 'validate_class' => 'validate-number', + 'index' => 'position', + 'width' => 60, + 'editable' => !$this->isReadonly(), + 'edit_only' => !$this->_getProduct()->getId() )); return parent::_prepareColumns(); } + /** + * Rerieve grid URL + * + * @return string + */ public function getGridUrl() { - return $this->getData('grid_url') ? $this->getData('grid_url') : $this->getUrl('*/*/related', array('_current'=>true)); + return $this->getData('grid_url') ? $this->getData('grid_url') : $this->getUrl('*/*/relatedGrid', array('_current'=>true)); } + /** + * Retrieve selected related products + * + * @return array + */ protected function _getSelectedProducts() { - $products = $this->getRequest()->getPost('products', null); + $products = $this->getProductsRelated(); if (!is_array($products)) { - $products = $this->_getProduct()->getRelatedProductIds(); + $products = $this->getSelectedRelatedProducts(); } return $products; } + + /** + * Retrieve related products + * + * @return array + */ + public function getSelectedRelatedProducts() + { + return Mage::registry('current_product')->getRelatedProductIds(); + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Filter/Inventory.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Filter/Inventory.php index 732a343b8e..a948597e47 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Filter/Inventory.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Filter/Inventory.php @@ -40,7 +40,7 @@ protected function _getOptions() return array( array( 'value' => '', - 'label' => Mage::helper('catalog')->__('') + 'label' => '' ), array( 'value' => 1, diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php index 551b07c022..9d2bd64756 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php @@ -164,18 +164,34 @@ protected function _prepareColumns() public function getGridUrl() { - return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/superGroup', array('_current'=>true)); + return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/superGroupGridOnly', array('_current'=>true)); } + /** + * Retrieve selected grouped products + * + * @return array + */ protected function _getSelectedProducts() { - $products = $this->getRequest()->getPost('products', null); + $products = $this->getProductsGrouped(); if (!is_array($products)) { - $products = $this->_getProduct()->getTypeInstance(true)->getAssociatedProductIds($this->_getProduct()); + $products = $this->getSelectedGroupedProducts(); } return $products; } + /** + * Retrieve grouped products + * + * @return array + */ + public function getSelectedGroupedProducts() + { + return Mage::registry('current_product')->getTypeInstance(true) + ->getAssociatedProductIds(Mage::registry('current_product')); + } + public function getTabLabel() { return Mage::helper('catalog')->__('Associated Products'); diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag.php index f46288f744..caa5f4df25 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag.php @@ -45,11 +45,10 @@ public function __construct() protected function _prepareCollection() { - $tagId = Mage::registry('tagId'); $collection = Mage::getModel('tag/tag') ->getResourceCollection() ->addProductFilter($this->getProductId()) - ->addPopularity($tagId); + ->addPopularity(); $this->setCollection($collection); return parent::_prepareCollection(); @@ -80,7 +79,7 @@ protected function _prepareColumns() 'width' => '90px', 'index' => 'status', 'type' => 'options', - 'options' => array( + 'options' => array( Mage_Tag_Model_Tag::STATUS_DISABLED => Mage::helper('catalog')->__('Disabled'), Mage_Tag_Model_Tag::STATUS_PENDING => Mage::helper('catalog')->__('Pending'), Mage_Tag_Model_Tag::STATUS_APPROVED => Mage::helper('catalog')->__('Approved'), @@ -93,17 +92,17 @@ protected function _prepareColumns() protected function getRowUrl($row) { return $this->getUrl('*/tag/edit', array( - 'tag_id' => $row->getId(), - 'product_id' => $this->getProductId(), + 'tag_id' => $row->getId(), + 'product_id' => $this->getProductId(), )); } public function getGridUrl() { return $this->getUrl('*/catalog_product/tagGrid', array( - '_current' => true, - 'id' => $this->getProductId(), - 'product_id' => $this->getProductId(), + '_current' => true, + 'id' => $this->getProductId(), + 'product_id' => $this->getProductId(), )); } } \ No newline at end of file diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag/Customer.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag/Customer.php index 2688a679dc..648bdb37df 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag/Customer.php @@ -49,7 +49,8 @@ protected function _prepareCollection() $collection = Mage::getModel('tag/tag') ->getCustomerCollection() ->addProductFilter($this->getProductId()) - ->addGroupByTag(); + ->addGroupByTag() + ->addDescOrder(); $this->setCollection($collection); return parent::_prepareCollection(); @@ -87,10 +88,7 @@ protected function _prepareColumns() protected function getRowUrl($row) { - return $this->getUrl('*/tag/edit', array( - 'tag_id' => $row->getTagId(), - 'product_id' => $this->getProductId(), - )); + return $this->getUrl('*/customer/edit', array('id' => $row->getCustomerId())); } public function getGridUrl() diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php index ba48494b5b..c3c0920305 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php @@ -34,6 +34,10 @@ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Upsell extends Mage_Adminhtml_Block_Widget_Grid { + /** + * Set grid params + * + */ public function __construct() { parent::__construct(); @@ -55,6 +59,12 @@ protected function _getProduct() return Mage::registry('current_product'); } + /** + * Add filter + * + * @param object $column + * @return Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Upsell + */ protected function _addColumnFilterToCollection($column) { // Set custom filter for in product flag @@ -65,14 +75,12 @@ protected function _addColumnFilterToCollection($column) } if ($column->getFilter()->getValue()) { $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds)); - } - else { + } else { if($productIds) { $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds)); } } - } - else { + } else { parent::_addColumnFilterToCollection($column); } return $this; @@ -88,6 +96,11 @@ public function isReadonly() return $this->_getProduct()->getUpsellReadonly(); } + /** + * Prepare collection + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ protected function _prepareCollection() { $collection = Mage::getModel('catalog/product_link')->useUpSellLinks() @@ -107,6 +120,11 @@ protected function _prepareCollection() return parent::_prepareCollection(); } + /** + * Add columns to grid + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ protected function _prepareColumns() { if (!$this->_getProduct()->getUpsellReadonly()) { @@ -123,7 +141,7 @@ protected function _prepareColumns() $this->addColumn('entity_id', array( 'header' => Mage::helper('catalog')->__('ID'), 'sortable' => true, - 'width' => '60px', + 'width' => 60, 'index' => 'entity_id' )); $this->addColumn('name', array( @@ -131,13 +149,12 @@ protected function _prepareColumns() 'index' => 'name' )); - $this->addColumn('type', - array( - 'header'=> Mage::helper('catalog')->__('Type'), - 'width' => '100px', - 'index' => 'type_id', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(), + $this->addColumn('type', array( + 'header' => Mage::helper('catalog')->__('Type'), + 'width' => 100, + 'index' => 'type_id', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(), )); $sets = Mage::getResourceModel('eav/entity_attribute_set_collection') @@ -145,71 +162,89 @@ protected function _prepareColumns() ->load() ->toOptionHash(); - $this->addColumn('set_name', - array( - 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'), - 'width' => '130px', - 'index' => 'attribute_set_id', - 'type' => 'options', - 'options' => $sets, + $this->addColumn('set_name', array( + 'header' => Mage::helper('catalog')->__('Attrib. Set Name'), + 'width' => 130, + 'index' => 'attribute_set_id', + 'type' => 'options', + 'options' => $sets, )); - $this->addColumn('status', - array( - 'header'=> Mage::helper('catalog')->__('Status'), - 'width' => '90px', - 'index' => 'status', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(), + $this->addColumn('status', array( + 'header' => Mage::helper('catalog')->__('Status'), + 'width' => 90, + 'index' => 'status', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(), )); - $this->addColumn('visibility', - array( - 'header'=> Mage::helper('catalog')->__('Visibility'), - 'width' => '90px', - 'index' => 'visibility', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(), + $this->addColumn('visibility', array( + 'header' => Mage::helper('catalog')->__('Visibility'), + 'width' => 90, + 'index' => 'visibility', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(), )); $this->addColumn('sku', array( 'header' => Mage::helper('catalog')->__('SKU'), - 'width' => '80px', + 'width' => 80, 'index' => 'sku' )); + $this->addColumn('price', array( - 'header' => Mage::helper('catalog')->__('Price'), - 'type' => 'currency', + 'header' => Mage::helper('catalog')->__('Price'), + 'type' => 'currency', 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE), - 'index' => 'price' + 'index' => 'price' )); $this->addColumn('position', array( - 'header' => Mage::helper('catalog')->__('Position'), - 'name' => 'position', - 'type' => 'number', - 'width' => '60px', - 'validate_class' => 'validate-number', - 'index' => 'position', - 'editable' => !$this->_getProduct()->getUpsellReadonly(), - 'edit_only' => !$this->_getProduct()->getId() + 'header' => Mage::helper('catalog')->__('Position'), + 'name' => 'position', + 'type' => 'number', + 'width' => 60, + 'validate_class' => 'validate-number', + 'index' => 'position', + 'editable' => !$this->_getProduct()->getUpsellReadonly(), + 'edit_only' => !$this->_getProduct()->getId() )); return parent::_prepareColumns(); } + /** + * Rerieve grid URL + * + * @return string + */ public function getGridUrl() { - return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/upsell', array('_current'=>true)); + return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/upsellGrid', array('_current'=>true)); } + /** + * Retrieve selected upsell products + * + * @return array + */ protected function _getSelectedProducts() { - $products = $this->getRequest()->getPost('products', null); + $products = $this->getProductsUpsell(); if (!is_array($products)) { - $products = $this->_getProduct()->getUpSellProductIds(); + $products = $this->getSelectedUpsellProducts(); } return $products; } + /** + * Retrieve upsell products + * + * @return array + */ + public function getSelectedUpsellProducts() + { + return Mage::registry('current_product')->getUpSellProductIds(); + } + } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser.php new file mode 100644 index 0000000000..92d0ecc79a --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser.php @@ -0,0 +1,288 @@ + + */ +class Mage_Adminhtml_Block_Catalog_Product_Widget_Chooser extends Mage_Adminhtml_Block_Widget_Grid +{ + protected $_selectedProducts = array(); + + /** + * Block construction, prepare grid params + * + * @param array $arguments Object data + */ + public function __construct($arguments=array()) + { + parent::__construct($arguments); + $this->setDefaultSort('name'); + $this->setUseAjax(true); + } + + /** + * Prepare chooser element HTML + * + * @param Varien_Data_Form_Element_Abstract $element Form Element + * @return Varien_Data_Form_Element_Abstract + */ + public function prepareElementHtml(Varien_Data_Form_Element_Abstract $element) + { + $uniqId = $element->getId() . md5(microtime()); + $sourceUrl = $this->getUrl('*/catalog_product_widget/chooser', array( + 'uniq_id' => $uniqId, + 'use_massaction' => false, + )); + + $chooser = $this->getLayout()->createBlock('adminhtml/cms_widget_chooser') + ->setElement($element) + ->setTranslationHelper($this->getTranslationHelper()) + ->setConfig($this->getConfig()) + ->setFieldsetId($this->getFieldsetId()) + ->setSourceUrl($sourceUrl) + ->setUniqId($uniqId); + + + if ($element->getValue()) { + $value = explode('/', $element->getValue()); + $productId = isset($value[1]) ? $value[1] : false; + $categoryId = isset($value[2]) ? $value[2] : false; + $label = ''; + if ($categoryId) { + $label = Mage::getSingleton('catalog/category')->load($categoryId)->getName() . ' / ' . $label; + } + if ($productId) { + $label .= Mage::getSingleton('catalog/product')->load($productId)->getName(); + } + $chooser->setLabel($label); + } + + $element->setData('after_element_html', $chooser->toHtml()); + return $element; + } + + /** + * Checkbox Check JS Callback + * + * @return string + */ + public function getCheckboxCheckCallback() + { + if ($this->getUseMassaction()) { + return "function (grid, event) { + $(grid.containerId).fire('product:changed', {}); + }"; + } + } + + /** + * Grid Row JS Callback + * + * @return string + */ + public function getRowClickCallback() + { + if (!$this->getUseMassaction()) { + $chooserJsObject = $this->getId(); + return ' + function (grid, event) { + var trElement = Event.findElement(event, "tr"); + var productId = trElement.down("td").innerHTML; + var productName = trElement.down("td").next().next().innerHTML; + var optionLabel = productName; + var optionValue = "product/" + productId; + if (grid.categoryId) { + optionValue += "/" + grid.categoryId; + } + if (grid.categoryName) { + optionLabel = grid.categoryName + " / " + optionLabel; + } + '.$chooserJsObject.'.setElementValue(optionValue); + '.$chooserJsObject.'.setElementLabel(optionLabel); + '.$chooserJsObject.'.close(); + } + '; + } + } + + /** + * Category Tree node onClick listener js function + * + * @return string + */ + public function getCategoryClickListenerJs() + { + $js = ' + function (node, e) { + {jsObject}.addVarToUrl("category_id", node.attributes.id); + {jsObject}.reload({jsObject}.url); + {jsObject}.categoryId = node.attributes.id; + {jsObject}.categoryName = node.text; + } + '; + $js = str_replace('{jsObject}', $this->getJsObjectName(), $js); + return $js; + } + + /** + * Filter checked/unchecked rows in grid + * + * @param Mage_Adminhtml_Block_Widget_Grid_Column $column + * @return Mage_Adminhtml_Block_Catalog_Product_Widget_Chooser + */ + protected function _addColumnFilterToCollection($column) + { + if ($column->getId() == 'in_products') { + $selected = $this->getSelectedProducts(); + if ($column->getFilter()->getValue()) { + $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$selected)); + } else { + $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$selected)); + } + } else { + parent::_addColumnFilterToCollection($column); + } + return $this; + } + + /** + * Prepare products collection, defined collection filters (category, product type) + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareCollection() + { + /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ + $collection = Mage::getResourceModel('catalog/product_collection') + ->setStoreId(0) + ->addAttributeToSelect('name'); + + if ($categoryId = $this->getCategoryId()) { + $category = Mage::getModel('catalog/category')->load($categoryId); + // $collection->addCategoryFilter($category); + $productIds = $category->getProductsPosition(); + $productIds = array_keys($productIds); + if (empty($productIds)) { + $productIds = 0; + } + $collection->addFieldToFilter('entity_id', array('in' => $productIds)); + } + + if ($productTypeId = $this->getProductTypeId()) { + $collection->addAttributeToFilter('type_id', $productTypeId); + } + + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + /** + * Prepare columns for products grid + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareColumns() + { + if ($this->getUseMassaction()) { + $this->addColumn('in_products', array( + 'header_css_class' => 'a-center', + 'type' => 'checkbox', + 'name' => 'in_products', + 'inline_css' => 'checkbox entities', + 'field_name' => 'in_products', + 'values' => $this->getSelectedProducts(), + 'align' => 'center', + 'index' => 'entity_id', + 'use_index' => true, + )); + } + + $this->addColumn('entity_id', array( + 'header' => Mage::helper('catalog')->__('ID'), + 'sortable' => true, + 'width' => '60px', + 'index' => 'entity_id' + )); + $this->addColumn('chooser_sku', array( + 'header' => Mage::helper('catalog')->__('SKU'), + 'name' => 'chooser_sku', + 'width' => '80px', + 'index' => 'sku' + )); + $this->addColumn('chooser_name', array( + 'header' => Mage::helper('catalog')->__('Product Name'), + 'name' => 'chooser_name', + 'index' => 'name' + )); + + return parent::_prepareColumns(); + } + + /** + * Adds additional parameter to URL for loading only products grid + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl('*/catalog_product_widget/chooser', array( + 'products_grid' => true, + '_current' => true, + 'uniq_id' => $this->getId(), + 'use_massaction' => $this->getUseMassaction(), + 'product_type_id' => $this->getProductTypeId() + )); + } + + /** + * Setter + * + * @param array $selectedProducts + * @return Mage_Adminhtml_Block_Catalog_Product_Widget_Chooser + */ + public function setSelectedProducts($selectedProducts) + { + $this->_selectedProducts = $selectedProducts; + return $this; + } + + /** + * Getter + * + * @return array + */ + public function getSelectedProducts() + { + if ($selectedProducts = $this->getRequest()->getParam('selected_products', null)) { + $this->setSelectedProducts($selectedProducts); + } + return $this->_selectedProducts; + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php index a7271a0a5f..da9e6eaf91 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php @@ -122,8 +122,8 @@ protected function _prepareForm() . Mage::helper('catalog')->__('(Will make search for the query above return results for this search.)') . '

'; - $fieldset->addField('synonim_for', 'text', array( - 'name' => 'synonim_for', + $fieldset->addField('synonym_for', 'text', array( + 'name' => 'synonym_for', 'label' => Mage::helper('catalog')->__('Synonym For'), 'title' => Mage::helper('catalog')->__('Synonym For'), 'after_element_html' => $afterElementHtml, @@ -137,6 +137,7 @@ protected function _prepareForm() 'name' => 'redirect', 'label' => Mage::helper('catalog')->__('Redirect URL'), 'title' => Mage::helper('catalog')->__('Redirect URL'), + 'class' => 'validate-url', 'after_element_html' => $afterElementHtml, )); diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Grid.php index c03b8a9965..67d8ed9526 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Grid.php @@ -100,10 +100,10 @@ protected function _prepareColumns() 'type' => 'number' )); - $this->addColumn('synonim_for', array( + $this->addColumn('synonym_for', array( 'header' => Mage::helper('catalog')->__('Synonym for'), 'align' => 'left', - 'index' => 'synonim_for', + 'index' => 'synonym_for', 'width' => '160px' )); diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php index 3c162c8fc2..86de942ba2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php @@ -45,6 +45,17 @@ public function __construct() $this->setTitle(Mage::helper('cms')->__('Block Information')); } + /** + * Load Wysiwyg on demand and Prepare layout + */ + protected function _prepareLayout() + { + parent::_prepareLayout(); + if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { + $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + } + } + protected function _prepareForm() { $model = Mage::registry('cms_block'); @@ -112,8 +123,8 @@ protected function _prepareForm() 'label' => Mage::helper('cms')->__('Content'), 'title' => Mage::helper('cms')->__('Content'), 'style' => 'height:36em', - 'wysiwyg' => false, 'required' => true, + 'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig() )); $form->setValues($model->getData()); diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Widget/Chooser.php new file mode 100644 index 0000000000..79ed5c9148 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Widget/Chooser.php @@ -0,0 +1,158 @@ + + */ +class Mage_Adminhtml_Block_Cms_Block_Widget_Chooser extends Mage_Adminhtml_Block_Widget_Grid +{ + /** + * Block construction, prepare grid params + * + * @param array $arguments Object data + */ + public function __construct($arguments=array()) + { + parent::__construct($arguments); + $this->setDefaultSort('block_identifier'); + $this->setDefaultDir('ASC'); + $this->setUseAjax(true); + } + + /** + * Prepare chooser element HTML + * + * @param Varien_Data_Form_Element_Abstract $element Form Element + * @return Varien_Data_Form_Element_Abstract + */ + public function prepareElementHtml(Varien_Data_Form_Element_Abstract $element) + { + $uniqId = $element->getId() . md5(microtime()); + $sourceUrl = $this->getUrl('*/cms_block_widget/chooser', array('uniq_id' => $uniqId)); + + $chooser = $this->getLayout()->createBlock('adminhtml/cms_widget_chooser') + ->setElement($element) + ->setTranslationHelper($this->getTranslationHelper()) + ->setConfig($this->getConfig()) + ->setFieldsetId($this->getFieldsetId()) + ->setSourceUrl($sourceUrl) + ->setUniqId($uniqId); + + + if ($element->getValue()) { + $block = Mage::getModel('cms/block')->load($element->getValue()); + if ($block->getId()) { + $chooser->setLabel($block->getTitle()); + } + } + + $element->setData('after_element_html', $chooser->toHtml()); + return $element; + } + + /** + * Grid Row JS Callback + * + * @return string + */ + public function getRowClickCallback() + { + $chooserJsObject = $this->getId(); + $js = ' + function (grid, event) { + var trElement = Event.findElement(event, "tr"); + var blockId = trElement.down("td").innerHTML; + var blockTitle = trElement.down("td").next().innerHTML; + '.$chooserJsObject.'.setElementValue(blockId); + '.$chooserJsObject.'.setElementLabel(blockTitle); + '.$chooserJsObject.'.close(); + } + '; + return $js; + } + + /** + * Prepare Cms static blocks collection + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareCollection() + { + $collection = Mage::getModel('cms/block')->getCollection(); + /* @var $collection Mage_Cms_Model_Mysql4_Block_Collection */ + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + /** + * Prepare columns for Cms blocks grid + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareColumns() + { + $this->addColumn('chooser_id', array( + 'header' => Mage::helper('cms')->__('ID'), + 'align' => 'right', + 'index' => 'block_id', + 'width' => 50 + )); + + $this->addColumn('chooser_title', array( + 'header' => Mage::helper('cms')->__('Title'), + 'align' => 'left', + 'index' => 'title', + )); + + $this->addColumn('chooser_identifier', array( + 'header' => Mage::helper('cms')->__('Identifier'), + 'align' => 'left', + 'index' => 'identifier' + )); + + + $this->addColumn('chooser_is_active', array( + 'header' => Mage::helper('cms')->__('Status'), + 'index' => 'is_active', + 'type' => 'options', + 'options' => array( + 0 => Mage::helper('cms')->__('Disabled'), + 1 => Mage::helper('cms')->__('Enabled') + ), + )); + + return parent::_prepareColumns(); + } + + public function getGridUrl() + { + return $this->getUrl('*/cms_block_widget/chooser', array('_current' => true)); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page.php index 81af057660..b0a439dd18 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page.php @@ -42,8 +42,26 @@ public function __construct() { $this->_controller = 'cms_page'; $this->_headerText = Mage::helper('cms')->__('Manage Pages'); - $this->_addButtonLabel = Mage::helper('cms')->__('Add New Page'); + parent::__construct(); + + if ($this->_isAllowedAction('save')) { + $this->_updateButton('add', 'label', Mage::helper('cms')->__('Add New Page')); + } else { + $this->_removeButton('add'); + } + + } + + /** + * Check permission for passed action + * + * @param string $action + * @return bool + */ + protected function _isAllowedAction($action) + { + return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php index 7f96bebac9..55f0ec0bf4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php @@ -41,14 +41,22 @@ public function __construct() parent::__construct(); - $this->_updateButton('save', 'label', Mage::helper('cms')->__('Save Page')); - $this->_updateButton('delete', 'label', Mage::helper('cms')->__('Delete Page')); + if ($this->_isAllowedAction('save')) { + $this->_updateButton('save', 'label', Mage::helper('cms')->__('Save Page')); + $this->_addButton('saveandcontinue', array( + 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save', + ), -100); + } else { + $this->_removeButton('save'); + } - $this->_addButton('saveandcontinue', array( - 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'), - 'onclick' => 'saveAndContinueEdit()', - 'class' => 'save', - ), -100); + if ($this->_isAllowedAction('delete')) { + $this->_updateButton('delete', 'label', Mage::helper('cms')->__('Delete Page')); + } else { + $this->_removeButton('delete'); + } $this->_formScripts[] = " function toggleEditor() { @@ -65,6 +73,11 @@ function saveAndContinueEdit(){ "; } + /** + * Retrieve text for header element depending on loaded page + * + * @return string + */ public function getHeaderText() { if (Mage::registry('cms_page')->getId()) { @@ -75,4 +88,14 @@ public function getHeaderText() } } -} \ No newline at end of file + /** + * Check permission for passed action + * + * @param string $action + * @return bool + */ + protected function _isAllowedAction($action) + { + return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php new file mode 100644 index 0000000000..65e14001b3 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php @@ -0,0 +1,146 @@ + + */ + +class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Content + extends Mage_Adminhtml_Block_Widget_Form + implements Mage_Adminhtml_Block_Widget_Tab_Interface +{ + /** + * Load Wysiwyg on demand and Prepare layout + */ + protected function _prepareLayout() + { + parent::_prepareLayout(); + if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { + $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + } + } + + protected function _prepareForm() + { + /** @var $model Mage_Cms_Model_Page */ + $model = Mage::registry('cms_page'); + + /* + * Checking if user have permissions to save information + */ + if ($this->_isAllowedAction('save')) { + $isElementDisabled = false; + } else { + $isElementDisabled = true; + } + + + $form = new Varien_Data_Form(); + + $form->setHtmlIdPrefix('page_'); + + $fieldset = $form->addFieldset('content_fieldset', array('legend'=>Mage::helper('cms')->__('Content'),'class'=>'fieldset-wide')); + + $wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig( + array('tab_id' => $this->getTabId()) + ); + + $contentField = $fieldset->addField('content', 'editor', array( + 'name' => 'content', + 'style' => 'width:99.15% !important; height:36em;', + 'required' => true, + 'disabled' => $isElementDisabled, + 'config' => $wysiwygConfig + )); + + // Setting custom renderer for content field to remove label column + $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element') + ->setTemplate('cms/page/edit/form/renderer/content.phtml'); + $contentField->setRenderer($renderer); + + $form->setValues($model->getData()); + $this->setForm($form); + + Mage::dispatchEvent('adminhtml_cms_page_edit_tab_content_prepare_form', array('form' => $form)); + + return parent::_prepareForm(); + } + + /** + * Prepare label for tab + * + * @return string + */ + public function getTabLabel() + { + return Mage::helper('cms')->__('Content'); + } + + /** + * Prepare title for tab + * + * @return string + */ + public function getTabTitle() + { + return Mage::helper('cms')->__('Content'); + } + + /** + * Returns status flag about this tab can be shown or not + * + * @return true + */ + public function canShowTab() + { + return true; + } + + /** + * Returns status flag about this tab hidden or not + * + * @return true + */ + public function isHidden() + { + return false; + } + + /** + * Check permission for passed action + * + * @param string $action + * @return bool + */ + protected function _isAllowedAction($action) + { + return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php index 63c7e1c207..ae4efb32ec 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php @@ -23,7 +23,9 @@ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Design extends Mage_Adminhtml_Block_Widget_Form +class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Design + extends Mage_Adminhtml_Block_Widget_Form + implements Mage_Adminhtml_Block_Widget_Tab_Interface { public function __construct() { @@ -31,53 +33,94 @@ public function __construct() $this->setShowGlobalIcon(true); } - public function _prepareForm() + protected function _prepareForm() { + /* + * Checking if user have permissions to save information + */ + if ($this->_isAllowedAction('save')) { + $isElementDisabled = false; + } else { + $isElementDisabled = true; + } + $form = new Varien_Data_Form(); $form->setHtmlIdPrefix('page_'); $model = Mage::registry('cms_page'); - $fieldset = $form->addFieldset('design_fieldset', array( - 'legend' => Mage::helper('cms')->__('Custom Design'), + $layoutFieldset = $form->addFieldset('layout_fieldset', array( + 'legend' => Mage::helper('cms')->__('Page Layout'), 'class' => 'fieldset-wide', + 'disabled' => $isElementDisabled )); - $fieldset->addField('custom_theme', 'select', array( - 'name' => 'custom_theme', - 'label' => Mage::helper('cms')->__('Custom Theme'), - 'values' => Mage::getModel('core/design_source_design')->getAllOptions(), + $layoutFieldset->addField('root_template', 'select', array( + 'name' => 'root_template', + 'label' => Mage::helper('cms')->__('Layout'), + 'required' => true, + 'values' => Mage::getSingleton('page/source_layout')->toOptionArray(), + 'disabled' => $isElementDisabled + )); + + $layoutFieldset->addField('layout_update_xml', 'textarea', array( + 'name' => 'layout_update_xml', + 'label' => Mage::helper('cms')->__('Layout Update XML'), + 'style' => 'height:24em;', + 'disabled' => $isElementDisabled + )); + + $designFieldset = $form->addFieldset('design_fieldset', array( + 'legend' => Mage::helper('cms')->__('Custom Design'), + 'class' => 'fieldset-wide', + 'disabled' => $isElementDisabled )); - $fieldset->addField('custom_theme_from', 'date', array( + $dateFormatIso = Mage::app()->getLocale()->getDateFormat( + Mage_Core_Model_Locale::FORMAT_TYPE_SHORT + ); + + $designFieldset->addField('custom_theme_from', 'date', array( 'name' => 'custom_theme_from', - 'label' => Mage::helper('cms')->__('Custom Theme From'), + 'label' => Mage::helper('cms')->__('Custom Design From'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT) + 'format' => $dateFormatIso, + 'disabled' => $isElementDisabled )); - $fieldset->addField('custom_theme_to', 'date', array( + $designFieldset->addField('custom_theme_to', 'date', array( 'name' => 'custom_theme_to', - 'label' => Mage::helper('cms')->__('Custom Theme To'), + 'label' => Mage::helper('cms')->__('Custom Design To'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT) + 'format' => $dateFormatIso, + 'disabled' => $isElementDisabled + )); + + $designFieldset->addField('custom_theme', 'select', array( + 'name' => 'custom_theme', + 'label' => Mage::helper('cms')->__('Custom Theme'), + 'values' => Mage::getModel('core/design_source_design')->getAllOptions(), + 'disabled' => $isElementDisabled )); - $fieldset->addField('root_template', 'select', array( - 'name' => 'root_template', - 'label' => Mage::helper('cms')->__('Layout'), - 'required' => true, - 'values' => Mage::getSingleton('page/source_layout')->toOptionArray(), + $designFieldset->addField('custom_root_template', 'select', array( + 'name' => 'custom_root_template', + 'label' => Mage::helper('cms')->__('Custom Layout'), + 'values' => Mage::getSingleton('page/source_layout')->toOptionArray(true), + 'disabled' => $isElementDisabled )); - $fieldset->addField('layout_update_xml', 'editor', array( - 'name' => 'layout_update_xml', - 'label' => Mage::helper('cms')->__('Layout Update XML'), - 'style' => 'height:24em;' + $designFieldset->addField('custom_layout_update_xml', 'textarea', array( + 'name' => 'custom_layout_update_xml', + 'label' => Mage::helper('cms')->__('Custom Layout Update XML'), + 'style' => 'height:24em;', + 'disabled' => $isElementDisabled )); + Mage::dispatchEvent('adminhtml_cms_page_edit_tab_design_prepare_form', array('form' => $form)); + $form->setValues($model->getData()); $this->setForm($form); @@ -85,4 +128,54 @@ public function _prepareForm() return parent::_prepareForm(); } + /** + * Prepare label for tab + * + * @return string + */ + public function getTabLabel() + { + return Mage::helper('cms')->__('Design'); + } + + /** + * Prepare title for tab + * + * @return string + */ + public function getTabTitle() + { + return Mage::helper('cms')->__('Design'); + } + + /** + * Returns status flag about this tab can be showen or not + * + * @return true + */ + public function canShowTab() + { + return true; + } + + /** + * Returns status flag about this tab hidden or not + * + * @return true + */ + public function isHidden() + { + return false; + } + + /** + * Check permission for passed action + * + * @param string $action + * @return bool + */ + protected function _isAllowedAction($action) + { + return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php index aa584e3dff..8e76726d8a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php @@ -32,39 +32,53 @@ * @author Magento Core Team */ -class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Main extends Mage_Adminhtml_Block_Widget_Form +class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Main + extends Mage_Adminhtml_Block_Widget_Form + implements Mage_Adminhtml_Block_Widget_Tab_Interface { - protected function _prepareForm() - {/** @var Cms_Model_Page */ + { + /* @var $model Mage_Cms_Model_Page */ $model = Mage::registry('cms_page'); + /* + * Checking if user have permissions to save information + */ + if ($this->_isAllowedAction('save')) { + $isElementDisabled = false; + } else { + $isElementDisabled = true; + } + + $form = new Varien_Data_Form(); $form->setHtmlIdPrefix('page_'); - $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('cms')->__('General Information'),'class'=>'fieldset-wide')); + $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('cms')->__('Page Information'),'class'=>'fieldset-wide')); if ($model->getPageId()) { - $fieldset->addField('page_id', 'hidden', array( + $fieldset->addField('page_id', 'hidden', array( 'name' => 'page_id', )); } - $fieldset->addField('title', 'text', array( + $fieldset->addField('title', 'text', array( 'name' => 'title', 'label' => Mage::helper('cms')->__('Page Title'), 'title' => Mage::helper('cms')->__('Page Title'), 'required' => true, + 'disabled' => $isElementDisabled )); - $fieldset->addField('identifier', 'text', array( + $fieldset->addField('identifier', 'text', array( 'name' => 'identifier', - 'label' => Mage::helper('cms')->__('SEF URL Identifier'), - 'title' => Mage::helper('cms')->__('SEF URL Identifier'), + 'label' => Mage::helper('cms')->__('URL Key'), + 'title' => Mage::helper('cms')->__('URL Key'), 'required' => true, 'class' => 'validate-identifier', 'after_element_html' => '

' . Mage::helper('cms')->__('(eg: domain.com/identifier)') . '

', + 'disabled' => $isElementDisabled )); /** @@ -77,6 +91,7 @@ protected function _prepareForm() 'title' => Mage::helper('cms')->__('Store View'), 'required' => true, 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true), + 'disabled' => $isElementDisabled )); } else { @@ -87,30 +102,71 @@ protected function _prepareForm() $model->setStoreId(Mage::app()->getStore(true)->getId()); } - $fieldset->addField('is_active', 'select', array( + $fieldset->addField('is_active', 'select', array( 'label' => Mage::helper('cms')->__('Status'), 'title' => Mage::helper('cms')->__('Page Status'), 'name' => 'is_active', 'required' => true, - 'options' => array( - '1' => Mage::helper('cms')->__('Enabled'), - '0' => Mage::helper('cms')->__('Disabled'), - ), - )); - - $fieldset->addField('content', 'editor', array( - 'name' => 'content', - 'label' => Mage::helper('cms')->__('Content'), - 'title' => Mage::helper('cms')->__('Content'), - 'style' => 'height:36em;', - 'wysiwyg' => false, - 'required' => true, + 'options' => $model->getAvailableStatuses(), + 'disabled' => $isElementDisabled )); + Mage::dispatchEvent('adminhtml_cms_page_edit_tab_main_prepare_form', array('form' => $form)); $form->setValues($model->getData()); $this->setForm($form); return parent::_prepareForm(); } + + /** + * Prepare label for tab + * + * @return string + */ + public function getTabLabel() + { + return Mage::helper('cms')->__('Page Information'); + } + + /** + * Prepare title for tab + * + * @return string + */ + public function getTabTitle() + { + return Mage::helper('cms')->__('Page Information'); + } + + /** + * Returns status flag about this tab can be shown or not + * + * @return true + */ + public function canShowTab() + { + return true; + } + + /** + * Returns status flag about this tab hidden or not + * + * @return true + */ + public function isHidden() + { + return false; + } + + /** + * Check permission for passed action + * + * @param string $action + * @return bool + */ + protected function _isAllowedAction($action) + { + return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php index d4eab819a2..a0f2121633 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php @@ -31,7 +31,9 @@ * @package Mage_Adminhtml * @author Magento Core Team */ -class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Meta extends Mage_Adminhtml_Block_Widget_Form +class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Meta + extends Mage_Adminhtml_Block_Widget_Form + implements Mage_Adminhtml_Block_Widget_Tab_Interface { public function __construct() { @@ -40,6 +42,15 @@ public function __construct() protected function _prepareForm() { + /* + * Checking if user have permissions to save information + */ + if ($this->_isAllowedAction('save')) { + $isElementDisabled = false; + } else { + $isElementDisabled = true; + } + $form = new Varien_Data_Form(); $form->setHtmlIdPrefix('page_'); @@ -48,18 +59,22 @@ protected function _prepareForm() $fieldset = $form->addFieldset('meta_fieldset', array('legend' => Mage::helper('cms')->__('Meta Data'), 'class' => 'fieldset-wide')); - $fieldset->addField('meta_keywords', 'editor', array( + $fieldset->addField('meta_keywords', 'textarea', array( 'name' => 'meta_keywords', 'label' => Mage::helper('cms')->__('Keywords'), 'title' => Mage::helper('cms')->__('Meta Keywords'), + 'disabled' => $isElementDisabled )); - $fieldset->addField('meta_description', 'editor', array( + $fieldset->addField('meta_description', 'textarea', array( 'name' => 'meta_description', 'label' => Mage::helper('cms')->__('Description'), 'title' => Mage::helper('cms')->__('Meta Description'), + 'disabled' => $isElementDisabled )); + Mage::dispatchEvent('adminhtml_cms_page_edit_tab_meta_prepare_form', array('form' => $form)); + $form->setValues($model->getData()); $this->setForm($form); @@ -67,4 +82,54 @@ protected function _prepareForm() return parent::_prepareForm(); } + /** + * Prepare label for tab + * + * @return string + */ + public function getTabLabel() + { + return Mage::helper('cms')->__('Meta Data'); + } + + /** + * Prepare title for tab + * + * @return string + */ + public function getTabTitle() + { + return Mage::helper('cms')->__('Meta Data'); + } + + /** + * Returns status flag about this tab can be showen or not + * + * @return true + */ + public function canShowTab() + { + return true; + } + + /** + * Returns status flag about this tab hidden or not + * + * @return true + */ + public function isHidden() + { + return false; + } + + /** + * Check permission for passed action + * + * @param string $action + * @return bool + */ + protected function _isAllowedAction($action) + { + return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tabs.php index bbb99b93b6..c2f85ff3e5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tabs.php @@ -41,36 +41,4 @@ public function __construct() $this->setDestElementId('edit_form'); $this->setTitle(Mage::helper('cms')->__('Page Information')); } - - protected function _beforeToHtml() - { - $this->addTab('main_section', array( - 'label' => Mage::helper('cms')->__('General Information'), - 'title' => Mage::helper('cms')->__('General Information'), - 'content' => $this->getLayout()->createBlock('adminhtml/cms_page_edit_tab_main')->toHtml(), - 'active' => true - )); - - $this->addTab('design_section', array( - 'label' => Mage::helper('cms')->__('Custom Design'), - 'title' => Mage::helper('cms')->__('Custom Design'), - 'content' => $this->getLayout()->createBlock('adminhtml/cms_page_edit_tab_design')->toHtml(), - )); - - $this->addTab('meta_section', array( - 'label' => Mage::helper('cms')->__('Meta Data'), - 'title' => Mage::helper('cms')->__('Meta Data'), - 'content' => $this->getLayout()->createBlock('adminhtml/cms_page_edit_tab_meta')->toHtml(), - )); - if (Mage::app()->getConfig()->getModuleConfig('Mage_GoogleOptimizer')->is('active', true) - && Mage::helper('googleoptimizer')->isOptimizerActiveForCms()) { - $this->addTab('googleoptimizer_section', array( - 'label' => Mage::helper('googleoptimizer')->__('Page View Optimization'), - 'title' => Mage::helper('googleoptimizer')->__('Page View Optimization'), - 'content' => $this->getLayout()->createBlock('googleoptimizer/adminhtml_cms_page_edit_tab_googleoptimizer')->toHtml(), - )); - } - return parent::_beforeToHtml(); - } - } diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid.php index 6ff54640df..768e066c42 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid.php @@ -97,10 +97,7 @@ protected function _prepareColumns() 'header' => Mage::helper('cms')->__('Status'), 'index' => 'is_active', 'type' => 'options', - 'options' => array( - 0 => Mage::helper('cms')->__('Disabled'), - 1 => Mage::helper('cms')->__('Enabled') - ), + 'options' => Mage::getSingleton('cms/page')->getAvailableStatuses() )); $this->addColumn('creation_time', array( diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Widget/Chooser.php new file mode 100644 index 0000000000..f9d458a42a --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Widget/Chooser.php @@ -0,0 +1,157 @@ + + */ +class Mage_Adminhtml_Block_Cms_Page_Widget_Chooser extends Mage_Adminhtml_Block_Widget_Grid +{ + /** + * Block construction, prepare grid params + * + * @param array $arguments Object data + */ + public function __construct($arguments=array()) + { + parent::__construct($arguments); + //$this->setDefaultSort('name'); + $this->setUseAjax(true); + } + + /** + * Prepare chooser element HTML + * + * @param Varien_Data_Form_Element_Abstract $element Form Element + * @return Varien_Data_Form_Element_Abstract + */ + public function prepareElementHtml(Varien_Data_Form_Element_Abstract $element) + { + $uniqId = $element->getId() . md5(microtime()); + $sourceUrl = $this->getUrl('*/cms_page_widget/chooser', array('uniq_id' => $uniqId)); + + $chooser = $this->getLayout()->createBlock('adminhtml/cms_widget_chooser') + ->setElement($element) + ->setTranslationHelper($this->getTranslationHelper()) + ->setConfig($this->getConfig()) + ->setFieldsetId($this->getFieldsetId()) + ->setSourceUrl($sourceUrl) + ->setUniqId($uniqId); + + + if ($element->getValue()) { + $page = Mage::getModel('cms/page')->load($element->getValue()); + if ($page->getId()) { + $chooser->setLabel($page->getTitle()); + } + } + + $element->setData('after_element_html', $chooser->toHtml()); + return $element; + } + + /** + * Grid Row JS Callback + * + * @return string + */ + public function getRowClickCallback() + { + $chooserJsObject = $this->getId(); + $js = ' + function (grid, event) { + var trElement = Event.findElement(event, "tr"); + var pageTitle = trElement.down("td").innerHTML; + var pageId = trElement.down("td").next().innerHTML; + '.$chooserJsObject.'.setElementValue(pageId); + '.$chooserJsObject.'.setElementLabel(pageTitle); + '.$chooserJsObject.'.close(); + } + '; + return $js; + } + + /** + * Prepare pages collection + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareCollection() + { + $collection = Mage::getModel('cms/page')->getCollection(); + /* @var $collection Mage_Cms_Model_Mysql4_Page_Collection */ + $collection->setFirstStoreFlag(true); + $this->setCollection($collection); + + return parent::_prepareCollection(); + } + + /** + * Prepare columns for pages grid + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareColumns() + { + $this->addColumn('chooser_title', array( + 'header' => Mage::helper('cms')->__('Title'), + 'align' => 'left', + 'index' => 'title', + )); + + $this->addColumn('chooser_identifier', array( + 'header' => Mage::helper('cms')->__('Identifier'), + 'align' => 'left', + 'index' => 'identifier' + )); + + $this->addColumn('chooser_root_template', array( + 'header' => Mage::helper('cms')->__('Layout'), + 'index' => 'root_template', + 'type' => 'options', + 'options' => Mage::getSingleton('page/source_layout')->getOptions(), + 'width' => '100', + )); + + $this->addColumn('chooser_is_active', array( + 'header' => Mage::helper('cms')->__('Status'), + 'index' => 'is_active', + 'type' => 'options', + 'options' => Mage::getModel('cms/page')->getAvailableStatuses(), + 'width' => '100', + )); + + return parent::_prepareColumns(); + } + + public function getGridUrl() + { + return $this->getUrl('*/cms_page_widget/chooser', array('_current' => true)); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Widget.php b/app/code/core/Mage/Adminhtml/Block/Cms/Widget.php new file mode 100644 index 0000000000..84ff69d22a --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Widget.php @@ -0,0 +1,57 @@ + + */ +class Mage_Adminhtml_Block_Cms_Widget extends Mage_Adminhtml_Block_Widget_Form_Container +{ + public function __construct() + { + parent::__construct(); + + $this->_controller = 'cms'; + $this->_mode = 'widget'; + $this->_headerText = 'CMS Widget Insertion'; + + $this->removeButton('reset'); + $this->removeButton('back'); + $this->_updateButton('save', 'label', $this->helper('cms')->__('Insert Widget')); + $this->_updateButton('save', 'class', 'add-widget'); + $this->_updateButton('save', 'id', 'insert_button'); + $this->_updateButton('save', 'onclick', 'wWidget.insertWidget()'); + + $this->_formInitScripts[] = ' + Event.observe(window, "load", function(){ + wWidget = new WysiwygWidget.Widget("edit_form", "select_widget_type", "widget_options", "'.$this->getUrl('*/*/loadOptions').'"); + }); + '; + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Cms/Widget/Chooser.php new file mode 100644 index 0000000000..970eb33d8b --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Widget/Chooser.php @@ -0,0 +1,194 @@ + + */ + +class Mage_Adminhtml_Block_Cms_Widget_Chooser extends Mage_Adminhtml_Block_Template +{ + /** + * Chooser source URL getter + * + * @return string + */ + public function getSourceUrl() + { + return $this->getData('source_url'); + } + + /** + * Chooser form element getter + * + * @return Varien_Data_Form_Element_Abstract + */ + public function getElement() + { + return $this->getData('element'); + } + + /** + * Convert XML config to Object + * + * @return Varien_Object + */ + public function getConfig() + { + if ($this->getData('config') instanceof Varien_Object) { + return $this->getData('config'); + } + + $configXml = $this->getData('config'); + $config = new Varien_Object(); + $this->setConfig($config); + if (!($configXml instanceof Varien_Simplexml_Element)) { + return $this->getData('config'); + } + + // define chooser label + if ($configXml->label) { + $config->setData('label', $this->getTranslationHelper()->__((string)$configXml->label)); + } + + // chooser control buttons + $buttons = array( + 'open' => Mage::helper('cms')->__('Choose'), + 'close' => Mage::helper('cms')->__('Close') + ); + if ($configXml->button && $configXml->button->hasChildren()) { + foreach ($configXml->button->children() as $button) { + $buttons[(string)$button->getName()] = $this->getTranslationHelper()->__((string)$button); + } + } + $config->setButtons($buttons); + + return $this->getData('config'); + } + + /** + * Helper getter for translations + * + * @return Mage_Core_Helper_Abstract + */ + public function getTranslationHelper() + { + if ($this->getData('translation_helper') instanceof Mage_Core_Helper_Abstract) { + return $this->getData('translation_helper'); + } + return $this->helper('cms'); + } + + /** + * Unique identifier for block that uses Chooser + * + * @return string + */ + public function getUniqId() + { + return $this->getData('uniq_id'); + } + + /** + * Form element fieldset id getter for working with form in chooser + * + * @return string + */ + public function getFieldsetId() + { + return $this->getData('fieldset_id'); + } + + /** + * Flag to indicate include hidden field before chooser or not + * + * @return bool + */ + public function getHiddenEnabled() + { + return $this->hasData('hidden_enabled') ? (bool)$this->getData('hidden_enabled') : true; + } + + /** + * Return chooser HTML and init scripts + * + * @return string + */ + protected function _toHtml() + { + $element = $this->getElement(); + /* @var $fieldset Varien_Data_Form_Element_Fieldset */ + $fieldset = $element->getForm()->getElement($this->getFieldsetId()); + + $chooserId = $this->getUniqId(); + + $hiddenHtml = ''; + if ($this->getHiddenEnabled()) { + $hidden = new Varien_Data_Form_Element_Hidden(array( + 'name' => $element->getName(), + 'required' => (bool)$element->required, + 'value' => $element->getValue(), + 'class' => $element->getClass(), + )); + $hidden->setId($chooserId . 'value'); + $hidden->setForm($element->getForm()); + $hiddenHtml = $hidden->getElementHtml(); + + // Unset element value in favour of hidden field + $element->setValue(""); + } + + $config = $this->getConfig(); + + $chooser = $fieldset->addField('chooser' . $element->getId(), 'label', array( + 'label' => $config->getLabel() ? $config->getLabel() : '' + )); + + $buttons = $config->getButtons(); + $chooseButton = $this->getLayout()->createBlock('adminhtml/widget_button') + ->setType('button') + ->setId($chooserId . 'control') + ->setClass('widget-option-chooser') + ->setLabel($buttons['open']) + ->setOnclick($chooserId.'.choose()'); + + $configJson = Mage::helper('core')->jsonEncode($config->getData()); + $html = ' + + + '; + + $chooser->setData('after_element_html', $hiddenHtml . $chooseButton->toHtml()); + return $html; + } + + +} diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Widget/Form.php b/app/code/core/Mage/Adminhtml/Block/Cms/Widget/Form.php new file mode 100644 index 0000000000..48eac3dd1d --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Widget/Form.php @@ -0,0 +1,176 @@ + + */ + +class Mage_Adminhtml_Block_Cms_Widget_Form extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * Form with widget to select + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + + $fieldset = $form->addFieldset('base_fieldset', array( + 'legend' => $this->helper('cms')->__('Widget') + )); + + $this->setEmptyOptionDescription($this->helper('cms')->__('Please select a Widget Type')); + $select = $fieldset->addField('select_widget_type', 'select', array( + 'label' => $this->helper('cms')->__('Widget Type'), + 'title' => $this->helper('cms')->__('Widget Type'), + 'name' => 'widget_type', + 'required' => true, + 'options' => $this->_getWidgetSelectOptions(), + 'note' => $this->getEmptyOptionDescription(), + 'after_element_html' => $this->_getWidgetSelectAfterHtml(), + )); + + $form->setUseContainer(true); + $form->setId('edit_form'); + $form->setMethod('post'); + $form->setAction($this->getUrl('*/*/buildWidget')); + $this->setForm($form); + } + + /** + * Prepare options for widgets HTML select + * + * @return array + */ + protected function _getWidgetSelectOptions() + { + foreach ($this->_getAvailableWidgets(true) as $data) { + $options[$data['type']] = $data['name']; + } + return $options; + } + + /** + * Prepare widgets select after element HTML + * + * @return string + */ + protected function _getWidgetSelectAfterHtml() + { + $html = ''; + $i = 0; + foreach ($this->_getAvailableWidgets(true) as $data) { + $html .= sprintf('
%s
', $i, $data['description']); + $i++; + } + return $html; + } + + /** + * Return array of available widgets based on configuration + * + * @return array + */ + protected function _getAvailableWidgets($withEmptyElement = false) + { + if (!$this->getData('available_widgets')) { + $config = Mage::getSingleton('cms/widget')->getXmlConfig(); + $widgets = $config->getNode('widgets'); + $result = array(); + if ($withEmptyElement) { + $result[] = array( + 'type' => '', + 'name' => $this->helper('adminhtml')->__('-- Please Select --'), + 'description' => $this->getEmptyOptionDescription(), + ); + } + $skipped = $this->_getSkippedWidgets(); + foreach ($widgets->children() as $widget) { + if ($widget->is_context && $this->_skipContextWidgets()) { + continue; + } + if (is_array($skipped) && in_array($widget->getAttribute('type'), $skipped)) { + continue; + } + if ($widget->getAttribute('module')) { + $helper = Mage::helper($widget->getAttribute('module')); + } else { + $helper = Mage::helper('cms'); + } + $result[$widget->getName()] = array( + 'name' => $helper->__((string)$widget->name), + 'code' => $widget->getName(), + 'type' => $widget->getAttribute('type'), + 'description' => $helper->__((string)$widget->description), + ); + } + usort($result, array($this, "_sortWidgets")); + $this->setData('available_widgets', $result); + } + return $this->getData('available_widgets'); + } + + /** + * Disable insertion of context(is_context) widgets or not + * + * @return bool + */ + protected function _skipContextWidgets() + { + return (bool)$this->getParentBlock()->getData('skip_context_widgets'); + } + + /** + * Return array of widgets disabled for selection + * + * @return array + */ + protected function _getSkippedWidgets() + { + $skipped = $this->getParentBlock()->getData('skip_widgets'); + if (is_array($skipped)) { + return $skipped; + } + $skipped = Mage::helper('core')->urlDecode($skipped); + $skipped = explode(',', $skipped); + return $skipped; + } + + /** + * User-defined widgets sorting by Name + * + * @param array $a + * @param array $b + * @return boolean + */ + protected function _sortWidgets($a, $b) + { + return strcmp($a["name"], $b["name"]); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Widget/Options.php b/app/code/core/Mage/Adminhtml/Block/Cms/Widget/Options.php new file mode 100644 index 0000000000..0ca8143899 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Widget/Options.php @@ -0,0 +1,177 @@ + + */ + +class Mage_Adminhtml_Block_Cms_Widget_Options extends Mage_Adminhtml_Block_Widget_Form +{ + protected $_defaultElementType = 'text'; + protected $_translationHelper = null; + + /** + * Prepare Widget Options Form and values according to specified type + * + * widget_type must be set in data before + * widget_values may be set before to render element values + */ + protected function _prepareForm() + { + // prepare form instance + $form = new Varien_Data_Form(); + $fieldset = $form->addFieldset('options_fieldset', array( + 'legend' => $this->helper('cms')->__('Widget Options') + )); + $form->setUseContainer(false); + $this->setForm($form); + + // get configuration node and translation helper + if (!$this->getWidgetType()) { + Mage::throwException($this->__('Widget Type is not specified')); + } + $config = Mage::getSingleton('cms/widget')->getXmlElementByType($this->getWidgetType()); + if (!($config instanceof Varien_Simplexml_Element)) { + return; + } + if (!$config->parameters) { + return; + } + $module = (string)$config->getAttribute('module'); + $this->_translationHelper = Mage::helper($module ? $module : 'cms'); + + // sort widget parameters and add them to form + $sortOrder = 0; + foreach ($config->parameters->children() as $option) { + $option->sort_order = $option->sort_order ? (int)$option->sort_order : $sortOrder; + $options[$option->getName()] = $option; + $sortOrder++; + } + uasort($options, array($this, '_sortParameters')); + foreach ($options as $option) { + $this->_addField($option); + } + } + + /** + * Widget parameters sort callback + * + * @param $a + * @param $b + * @return int + */ + protected function _sortParameters($a, $b) + { + $aOrder = (int)$a->sort_order; + $bOrder = (int)$b->sort_order; + return $aOrder < $bOrder ? -1 : ($aOrder > $bOrder ? 1 : 0); + } + + /** + * Add field to Options form based on option configuration + * + * @param Varien_Simplexml_Element $option + * @param Mage_Core_Helper_Abstract $helper + * @return Varien_Data_Form_Element_Abstract + */ + protected function _addField($config) + { + $form = $this->getForm(); + $fieldset = $form->getElement('options_fieldset'); + + // prepare element data with values (either from request of from default values) + $fieldName = (string)$config->getName(); + $data = array( + 'name' => $form->addSuffixToName($fieldName, 'parameters'), + 'label' => $this->_translationHelper->__((string)$config->label), + 'required' => (bool)(int)(string)$config->required, + 'class' => 'widget-option', + 'note' => $this->_translationHelper->__((string)$config->description), + ); + if ($values = $this->getWidgetValues()) { + $data['value'] = (isset($values[$fieldName]) ? $values[$fieldName] : ''); + } + else { + $data['value'] = (string)$config->value; + } + + // prepare element dropdown values, if any + if ($config->values) { + // dropdown options are specified in configuration + if ($config->values->hasChildren()) { + $data['values'] = array(); + foreach ($config->values->children() as $option) { + $data['values'][] = array( + 'value' => (string)$option->value, + 'label' => $this->_translationHelper->__((string)$option->label) + ); + } + } + // a source model is specified + elseif ($model = Mage::getModel((string)$config->values)) { + $data['values'] = $model->toOptionArray(); + } + } + + // prepare field type and renderers + $fieldRenderer = false; + $fieldChooserRenderer = false; + $fieldType = (string)$config->type; + // hidden element + if (!(int)(string)$config->visible) { + $fieldType = 'hidden'; + } + // element of specified type with a chooser + elseif ($config->type->hasChildren()) { + $fieldType = $config->type->element_type ? (string)$config->type->element_type : $this->_defaultElementType; + if ($config->type->element_helper) { + $fieldChooserRenderer = $this->getLayout()->getBlockSingleton((string)$config->type->element_helper); + } + } + // just an element renderer + elseif (false !== strpos($config->type, '/')) { + $fieldType = $this->_defaultElementType; + $fieldRenderer = $this->getLayout()->createBlock((string)$config->type); + } + + // instantiate field and prepare extra html + $field = $fieldset->addField('option_' . $fieldName, $fieldType, $data); + if ($fieldRenderer) { + $field->setRenderer($fieldRenderer); + } elseif ($fieldChooserRenderer) { + $fieldChooserRenderer->setFieldsetId($fieldset->getId()) + ->setTranslationHelper($this->_translationHelper) + ->setConfig($config->type) + ->prepareElementHtml($field); + } + + return $field; + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content.php new file mode 100644 index 0000000000..22ddab6381 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content.php @@ -0,0 +1,132 @@ + + */ +class Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Content extends Mage_Adminhtml_Block_Widget_Container +{ + /** + * Block construction + */ + public function __construct() + { + parent::__construct(); + $this->_headerText = $this->helper('cms')->__('Image Gallery'); + $this->_removeButton('back')->_removeButton('edit'); + $this->_addButton('newfolder', array( + 'class' => 'save', + 'label' => $this->helper('cms')->__('Create Folder'), + 'type' => 'button', + 'onclick' => 'Images.newFolder();' + )); + $this->_addButton('upload', array( + 'class' => 'add', + 'label' => $this->helper('cms')->__('Add Files'), + 'type' => 'button', + 'onclick' => 'Images.upload();' + )); + + $this->_addButton('delete_folder', array( + 'class' => 'delete no-display', + 'label' => $this->helper('cms')->__('Delete Folder'), + 'type' => 'button', + 'onclick' => 'Images.deleteFolder();', + 'id' => 'button_delete_folder' + )); + + $this->_addButton('delete_files', array( + 'class' => 'delete no-display', + 'label' => $this->helper('cms')->__('Delete File'), + 'type' => 'button', + 'onclick' => 'Images.deleteFiles();', + 'id' => 'button_delete_files' + )); + + $this->_addButton('insert_files', array( + 'class' => 'save no-display', + 'label' => $this->helper('cms')->__('Insert File'), + 'type' => 'button', + 'onclick' => 'Images.insert();', + 'id' => 'button_insert_files' + )); + } + + /** + * Files action source URL + * + * @return string + */ + public function getContentsUrl() + { + return $this->getUrl('*/*/contents', array('type' => $this->getRequest()->getParam('type'))); + } + + /** + * New directory action target URL + * + * @return string + */ + public function getNewfolderUrl() + { + return $this->getUrl('*/*/newFolder'); + } + + /** + * Delete directory action target URL + * + * @return string + */ + protected function getDeletefolderUrl() + { + return $this->getUrl('*/*/deleteFolder'); + } + + /** + * Description goes here... + * + * @param none + * @return void + */ + public function getDeleteFilesUrl() + { + return $this->getUrl('*/*/deleteFiles'); + } + + /** + * New directory action target URL + * + * @return string + */ + public function getOnInsertUrl() + { + return $this->getUrl('*/*/onInsert'); + } +} \ No newline at end of file diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Files.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Files.php new file mode 100644 index 0000000000..f0f0d860c9 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Files.php @@ -0,0 +1,89 @@ + + */ +class Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Content_Files extends Mage_Adminhtml_Block_Template +{ + /** + * Prepare Files collection + * + * @return Varien_Data_Collection_Filesystem + */ + public function getContentsCollection() + { + $helper = Mage::helper('cms/wysiwyg_images'); + $type = $this->getRequest()->getParam('type'); + $collection = $helper->getStorage()->getFilesCollection($helper->getCurrentPath(), $type); + foreach ($collection as $item) { + $item->setId(Mage::helper('core')->urlEncode($item->getBasename())); + $item->setName($this->getShortFilename($item->getBasename())); + $item->setUrl($helper->getCurrentUrl() . $item->getBasename()); + $item->setEncodedPath(Mage::helper('core')->urlEncode($item->getFilename())); + + if(is_file($helper->getCurrentPath() . DS . '.thumbs' . DS . $item->getBasename())) { + $item->setThumbUrl($helper->getCurrentUrl() . '.thumbs/' . $item->getBasename()); + } + + $size = @getimagesize($item->getFilename()); + if (is_array($size)) { + $item->setWidth($size[0]); + $item->setHeight($size[1]); + } + } + return $collection; + } + + public function getImagesWidth() + { + return Mage::getSingleton('cms/wysiwyg_images_storage')->getConfigData('browser_resize_width'); + } + + public function getImagesHeight() + { + return Mage::getSingleton('cms/wysiwyg_images_storage')->getConfigData('browser_resize_height'); + } + + /** + * Reduce filename by replacing some characters with dots + * + * @param string $filename + * @param int $maxLength Maximum filename + * @return string Truncated filename + */ + public function getShortFilename($filename, $maxLength = 15) + { + if (strlen($filename) <= $maxLength) { + return $filename; + } + return preg_replace('/^(.{1,'.($maxLength - 3).'})(.*)(\.[a-z0-9]+)$/i', '$1..$3', $filename); + } +} \ No newline at end of file diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Newfolder.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Newfolder.php new file mode 100644 index 0000000000..592f7bb85f --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Newfolder.php @@ -0,0 +1,37 @@ + + */ +class Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Content_Newfolder extends Mage_Adminhtml_Block_Template +{ + +} \ No newline at end of file diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Uploader.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Uploader.php new file mode 100644 index 0000000000..1fd305c604 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Uploader.php @@ -0,0 +1,59 @@ + +*/ +class Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Content_Uploader extends Mage_Adminhtml_Block_Media_Uploader +{ + public function __construct() + { + parent::__construct(); + $params = $this->getConfig()->getParams(); + $type = $this->getRequest()->getParam('type'); + $allowed = Mage::getSingleton('cms/wysiwyg_images_storage')->getAllowedExtensions($type); + $labels = array(); + $files = array(); + foreach ($allowed as $ext) { + $labels[] = '.' . $ext; + $files[] = '*.' . $ext; + } + $this->getConfig() + ->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/*/upload', array('type' => $type))) + ->setParams($params) + ->setFileField('image') + ->setFilters(array( + 'images' => array( + 'label' => $this->helper('cms')->__('Images (%s)', implode(', ', $labels)), + 'files' => $files + ) + )); + } +} \ No newline at end of file diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Tree.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Tree.php new file mode 100644 index 0000000000..a8484c7e82 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Tree.php @@ -0,0 +1,98 @@ + + */ +class Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Tree extends Mage_Adminhtml_Block_Template +{ + + /** + * Json tree builder + * + * @return string + */ + public function getTreeJson() + { + $helper = Mage::helper('cms/wysiwyg_images'); + $storageRoot = $helper->getStorageRoot(); + $collection = Mage::registry('storage')->getDirsCollection($helper->getCurrentPath()); + $jsonArray = array(); + foreach ($collection as $item) { + $jsonArray[] = array( + 'text' => $item->getBasename(), + 'id' => $helper->convertPathToId($item->getFilename()), + 'cls' => 'folder' + ); + } + return Zend_Json::encode($jsonArray); + } + + /** + * Json source URL + * + * @return string + */ + public function getTreeLoaderUrl() + { + return $this->getUrl('*/*/treeJson'); + } + + /** + * Root node name of tree + * + * @return string + */ + public function getRootNodeName() + { + return $this->helper('cms')->__('Storage Root'); + } + + /** + * Return tree node full path based on current path + * + * @return string + */ + public function getTreeCurrentPath() + { + $treePath = '/root'; + if ($path = Mage::registry('storage')->getSession()->getCurrentPath()) { + $path = str_replace(Mage::helper('cms/wysiwyg_images')->getStorageRoot(), '', $path); + $relative = ''; + foreach (explode(DS, $path) as $dirName) { + if ($dirName) { + $relative .= DS . $dirName; + $treePath .= '/' . Mage::helper('core')->urlEncode($relative); + } + } + } + return $treePath; + } +} \ No newline at end of file diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Region.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Region.php index 586c120073..ad540f93f3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Region.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Region.php @@ -31,7 +31,12 @@ */ class Mage_Adminhtml_Block_Customer_Edit_Renderer_Region extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface { - + /** + * Output the region element and javasctipt that makes it dependent from country element + * + * @param Varien_Data_Form_Element_Abstract $element + * @return string + */ public function render(Varien_Data_Form_Element_Abstract $element) { if ($country = $element->getForm()->getElement('country_id')) { @@ -42,7 +47,6 @@ public function render(Varien_Data_Form_Element_Abstract $element) } $regionId = $element->getForm()->getElement('region_id')->getValue(); - $postcode = $element->getForm()->getElement('postcode'); $html = ''; $element->setClass('input-text'); @@ -54,27 +58,12 @@ public function render(Varien_Data_Form_Element_Abstract $element) $html.= ''; - $html.= ''; + + $html.= ''."\n"; + $html.= ''."\n"; return $html; } - } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php index bcde34a2d9..c0626b55d5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php @@ -133,23 +133,23 @@ public function initForm() 'id' => 'sendemail', )); if (!Mage::app()->isSingleStoreMode()) { - $fieldset->addField('store_id', 'select', array( + $fieldset->addField('sendemail_store_id', 'select', array( 'label' => $this->helper('customer')->__('Send From'), - 'name' => 'store_id', + 'name' => 'sendemail_store_id', 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm() )); } } - // make sendemail and store_id disabled, if website_id has empty value - if ($sendemail = $form->getElement('store_id')) { + // make sendemail and sendmail_store_id disabled, if website_id has empty value + if ($sendemail = $form->getElement('sendemail_store_id')) { $prefix = $form->getHtmlIdPrefix(); $sendemail->setAfterElementHtml( '"; + } + + /** + * Target element ID setter + * + * @param string $value + * @return Mage_Adminhtml_Block_Promo_Widget_Chooser_Daterange + */ + public function setTargetElementId($value) + { + $this->_targetElementId = trim($value); + return $this; + } + + /** + * Range values setter + * + * @param string $from + * @param string $to + * @return Mage_Adminhtml_Block_Promo_Widget_Chooser_Daterange + */ + public function setRangeValues($from, $to) + { + $this->_rangeValues = array('from' => $from, 'to' => $to); + return $this; + } + + /** + * Range values setter, string implementation. + * Automatically attempts to split the string by delimiter + * + * @param string $delimitedString + * @return Mage_Adminhtml_Block_Promo_Widget_Chooser_Daterange + */ + public function setRangeValue($delimitedString) + { + $split = explode($this->_rangeDelimiter, $delimitedString, 2); + $from = $split[0]; $to = ''; + if (isset($split[1])) { + $to = $split[1]; + } + return $this->setRangeValues($from, $to); + } + + /** + * Range delimiter setter + * + * @param string $value + * @return Mage_Adminhtml_Block_Promo_Widget_Chooser_Daterange + */ + public function setRangeDelimiter($value) + { + $this->_rangeDelimiter = (string)$value; + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer/Grid.php index aee466ac6c..e4fd38758a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer/Grid.php @@ -73,7 +73,8 @@ protected function _prepareColumns() 'align' => 'center', 'filter' => false, 'sortable' => false, - 'renderer' => 'adminhtml/report_grid_column_renderer_customer' + 'renderer' => 'adminhtml/report_grid_column_renderer_customer', + 'is_system' => true )); $this->setFilterVisibility(false); diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Review/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Review/Product/Grid.php index 129b17e67d..54ddd1d0e5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Review/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Review/Product/Grid.php @@ -100,7 +100,8 @@ protected function _prepareColumns() 'align' => 'center', 'filter' => false, 'sortable' => false, - 'renderer' => 'adminhtml/report_grid_column_renderer_product' + 'renderer' => 'adminhtml/report_grid_column_renderer_product', + 'is_system' => true )); $this->setFilterVisibility(false); diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php index 8e2bb2691d..5d3812c45b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php @@ -64,6 +64,15 @@ protected function _prepareColumns() $currency_code = $this->getCurrentCurrencyCode(); + $this->addColumn('profit', array( + 'header' =>Mage::helper('reports')->__('Profit'), + 'type' =>'currency', + 'currency_code' => $currency_code, + 'index' =>'profit', + 'total' =>'sum', + 'renderer' =>'adminhtml/report_grid_column_renderer_currency' + )); + $this->addColumn('subtotal', array( 'header' =>Mage::helper('reports')->__('Subtotal'), 'type' =>'currency', @@ -127,6 +136,7 @@ protected function _prepareColumns() 'renderer' =>'adminhtml/report_grid_column_renderer_currency' )); + $this->addExportType('*/*/exportSalesCsv', Mage::helper('reports')->__('CSV')); $this->addExportType('*/*/exportSalesExcel', Mage::helper('reports')->__('Excel')); diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Search/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Search/Grid.php index 0c52a8f155..4c31e3eab7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Search/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Search/Grid.php @@ -74,7 +74,7 @@ protected function _prepareColumns() )); $this->addColumn('query_text', array( - 'header' =>__('Search Query'), + 'header' =>Mage::helper('reports')->__('Search Query'), 'filter' =>false, 'index' =>'query_text' )); diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Grid.php index 50932e2ece..bbd94280e8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Grid.php @@ -95,6 +95,7 @@ protected function _prepareColumns() 'field' => 'id' ) ), + 'is_system' => true, 'filter' => false, 'sortable' => false, 'index' => 'stores', diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Grid.php index a6dd4cf053..9595770dbe 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Grid.php @@ -112,6 +112,7 @@ protected function _prepareColumns() 'field' => 'id' ) ), + 'is_system' => true, 'filter' => false, 'sortable' => false, 'index' => 'stores', diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Grid.php index 71546c09b5..4d151812ef 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Grid.php @@ -98,6 +98,7 @@ protected function _prepareColumns() 'field' => 'id' ) ), + 'is_system' => true, 'filter' => false, 'sortable' => false, 'index' => 'stores', diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php index 08a92db458..c34106c0f5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php @@ -36,6 +36,7 @@ public function __construct() { parent::__construct(); $this->setId('sales_invoice_grid'); + $this->setUseAjax(true); $this->setDefaultSort('created_at'); $this->setDefaultDir('DESC'); } @@ -155,7 +156,7 @@ public function getRowUrl($row) public function getGridUrl() { - return $this->getUrl('*/*/*', array('_current' => true)); + return $this->getUrl('*/*/grid', array('_current' => true)); } -} \ No newline at end of file +} diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method/Form.php index c2312c89ed..94291582ed 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method/Form.php @@ -61,18 +61,18 @@ public function hasMethods() } /** - * Retrieve code of current payment method + * Get current payment method code or the only available, if there is only one method * - * @return mixed + * @return string|false */ public function getSelectedMethodCode() { - if ($method = $this->getQuote()->getPayment()->getMethod()) { - return $method; + if ($currentMethodCode = $this->getQuote()->getPayment()->getMethod()) { + return $currentMethodCode; } if (count($this->getMethods()) == 1) { - foreach ($this->getMethods() as $_method) { - return $_method->getCode(); + foreach ($this->getMethods() as $method) { + return $method->getCode(); } } return false; diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php index e40accd08d..c68f22d4b6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php @@ -74,7 +74,7 @@ protected function _prepareForm() $addressModel = Mage::getModel('customer/address'); foreach ($addressModel->getAttributes() as $attribute) { - if (!$attribute->getIsVisible()) { + if ($attribute->hasData('is_visible') && !$attribute->getIsVisible()) { continue; } if ($inputType = $attribute->getFrontend()->getInputType()) { @@ -96,9 +96,7 @@ protected function _prepareForm() if ($regionElement = $this->_form->getElement('region')) { $regionElement->setRenderer( - $this->getLayout() - ->createBlock('adminhtml/customer_edit_renderer_region') - ->setStoreId($this->getStoreId()) + $this->getLayout()->createBlock('adminhtml/customer_edit_renderer_region') ); } if ($regionElement = $this->_form->getElement('region_id')) { diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php index 179e6e4a97..840222ad05 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php @@ -55,6 +55,13 @@ public function __construct() ); } + $this->addButton('send_notification', array( + 'label' => Mage::helper('sales')->__('Send Email'), + 'onclick' => 'confirmSetLocation(\'' . Mage::helper('sales')->__( + 'Are you sure you want to send Creditmemo email to customer?' + ) . '\', \'' . $this->getEmailUrl() . '\')' + )); + if ($this->getCreditmemo()->canRefund()) { $this->_addButton('refund', array( 'label' => Mage::helper('sales')->__('Refund'), @@ -72,7 +79,7 @@ public function __construct() ) ); } - + if ($this->getCreditmemo()->getId()) { $this->_addButton('print', array( 'label' => Mage::helper('sales')->__('Print'), @@ -136,13 +143,21 @@ public function getCancelUrl() return $this->getUrl('*/*/cancel', array('creditmemo_id'=>$this->getCreditmemo()->getId())); } + public function getEmailUrl() + { + return $this->getUrl('*/*/email', array( + 'creditmemo_id' => $this->getCreditmemo()->getId(), + 'order_id' => $this->getCreditmemo()->getOrderId() + )); + } + public function getPrintUrl() { return $this->getUrl('*/*/print', array( 'invoice_id' => $this->getCreditmemo()->getId() )); } - + public function updateBackButtonUrl($flag) { if ($flag) { diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php index c3a8e754b5..20a7e72084 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php @@ -54,6 +54,13 @@ public function __construct() ); } + $this->addButton('send_notification', array( + 'label' => Mage::helper('sales')->__('Send Email'), + 'onclick' => 'confirmSetLocation(\'' . Mage::helper('sales')->__( + 'Are you sure you want to send Invoice email to customer?' + ) . '\', \'' . $this->getEmailUrl() . '\')' + )); + if ($this->getInvoice()->getOrder()->canCreditmemo()) { if ($this->getInvoice()->getOrder()->getPayment()->canRefundPartialPerInvoice() || !$this->getInvoice()->getIsUsedForRefund()) @@ -153,6 +160,14 @@ public function getCancelUrl() return $this->getUrl('*/*/cancel', array('invoice_id'=>$this->getInvoice()->getId())); } + public function getEmailUrl() + { + return $this->getUrl('*/*/email', array( + 'order_id' => $this->getInvoice()->getOrder()->getId(), + 'invoice_id'=> $this->getInvoice()->getId(), + )); + } + public function getCreditMemoUrl() { return $this->getUrl('*/sales_order_creditmemo/start', array( diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php index 3ac1eafd64..9cb7f3ad1b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php @@ -45,8 +45,9 @@ public function __construct() $this->_removeButton('reset'); $this->_removeButton('delete'); $this->_updateButton('save', 'label', Mage::helper('sales')->__('Send Tracking Information')); - $this->_updateButton('save', 'onclick', "setLocation('".$this->getEmailUrl()."')"); - + $this->_updateButton('save', + 'onclick', "deleteConfirm('" . Mage::helper('sales')->__('Are you sure you want to send Shipment email to customer?') . "', '" . $this->getEmailUrl() . "')"); + if ($this->getShipment()->getId()) { $this->_addButton('print', array( 'label' => Mage::helper('sales')->__('Print'), @@ -101,7 +102,7 @@ public function getPrintUrl() 'invoice_id' => $this->getShipment()->getId() )); } - + public function updateBackButtonUrl($flag) { if ($flag) { diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Item.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Item.php index 3336b115f2..a7b155db78 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Item.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Item.php @@ -23,8 +23,17 @@ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + + /** + * Totals item block + */ class Mage_Adminhtml_Block_Sales_Order_Totals_Item extends Mage_Adminhtml_Block_Sales_Order_Totals { + /** + * Determine display parameters before rendering HTML + * + * @return Mage_Adminhtml_Block_Sales_Order_Totals_Item + */ protected function _beforeToHtml() { parent::_beforeToHtml(); @@ -32,12 +41,14 @@ protected function _beforeToHtml() $this->setCanDisplayTotalPaid($this->getParentBlock()->getCanDisplayTotalPaid()); $this->setCanDisplayTotalRefunded($this->getParentBlock()->getCanDisplayTotalRefunded()); $this->setCanDisplayTotalDue($this->getParentBlock()->getCanDisplayTotalDue()); + + return $this; } /** - * Initialize giftcard order total + * Initialize totals object * - * @return Enterprise_GiftCardAccount_Block_Sales_Order_Giftcards + * @return Mage_Adminhtml_Block_Sales_Order_Totals_Item */ public function initTotals() { @@ -50,18 +61,38 @@ public function initTotals() return $this; } + /** + * Price HTML getter + * + * @param float $baseAmount + * @param float $amount + * @return string + */ public function displayPrices($baseAmount, $amount) { return $this->helper('adminhtml/sales')->displayPrices($this->getOrder(), $baseAmount, $amount); } + /** + * Price attribute HTML getter + * + * @param string $code + * @param bool $strong + * @param string $separator + * @return string + */ public function displayPriceAttribute($code, $strong = false, $separator = '
') { return $this->helper('adminhtml/sales')->displayPriceAttribute($this->getSource(), $code, $strong, $separator); } + /** + * Source order getter + * + * @return Mage_Sales_Model_Order + */ public function getSource() { return $this->getParentBlock()->getSource(); } -} \ No newline at end of file +} diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php index 0da3ca7258..2c2ee5924e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php @@ -78,6 +78,13 @@ public function __construct() )); } + $this->addButton('send_notification', array( + 'label' => Mage::helper('sales')->__('Send Order Email'), + 'onclick' => 'confirmSetLocation(\'' . Mage::helper('sales')->__( + 'Are you sure you want to send Order email to customer?' + ) . '\', \'' . $this->getEmailUrl() . '\')' + )); + if ($this->_isAllowedAction('creditmemo') && $this->getOrder()->canCreditmemo()) { $this->_addButton('order_creditmemo', array( 'label' => Mage::helper('sales')->__('Credit Memo'), @@ -169,6 +176,11 @@ public function getEditUrl() return $this->getUrl('*/sales_order_edit/start'); } + public function getEmailUrl() + { + return $this->getUrl('*/*/email'); + } + public function getCancelUrl() { return $this->getUrl('*/*/cancel'); diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Totals.php b/app/code/core/Mage/Adminhtml/Block/Sales/Totals.php index 882adf0211..f5269cf651 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Totals.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Totals.php @@ -62,7 +62,7 @@ protected function _initTotals() /** * Add shipping */ - if ($this->getSource()->getShippingAmount() || $this->getSource()->getShippingDescription()) + if (!$this->getSource()->getIsVirtual() && ((float) $this->getSource()->getShippingAmount() || $this->getSource()->getShippingDescription())) { $this->_totals['shipping'] = new Varien_Object(array( 'code' => 'shipping', diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Assigned/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tag/Assigned/Grid.php new file mode 100644 index 0000000000..79a63b7f19 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Assigned/Grid.php @@ -0,0 +1,271 @@ + + */ +class Mage_Adminhtml_Block_Tag_Assigned_Grid extends Mage_Adminhtml_Block_Widget_Grid +{ + /** + * Set grid params + * + */ + public function __construct() + { + parent::__construct(); + $this->setId('tag_assigned_product_grid'); + $this->setDefaultSort('entity_id'); + $this->setDefaultDir('DESC'); + $this->setUseAjax(true); + if ($this->_getTagId()) { + $this->setDefaultFilter(array('in_products'=>1)); + } + } + + /** + * Tag ID getter + * + * @return int + */ + protected function _getTagId() + { + return Mage::registry('current_tag')->getId(); + } + + /** + * Store getter + * + * @return Mage_Core_Model_Store + */ + protected function _getStore() + { + $storeId = (int) $this->getRequest()->getParam('store', 0); + return Mage::app()->getStore($storeId); + } + + /** + * Add filter to grid columns + * + * @param mixed $column + * @return Mage_Adminhtml_Block_Tag_Assigned_Grid + */ + protected function _addColumnFilterToCollection($column) + { + // Set custom filter for in product flag + if ($column->getId() == 'in_products') { + $productIds = $this->_getSelectedProducts(); + if (empty($productIds)) { + $productIds = 0; + } + if ($column->getFilter()->getValue()) { + $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds)); + } else { + if($productIds) { + $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds)); + } + } + } else { + parent::_addColumnFilterToCollection($column); + } + return $this; + } + + /** + * Retrieve Products Collection + * + * @return Mage_Adminhtml_Block_Tag_Assigned_Grid + */ + protected function _prepareCollection() + { + $store = $this->_getStore(); + $collection = Mage::getModel('catalog/product')->getCollection() + ->addAttributeToSelect('sku') + ->addAttributeToSelect('name') + ->addAttributeToSelect('attribute_set_id') + ->addAttributeToSelect('type_id') + ->joinField('qty', + 'cataloginventory/stock_item', + 'qty', + 'product_id=entity_id', + '{{table}}.stock_id=1', + 'left'); + + if ($store->getId()) { + $collection->addStoreFilter($store); + $collection->joinAttribute('custom_name', 'catalog_product/name', 'entity_id', null, 'inner', $store->getId()); + $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', $store->getId()); + $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $store->getId()); + $collection->joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left', $store->getId()); + } else { + $collection->addAttributeToSelect('price'); + $collection->addAttributeToSelect('status'); + $collection->addAttributeToSelect('visibility'); + } + + $this->setCollection($collection); + + parent::_prepareCollection(); + $this->getCollection()->addWebsiteNamesToResult(); + return $this; + } + + /** + * Prepeare columns for grid + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareColumns() + { + $this->addColumn('in_products', array( + 'header_css_class' => 'a-center', + 'type' => 'checkbox', + 'field_name' => 'in_products', + 'values' => $this->_getSelectedProducts(), + 'align' => 'center', + 'index' => 'entity_id' + )); + + $this->addColumn('entity_id', + array( + 'header'=> Mage::helper('catalog')->__('ID'), + 'width' => 50, + 'sortable' => true, + 'type' => 'number', + 'index' => 'entity_id', + )); + $this->addColumn('name', + array( + 'header'=> Mage::helper('catalog')->__('Name'), + 'index' => 'name', + )); + + $store = $this->_getStore(); + if ($store->getId()) { + $this->addColumn('custom_name', + array( + 'header'=> Mage::helper('catalog')->__('Name In %s', $store->getName()), + 'index' => 'custom_name', + )); + } + + $this->addColumn('type', + array( + 'header' => Mage::helper('catalog')->__('Type'), + 'width' => 100, + 'index' => 'type_id', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(), + )); + + $sets = Mage::getResourceModel('eav/entity_attribute_set_collection') + ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId()) + ->load() + ->toOptionHash(); + + $this->addColumn('set_name', + array( + 'header' => Mage::helper('catalog')->__('Attrib. Set Name'), + 'width' => 100, + 'index' => 'attribute_set_id', + 'type' => 'options', + 'options' => $sets, + )); + + $this->addColumn('sku', + array( + 'header'=> Mage::helper('catalog')->__('SKU'), + 'width' => 80, + 'index' => 'sku', + )); + + $store = $this->_getStore(); + $this->addColumn('price', + array( + 'header' => Mage::helper('catalog')->__('Price'), + 'type' => 'price', + 'currency_code' => $store->getBaseCurrency()->getCode(), + 'index' => 'price', + )); + + $this->addColumn('visibility', + array( + 'header' => Mage::helper('catalog')->__('Visibility'), + 'width' => 100, + 'index' => 'visibility', + 'type' => 'options', + 'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(), + )); + + $this->addColumn('status', + array( + 'header' => Mage::helper('catalog')->__('Status'), + 'width' => 70, + 'index' => 'status', + 'type' => 'options', + 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(), + )); + + return parent::_prepareColumns(); + } + + /** + * Retrieve related products + * + * @return array + */ + protected function _getSelectedProducts() + { + $products = $this->getRequest()->getPost('assigned_products', null); + if (!is_array($products)) { + $products = $this->getRelatedProducts(); + } + return $products; + } + + /** + * Retrieve Grid Url + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl('*/*/assignedGridOnly', array('_current' => true)); + } + + /** + * Retrieve related products + * + * @return array + */ + public function getRelatedProducts() + { + return Mage::registry('current_tag')->getRelatedProductIds(); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Customer/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tag/Customer/Grid.php index 2ce80ddc36..43a022f1c0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Customer/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Customer/Grid.php @@ -37,18 +37,30 @@ class Mage_Adminhtml_Block_Tag_Customer_Grid extends Mage_Adminhtml_Block_Widget public function __construct() { parent::__construct(); - $this->setId('tag_grid' . Mage::registry('tagId')); + $this->setId('tag_customer_grid' . Mage::registry('current_tag')->getId()); $this->setDefaultSort('name'); $this->setDefaultDir('ASC'); + $this->setUseAjax(true); + } + /* + * Retrieves Grid Url + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl('*/*/customer', array('_current' => true)); } protected function _prepareCollection() { - $tagId = Mage::registry('tagId'); + $tagId = Mage::registry('current_tag')->getId(); + $storeId = Mage::registry('current_tag')->getStoreId(); $collection = Mage::getModel('tag/tag') ->getCustomerCollection() ->addTagFilter($tagId) ->setCountAttribute('tr.tag_relation_id') + ->addStoreFilter($storeId) ->addGroupByCustomerProduct(); $this->setCollection($collection); @@ -65,7 +77,7 @@ protected function _prepareColumns() { $this->addColumn('customer_id', array( 'header' => Mage::helper('tag')->__('ID'), - 'width' => '50px', + 'width' => 50, 'align' => 'right', 'index' => 'entity_id', )); @@ -80,15 +92,6 @@ protected function _prepareColumns() 'index' => 'lastname', )); - if (!Mage::app()->isSingleStoreMode()) { - $this->addColumn('store_id', array( - 'header' => Mage::helper('tag')->__('Tagged in'), - 'index' => 'store_id', - 'type' => 'store', - 'store_view' => true, - )); - } - $this->addColumn('product', array( 'header' => Mage::helper('tag')->__('Product Name'), 'filter' => false, @@ -100,19 +103,12 @@ protected function _prepareColumns() 'header' => Mage::helper('tag')->__('Product SKU'), 'filter' => false, 'sortable' => false, - 'width' => '50px', + 'width' => 50, 'align' => 'right', 'index' => 'product_sku', )); - $this->addColumn('product_sku', array( - 'header' => Mage::helper('tag')->__('Product SKU'), - 'filter' => false, - 'sortable' => false, - 'width' => '50px', - 'align' => 'right', - 'index' => 'product_sku', - )); + return parent::_prepareColumns(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Edit.php b/app/code/core/Mage/Adminhtml/Block/Tag/Edit.php index 2eaef52363..1a8c691e2e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Edit.php @@ -35,6 +35,10 @@ class Mage_Adminhtml_Block_Tag_Edit extends Mage_Adminhtml_Block_Widget_Form_Container { + /** + * Add and update buttons + * + */ public function __construct() { $this->_objectId = 'tag_id'; @@ -44,16 +48,102 @@ public function __construct() $this->_updateButton('save', 'label', Mage::helper('tag')->__('Save Tag')); $this->_updateButton('delete', 'label', Mage::helper('tag')->__('Delete Tag')); + + $this->addButton('save_and_edit_button', array( + 'label' => Mage::helper('tag')->__('Save And Continue Edit'), + 'onclick' => 'saveAndContinueEdit(\''.$this->getSaveAndContinueUrl().'\')', + 'class' => 'save' + ), 1); } + /** + * Add child HTML to layout + * + * @return Mage_Adminhtml_Block_Tag_Edit + */ + protected function _prepareLayout() + { + parent::_prepareLayout(); + + $this->setChild('store_switcher', $this->getLayout()->createBlock('adminhtml/tag_store_switcher')); + + $this->setChild('tag_assign_accordion', $this->getLayout()->createBlock('adminhtml/tag_edit_assigned')); + + $this->setChild('accordion', $this->getLayout()->createBlock('adminhtml/tag_edit_accordion')); + + return $this; + } + + /** + * Retrieve Header text + * + * @return string + */ public function getHeaderText() { - if (Mage::registry('tag_tag')->getId()) { - return Mage::helper('tag')->__("Edit Tag '%s'", $this->htmlEscape(Mage::registry('tag_tag')->getName())); - } - else { - return Mage::helper('tag')->__('New Tag'); + if (Mage::registry('current_tag')->getId()) { + return Mage::helper('tag')->__("Edit Tag '%s'", $this->htmlEscape(Mage::registry('current_tag')->getName())); } + return Mage::helper('tag')->__('New Tag'); + } + + /** + * Retrieve Accordions HTML + * + * @return string + */ + public function getAcordionsHtml() + { + return $this->getChildHtml('accordion'); + } + + /** + * Retrieve Assigned Tags Accordion HTML + * + * @return string + */ + public function getTagAssignAccordionHtml() + { + return $this->getChildHtml('tag_assign_accordion'); } + /** + * Retrieve Store Switcher HTML + * + * @return string + */ + public function getStoreSwitcherHtml() + { + return $this->getChildHtml('store_switcher'); + } + + /** + * Check whether it is single store mode + * + * @return bool + */ + public function isSingleStoreMode() + { + return Mage::app()->isSingleStoreMode(); + } + + /** + * Retrieve Tag Save URL + * + * @return string + */ + public function getSaveUrl() + { + return $this->getUrl('*/*/save', array('_current'=>true)); + } + + /** + * Retrieve Tag SaveAndContinue URL + * + * @return string + */ + public function getSaveAndContinueUrl() + { + return $this->getUrl('*/*/save', array('_current' => true, 'ret' => 'edit')); + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Accordion.php b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Accordion.php new file mode 100644 index 0000000000..97a5354b34 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Accordion.php @@ -0,0 +1,64 @@ + + */ + +class Mage_Adminhtml_Block_Tag_Edit_Accordion extends Mage_Adminhtml_Block_Widget_Accordion +{ + /** + * Add products and customers accordion to layout + * + */ + protected function _prepareLayout() + { + if (is_null(Mage::registry('current_tag')->getId())) { + return $this; + } + + $tagModel = Mage::registry('current_tag'); + + $this->setId('tag_customer_and_product_accordion'); + + $this->addItem('tag_customer', array( + 'title' => Mage::helper('tag')->__('Customers Submitted this Tag'), + 'ajax' => true, + 'content_url' => $this->getUrl('*/*/customer', array('ret' => 'all', 'tag_id'=>$tagModel->getId(), 'store'=>$tagModel->getStoreId())), + )); + + $this->addItem('tag_product', array( + 'title' => Mage::helper('tag')->__('Products Tagged by Customers'), + 'ajax' => true, + 'content_url' => $this->getUrl('*/*/product', array('ret' => 'all', 'tag_id'=>$tagModel->getId(), 'store'=>$tagModel->getStoreId())), + )); + return parent::_prepareLayout(); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Assigned.php b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Assigned.php new file mode 100644 index 0000000000..74af7ba2a9 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Assigned.php @@ -0,0 +1,58 @@ + + */ + +class Mage_Adminhtml_Block_Tag_Edit_Assigned extends Mage_Adminhtml_Block_Widget_Accordion +{ + /** + * Add Assigned products accordion to layout + * + */ + protected function _prepareLayout() + { + if (is_null(Mage::registry('current_tag')->getId())) { + return $this; + } + + $tagModel = Mage::registry('current_tag'); + + $this->setId('tag_assigned_grid'); + + $this->addItem('tag_assign', array( + 'title' => Mage::helper('tag')->__('Products Tagged by Administrators'), + 'ajax' => true, + 'content_url' => $this->getUrl('*/*/assigned', array('ret' => 'all', 'tag_id'=>$tagModel->getId(), 'store'=>$tagModel->getStoreId())), + )); + return parent::_prepareLayout(); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php index f7ca2ff1fa..fe436354d9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php @@ -46,33 +46,54 @@ protected function _prepareForm() { $model = Mage::registry('tag_tag'); - $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')); + $form = new Varien_Data_Form( + array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post') + ); $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('tag')->__('General Information'))); if ($model->getTagId()) { - $fieldset->addField('tag_id', 'hidden', array( + $fieldset->addField('tag_id', 'hidden', array( 'name' => 'tag_id', )); } - $fieldset->addField('name', 'text', array( - 'name' => 'name', + $fieldset->addField('form_key', 'hidden', array( + 'name' => 'form_key', + 'value' => Mage::getSingleton('core/session')->getFormKey(), + )); + + $fieldset->addField('store_id', 'hidden', array( + 'name' => 'store_id', + 'value' => (int)$this->getRequest()->getParam('store') + )); + + $fieldset->addField('name', 'text', array( + 'name' => 'tag_name', 'label' => Mage::helper('tag')->__('Tag Name'), 'title' => Mage::helper('tag')->__('Tag Name'), 'required' => true, + 'after_element_html' => ' [GLOBAL]', )); - $fieldset->addField('status', 'select', array( + $fieldset->addField('status', 'select', array( 'label' => Mage::helper('tag')->__('Status'), 'title' => Mage::helper('tag')->__('Status'), - 'name' => 'status', + 'name' => 'tag_status', 'required' => true, 'options' => array( Mage_Tag_Model_Tag::STATUS_DISABLED => Mage::helper('tag')->__('Disabled'), Mage_Tag_Model_Tag::STATUS_PENDING => Mage::helper('tag')->__('Pending'), Mage_Tag_Model_Tag::STATUS_APPROVED => Mage::helper('tag')->__('Approved'), ), + 'after_element_html' => ' [GLOBAL]', + )); + + $fieldset->addField('base_popularity', 'text', array( + 'name' => 'base_popularity', + 'label' => Mage::helper('tag')->__('Base Popularity'), + 'title' => Mage::helper('tag')->__('Base Popularity'), + 'after_element_html' => ' [STORE VIEW]', )); if (!$model->getId() && !Mage::getSingleton('adminhtml/session')->getTagData() ) { @@ -80,17 +101,13 @@ protected function _prepareForm() } if ( Mage::getSingleton('adminhtml/session')->getTagData() ) { - $form->setValues(Mage::getSingleton('adminhtml/session')->getTagData()); + $form->addValues(Mage::getSingleton('adminhtml/session')->getTagData()); Mage::getSingleton('adminhtml/session')->setTagData(null); } else { - $form->setValues($model->getData()); + $form->addValues($model->getData()); } - $form->setUseContainer(true); - $form->setAction( $form->getAction() . 'ret/' . $this->getRequest()->getParam('ret') ); $this->setForm($form); - return parent::_prepareForm(); } - } diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tag/Product/Grid.php index 6b5339b016..03dffcf868 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Product/Grid.php @@ -37,17 +37,31 @@ class Mage_Adminhtml_Block_Tag_Product_Grid extends Mage_Adminhtml_Block_Widget_ public function __construct() { parent::__construct(); - $this->setId('tag_grid' . Mage::registry('tagId')); + $this->setId('tag_product_grid' . Mage::registry('current_tag')->getId()); $this->setDefaultSort('name'); $this->setDefaultDir('ASC'); + $this->setUseAjax(true); + } + + /* + * Retrieves Grid Url + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl('*/*/product', array('_current' => true)); } protected function _prepareCollection() { - $tagId = Mage::registry('tagId'); + $tagId = Mage::registry('current_tag')->getId(); + $storeId = Mage::registry('current_tag')->getStoreId(); $collection = Mage::getModel('tag/tag') ->getEntityCollection() ->addTagFilter($tagId) + ->addCustomerFilter(array('null' => false)) + ->addStoreFilter($storeId) ->addPopularity($tagId); $this->setCollection($collection); @@ -81,6 +95,15 @@ protected function _prepareColumns() 'type' => 'number' )); + $this->addColumn('sku', array( + 'header' => Mage::helper('tag')->__('SKU'), + 'filter' => false, + 'sortable' => false, + 'width' => 50, + 'align' => 'right', + 'index' => 'sku', + )); + return parent::_prepareColumns(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Store/Switcher.php b/app/code/core/Mage/Adminhtml/Block/Tag/Store/Switcher.php new file mode 100644 index 0000000000..5c72a50451 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Store/Switcher.php @@ -0,0 +1,51 @@ + + */ +class Mage_Adminhtml_Block_Tag_Store_Switcher extends Mage_Adminhtml_Block_Store_Switcher +{ + /** + * @var bool + */ + protected $_hasDefaultOption = false; + + /** + * Set overriden params + */ + public function __construct() + { + parent::__construct(); + $this->setUseConfirm(false)->setSwitchUrl( + $this->getUrl('*/*/*/', array('store' => null, '_current' => true)) + ); + } +} \ No newline at end of file diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Tag.php b/app/code/core/Mage/Adminhtml/Block/Tag/Tag.php index b9bb0b263e..5b27f715af 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Tag.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Tag.php @@ -38,7 +38,7 @@ class Mage_Adminhtml_Block_Tag_Tag extends Mage_Adminhtml_Block_Widget_Grid_Cont public function __construct() { $this->_controller = 'tag_tag'; - $this->_headerText = Mage::helper('tag')->__('All Tags'); + $this->_headerText = Mage::helper('tag')->__('Manage Tags'); $this->_addButtonLabel = Mage::helper('tag')->__('Add New Tag'); parent::__construct(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit.php b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit.php index 477b7fd6d1..4a246e5645 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit.php @@ -27,6 +27,7 @@ /** * Admin tag edit block * + * @deprecated after 1.3.2.3 * @category Mage * @package Mage_Adminhtml * @author Magento Core Team @@ -63,6 +64,29 @@ public function __construct() $this->_updateButton('delete', 'label', Mage::helper('tag')->__('Delete Tag')); } + /** + * Add to layout accordion block + * + * @return Mage_Adminhtml_Block_Tag_Edit + */ + protected function _prepareLayout() + { + parent::_prepareLayout(); + $this->setChild('accordion', $this->getLayout()->createBlock('adminhtml/tag_edit_accordion')); + return $this; + } + + /** + * Adds to html of form html of accordion block + * + * @return string + */ + public function getFormHtml() + { + $html = parent::getFormHtml(); + return $html . $this->getChildHtml('accordion'); + } + public function getHeaderText() { if (Mage::registry('tag_tag')->getId()) { diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit/Form.php index f99bf71b5a..e8b7508c10 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit/Form.php @@ -27,6 +27,7 @@ /** * Adminhtml tag edit form * + * @deprecated after 1.3.2.3 * @category Mage * @package Mage_Adminhtml * @author Magento Core Team @@ -54,19 +55,19 @@ protected function _prepareForm() $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('tag')->__('General Information'))); if ($model->getTagId()) { - $fieldset->addField('tag_id', 'hidden', array( + $fieldset->addField('tag_id', 'hidden', array( 'name' => 'tag_id', )); } - $fieldset->addField('name', 'text', array( + $fieldset->addField('name', 'text', array( 'name' => 'name', 'label' => Mage::helper('tag')->__('Tag Name'), 'title' => Mage::helper('tag')->__('Tag Name'), 'required' => true, )); - $fieldset->addField('status', 'select', array( + $fieldset->addField('status', 'select', array( 'label' => Mage::helper('tag')->__('Status'), 'title' => Mage::helper('tag')->__('Status'), 'name' => 'status', diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Grid.php index 4ff434e464..66f7ac9274 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Grid.php @@ -40,6 +40,17 @@ public function __construct() $this->setId('tag_tag_grid'); $this->setDefaultSort('name'); $this->setDefaultDir('ASC'); + $this->setUseAjax(true); + } + + /* + * Retrieves Grid Url + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl('*/tag/ajaxGrid'); } protected function _prepareCollection() @@ -97,7 +108,7 @@ protected function _prepareColumns() 'width' => '90px', 'index' => 'status', 'type' => 'options', - 'options' => $this->helper('tag/data')->getStatusesArray(), + 'options' => $this->helper('tag/data')->getStatusesArray(), )); if (!Mage::app()->isSingleStoreMode()) { @@ -111,30 +122,6 @@ protected function _prepareColumns() )); } - $this->addColumn('actions', array( - 'header' => Mage::helper('tag')->__('Actions'), - 'width' => '100px', - 'type' => 'action', - 'getter' => 'getId', - 'sortable' => false, - 'filter' => false, - 'actions' => array( - array( - 'caption' => Mage::helper('tag')->__('Edit Tag'), - 'url' => $this->getUrl('*/*/edit', array('ret' => 'all', 'tag_id'=>'$tag_id')), - ), - array( - 'caption' => Mage::helper('tag')->__('View Products'), - 'url' => $this->getUrl('*/*/product', array('ret' => 'all', 'tag_id'=>'$tag_id')), - ), - - array( - 'caption' => Mage::helper('tag')->__('View Customers'), - 'url' => $this->getUrl('*/*/customer', array('ret' => 'all', 'tag_id'=>'$tag_id')), - ) - ), - )); - return parent::_prepareColumns(); } @@ -148,11 +135,11 @@ public function getRowUrl($row) protected function _addColumnFilterToCollection($column) { - if($column->getIndex()=='stores') { - $this->getCollection()->addStoreFilter($column->getFilter()->getCondition(), false); - } else { - parent::_addColumnFilterToCollection($column); - } + if($column->getIndex()=='stores') { + $this->getCollection()->addStoreFilter($column->getFilter()->getCondition(), false); + } else { + parent::_addColumnFilterToCollection($column); + } return $this; } diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php index b6e5d0c5fc..dc4585f351 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php @@ -144,6 +144,7 @@ protected function _prepareForm() array( 'name' => 'tax_postcode', 'label' => Mage::helper('tax')->__('Zip/Post Code'), + 'note' => Mage::helper('tax')->__("'*' - matches any; 'xyz*' - matches any that begins on 'xyz' and not longer than %d; '9001-9099' - matches range.", Mage::helper('tax')->getPostCodeSubStringLength()), 'value' => $postcode ) ); diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit.php index 3da022d676..fe98fa3c67 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit.php @@ -47,6 +47,14 @@ public function __construct() $this->_updateButton('save', 'label', Mage::helper('tax')->__('Save Rule')); $this->_updateButton('delete', 'label', Mage::helper('tax')->__('Delete Rule')); + + $this->_addButton('save_and_continue', array( + 'label' => Mage::helper('tax')->__('Save And Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save' + ), 10); + + $this->_formScripts[] = " function saveAndContinueEdit(){ editForm.submit($('edit_form').action + 'back/edit/') } "; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Widget.php b/app/code/core/Mage/Adminhtml/Block/Widget.php index a5e8ce1f39..f855325f4d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget.php @@ -46,9 +46,18 @@ public function getHtmlId() return $this->getId(); } - public function getCurrentUrl($params=array()) + /** + * Get current url + * + * @param array $params url parameters + * @return string current url + */ + public function getCurrentUrl($params = array()) { - return $this->getUrl('*/*/*', array('_current'=>true)); + if (!isset($params['_current'])) { + $params['_current'] = true; + } + return $this->getUrl('*/*/*', $params); } protected function _addBreadcrumb($label, $title=null, $link=null) diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Button.php b/app/code/core/Mage/Adminhtml/Block/Widget/Button.php index 772cc66581..7e314c7227 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Button.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Button.php @@ -55,7 +55,7 @@ protected function _toHtml() { $html = $this->getBeforeHtml().'