Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI to edit "Category Attributes" #2264

Closed
wants to merge 15 commits into from
36 changes: 36 additions & 0 deletions app/code/core/Mage/Adminhtml/Block/Catalog/Category/Attribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
fballiano marked this conversation as resolved.
Show resolved Hide resolved
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

luigifab marked this conversation as resolved.
Show resolved Hide resolved
class Mage_Adminhtml_Block_Catalog_Category_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'catalog_category_attribute';
$this->_headerText = Mage::helper('catalog')->__('Manage Category Attributes');
$this->_addButtonLabel = Mage::helper('catalog')->__('Add New Attribute');
parent::__construct();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Adminhtml_Block_Catalog_Category_Attribute_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{

public function __construct()
{
$this->_objectId = 'attribute_id';
$this->_controller = 'catalog_category_attribute';

parent::__construct();

if($this->getRequest()->getParam('popup')) {
fballiano marked this conversation as resolved.
Show resolved Hide resolved
$this->_removeButton('back');
$this->_addButton(
'close',
array(
'label' => Mage::helper('catalog')->__('Close Window'),
'class' => 'cancel',
'onclick' => 'window.close()',
'level' => -1
)
);
} else {
$this->_addButton(
'save_and_edit_button',
array(
'label' => Mage::helper('catalog')->__('Save and Continue Edit'),
'onclick' => 'saveAndContinueEdit()',
'class' => 'save'
),
100
);
}

$this->_updateButton('save', 'label', Mage::helper('catalog')->__('Save Attribute'));
$this->_updateButton('save', 'onclick', 'saveAttribute()');

if (! Mage::registry('entity_attribute')->getIsUserDefined()) {
fballiano marked this conversation as resolved.
Show resolved Hide resolved
$this->_removeButton('delete');
} else {
$this->_updateButton('delete', 'label', Mage::helper('catalog')->__('Delete Attribute'));
}
}

public function getHeaderText()
{
if (Mage::registry('entity_attribute')->getId()) {
$frontendLabel = Mage::registry('entity_attribute')->getFrontendLabel();
if (is_array($frontendLabel)) {
$frontendLabel = $frontendLabel[0];
}
return Mage::helper('catalog')->__('Edit Category Attribute "%s"', $this->escapeHtml($frontendLabel));
}
else {
return Mage::helper('catalog')->__('New Category Attribute');
}
}

public function getValidationUrl()
{
return $this->getUrl('*/*/validate', array('_current'=>true));
}

public function getSaveUrl()
{
return $this->getUrl('*/'.$this->_controller.'/save', array('_current'=>true, 'back'=>null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Adminhtml_Block_Catalog_Category_Attribute_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Adminhtml_Block_Catalog_Category_Attribute_Edit_Tab_Main
extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract
{
/**
* Adding product form elements for editing attribute
*
* @return $this
*/
protected function _prepareForm()
{
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');

$fieldset->getElements()
->searchById('attribute_code')
->setData(
'class',
'validate-code-event ' . $fieldset->getElements()->searchById('attribute_code')->getData('class')
)->setData(
'note',
$fieldset->getElements()->searchById('attribute_code')->getData('note')
. Mage::helper('eav')->__('. Do not use "event" for an attribute code, it is a reserved keyword.')
);

$frontendInputElm = $form->getElement('frontend_input');
$additionalTypes = array(
array(
'value' => 'price',
'label' => Mage::helper('catalog')->__('Price')
),
array(
'value' => 'media_image',
'label' => Mage::helper('catalog')->__('Media Image')
)
);
if ($attributeObject->getFrontendInput() == 'gallery') {
$additionalTypes[] = array(
'value' => 'gallery',
'label' => Mage::helper('catalog')->__('Gallery')
);
}

$response = new Varien_Object();
$response->setTypes(array());
Mage::dispatchEvent('adminhtml_category_attribute_types', array('response'=>$response));
$_disabledTypes = array();
$_hiddenFields = array();
foreach ($response->getTypes() as $type) {
$additionalTypes[] = $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);

$frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes);
$frontendInputElm->setValues($frontendInputValues);

$yesnoSource = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();

$scopes = array(
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'),
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>Mage::helper('catalog')->__('Website'),
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'),
);

if (
$attributeObject->getAttributeCode() == 'status'
|| $attributeObject->getAttributeCode() == 'tax_class_id'
) {
unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]);
}

$fieldset->addField('is_global', 'select', array(
'name' => 'is_global',
'label' => Mage::helper('catalog')->__('Scope'),
'title' => Mage::helper('catalog')->__('Scope'),
'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'),
'values'=> $scopes
), 'attribute_code');

// frontend properties fieldset
$fieldset = $form->addFieldset('front_fieldset', array('legend'=>Mage::helper('catalog')->__('Frontend Properties')));

$fieldset->addField('position', 'text', array(
'name' => 'position',
'label' => Mage::helper('catalog')->__('Position'),
'title' => Mage::helper('catalog')->__('Position in Layered Navigation'),
'note' => Mage::helper('catalog')->__('Position of attribute in layered navigation block'),
'class' => 'validate-digits',
));

$fieldset->addField('is_wysiwyg_enabled', 'select', array(
'name' => 'is_wysiwyg_enabled',
'label' => Mage::helper('catalog')->__('Enable WYSIWYG'),
'title' => Mage::helper('catalog')->__('Enable WYSIWYG'),
'values' => $yesnoSource,
));

// define field dependencies
$this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
->addFieldMap("is_wysiwyg_enabled", 'wysiwyg_enabled')
->addFieldMap("frontend_input", 'frontend_input_type')
->addFieldDependence('wysiwyg_enabled', 'frontend_input_type', 'textarea')
);

Mage::dispatchEvent('adminhtml_catalog_category_attribute_edit_prepare_form', array(
'form' => $form,
'attribute' => $attributeObject
));

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Adminhtml_Block_Catalog_Category_Attribute_Edit_Tab_Options extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract
{
}
Loading