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/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/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/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/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/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/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( ''; diff --git a/app/code/core/Mage/Core/Block/Messages.php b/app/code/core/Mage/Core/Block/Messages.php index 732fd6020f..51657b7be0 100644 --- a/app/code/core/Mage/Core/Block/Messages.php +++ b/app/code/core/Mage/Core/Block/Messages.php @@ -40,13 +40,30 @@ class Mage_Core_Block_Messages extends Mage_Core_Block_Template */ protected $_messages; + /** + * Flag which require message text escape + * + * @var bool + */ + protected $_escapeMessageFlag = false; + public function _prepareLayout() { $this->addMessages(Mage::getSingleton('core/session')->getMessages(true)); - parent::_prepareLayout(); } + /** + * Set message escape flag + * @param bool $flag + * @return Mage_Core_Block_Messages + */ + public function setEscapeMessageFlag($flag) + { + $this->_escapeMessageFlag = $flag; + return $this; + } + /** * Set messages collection * @@ -59,6 +76,12 @@ public function setMessages(Mage_Core_Model_Message_Collection $messages) return $this; } + /** + * Add messages to display + * + * @param Mage_Core_Model_Message_Collection $messages + * @return Mage_Core_Block_Messages + */ public function addMessages(Mage_Core_Model_Message_Collection $messages) { foreach ($messages->getItems() as $message) { @@ -161,7 +184,9 @@ public function getHtml($type=null) { $html = '
    '; foreach ($this->getMessages($type) as $message) { - $html.= '
  • '.$message->getText().'
  • '; + $html.= '
  • ' + . ($this->_escapeMessageFlag) ? $this->htmlEscape($message->getText()) : $message->getText() + . '
  • '; } $html .= '
'; return $html; @@ -192,7 +217,7 @@ public function getGroupedHtml() foreach ( $messages as $message ) { $html.= '
  • '; - $html.= $message->getText(); + $html.= ($this->_escapeMessageFlag) ? $this->htmlEscape($message->getText()) : $message->getText(); $html.= '
  • '; } $html .= ''; diff --git a/app/code/core/Mage/Core/Block/Template.php b/app/code/core/Mage/Core/Block/Template.php index 6421d66b1f..65086f8f0f 100644 --- a/app/code/core/Mage/Core/Block/Template.php +++ b/app/code/core/Mage/Core/Block/Template.php @@ -56,9 +56,53 @@ class Mage_Core_Block_Template extends Mage_Core_Block_Abstract protected static $_showTemplateHints; protected static $_showTemplateHintsBlocks; + /** + * Path to template file in theme. + * + * @var string + */ + protected $_template; + + /** + * Internal constructor, that is called from real constructor + * + */ + protected function _construct() + { + parent::_construct(); + + /* + * In case template was passed through constructor + * we assign it to block's property _template + * Mainly for those cases when block created + * not via Mage_Core_Model_Layout::addBlock() + */ + if ($this->hasData('template')) { + $this->setTemplate($this->getData('template')); + } + } + + /** + * Retrieve path to template used for generating block's output. + * + * @return string + */ public function getTemplate() { - return $this->_getData('template'); + return $this->_template; + } + + /** + * Set path to template used for generating block's output. + * + * @param string $template + * @return Mage_Core_Block_Template + */ + public function setTemplate($template) + { + $this->_template = $template; + + return $this; } public function getArea() diff --git a/app/code/core/Mage/Core/Controller/Front/Action.php b/app/code/core/Mage/Core/Controller/Front/Action.php index 81a36e3f7b..9d5aff916e 100644 --- a/app/code/core/Mage/Core/Controller/Front/Action.php +++ b/app/code/core/Mage/Core/Controller/Front/Action.php @@ -33,6 +33,20 @@ */ class Mage_Core_Controller_Front_Action extends Mage_Core_Controller_Varien_Action { + /** + * Currently used area + * + * @var string + */ + protected $_currentArea = 'frontend'; + + /** + * Namespace for session. + * + * @var string + */ + protected $_sessionNamespace = 'frontend'; + /** * Predispatch: shoud set layout area * @@ -40,7 +54,7 @@ class Mage_Core_Controller_Front_Action extends Mage_Core_Controller_Varien_Acti */ public function preDispatch() { - $this->getLayout()->setArea('frontend'); + $this->getLayout()->setArea($this->_currentArea); parent::preDispatch(); return $this; diff --git a/app/code/core/Mage/Core/Controller/Request/Http.php b/app/code/core/Mage/Core/Controller/Request/Http.php index 269151b7cf..ef29372fba 100644 --- a/app/code/core/Mage/Core/Controller/Request/Http.php +++ b/app/code/core/Mage/Core/Controller/Request/Http.php @@ -57,6 +57,13 @@ class Mage_Core_Controller_Request_Http extends Zend_Controller_Request_Http protected $_directFrontNames = array(); protected $_controllerModule = null; + /** + * Request's original information before forward. + * + * @var array + */ + protected $_beforeForwardInfo = array(); + public function __construct($uri = null) { parent::__construct($uri); @@ -391,4 +398,43 @@ public function getRequestedActionName() } return $this->getActionName(); } + + /** + * Collect properties changed by _forward in protected storage + * before _forward was called first time. + * + * @return Mage_Core_Controller_Varien_Action + */ + public function initForward() + { + if (empty($this->_beforeForwardInfo)) { + $this->_beforeForwardInfo = array( + 'params' => $this->getParams(), + 'action_name' => $this->getActionName(), + 'controller_name' => $this->getControllerName(), + 'module_name' => $this->getModuleName() + ); + } + + return $this; + } + + /** + * Retrieve property's value which was before _forward call. + * If property was not changed during _forward call null will be returned. + * If passed name will be null whole state array will be returned. + * + * @param string $name + * @return array|string|null + */ + public function getBeforeForwardInfo($name = null) + { + if (is_null($name)) { + return $this->_beforeForwardInfo; + } elseif (isset($this->_beforeForwardInfo[$name])) { + return $this->_beforeForwardInfo[$name]; + } + + return null; + } } \ No newline at end of file diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php index e3ec66df0d..5b12422e7f 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Action.php +++ b/app/code/core/Mage/Core/Controller/Varien/Action.php @@ -89,6 +89,21 @@ abstract class Mage_Core_Controller_Varien_Action */ protected $_cookieCheckActions = array(); + /** + * Currently used area + * + * @var string + */ + protected $_currentArea; + + /** + * Namespace for session. + * Should be defined for proper working session. + * + * @var string + */ + protected $_sessionNamespace; + /** * Constructor * @@ -432,14 +447,13 @@ public function preDispatch() } if (!$this->getFlag('', self::FLAG_NO_START_SESSION)) { - $namespace = $this->getLayout()->getArea(); $checkCookie = in_array($this->getRequest()->getActionName(), $this->_cookieCheckActions); $checkCookie = $checkCookie && !$this->getRequest()->getParam('nocookie', false); $cookies = Mage::getSingleton('core/cookie')->get(); if ($checkCookie && empty($cookies)) { $this->setFlag('', self::FLAG_NO_COOKIES_REDIRECT, true); } - Mage::getSingleton('core/session', array('name' => $namespace))->start(); + Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start(); } Mage::app()->loadArea($this->getLayout()->getArea()); @@ -530,10 +544,20 @@ public function noCookiesAction() $this->getRequest()->setDispatched(true); } + /** + * Throw control to different action (control and module if was specified). + * + * @param string $action + * @param string|null $controller + * @param string|null $module + * @param string|null $params + */ protected function _forward($action, $controller = null, $module = null, array $params = null) { $request = $this->getRequest(); + $request->initForward(); + if (!is_null($params)) { $request->setParams($params); } @@ -555,6 +579,9 @@ protected function _initLayoutMessages($messagesStorage) { if ($storage = Mage::getSingleton($messagesStorage)) { $this->getLayout()->getMessagesBlock()->addMessages($storage->getMessages(true)); + $this->getLayout()->getMessagesBlock()->setEscapeMessageFlag( + $storage->getEscapeMessages(true) + ); } else { Mage::throwException( @@ -577,7 +604,7 @@ protected function _redirectUrl($url) } /** - * Set redirect into responce + * Set redirect into response * * @param string $path * @param array $arguments diff --git a/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php b/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php index 917dd09225..1eea173cd4 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php +++ b/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php @@ -104,7 +104,7 @@ protected function _afterModuleMatch() public function match(Zend_Controller_Request_Http $request) { - //checkings before even try to findout that current module + //checking before even try to find out that current module //should use this router if (!$this->_beforeModuleMatch()) { return false; @@ -198,7 +198,7 @@ public function match(Zend_Controller_Request_Http $request) } // instantiate controller class - $controllerInstance = new $controllerClassName($request, $front->getResponse()); + $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse()); if (!$controllerInstance->hasAction($action)) { continue; @@ -222,7 +222,7 @@ public function match(Zend_Controller_Request_Http $request) } // instantiate controller class - $controllerInstance = Mage::getControllerInstance($request, $front->getResponse()); + $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse()); if (!$controllerInstance->hasAction($action)) { return false; @@ -251,7 +251,7 @@ public function match(Zend_Controller_Request_Http $request) } /** - * Allow to control if we need to enable norout functionality in current router + * Allow to control if we need to enable no route functionality in current router * * @return bool */ diff --git a/app/code/core/Mage/Core/Helper/String.php b/app/code/core/Mage/Core/Helper/String.php index 5a64ae7fb4..03780a5d2e 100644 --- a/app/code/core/Mage/Core/Helper/String.php +++ b/app/code/core/Mage/Core/Helper/String.php @@ -51,20 +51,20 @@ public function truncate($string, $length = 80, $etc = '...', &$remainder = '', return ''; } - $originalLength = iconv_strlen($string, self::ICONV_CHARSET); + $originalLength = $this->strlen($string); if ($originalLength > $length) { - $length -= iconv_strlen($etc, self::ICONV_CHARSET); + $length -= $this->strlen($etc); if ($length <= 0) { return ''; } $preparedString = $string; $preparedlength = $length; if (!$breakWords) { - $preparedString = preg_replace('/\s+?(\S+)?$/', '', iconv_substr($string, 0, $length + 1, self::ICONV_CHARSET)); - $preparedlength = iconv_strlen($preparedString, self::ICONV_CHARSET); + $preparedString = preg_replace('/\s+?(\S+)?$/', '', $this->substr($string, 0, $length + 1)); + $preparedlength = $this->strlen($preparedString); } - $remainder = iconv_substr($string, $preparedlength, $originalLength, self::ICONV_CHARSET); - return iconv_substr($preparedString, 0, $length, self::ICONV_CHARSET) . $etc; + $remainder = $this->substr($string, $preparedlength, $originalLength); + return $this->substr($preparedString, 0, $length) . $etc; } return $string; @@ -92,7 +92,7 @@ public function strlen($str) public function substr($str, $offset, $length = null) { if (is_null($length)) { - $length = iconv_strlen($str, self::ICONV_CHARSET) - $offset; + $length = $this->strlen($str) - $offset; } return iconv_substr($str, $offset, $length, self::ICONV_CHARSET); } @@ -112,10 +112,10 @@ public function splitInjection($str, $length = 50, $needle = '-', $insert = ' ') $newStr = ''; foreach ($str as $part) { if ($this->strlen($part) >= $length) { - $lastDelimetr = iconv_strpos(strrev($part), $needle, null, self::ICONV_CHARSET); + $lastDelimetr = iconv_strpos($this->strrev($part), $needle, null, self::ICONV_CHARSET); $tmpNewStr = ''; - $tmpNewStr = $this->substr(strrev($part), 0, $lastDelimetr) . $insert . $this->substr(strrev($part), $lastDelimetr); - $newStr .= strrev($tmpNewStr); + $tmpNewStr = $this->substr($this->strrev($part), 0, $lastDelimetr) . $insert . $this->substr($this->strrev($part), $lastDelimetr); + $newStr .= $this->strrev($tmpNewStr); } else { $newStr .= $part; } @@ -137,7 +137,7 @@ public function strrev($str) return $result; } for ($i = $strlen-1; $i >= 0; $i--) { - $result .= iconv_substr($str, $i, 1, self::ICONV_CHARSET); + $result .= $this->substr($str, $i, 1); } return $result; } @@ -169,7 +169,7 @@ public function str_split($str, $length = 1, $keepWords = false, $trim = false, // do a usual str_split, but safe for our encoding if ((!$keepWords) || ($length < 2)) { for ($offset = 0; $offset < $strlen; $offset += $length) { - $result[] = iconv_substr($str, $offset, $length, self::ICONV_CHARSET); + $result[] = $this->substr($str, $offset, $length); } } // split smartly, keeping words @@ -194,9 +194,9 @@ public function str_split($str, $length = 1, $keepWords = false, $trim = false, $spaceLen = 0; } else { - $currentLength = iconv_strlen($result[$i], self::ICONV_CHARSET); + $currentLength = $this->strlen($result[$i]); } - $partLength = iconv_strlen($part, self::ICONV_CHARSET); + $partLength = $this->strlen($part); // add part to current last element if (($currentLength + $spaceLen + $partLength) <= $length) { $result[$i] .= $space . $part; @@ -217,12 +217,12 @@ public function str_split($str, $length = 1, $keepWords = false, $trim = false, } // remove last element, if empty if ($count = count($result)) { - if (empty($result[$count - 1])) { + if ($result[$count - 1] === '') { unset($result[$count - 1]); } } // remove first element, if empty - if (isset($result[0]) && empty($result[0])) { + if (isset($result[0]) && $result[0] === '') { array_shift($result); } return $result; @@ -233,11 +233,11 @@ public function str_split($str, $length = 1, $keepWords = false, $trim = false, * * @param string $str The source string * @param bool $uniqueOnly Unique words only - * @param int $maxWordLenght Limit words count + * @param int $maxWordLength Limit words count * @param string $wordSeparatorRegexp * @return array */ - function splitWords($str, $uniqueOnly = false, $maxWordLenght = 0, $wordSeparatorRegexp = '\s') + function splitWords($str, $uniqueOnly = false, $maxWordLength = 0, $wordSeparatorRegexp = '\s') { $result = array(); $split = preg_split('#' . $wordSeparatorRegexp . '#si', $str, null, PREG_SPLIT_NO_EMPTY); @@ -249,8 +249,8 @@ function splitWords($str, $uniqueOnly = false, $maxWordLenght = 0, $wordSeparato $result[] = $word; } } - if ($maxWordLenght && count($result) > $maxWordLenght) { - $result = array_slice($result, 0, $maxWordLenght); + if ($maxWordLength && count($result) > $maxWordLength) { + $result = array_slice($result, 0, $maxWordLength); } return $result; } diff --git a/app/code/core/Mage/Core/Model/Abstract.php b/app/code/core/Mage/Core/Model/Abstract.php index 40e9e6084e..80e5b1d94f 100644 --- a/app/code/core/Mage/Core/Model/Abstract.php +++ b/app/code/core/Mage/Core/Model/Abstract.php @@ -89,6 +89,13 @@ abstract class Mage_Core_Model_Abstract extends Varien_Object */ protected $_dataSaveAllowed = true; + /** + * Flag which allow detect object state: is it new object (without id) or existing one (with id) + * + * @var bool + */ + protected $_isObjectNew = null; + /** * Standard model initialization * @@ -244,7 +251,14 @@ public function afterLoad() */ public function save() { + /** + * Direct deleted items to delete method + */ + if ($this->isDeleted()) { + return $this->delete(); + } $this->_getResource()->beginTransaction(); + $dataCommited = false; try { $this->_beforeSave(); if ($this->_dataSaveAllowed) { @@ -252,14 +266,49 @@ public function save() $this->_afterSave(); } $this->_getResource()->commit(); - } - catch (Exception $e){ + $dataCommited = true; + } catch (Exception $e) { $this->_getResource()->rollBack(); throw $e; } + if ($dataCommited) { + $this->_afterSaveCommit(); + } return $this; } + /** + * Processing data save after main transaction commit + * + * @return Mage_Core_Model_Abstract + */ + protected function _afterSaveCommit() + { + Mage::dispatchEvent('model_save_commit_after', array('object'=>$this)); + Mage::dispatchEvent($this->_eventPrefix.'_save_commit_after', array($this->_eventObject=>$this)); + return $this; + } + + /** + * Check object state (true - if it is object without id on object just created) + * This method can help detect if object just created in _afterSave method + * problem is what in after save onject has id and we can't detect what object was + * created in this transaction + * + * @param bool $flag + * @return bool + */ + public function isObjectNew($flag=null) + { + if ($flag !== null) { + $this->_isObjectNew = $flag; + } + if ($this->_isObjectNew !== null) { + return $this->_isObjectNew; + } + return !(bool)$this->getId(); + } + /** * Processing object before save data * @@ -267,6 +316,9 @@ public function save() */ protected function _beforeSave() { + if (!$this->getId()) { + $this->isObjectNew(true); + } Mage::dispatchEvent('model_save_before', array('object'=>$this)); Mage::dispatchEvent($this->_eventPrefix.'_save_before', array($this->_eventObject=>$this)); return $this; @@ -282,8 +334,9 @@ protected function _afterSave() if ($this->_cacheTag) { if ($this->_cacheTag === true) { $tags = array(); - } - else { + } elseif (is_array($this->_cacheTag)) { + $tags = $this->_cacheTag; + } else { $tags = array($this->_cacheTag); } Mage::app()->cleanCache($tags); @@ -307,6 +360,7 @@ public function delete() $this->_afterDelete(); $this->_getResource()->commit(); + $this->_afterDeleteCommit(); } catch (Exception $e){ $this->_getResource()->rollBack(); @@ -363,6 +417,18 @@ protected function _afterDelete() return $this; } + /** + * Processing manipulation after main transaction commit + * + * @return Mage_Core_Model_Abstract + */ + protected function _afterDeleteCommit() + { + Mage::dispatchEvent('model_delete_commit_after', array('object'=>$this)); + Mage::dispatchEvent($this->_eventPrefix.'_delete_commit_after', array($this->_eventObject=>$this)); + return $this; + } + /** * Retrieve model resource * diff --git a/app/code/core/Mage/Core/Model/App.php b/app/code/core/Mage/Core/Model/App.php index a4f9c4004e..d4a7d6ebee 100644 --- a/app/code/core/Mage/Core/Model/App.php +++ b/app/code/core/Mage/Core/Model/App.php @@ -1197,10 +1197,10 @@ public function dispatchEvent($eventName, $args) $observers = array(); foreach ($eventConfig->observers->children() as $obsName=>$obsConfig) { $observers[$obsName] = array( - 'type' => $obsConfig->type ? (string)$obsConfig->type : 'singleton', + 'type' => (string)$obsConfig->type, 'model' => $obsConfig->class ? (string)$obsConfig->class : $obsConfig->getClassName(), - 'method' => (string)$obsConfig->method, - 'args' => (array)$obsConfig->args, + 'method'=> (string)$obsConfig->method, + 'args' => (array)$obsConfig->args, ); } $events[$eventName]['observers'] = $observers; @@ -1218,17 +1218,16 @@ public function dispatchEvent($eventName, $args) $observer->setData(array('event'=>$event)); Varien_Profiler::start('OBSERVER: '.$obsName); switch ($obs['type']) { - case 'singleton': + case 'object': case 'model': $method = $obs['method']; $observer->addData($args); - $object = Mage::getSingleton($obs['model']); + $object = Mage::getModel($obs['model']); $object->$method($observer); break; - - case 'object': case 'model': + default: $method = $obs['method']; $observer->addData($args); - $object = Mage::getModel($obs['model']); + $object = Mage::getSingleton($obs['model']); $object->$method($observer); break; } diff --git a/app/code/core/Mage/Core/Model/Config.php b/app/code/core/Mage/Core/Model/Config.php index d23e252a1a..7c80eef899 100644 --- a/app/code/core/Mage/Core/Model/Config.php +++ b/app/code/core/Mage/Core/Model/Config.php @@ -310,7 +310,7 @@ protected function _canUseLocalModules() $disableLocalModules = false; } - if ($disableLocalModules) { + if ($disableLocalModules && !defined('COMPILER_INCLUDE_PATH')) { set_include_path( // excluded '/app/code/local' BP . DS . 'app' . DS . 'code' . DS . 'community' . PS . @@ -1141,10 +1141,12 @@ public function getResourceConnectionConfig($name) $config = $this->getResourceConfig($name); if ($config) { $conn = $config->connection; - if (!empty($conn->use)) { - return $this->getResourceConnectionConfig((string)$conn->use); - } else { - return $conn; + if ($conn) { + if (!empty($conn->use)) { + return $this->getResourceConnectionConfig((string)$conn->use); + } else { + return $conn; + } } } return false; diff --git a/app/code/core/Mage/Core/Model/Config/Data.php b/app/code/core/Mage/Core/Model/Config/Data.php index 2df0086840..b08369d787 100644 --- a/app/code/core/Mage/Core/Model/Config/Data.php +++ b/app/code/core/Mage/Core/Model/Config/Data.php @@ -33,6 +33,22 @@ */ class Mage_Core_Model_Config_Data extends Mage_Core_Model_Abstract { + const ENTITY = 'core_config_data'; + /** + * Prefix of model events names + * + * @var string + */ + protected $_eventPrefix = 'core_config_data'; + + /** + * Parameter name in event + * + * In observe method you can use $observer->getEvent()->getObject() in this case + * + * @var string + */ + protected $_eventObject = 'config_data'; /** * Varien model constructor diff --git a/app/code/core/Mage/Core/Model/Config/Element.php b/app/code/core/Mage/Core/Model/Config/Element.php index 0bf57663d3..b61339e0ed 100644 --- a/app/code/core/Mage/Core/Model/Config/Element.php +++ b/app/code/core/Mage/Core/Model/Config/Element.php @@ -41,20 +41,20 @@ class Mage_Core_Model_Config_Element extends Varien_Simplexml_Element * @param boolean $value * @return boolean */ - public function is($var, $value=true) + public function is($var, $value = true) { $flag = $this->$var; - if ($value===true) { + if ($value === true) { $flag = strtolower((string)$flag); - if (!empty($flag) && 'false'!==$flag && '0'!==$flag && 'off'!==$flag) { + if (!empty($flag) && 'false' !== $flag && 'off' !== $flag) { return true; } else { return false; } } - return !empty($flag) && (0===strcasecmp($value, (string)$flag)); + return !empty($flag) && (0 === strcasecmp($value, (string)$flag)); } /** diff --git a/app/code/core/Mage/Core/Model/Config/Options.php b/app/code/core/Mage/Core/Model/Config/Options.php index 766b11b620..84cf952648 100644 --- a/app/code/core/Mage/Core/Model/Config/Options.php +++ b/app/code/core/Mage/Core/Model/Config/Options.php @@ -68,7 +68,6 @@ protected function _construct() public function getDir($type) { - $this->_construct(); $method = 'get'.ucwords($type).'Dir'; $dir = $this->$method(); if (!$dir) { diff --git a/app/code/core/Mage/Core/Model/Cookie.php b/app/code/core/Mage/Core/Model/Cookie.php index 8129085435..14d311d0f2 100644 --- a/app/code/core/Mage/Core/Model/Cookie.php +++ b/app/code/core/Mage/Core/Model/Cookie.php @@ -100,13 +100,23 @@ protected function _getResponse() */ public function getDomain() { - $domain = Mage::getStoreConfig(self::XML_PATH_COOKIE_DOMAIN, $this->getStore()); + $domain = $this->getConfigDomain(); if (empty($domain)) { $domain = $this->_getRequest()->getHttpHost(); } return $domain; } + /** + * Retrieve Config Domain for cookie + * + * @return string + */ + public function getConfigDomain() + { + return (string)Mage::getStoreConfig(self::XML_PATH_COOKIE_DOMAIN, $this->getStore()); + } + /** * Retrieve Path for cookie * @@ -128,10 +138,9 @@ public function getPath() */ public function getLifetime() { - if (null !== $this->_lifetime) { + if (!is_null($this->_lifetime)) { $lifetime = $this->_lifetime; - } - else { + } else { $lifetime = Mage::getStoreConfig(self::XML_PATH_COOKIE_LIFETIME, $this->getStore()); } if (!is_numeric($lifetime)) { diff --git a/app/code/core/Mage/Core/Model/Design/Source/Design.php b/app/code/core/Mage/Core/Model/Design/Source/Design.php index 954e47911b..fd920f911f 100644 --- a/app/code/core/Mage/Core/Model/Design/Source/Design.php +++ b/app/code/core/Mage/Core/Model/Design/Source/Design.php @@ -27,28 +27,62 @@ class Mage_Core_Model_Design_Source_Design extends Mage_Eav_Model_Entity_Attribute_Source_Abstract { + protected $_isFullLabel = false; + + /** + * Setter + * Add package name to label + * + * @param boolean $isFullLabel + * @return Mage_Core_Model_Design_Source_Design + */ + public function setIsFulllabel($isFullLabel) + { + $this->_isFullLabel = $isFullLabel; + return $this; + } + + /** + * Getter + * + * @return boolean + */ + public function getIsFullLabel() + { + return $this->_isFullLabel; + } + + /** + * Retrieve All Design Theme Options + * + * @param bool $withEmpty add empty (please select) values to result + * @return array + */ public function getAllOptions($withEmpty = true) { if (is_null($this->_options)) { $design = Mage::getModel('core/design_package')->getThemeList(); $options = array(); - foreach ($design as $package=>$themes){ - $packageOption = array('label'=>$package); + foreach ($design as $package => $themes){ + $packageOption = array('label' => $package); $themeOptions = array(); foreach ($themes as $theme) { - $themeOptions[] = array('label'=>$theme, 'value'=>$package . '/' . $theme); + $themeOptions[] = array( + 'label' => ($this->getIsFullLabel() ? $package . ' / ' : '') . $theme, + 'value' => $package . '/' . $theme + ); } - $packageOption['value'] = $themeOptions; - $options[] = $packageOption; } $this->_options = $options; } - $options = $this->_options; if ($withEmpty) { - array_unshift($options, array('value'=>'', 'label'=>Mage::helper('core')->__('-- Please Select --'))); + array_unshift($options, array( + 'value'=>'', + 'label'=>Mage::helper('core')->__('-- Please Select --')) + ); } return $options; } diff --git a/app/code/core/Mage/Core/Model/Email/Template.php b/app/code/core/Mage/Core/Model/Email/Template.php index 86776fbfc2..659ae977bf 100644 --- a/app/code/core/Mage/Core/Model/Email/Template.php +++ b/app/code/core/Mage/Core/Model/Email/Template.php @@ -54,7 +54,8 @@ class Mage_Core_Model_Email_Template extends Varien_Object * Configuration path for default email templates * */ - const XML_PATH_TEMPLATE_EMAIL = 'global/template/email'; + const XML_PATH_TEMPLATE_EMAIL = 'global/template/email'; + const XML_PATH_SENDING_SET_RETURN_PATH = 'system/smtp/set_return_path'; protected $_templateFilter; protected $_preprocessFlag = false; @@ -315,9 +316,9 @@ public function getInclude($template, array $variables) * @param array $variables template variables * @return boolean **/ - public function send($email, $name=null, array $variables = array()) + public function send($email, $name = null, array $variables = array()) { - if(!$this->isValidForSend()) { + if (!$this->isValidForSend()) { return false; } @@ -332,6 +333,11 @@ public function send($email, $name=null, array $variables = array()) ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port')); $mail = $this->getMail(); + + if (Mage::getStoreConfigFlag(self::XML_PATH_SENDING_SET_RETURN_PATH)) { + $mail->setReturnPath($this->getSenderEmail()); + } + if (is_array($email)) { foreach ($email as $emailOne) { $mail->addTo($emailOne, $name); diff --git a/app/code/core/Mage/Core/Model/Email/Template/Filter.php b/app/code/core/Mage/Core/Model/Email/Template/Filter.php index 952a929856..acc4599f52 100644 --- a/app/code/core/Mage/Core/Model/Email/Template/Filter.php +++ b/app/code/core/Mage/Core/Model/Email/Template/Filter.php @@ -113,16 +113,20 @@ public function blockDirective($construction) } elseif (isset($blockParameters['id'])) { $block = $layout->createBlock('cms/block'); if ($block) { - $block->setBlockId($blockParameters['id']) - ->setBlockParams($blockParameters); - foreach ($blockParameters as $k => $v) { - if (in_array($k, $skipParams)) { - continue; - } - $block->setDataUsingMethod($k, $v); + $block->setBlockId($blockParameters['id']); + } + } + + if ($block) { + $block->setBlockParams($blockParameters); + foreach ($blockParameters as $k => $v) { + if (in_array($k, $skipParams)) { + continue; } + $block->setDataUsingMethod($k, $v); } } + if (!$block) { return ''; } diff --git a/app/code/core/Mage/Core/Model/Layout.php b/app/code/core/Mage/Core/Model/Layout.php index 2f38aa4af6..9ee4bc554e 100644 --- a/app/code/core/Mage/Core/Model/Layout.php +++ b/app/code/core/Mage/Core/Model/Layout.php @@ -368,7 +368,7 @@ protected function _translateLayoutNode($node, &$args) $args[$arg] = Mage::helper((string)$node['module'])->__($args[$arg]); } else { - $args[$arg] = __($args[$arg]); + $args[$arg] = Mage::helper('core')->__($args[$arg]); } } } diff --git a/app/code/core/Mage/Core/Model/Layout/Update.php b/app/code/core/Mage/Core/Model/Layout/Update.php index f772ced03a..68abaddefc 100644 --- a/app/code/core/Mage/Core/Model/Layout/Update.php +++ b/app/code/core/Mage/Core/Model/Layout/Update.php @@ -243,71 +243,97 @@ public function asSimplexml() */ public function merge($handle) { - if (!$this->fetchPackageLayoutUpdates($handle) - && !$this->fetchDbLayoutUpdates($handle)) { - #$this->removeHandle($handle); + $packageUpdatesStatus = $this->fetchPackageLayoutUpdates($handle); + if (Mage::app()->isInstalled()) { + $this->fetchDbLayoutUpdates($handle); } +// if (!$this->fetchPackageLayoutUpdates($handle) +// && !$this->fetchDbLayoutUpdates($handle)) { +// #$this->removeHandle($handle); +// } return $this; } public function fetchFileLayoutUpdates() { + $storeId = Mage::app()->getStore()->getId(); $elementClass = $this->getElementClass(); - $design = Mage::getSingleton('core/design_package'); - $area = $design->getArea(); - $storeId = Mage::app()->getStore()->getId(); - $cacheKey = 'LAYOUT_'.$area.'_STORE'.$storeId.'_'.$design->getPackageName().'_'.$design->getTheme('layout'); -#echo "TEST:".$cacheKey; + $cacheKey = 'LAYOUT_'.$design->getArea().'_STORE'.$storeId.'_'.$design->getPackageName().'_'.$design->getTheme('layout'); $cacheTags = array('layout'); - if (Mage::app()->useCache('layout') && ($layoutStr = Mage::app()->loadCache($cacheKey))) { $this->_packageLayout = simplexml_load_string($layoutStr, $elementClass); } - if (empty($layoutStr)) { - $updatesRoot = Mage::app()->getConfig()->getNode($area.'/layout/updates'); - Mage::dispatchEvent('core_layout_update_updates_get_after', array('updates' => $updatesRoot)); - $updateFiles = array(); - foreach ($updatesRoot->children() as $updateNode) { - if ($updateNode->file) { - $module = $updateNode->getAttribute('module'); - if ($module && Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $module)) { - continue; - } - $updateFiles[] = (string)$updateNode->file; - } - } - - // custom local layout updates file - load always last - $updateFiles[] = 'local.xml'; - - $layoutStr = ''; - #$layoutXml = new $elementClass(''); - foreach ($updateFiles as $file) { - $filename = $design->getLayoutFilename($file); - if (!is_readable($filename)) { - continue; - } - $fileStr = file_get_contents($filename); - $fileStr = str_replace($this->_subst['from'], $this->_subst['to'], $fileStr); - $fileXml = simplexml_load_string($fileStr, $elementClass); - if (!$fileXml instanceof SimpleXMLElement) { - continue; - } - $layoutStr .= $fileXml->innerXml(); - - #$layoutXml->appendChild($fileXml); - } - $layoutXml = simplexml_load_string(''.$layoutStr.'', $elementClass); - - $this->_packageLayout = $layoutXml; - + $this->_packageLayout = $this->getFileLayoutUpdatesXml( + $design->getArea(), + $design->getPackageName(), + $design->getTheme('layout'), + $storeId + ); if (Mage::app()->useCache('layout')) { Mage::app()->saveCache($this->_packageLayout->asXml(), $cacheKey, $cacheTags, null); } } + + +// $elementClass = $this->getElementClass(); +// +// $design = Mage::getSingleton('core/design_package'); +// $area = $design->getArea(); +// $storeId = Mage::app()->getStore()->getId(); +// $cacheKey = 'LAYOUT_'.$area.'_STORE'.$storeId.'_'.$design->getPackageName().'_'.$design->getTheme('layout'); +//#echo "TEST:".$cacheKey; +// $cacheTags = array('layout'); +// +// if (Mage::app()->useCache('layout') && ($layoutStr = Mage::app()->loadCache($cacheKey))) { +// $this->_packageLayout = simplexml_load_string($layoutStr, $elementClass); +// } +// +// if (empty($layoutStr)) { +// $updatesRoot = Mage::app()->getConfig()->getNode($area.'/layout/updates'); +// Mage::dispatchEvent('core_layout_update_updates_get_after', array('updates' => $updatesRoot)); +// $updateFiles = array(); +// foreach ($updatesRoot->children() as $updateNode) { +// if ($updateNode->file) { +// $module = $updateNode->getAttribute('module'); +// if ($module && Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $module)) { +// continue; +// } +// $updateFiles[] = (string)$updateNode->file; +// } +// } +// +// // custom local layout updates file - load always last +// $updateFiles[] = 'local.xml'; +// +// $layoutStr = ''; +// #$layoutXml = new $elementClass(''); +// foreach ($updateFiles as $file) { +// $filename = $design->getLayoutFilename($file); +// if (!is_readable($filename)) { +// continue; +// } +// $fileStr = file_get_contents($filename); +// $fileStr = str_replace($this->_subst['from'], $this->_subst['to'], $fileStr); +// $fileXml = simplexml_load_string($fileStr, $elementClass); +// if (!$fileXml instanceof SimpleXMLElement) { +// continue; +// } +// $layoutStr .= $fileXml->innerXml(); +// +// #$layoutXml->appendChild($fileXml); +// } +// $layoutXml = simplexml_load_string(''.$layoutStr.'', $elementClass); +// +// $this->_packageLayout = $layoutXml; +// +// if (Mage::app()->useCache('layout')) { +// Mage::app()->saveCache($this->_packageLayout->asXml(), $cacheKey, $cacheTags, null); +// } +// } + return $this; } @@ -315,17 +341,14 @@ public function fetchPackageLayoutUpdates($handle) { $_profilerKey = 'layout/package_update: '.$handle; Varien_Profiler::start($_profilerKey); - if (empty($this->_packageLayout)) { $this->fetchFileLayoutUpdates(); } foreach ($this->_packageLayout->$handle as $updateXml) { #echo ''; $this->fetchRecursiveUpdates($updateXml); - $this->addUpdate($updateXml->innerXml()); } - Varien_Profiler::stop($_profilerKey); return true; @@ -335,22 +358,15 @@ public function fetchDbLayoutUpdates($handle) { $_profilerKey = 'layout/db_update: '.$handle; Varien_Profiler::start($_profilerKey); - - try { - $updateStr = Mage::getResourceModel('core/layout')->fetchUpdatesByHandle($handle); - if (!$updateStr) { - return false; - } - $updateStr = str_replace($this->_subst['from'], $this->_subst['to'], $updateStr); - $updateXml = simplexml_load_string($updateStr, $this->getElementClass()); - $this->fetchRecursiveUpdates($updateXml); - - $this->addUpdate($update); - } catch (PDOException $e) { - throw $e; - } catch (Exception $e) { - + $updateStr = Mage::getResourceModel('core/layout')->fetchUpdatesByHandle($handle); + if (!$updateStr) { + return false; } + $updateStr = '' . $updateStr . ''; + $updateStr = str_replace($this->_subst['from'], $this->_subst['to'], $updateStr); + $updateXml = simplexml_load_string($updateStr, $this->getElementClass()); + $this->fetchRecursiveUpdates($updateXml); + $this->addUpdate($updateXml->innerXml()); Varien_Profiler::stop($_profilerKey); return true; @@ -365,4 +381,55 @@ public function fetchRecursiveUpdates($updateXml) } return $this; } + + /** + * Collect and merge layout updates from file + * + * @param string $area + * @param string $package + * @param string $theme + * @param integer $storeId + * @return Mage_Core_Model_Layout_Element + */ + public function getFileLayoutUpdatesXml($area, $package, $theme, $storeId) + { + /* @var $design Mage_Core_Model_Design_Package */ + $design = Mage::getSingleton('core/design_package'); + $layoutXml = null; + $elementClass = $this->getElementClass(); + $updatesRoot = Mage::app()->getConfig()->getNode($area.'/layout/updates'); + Mage::dispatchEvent('core_layout_update_updates_get_after', array('updates' => $updatesRoot)); + $updateFiles = array(); + foreach ($updatesRoot->children() as $updateNode) { + if ($updateNode->file) { + $module = $updateNode->getAttribute('module'); + if ($module && Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $module, $storeId)) { + continue; + } + $updateFiles[] = (string)$updateNode->file; + } + } + // custom local layout updates file - load always last + $updateFiles[] = 'local.xml'; + $layoutStr = ''; + foreach ($updateFiles as $file) { + $filename = $design->getLayoutFilename($file, array( + '_area' => $area, + '_package' => $package, + '_theme' => $theme + )); + if (!is_readable($filename)) { + continue; + } + $fileStr = file_get_contents($filename); + $fileStr = str_replace($this->_subst['from'], $this->_subst['to'], $fileStr); + $fileXml = simplexml_load_string($fileStr, $elementClass); + if (!$fileXml instanceof SimpleXMLElement) { + continue; + } + $layoutStr .= $fileXml->innerXml(); + } + $layoutXml = simplexml_load_string(''.$layoutStr.'', $elementClass); + return $layoutXml; + } } diff --git a/app/code/core/Mage/Core/Model/Locale.php b/app/code/core/Mage/Core/Model/Locale.php index 935b327475..9996482077 100644 --- a/app/code/core/Mage/Core/Model/Locale.php +++ b/app/code/core/Mage/Core/Model/Locale.php @@ -229,7 +229,7 @@ protected function _getOptionLocales($translatedName=false) { $options = array(); $locales = $this->getLocale()->getLocaleList(); - $languages = $this->getLocale()->getLanguageTranslationList($this->getLocale()); + $languages = $this->getLocale()->getTranslationList('language', $this->getLocale()); $countries = $this->getCountryTranslationList(); $allowed = $this->getAllowLocales(); @@ -243,8 +243,8 @@ protected function _getOptionLocales($translatedName=false) continue; } if ($translatedName) { - $label = ucwords($this->getLocale()->getLanguageTranslation($data[0], $code)) - . ' (' . $this->getLocale()->getCountryTranslation($data[1], $code) . ') / ' + $label = ucwords($this->getLocale()->getTranslation($data[0], 'language', $code)) + . ' (' . $this->getLocale()->getTranslation($data[1], 'country', $code) . ') / ' . $languages[$data[0]] . ' (' . $countries[$data[1]] . ')'; } else { $label = $languages[$data[0]] . ' (' . $countries[$data[1]] . ')'; @@ -511,6 +511,25 @@ public function storeDate($store=null, $date=null, $includeTime=false) return $date; } + /** + * Create Zend_Date object with date converted from store's timezone + * to UTC time zone. Date can be passed in format of store's locale + * or in format which was passed as parameter. + * + * @param mixed $store Information about store + * @param string|integer|Zend_Date|array|null $date date in store's timezone + * @param boolean $includeTime flag for including time to date + * @param null|string $format + * @return Zend_Date + */ + public function utcDate($store=null, $date, $includeTime = false, $format = null) + { + $dateObj = $this->storeDate($store, $date, $includeTime); + $dateObj->set($date, $format); + $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE); + return $dateObj; + } + /** * Get store timestamp * Timstamp will be builded with store timezone settings @@ -529,19 +548,19 @@ public function storeTimeStamp($store=null) } /** - * Create Mage_Core_Model_Locale_Currency object for current locale + * Create Zend_Currency object for current locale * * @param string $currency - * @return Mage_Core_Model_Locale_Currency + * @return Zend_Currency */ public function currency($currency) { Varien_Profiler::start('locale/currency'); if (!isset(self::$_currencyCache[$this->getLocaleCode()][$currency])) { try { - $currencyObject = new Mage_Core_Model_Locale_Currency($currency, $this->getLocale()); + $currencyObject = new Zend_Currency($currency, $this->getLocale()); } catch (Exception $e) { - $currencyObject = new Mage_Core_Model_Locale_Currency($this->getCurrency(), $this->getLocale()); + $currencyObject = new Zend_Currency($this->getCurrency(), $this->getLocale()); $options = array( 'name' => $currency, 'currency' => $currency, @@ -724,7 +743,7 @@ public function getTranslation($value = null, $path = null) */ public function getCountryTranslation($value) { - return $this->getLocale()->getCountryTranslation($value, $this->getLocale()); + return $this->getLocale()->getTranslation($value, 'country', $this->getLocale()); } /** @@ -734,7 +753,7 @@ public function getCountryTranslation($value) */ public function getCountryTranslationList() { - return $this->getLocale()->getCountryTranslationList($this->getLocale()); + return $this->getLocale()->getTranslationList('territory', $this->getLocale(), 2); } /** diff --git a/app/code/core/Mage/Core/Model/Locale/Currency.php b/app/code/core/Mage/Core/Model/Locale/Currency.php deleted file mode 100644 index 3126c1e0e3..0000000000 --- a/app/code/core/Mage/Core/Model/Locale/Currency.php +++ /dev/null @@ -1,197 +0,0 @@ - - */ -class Mage_Core_Model_Locale_Currency extends Zend_Currency -{ - const XML_PATH_TRIM_CURRENCY_SIGN = 'currency/options/trim_sign'; - const US_LOCALE = 'en_US'; - protected $_locale; - - /** - * Creates a currency instance. Every supressed parameter is used from the actual or the given locale. - * - * @param string $currency OPTIONAL currency short name - * @param string|Zend_Locale $locale OPTIONAL locale name - * @throws Zend_Currency_Exception When currency is invalid - */ - public function __construct($currency = null, $locale = null) - { - parent::__construct($currency, $locale); - $this->_options['symbol_choice'] = self::getSymbolChoice($currency, $this->_locale); - } - - /** - * Returns the actual or details of available currency symbol choice, - * - * @param string $currency (Optional) Currency name - * @param string|Zend_Locale $locale (Optional) Locale to display informations - * @return string - */ - public function getSymbolChoice($currency = null, $locale = null) - { - if (($currency === null) and ($locale === null)) { - return $this->_options['symbol_choice']; - } - - $params = self::_checkParams($currency, $locale); - - //Get the symbol choice - $symbolChoice = Zend_Locale_Data::getContent($params['locale'], 'currencysymbolchoice', $params['currency']); - if (empty($symbolChoice) === true) { - $symbolChoice = Zend_Locale_Data::getContent($params['locale'], 'currencysymbolchoice', $params['name']); - } - if (empty($symbolChoice) === true) { - return null; - } - return $symbolChoice; - } - - public function setLocale($locale = null) - { - $this->_locale = $locale; - parent::setLocale($locale); - return $this; - } - - /** - * Place the sign next to the number - * - * @param string $value - * @param string $sign - * @param array $options - * @return string - */ - protected function _concatSign($value, $sign, $options) - { - $trimSign = $this->getStore()->getConfig(self::XML_PATH_TRIM_CURRENCY_SIGN); - if (is_null($trimSign) && $this->_locale && $this->_locale == self::US_LOCALE) { - $trimSign = true; - } - if ($trimSign) { - $sign = trim($sign); - } - - // Place the sign next to the number - if ($options['position'] === self::RIGHT) { - $result = $value . $sign; - } else if ($options['position'] === self::LEFT) { - // Do not place sign before minus. And do not allow space between minus and sign - if (0 === strpos($value, '-', 0)) { - $result = '-' . ltrim($sign) . substr($value, 1); - } else { - $result = $sign . $value; - } - } - return $result; - } - - /** - * Get store instance - * - * @return Mage_Core_Model_Store - */ - public function getStore() - { - return Mage::app()->getStore(); - } - -/** - * Internal method for checking the options array - * - * @param array $options - * @return array - * @throws Zend_Currency_Exception - */ - private function checkOptions(array $options = array()) - { - if (count($options) == 0) { - return $this->_options; - } - foreach($options as $name => $value) { - $name = strtolower($name); - if ($name !== 'format') { - if (gettype($value) === 'string') { - $value = strtolower($value); - } - } - if (array_key_exists($name, $this->_options)) { - switch($name) { - case 'position' : - if (($value !== self::STANDARD) and ($value !== self::RIGHT) and ($value !== self::LEFT)) { - #require_once 'Zend/Currency/Exception.php'; - throw new Zend_Currency_Exception("Unknown position '" . $value . "'"); - } - if ($value === self::STANDARD) { - $options['position'] = $this->_updateFormat(); - } - break; - case 'format' : - if (!empty($value) && (!Zend_Locale::isLocale($value))) { - #require_once 'Zend/Currency/Exception.php'; - throw new Zend_Currency_Exception("'" . - (gettype($value) === 'object' ? get_class($value) : $value) - . "' is not a known locale."); - } - break; - case 'display' : - if (is_numeric($value) and ($value !== self::NO_SYMBOL) and ($value !== self::USE_SYMBOL) and - ($value !== self::USE_SHORTNAME) and ($value !== self::USE_NAME)) { - #require_once 'Zend/Currency/Exception.php'; - throw new Zend_Currency_Exception("Unknown display '$value'"); - } - break; - case 'precision' : - if ($value === NULL) { - $value = -1; - } - if (($value < -1) || ($value > 30)) { - #require_once 'Zend/Currency/Exception.php'; - throw new Zend_Currency_Exception("'$value' precision has to be between -1 and 30."); - } - break; - case 'script' : - try { - Zend_Locale_Format::convertNumerals(0,$options['script']); - } catch (Zend_Locale_Exception $e) { - #require_once 'Zend/Currency/Exception.php'; - throw new Zend_Currency_Exception($e->getMessage()); - } - break; - } - } - else { - #require_once 'Zend/Currency/Exception.php'; - throw new Zend_Currency_Exception("Unknown option: '$name' = '$value'"); - } - } - return $options; - } -} diff --git a/app/code/core/Mage/Core/Model/Mysql4/Abstract.php b/app/code/core/Mage/Core/Model/Mysql4/Abstract.php index c2ed5e936c..aed549d3cd 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Abstract.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Abstract.php @@ -229,6 +229,7 @@ public function getMainTable() * Get table name for the entity * * @param string $entityName + * @return string */ public function getTable($entityName) { @@ -246,6 +247,18 @@ public function getTable($entityName) return $this->_tables[$entityName]; } + /** + * Retrieve table name for the entity separated value + * + * @param string $entityName + * @param string $valueType + * @return string + */ + public function getValueTable($entityName, $valueType) + { + return $this->getTable($entityName) . '_' . $valueType; + } + /** * Get connection by name or type * @@ -270,7 +283,7 @@ protected function _getConnection($connectionName) /** * Retrieve connection for read data * - * @return Zend_Db_Adapter_Abstract + * @return Varien_Db_Adapter_Pdo_Mysql */ protected function _getReadAdapter() { @@ -280,7 +293,7 @@ protected function _getReadAdapter() /** * Retrieve connection for write data * - * @return Zend_Db_Adapter_Abstract + * @return Varien_Db_Adapter_Pdo_Mysql */ protected function _getWriteAdapter() { @@ -290,7 +303,7 @@ protected function _getWriteAdapter() /** * Temporary resolving collection compatibility * - * @return Zend_Db_Adapter_Abstract + * @return Varien_Db_Adapter_Pdo_Mysql */ public function getReadConnection() { @@ -364,7 +377,8 @@ public function save(Mage_Core_Model_Abstract $object) if ($this->_isPkAutoIncrement) { $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $condition); } else { - $select = $this->_getWriteAdapter()->select($this->getMainTable(), array($this->getIdFieldName())) + $select = $this->_getWriteAdapter()->select() + ->from($this->getMainTable(), array($this->getIdFieldName())) ->where($condition); if ($this->_getWriteAdapter()->fetchOne($select) !== false) { $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $condition); @@ -482,9 +496,21 @@ public function getUniqueFields() * @return array */ protected function _prepareDataForSave(Mage_Core_Model_Abstract $object) + { + return $this->_prepareDataForTable($object, $this->getMainTable()); + } + + /** + * Prepare data for passed table + * + * @param Varien_Object $object + * @param string $table + * @return array + */ + protected function _prepareDataForTable(Varien_Object $object, $table) { $data = array(); - $fields = $this->_getWriteAdapter()->describeTable($this->getMainTable()); + $fields = $this->_getWriteAdapter()->describeTable($table); foreach (array_keys($fields) as $field) { if ($object->hasData($field)) { $fieldValue = $object->getData($field); @@ -567,10 +593,10 @@ protected function _checkUnique(Mage_Core_Model_Abstract $object) if (!empty($existent)) { if (count($existent) == 1 ) { - $error = Mage::helper('core')->__('%s already exist', $existent[0]); + $error = Mage::helper('core')->__('%s already exists', $existent[0]); } else { - $error = Mage::helper('core')->__('%s already exists', implode(', ', $existent)); + $error = Mage::helper('core')->__('%s already exist', implode(', ', $existent)); } Mage::throwException($error); } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Email/Template.php b/app/code/core/Mage/Core/Model/Mysql4/Email/Template.php index d7d1808d2b..dbdc2fd38f 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Email/Template.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Email/Template.php @@ -189,7 +189,7 @@ protected function _prepareSave(Mage_Core_Model_Email_Template $template) $validators = array( 'template_code' => array(Zend_Filter_Input::ALLOW_EMPTY => false), - 'template_type' => 'Alnum', + #'template_type' => 'Alnum', #'template_sender_email' => 'EmailAddress', #'template_sender_name' => array(Zend_Filter_Input::ALLOW_EMPTY => false) ); diff --git a/app/code/core/Mage/Core/Model/Mysql4/Layout.php b/app/code/core/Mage/Core/Model/Mysql4/Layout.php index 9acb04c3d4..049ea8ec34 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Layout.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Layout.php @@ -44,22 +44,22 @@ public function fetchUpdatesByHandle($handle, $params = array()) $package = isset($params['package']) ? $params['package'] : Mage::getSingleton('core/design_package')->getPackageName(); $theme = isset($params['theme']) ? $params['theme'] : Mage::getSingleton('core/design_package')->getTheme('layout'); - $read = $this->_getReadAdapter(); $updateStr = ''; - - if ($read) { - $select = $read->select()->from(array('update'=>$this->getMainTable()), 'xml') + + $readAdapter = $this->_getReadAdapter(); + if ($readAdapter) { + $select = $readAdapter->select() + ->from(array('update'=>$this->getMainTable()), array('xml')) ->join(array('link'=>$this->getTable('core/layout_link')), 'link.layout_update_id=update.layout_update_id', '') ->where('link.store_id=?', $storeId) ->where('link.package=?', $package) - ->where('link.theme=?', $theme); - - if ($updates = $read->fetchAll($select)) { - foreach ($updates as $update) { - $updateStr .= $update['xml']; - } + ->where('link.theme=?', $theme) + ->where('update.handle = ?', $handle); + + foreach ($readAdapter->fetchAll($select) as $update) { + $updateStr .= $update['xml']; } } return $updateStr; } -} \ No newline at end of file +} diff --git a/app/code/core/Mage/Core/Model/Mysql4/Session.php b/app/code/core/Mage/Core/Model/Mysql4/Session.php index fa85569d98..af05d7a7a7 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Session.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Session.php @@ -62,6 +62,14 @@ class Mage_Core_Model_Mysql4_Session implements Zend_Session_SaveHandler_Interfa */ protected $_write; + /** + * Automatic cleaning factor of expired sessions + * + * value zero means no automatic cleaning, one means automatic cleaning each time a session is closed, and x>1 means + * cleaning once in x calls + */ + protected $_automaticCleaningFactor = 50; + public function __construct() { $this->_sessionTable = Mage::getSingleton('core/resource')->getTableName('core/session'); @@ -211,7 +219,12 @@ public function destroy($sessId) */ public function gc($sessMaxLifeTime) { - $this->_write->query("DELETE FROM `{$this->_sessionTable}` WHERE `session_expires` < ?", array(time())); + if ($this->_automaticCleaningFactor > 0) { + if ($this->_automaticCleaningFactor == 1 || + rand(1, $this->_automaticCleaningFactor)==1) { + $this->_write->query("DELETE FROM `{$this->_sessionTable}` WHERE `session_expires` < ?", array(time())); + } + } return true; } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Store/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Store/Collection.php index 5e936bf107..c6ad7e0b60 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Store/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Store/Collection.php @@ -57,9 +57,21 @@ public function setWithoutDefaultFilter() return $this; } + /** + * Add filter by group id. + * Group id can be passed as one single value or array of values. + * + * @param int|array $groupId + * @return Mage_Core_Model_Mysql4_Store_Collection + */ public function addGroupFilter($groupId) { - $condition = $this->getConnection()->quoteInto("main_table.group_id=?", $groupId); + if (is_array($groupId)) { + $condition = $this->getConnection()->quoteInto("main_table.group_id IN (?)", $groupId); + } else { + $condition = $this->getConnection()->quoteInto("main_table.group_id = ?",$groupId); + } + $this->addFilter('group_id', $condition, 'string'); return $this; } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php b/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php index 7db12ba479..b963717606 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php @@ -81,4 +81,29 @@ protected function _getLoadSelect($field, $value, $object) return $select; } -} \ No newline at end of file + + /** + * Retrieve request_path using id_path and current store's id. + * + * @param string $idPath + * @param int|Mage_Core_Model_Store $store + * @return string|false + */ + public function getRequestPathByIdPath($idPath, $store) + { + if ($store instanceof Mage_Core_Model_Store) { + $storeId = (int)$store->getId(); + } else { + $storeId = (int)$store; + } + + $select = $this->_getReadAdapter()->select(); + /* @var $select Zend_Db_Select */ + $select->from(array('main_table' => $this->getMainTable()), 'request_path') + ->where('main_table.store_id = ?', $storeId) + ->where('main_table.id_path = ?', $idPath) + ->limit(1); + + return $this->_getReadAdapter()->fetchOne($select); + } +} diff --git a/app/code/core/Mage/Core/Model/Mysql4/Website/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Website/Collection.php index 04983b9f61..3923ccabe9 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Website/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Website/Collection.php @@ -91,23 +91,50 @@ public function load($printQuery = false, $logQuery = false) return $this; } + /** + * Join group and store info from appropriate tables. + * Defines new _idFiledName as 'website_group_store' bc for + * one website can be more then one row in collection. + * Sets extra combined ordering by group's name, defined + * sort ordering and store's name. + * + * @return Mage_Core_Model_Mysql4_Website_Collection + */ public function joinGroupAndStore() { - $this->_idFieldName = 'website_group_store'; - $this->getSelect()->joinLeft( - array('group_table' => $this->getTable('core/store_group')), - 'main_table.website_id=group_table.website_id', - array('group_id'=>'group_id', 'group_title'=>'name') - )->joinLeft( - array('store_table' => $this->getTable('core/store')), - 'group_table.group_id=store_table.group_id', - array('store_id'=>'store_id', 'store_title'=>'name') - ); - $this->addOrder('group_table.name', 'ASC') // store name - ->addOrder('CASE WHEN store_table.store_id = 0 THEN 0 ELSE 1 END', 'ASC') // view is admin - ->addOrder('store_table.sort_order', 'ASC') // view sort order - ->addOrder('store_table.name', 'ASC') // view name - ; + if (!$this->getFlag('groups_and_stores_joined')) { + $this->_idFieldName = 'website_group_store'; + $this->getSelect()->joinLeft( + array('group_table' => $this->getTable('core/store_group')), + 'main_table.website_id=group_table.website_id', + array('group_id'=>'group_id', 'group_title'=>'name') + )->joinLeft( + array('store_table' => $this->getTable('core/store')), + 'group_table.group_id=store_table.group_id', + array('store_id'=>'store_id', 'store_title'=>'name') + ); + $this->addOrder('group_table.name', 'ASC') // store name + ->addOrder('CASE WHEN store_table.store_id = 0 THEN 0 ELSE 1 END', 'ASC') // view is admin + ->addOrder('store_table.sort_order', 'ASC') // view sort order + ->addOrder('store_table.name', 'ASC') // view name + ; + $this->setFlag('groups_and_stores_joined', true); + } + return $this; + } + + /** + * Adding filter by group id or array of ids but only if + * tables with appropriate information were joined before. + * + * @param int|array $groupIds + * @return Mage_Core_Model_Mysql4_Website_Collection + */ + public function addFilterByGroupIds($groupIds) + { + if ($this->getFlag('groups_and_stores_joined')) { + $this->addFieldToFilter('group_table.group_id', $groupIds); + } return $this; } } diff --git a/app/code/core/Mage/Core/Model/Resource.php b/app/code/core/Mage/Core/Model/Resource.php index 907491ffbd..d93a9ee277 100644 --- a/app/code/core/Mage/Core/Model/Resource.php +++ b/app/code/core/Mage/Core/Model/Resource.php @@ -37,6 +37,9 @@ class Mage_Core_Model_Resource const AUTO_UPDATE_NEVER = -1; const AUTO_UPDATE_ALWAYS = 1; + const DEFAULT_READ_RESOURCE = 'core_read'; + const DEFAULT_WRITE_RESOURCE= 'core_write'; + /** * Instances of classes for connection types * @@ -68,12 +71,16 @@ class Mage_Core_Model_Resource */ public function getConnection($name) { +// echo $name . '
    '; if (isset($this->_connections[$name])) { return $this->_connections[$name]; } $connConfig = Mage::getConfig()->getResourceConnectionConfig($name); - - if (!$connConfig || !$connConfig->is('active', 1)) { + if (!$connConfig) { + $this->_connections[$name] = $this->_getDefaultConnection($name); + return $this->_connections[$name]; + } + if (!$connConfig->is('active', 1)) { return false; } $origName = $connConfig->getParent()->getName(); @@ -93,6 +100,14 @@ public function getConnection($name) return $conn; } + protected function _getDefaultConnection($requiredConnectionName) + { + if (strpos($requiredConnectionName, 'read') !== false) { + return $this->getConnection(self::DEFAULT_READ_RESOURCE); + } + return $this->getConnection(self::DEFAULT_WRITE_RESOURCE); + } + /** * Get connection type instance * diff --git a/app/code/core/Mage/Core/Model/Resource/Setup.php b/app/code/core/Mage/Core/Model/Resource/Setup.php index 5498e9c9fe..b3b2e3902f 100644 --- a/app/code/core/Mage/Core/Model/Resource/Setup.php +++ b/app/code/core/Mage/Core/Model/Resource/Setup.php @@ -31,6 +31,7 @@ */ class Mage_Core_Model_Resource_Setup { + const DEFAULT_SETUP_CONNECTION = 'core_setup'; const VERSION_COMPARE_EQUAL = 0; const VERSION_COMPARE_LOWER = -1; const VERSION_COMPARE_GREATER = 1; @@ -56,7 +57,13 @@ public function __construct($resourceName) $config = Mage::getConfig(); $this->_resourceName = $resourceName; $this->_resourceConfig = $config->getResourceConfig($resourceName); - $this->_connectionConfig = $config->getResourceConnectionConfig($resourceName); + $connection = $config->getResourceConnectionConfig($resourceName); + if ($connection) { + $this->_connectionConfig = $connection; + } else { + $this->_connectionConfig = $config->getResourceConnectionConfig(self::DEFAULT_SETUP_CONNECTION); + } + $modName = (string)$this->_resourceConfig->setup->module; $this->_moduleConfig = $config->getModuleConfig($modName); $this->_conn = Mage::getSingleton('core/resource')->getConnection($this->_resourceName); diff --git a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php index cad2ee993e..36961c55e2 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php @@ -45,12 +45,6 @@ public function start($sessionName=null) return $this; } - Varien_Profiler::start(__METHOD__.'/setOptions'); - if (is_writable(Mage::getBaseDir('session'))) { - session_save_path($this->getSessionSavePath()); - } - Varien_Profiler::stop(__METHOD__.'/setOptions'); - switch($this->getSessionSaveMethod()) { case 'db': ini_set('session.save_handler', 'user'); @@ -62,27 +56,49 @@ public function start($sessionName=null) ini_set('session.save_handler', 'memcache'); session_save_path($this->getSessionSavePath()); break; + case 'eaccelerator': + ini_set('session.save_handler', 'eaccelerator'); + break; default: session_module_name('files'); + if (is_writable(Mage::getBaseDir('session'))) { + session_save_path($this->getSessionSavePath()); + } break; } if (Mage::app()->getStore()->isAdmin()) { $adminSessionLifetime = (int)Mage::getStoreConfig('admin/security/session_cookie_lifetime'); if ($adminSessionLifetime > 60) { - Mage::getSingleton('core/cookie')->setLifetime($adminSessionLifetime); + $this->getCookie()->setLifetime($adminSessionLifetime); } } - // set session cookie params - session_set_cookie_params( - $this->getCookie()->getLifetime(), - $this->getCookie()->getPath(), - $this->getCookie()->getDomain(), - $this->getCookie()->isSecure(), - $this->getCookie()->getHttponly() + // session cookie params + $cookieParams = array( + 'lifetime' => $this->getCookie()->getLifetime(), + 'path' => $this->getCookie()->getPath(), + 'domain' => $this->getCookie()->getConfigDomain(), + 'secure' => $this->getCookie()->isSecure(), + 'httponly' => $this->getCookie()->getHttponly() ); + if (!$cookieParams['httponly']) { + unset($cookieParams['httponly']); + if (!$cookieParams['secure']) { + unset($cookieParams['secure']); + if (!$cookieParams['domain']) { + unset($cookieParams['domain']); + } + } + } + + if (isset($cookieParams['domain'])) { + $cookieParams['domain'] = $this->getCookie()->getDomain(); + } + + call_user_func_array('session_set_cookie_params', $cookieParams); + if (!empty($sessionName)) { $this->setSessionName($sessionName); } diff --git a/app/code/core/Mage/Core/Model/Store.php b/app/code/core/Mage/Core/Model/Store.php index 709bab5655..529969f4f4 100644 --- a/app/code/core/Mage/Core/Model/Store.php +++ b/app/code/core/Mage/Core/Model/Store.php @@ -28,12 +28,14 @@ /** * Store model * - * @author Magento Core Team + * @author Magento Core Team * @category Mage * @package Mage_Core */ class Mage_Core_Model_Store extends Mage_Core_Model_Abstract { + const ENTITY = 'core_store'; + const XML_PATH_STORE_IN_URL = 'web/url/use_store'; const XML_PATH_USE_REWRITES = 'web/seo/use_rewrites'; const XML_PATH_UNSECURE_BASE_URL = 'web/unsecure/base_url'; @@ -875,9 +877,18 @@ public function getName() return $this->_getData('name'); } + /** + * Protect delete from non admin area + * Register indexing event before delete store + * + * @return Mage_Core_Model_Store + */ protected function _beforeDelete() { $this->_protectFromNonAdmin(); + Mage::getSingleton('index/indexer')->logEvent( + $this, self::ENTITY, Mage_Index_Model_Event::TYPE_DELETE + ); return parent::_beforeDelete(); } @@ -893,6 +904,19 @@ protected function _afterDelte() return $this; } + /** + * Init indexing process after store delete commit + * + * @return Mage_Core_Model_Store + */ + protected function _afterDeleteCommit() + { + parent::_afterDeleteCommit(); + Mage::getSingleton('index/indexer')->indexEvents( + self::ENTITY, Mage_Index_Model_Event::TYPE_DELETE + ); + } + /** * Reinit and reset Config Data * diff --git a/app/code/core/Mage/Core/Model/Store/Group.php b/app/code/core/Mage/Core/Model/Store/Group.php index 213b9f12eb..fb91ce24f0 100644 --- a/app/code/core/Mage/Core/Model/Store/Group.php +++ b/app/code/core/Mage/Core/Model/Store/Group.php @@ -34,6 +34,7 @@ class Mage_Core_Model_Store_Group extends Mage_Core_Model_Abstract { + const ENTITY = 'store_group'; const CACHE_TAG = 'store_group'; protected $_cacheTag = true; diff --git a/app/code/core/Mage/Core/Model/Translate/Inline.php b/app/code/core/Mage/Core/Model/Translate/Inline.php index 52cd96b891..7bec912c31 100644 --- a/app/code/core/Mage/Core/Model/Translate/Inline.php +++ b/app/code/core/Mage/Core/Model/Translate/Inline.php @@ -168,7 +168,6 @@ public function processResponseBody(&$body) $this->processResponseBody($part); } } else if (is_string($body)) { - Mage::log($body); $this->_content = $body; $this->_tagAttributes(); diff --git a/app/code/core/Mage/Core/Model/Url/Rewrite.php b/app/code/core/Mage/Core/Model/Url/Rewrite.php index ea48def69e..b3af300f32 100644 --- a/app/code/core/Mage/Core/Model/Url/Rewrite.php +++ b/app/code/core/Mage/Core/Model/Url/Rewrite.php @@ -40,11 +40,34 @@ class Mage_Core_Model_Url_Rewrite extends Mage_Core_Model_Abstract const TYPE_CUSTOM = 3; const REWRITE_REQUEST_PATH_ALIAS = 'rewrite_request_path'; + /** + * Cache tag for clear cache in after save and after delete + * + * @var mixed | array | string | boolean + */ + protected $_cacheTag = false; + protected function _construct() { $this->_init('core/url_rewrite'); } + /** + * Clean cache for front-end menu + * + * @return Mage_Core_Model_Url_Rewrite + */ + protected function _afterSave() + { + if ($this->hasCategoryId()) { + $this->_cacheTag = array(Mage_Catalog_Model_Category::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG); + } + + parent::_afterSave(); + + return $this; + } + /** * Load rewrite information for request * diff --git a/app/code/core/Mage/Core/Model/Website.php b/app/code/core/Mage/Core/Model/Website.php index 56772cb00a..d64570bce4 100644 --- a/app/code/core/Mage/Core/Model/Website.php +++ b/app/code/core/Mage/Core/Model/Website.php @@ -34,6 +34,7 @@ class Mage_Core_Model_Website extends Mage_Core_Model_Abstract { + const ENTITY = 'core_website'; const CACHE_TAG = 'website'; protected $_cacheTag = true; diff --git a/app/code/core/Mage/Core/etc/system.xml b/app/code/core/Mage/Core/etc/system.xml index 0843279ab2..81c43ac546 100644 --- a/app/code/core/Mage/Core/etc/system.xml +++ b/app/code/core/Mage/Core/etc/system.xml @@ -586,15 +586,6 @@ 1 1 - - - multiselect - 3 - adminhtml/system_config_source_country - 1 - 1 - 0 - @@ -656,7 +647,7 @@ 1 - + text 20 1 @@ -679,6 +670,7 @@ 1 1 1 + For Windows Server Only @@ -687,6 +679,7 @@ 1 1 1 + For Windows Server Only + + + select + adminhtml/system_config_source_yesno + 70 + 1 + 0 + 0 + @@ -825,7 +827,7 @@ - Values less than 60 are ignored. + Values less than 60 are ignored. Please note, that changes will apply after logout. 3 1 0 @@ -1058,19 +1060,11 @@ text - 30 - 1 - 1 - 1 - - - - text 10 1 1 1 - + text @@ -1079,6 +1073,14 @@ 1 1 + + + text + 30 + 1 + 1 + 1 + select diff --git a/app/code/core/Mage/Core/functions.php b/app/code/core/Mage/Core/functions.php index 9541627c7a..1c50b92430 100644 --- a/app/code/core/Mage/Core/functions.php +++ b/app/code/core/Mage/Core/functions.php @@ -180,13 +180,13 @@ function mageCoreErrorHandler($errno, $errstr, $errfile, $errline){ // PEAR specific message handling if (stripos($errfile.$errstr, 'pear') !== false) { - // ignore strict notices - if ($errno == E_STRICT) { - return false; + // ignore strict and deprecated notices + if (($errno == E_STRICT) || ($errno == E_DEPRECATED)) { + return true; } // ignore attempts to read system files when open_basedir is set if ($errno == E_WARNING && stripos($errstr, 'open_basedir') !== false) { - return false; + return true; } } @@ -371,4 +371,4 @@ function sys_get_temp_dir() } } } -} \ No newline at end of file +} diff --git a/app/code/core/Mage/Cron/etc/config.xml b/app/code/core/Mage/Cron/etc/config.xml index fa5fc6caff..8fa3ad147e 100644 --- a/app/code/core/Mage/Cron/etc/config.xml +++ b/app/code/core/Mage/Cron/etc/config.xml @@ -37,20 +37,7 @@ Mage_Cron - - core_setup - - - - core_write - - - - - core_read - - @@ -73,7 +60,6 @@ - singleton cron/observer dispatch diff --git a/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php b/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php index e5280238fa..3ad8246f15 100644 --- a/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php +++ b/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php @@ -199,7 +199,7 @@ public function getRegionId($country, $regionName) * * @return array */ - public function getCustomerGoups() + public function getCustomerGroups() { if (is_null($this->_customerGroups)) { $this->_customerGroups = array(); @@ -213,7 +213,15 @@ public function getCustomerGoups() return $this->_customerGroups; } - + /** + * Alias at getCustomerGroups() + * + * @return array + */ + public function getCustomerGoups() + { + return $this->getCustomerGroups(); + } public function __construct() { @@ -433,7 +441,7 @@ public function saveRow($importData) $customer->setWebsiteId($website->getId()) ->loadByEmail($importData['email']); if (!$customer->getId()) { - $customerGroups = $this->getCustomerGoups(); + $customerGroups = $this->getCustomerGroups(); /** * Check customer group */ @@ -465,7 +473,7 @@ public function saveRow($importData) } } elseif (!empty($importData['group_id'])) { - $customerGroups = $this->getCustomerGoups(); + $customerGroups = $this->getCustomerGroups(); /** * Check customer group */ diff --git a/app/code/core/Mage/Customer/Model/Convert/Parser/Customer.php b/app/code/core/Mage/Customer/Model/Convert/Parser/Customer.php index b3fa4f5d11..3e04c3539e 100644 --- a/app/code/core/Mage/Customer/Model/Convert/Parser/Customer.php +++ b/app/code/core/Mage/Customer/Model/Convert/Parser/Customer.php @@ -316,11 +316,19 @@ public function unparse() $row['created_in'] = $store->getCode(); $newsletter = $this->getNewsletterModel() + ->setData(array()) ->loadByCustomer($customer); $row['is_subscribed'] = ($newsletter->getId() && $newsletter->getSubscriberStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) ? 1 : 0; + if($customer->getGroupId()){ + $group = Mage::getResourceModel('customer/group_collection') + ->addFilter('customer_group_id',$customer->getGroupId()) + ->load(); + $row['group'] = $group->getFirstItem()->getCustomerGroupCode(); + } + $batchExport = $this->getBatchExportModel() ->setId(null) ->setBatchId($this->getBatchModel()->getId()) @@ -345,14 +353,10 @@ public function getExternalAttributes() 'country_id' ); - $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('customer')->getId(); - $customerAttributes = Mage::getResourceModel('eav/entity_attribute_collection') - ->setEntityTypeFilter($entityTypeId) + $customerAttributes = Mage::getResourceModel('customer/attribute_collection') ->load()->getIterator(); - $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('customer_address')->getId(); - $addressAttributes = Mage::getResourceModel('eav/entity_attribute_collection') - ->setEntityTypeFilter($entityTypeId) + $addressAttributes = Mage::getResourceModel('customer/address_attribute_collection') ->load()->getIterator(); $attributes = array( diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index f02b3f45e5..c84d77db80 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -450,7 +450,7 @@ public function isAddressPrimary(Mage_Customer_Model_Address $address) * * @return Mage_Customer_Model_Customer */ - public function sendNewAccountEmail($type = 'registered', $backUrl = '', $store_id = '0') + public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0') { $types = array( 'registered' => self::XML_PATH_REGISTER_EMAIL_TEMPLATE, // welcome email, when confirmation is disabled @@ -465,7 +465,7 @@ public function sendNewAccountEmail($type = 'registered', $backUrl = '', $store_ /* @var $translate Mage_Core_Model_Translate */ $translate->setTranslateInline(false); - $storeId = ($store_id == '0')?$this->getStoreId():$store_id; + $storeId = ($storeId == '0')?$this->getSendemailStoreId():$storeId; if ($this->getWebsiteId() != '0' && $storeId == '0') { $storeIds = Mage::app()->getWebsite($this->getWebsiteId())->getStoreIds(); reset($storeIds); @@ -695,6 +695,10 @@ public function validate() && '' == trim($this->getTaxvat())) { $errors[] = Mage::helper('customer')->__('TAX/VAT number is required.'); } + if (('req' === Mage::helper('customer/address')->getConfig('gender_show')) + && '' == trim($this->getGender())) { + $errors[] = Mage::helper('customer')->__('Gender is required.'); + } if (empty($errors)) { return true; diff --git a/app/code/core/Mage/Customer/Model/Entity/Customer/Collection.php b/app/code/core/Mage/Customer/Model/Entity/Customer/Collection.php index 1335a9f962..9579e8a19e 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Customer/Collection.php +++ b/app/code/core/Mage/Customer/Model/Entity/Customer/Collection.php @@ -91,21 +91,15 @@ public function getSelectCountSql() } /** - * Retrive all ids for collection + * Reset left join * - * @return array + * @return Mage_Eav_Model_Entity_Collection_Abstract */ - public function getAllIds($limit=null, $offset=null) + protected function _getAllIdsSelect($limit=null, $offset=null) { - $idsSelect = clone $this->getSelect(); - $idsSelect->reset(Zend_Db_Select::ORDER); - $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $idsSelect->reset(Zend_Db_Select::COLUMNS); - $idsSelect->from(null, 'e.'.$this->getEntity()->getIdFieldName()); - $idsSelect->limit($limit, $offset); + $idsSelect = parent::_getAllIdsSelect($limit, $offset); $idsSelect->resetJoinLeft(); - - return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams); + return $idsSelect; } -} \ No newline at end of file + +} diff --git a/app/code/core/Mage/Customer/Model/Entity/Setup.php b/app/code/core/Mage/Customer/Model/Entity/Setup.php index cef4830b6a..3d796143e7 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Setup.php +++ b/app/code/core/Mage/Customer/Model/Entity/Setup.php @@ -34,6 +34,26 @@ class Mage_Customer_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup { + /** + * Prepare customer attribute values to save + * + * @param array $attr + * @return array + */ + protected function _prepareValues($attr) + { + $data = parent::_prepareValues($attr); + $data = array_merge($data, array( + 'is_visible' => $this->_getValue($attr, 'visible', 1), + 'is_visible_on_front' => $this->_getValue($attr, 'visible_on_front', 0), + 'input_filter' => $this->_getValue($attr, 'input_filter', ''), + 'lines_to_divide_multiline' => $this->_getValue($attr, 'lines_to_divide', 0), + 'min_text_length' => $this->_getValue($attr, 'min_text_length', 0), + 'max_text_length' => $this->_getValue($attr, 'max_text_length', 0) + )); + return $data; + } + public function getDefaultEntities() { return array( @@ -42,6 +62,8 @@ public function getDefaultEntities() 'table' => 'customer/entity', 'increment_model' => 'eav/entity_increment_numeric', 'increment_per_store' => false, + 'additional_attribute_table' => 'customer/eav_attribute', + 'entity_attribute_collection' => 'customer/eav_attribute', 'attributes' => array( // 'entity_id' => array('type'=>'static'), // 'entity_type_id' => array('type'=>'static'), @@ -105,7 +127,7 @@ public function getDefaultEntities() 'group_id' => array( 'type' => 'static', 'input' => 'select', - 'label' => 'Customer Group', + 'label' => 'Group', 'source' => 'customer/customer_attribute_source_group', 'sort_order' => 70, ), @@ -138,7 +160,6 @@ public function getDefaultEntities() 'label' => 'Tax/VAT number', 'visible' => true, 'required' => false, - 'position' => 1, ), 'confirmation' => array( 'label' => 'Is confirmed', @@ -151,6 +172,8 @@ public function getDefaultEntities() 'customer_address'=>array( 'entity_model' =>'customer/customer_address', 'table' => 'customer/address_entity', + 'additional_attribute_table' => 'customer/eav_attribute', + 'entity_attribute_collection' => 'customer/eav_attribute', 'attributes' => array( // 'entity_id' => array('type'=>'static'), // 'entity_type_id' => array('type'=>'static'), @@ -220,6 +243,7 @@ public function getDefaultEntities() 'source' => 'customer_entity/address_attribute_source_region', 'required' => 'false', 'sort_order' => 80, + 'label' => 'State/Province' ), 'postcode' => array( 'label' => 'Zip/Postal Code', diff --git a/app/code/core/Mage/Customer/Model/Group.php b/app/code/core/Mage/Customer/Model/Group.php index fb67b289c4..a8ecb7dd08 100644 --- a/app/code/core/Mage/Customer/Model/Group.php +++ b/app/code/core/Mage/Customer/Model/Group.php @@ -1,102 +1,119 @@ - - */ -class Mage_Customer_Model_Group extends Mage_Core_Model_Abstract -{ - const XML_PATH_DEFAULT_ID = 'customer/create_account/default_group'; - const NOT_LOGGED_IN_ID = 0; - const CUST_GROUP_ALL = 32000; - - /** - * Prefix of model events names - * - * @var string - */ - protected $_eventPrefix = 'customer_group'; - - /** - * Parameter name in event - * - * In observe method you can use $observer->getEvent()->getObject() in this case - * - * @var string - */ - protected $_eventObject = 'object'; - - protected static $_taxClassIds = array(); - - protected function _construct() - { - $this->_init('customer/group'); - } - - /** - * Alias for setCustomerGroupCode - * - * @param string $value - */ - public function setCode($value) - { - return $this->setCustomerGroupCode($value); - } - - /** - * Alias for getCustomerGroupCode - * - * @return string - */ - public function getCode() - { - return $this->getCustomerGroupCode(); - } - - public function getTaxClassId($groupId=null) - { - if (!is_null($groupId)) { - if (empty(self::$_taxClassIds[$groupId])) { - $this->load($groupId); - self::$_taxClassIds[$groupId] = $this->getData('tax_class_id'); - } - $this->setData('tax_class_id', self::$_taxClassIds[$groupId]); - } - return $this->getData('tax_class_id'); - } - - - public function usesAsDefault() - { - $data = Mage::getConfig()->getStoresConfigByPath(self::XML_PATH_DEFAULT_ID); - if (in_array($this->getId(), $data)) { - return true; - } - return false; - } -} \ No newline at end of file + + */ +class Mage_Customer_Model_Group extends Mage_Core_Model_Abstract +{ + const XML_PATH_DEFAULT_ID = 'customer/create_account/default_group'; + + const NOT_LOGGED_IN_ID = 0; + const CUST_GROUP_ALL = 32000; + + const ENTITY = 'customer_group'; + + /** + * Prefix of model events names + * + * @var string + */ + protected $_eventPrefix = 'customer_group'; + + /** + * Parameter name in event + * + * In observe method you can use $observer->getEvent()->getObject() in this case + * + * @var string + */ + protected $_eventObject = 'object'; + + protected static $_taxClassIds = array(); + + protected function _construct() + { + $this->_init('customer/group'); + } + + /** + * Alias for setCustomerGroupCode + * + * @param string $value + */ + public function setCode($value) + { + return $this->setCustomerGroupCode($value); + } + + /** + * Alias for getCustomerGroupCode + * + * @return string + */ + public function getCode() + { + return $this->getCustomerGroupCode(); + } + + public function getTaxClassId($groupId=null) + { + if (!is_null($groupId)) { + if (empty(self::$_taxClassIds[$groupId])) { + $this->load($groupId); + self::$_taxClassIds[$groupId] = $this->getData('tax_class_id'); + } + $this->setData('tax_class_id', self::$_taxClassIds[$groupId]); + } + return $this->getData('tax_class_id'); + } + + + public function usesAsDefault() + { + $data = Mage::getConfig()->getStoresConfigByPath(self::XML_PATH_DEFAULT_ID); + if (in_array($this->getId(), $data)) { + return true; + } + return false; + } + + /** + * Processing data save after transaction commit + * + * @return Mage_Customer_Model_Group + */ + protected function _afterSaveCommit() + { + parent::_afterSaveCommit(); + Mage::getSingleton('index/indexer')->processEntityAction( + $this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE + ); + return $this; + } +} diff --git a/app/code/core/Mage/Customer/controllers/AccountController.php b/app/code/core/Mage/Customer/controllers/AccountController.php index dc98ca5f8a..f942838099 100644 --- a/app/code/core/Mage/Customer/controllers/AccountController.php +++ b/app/code/core/Mage/Customer/controllers/AccountController.php @@ -188,6 +188,8 @@ protected function _loginPostRedirect() } else { $session->setBeforeAuthUrl(Mage::helper('customer')->getLoginUrl()); } + } else if ($session->getBeforeAuthUrl() == Mage::helper('customer')->getLogoutUrl()) { + $session->setBeforeAuthUrl(Mage::helper('customer')->getDashboardUrl()); } $this->_redirectUrl($session->getBeforeAuthUrl(true)); @@ -246,6 +248,9 @@ public function createPostAction() foreach (Mage::getConfig()->getFieldset('customer_account') as $code=>$node) { if ($node->is('create') && ($value = $this->getRequest()->getParam($code)) !== null) { + if ($code == 'email') { + $value = trim($value); + } $customer->setData($code, $value); } } @@ -318,7 +323,10 @@ public function createPostAction() ->addException($e, $this->__('Can\'t save customer')); } } - + /** + * Protect XSS injection in user input + */ + $this->_getSession()->setEscapeMessages(true); $this->_redirectError(Mage::getUrl('*/*/create', array('_secure'=>true))); } diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index f05f5af695..36cd15f621 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -28,7 +28,7 @@ - 0.8.11 + 1.4.0.0.2 @@ -91,6 +91,7 @@ 1 11 11 + 11 @@ -180,6 +181,9 @@ T: {{var telephone}} customer_group
    + + customer_eav_attribute
    +
    @@ -189,20 +193,7 @@ T: {{var telephone}} Mage_Customer Mage_Customer_Model_Entity_Setup - - core_setup - - - - core_write - - - - - core_read - -