Version Notes
First version
Download this release
Release Info
| Developer | Sanjay Modasia |
| Extension | Hwg_Attributemanager |
| Version | 0.1.0 |
| Comparing to | |
| See all releases | |
Version 0.1.0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address.php +20 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit.php +99 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit/Form.php +14 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit/Tab/Main.php +308 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit/Tab/Options.php +153 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit/Tabs.php +42 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Grid.php +106 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category.php +20 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit.php +91 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Form.php +15 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tab/Front.php +73 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tab/Main.php +267 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tab/Options.php +153 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tab/System.php +103 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tabs.php +43 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Grid.php +102 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer.php +20 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit.php +91 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Form.php +15 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tab/Front.php +73 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tab/Main.php +274 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tab/Options.php +153 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tab/System.php +103 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tabs.php +43 -0
- app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Grid.php +107 -0
- app/code/local/Hwg/Attributemanager/Helper/Data.php +141 -0
- app/code/local/Hwg/Attributemanager/Model/Attributemanager.php +50 -0
- app/code/local/Hwg/Attributemanager/controllers/Adminhtml/AddressController.php +201 -0
- app/code/local/Hwg/Attributemanager/controllers/Adminhtml/CategoryController.php +200 -0
- app/code/local/Hwg/Attributemanager/controllers/Adminhtml/CustomerController.php +197 -0
- app/code/local/Hwg/Attributemanager/controllers/Adminhtml/IndexController.php +264 -0
- app/code/local/Hwg/Attributemanager/etc/config.xml +87 -0
- app/design/adminhtml/default/default/layout/attributemanager.xml +20 -0
- app/etc/modules/Hwg_Attributemanager.xml +9 -0
- package.xml +18 -0
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address.php
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Address extends Mage_Adminhtml_Block_Widget_Grid_Container
|
| 3 |
+
{
|
| 4 |
+
public function __construct()
|
| 5 |
+
{
|
| 6 |
+
$this->_controller = 'adminhtml_address';
|
| 7 |
+
$this->_blockGroup = 'attributemanager';
|
| 8 |
+
$this->_headerText = Mage::helper('attributemanager')->__('Manage Customer Address Attribute');
|
| 9 |
+
$this->_addButtonLabel = Mage::helper('attributemanager')->__('Add New Attribute');
|
| 10 |
+
parent::__construct();
|
| 11 |
+
|
| 12 |
+
$this->_addButton('add', array(
|
| 13 |
+
'label' => $this->getAddButtonLabel(),
|
| 14 |
+
'onclick' => 'setLocation(\''.$this->getUrl('*/*/new', array('type' => 'customer_address','attribute_id'=>0)).'\')',
|
| 15 |
+
'class' => 'add',
|
| 16 |
+
));
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
?>
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit.php
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Address_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
|
| 3 |
+
{
|
| 4 |
+
protected function _prepareLayout()
|
| 5 |
+
{
|
| 6 |
+
$this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_mode . '_form'));
|
| 7 |
+
return parent::_prepareLayout();
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
public function __construct()
|
| 11 |
+
{
|
| 12 |
+
$this->_objectId = 'attribute_id';
|
| 13 |
+
$this->_controller = 'adminhtml_address';
|
| 14 |
+
$this->_blockGroup = 'attributemanager';
|
| 15 |
+
|
| 16 |
+
parent::__construct();
|
| 17 |
+
|
| 18 |
+
if($this->getRequest()->getParam('popup')) {
|
| 19 |
+
$this->_removeButton('back');
|
| 20 |
+
$this->_addButton(
|
| 21 |
+
'close',
|
| 22 |
+
array(
|
| 23 |
+
'label' => Mage::helper('catalog')->__('Close Window'),
|
| 24 |
+
'class' => 'cancel',
|
| 25 |
+
'onclick' => 'window.close()',
|
| 26 |
+
'level' => -1
|
| 27 |
+
)
|
| 28 |
+
);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
$this->_updateButton('back', 'onclick', "setLocation('".$this->getUrl('*/*/address')."')");
|
| 32 |
+
|
| 33 |
+
$this->_updateButton('save', 'label', Mage::helper('catalog')->__('Save Attribute'));
|
| 34 |
+
$this->_addButton(
|
| 35 |
+
'save_and_edit_button',
|
| 36 |
+
array(
|
| 37 |
+
'label' => Mage::helper('catalog')->__('Save And Continue Edit'),
|
| 38 |
+
'onclick' => 'saveAndContinueEdit()',
|
| 39 |
+
'class' => 'save'
|
| 40 |
+
),
|
| 41 |
+
100
|
| 42 |
+
);
|
| 43 |
+
$this->_formScripts[] = "
|
| 44 |
+
function toggleEditor() {
|
| 45 |
+
if (tinyMCE.getInstanceById('company_content') == null) {
|
| 46 |
+
tinyMCE.execCommand('mceAddControl', false, 'company_content');
|
| 47 |
+
} else {
|
| 48 |
+
tinyMCE.execCommand('mceRemoveControl', false, 'company_content');
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
function saveAndContinueEdit(){
|
| 53 |
+
editForm.submit($('edit_form').action+'back/edit/');
|
| 54 |
+
}
|
| 55 |
+
";
|
| 56 |
+
if (! Mage::registry('attributemanager_data')->getIsUserDefined()) {
|
| 57 |
+
$this->_removeButton('delete');
|
| 58 |
+
} else {
|
| 59 |
+
$this->_updateButton('delete', 'label', Mage::helper('catalog')->__('Delete Attribute'));
|
| 60 |
+
$this->_updateButton('delete', 'onclick', "deleteConfirm(
|
| 61 |
+
'".Mage::helper('adminhtml')->__('Are you sure you want to do this?')."',
|
| 62 |
+
'".$this->getUrl('*/*/delete/type/'.$this->getRequest()->getParam('type').'/attribute_id/'.$this->getRequest()->getParam('attribute_id')
|
| 63 |
+
)."')");
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
public function getHeaderText()
|
| 68 |
+
{
|
| 69 |
+
switch ($this->getRequest()->getParam('type')){
|
| 70 |
+
case 'catalog_category':
|
| 71 |
+
$type="Category";
|
| 72 |
+
break;
|
| 73 |
+
case 'customer':
|
| 74 |
+
$type="Customer";
|
| 75 |
+
break;
|
| 76 |
+
case 'customer_address':
|
| 77 |
+
$type="Customer address";
|
| 78 |
+
break;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
if (Mage::registry('attributemanager_data')->getId()) {
|
| 82 |
+
return Mage::helper('attributemanager')->__('Edit %s Attribute "%s"', $type, $this->htmlEscape(Mage::registry('attributemanager_data')->getFrontendLabel()));
|
| 83 |
+
}
|
| 84 |
+
else {
|
| 85 |
+
return Mage::helper('attributemanager')->__('New %s Attribute', $type);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
public function getValidationUrl()
|
| 91 |
+
{
|
| 92 |
+
return $this->getUrl('*/*/validate', array('_current'=>true));
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
public function getSaveUrl()
|
| 96 |
+
{
|
| 97 |
+
return $this->getUrl('*/*/save', array('_current'=>true, 'back'=>null));
|
| 98 |
+
}
|
| 99 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit/Form.php
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Address_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
protected function _prepareForm()
|
| 6 |
+
{
|
| 7 |
+
$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
|
| 8 |
+
|
| 9 |
+
$form->setUseContainer(true);
|
| 10 |
+
$this->setForm($form);
|
| 11 |
+
return parent::_prepareForm();
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit/Tab/Main.php
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Address_Edit_Tab_Main extends Mage_Adminhtml_Block_Widget_Form
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
protected function _prepareForm()
|
| 6 |
+
{
|
| 7 |
+
$model = Mage::registry('attributemanager_data');
|
| 8 |
+
|
| 9 |
+
$form = new Varien_Data_Form(array(
|
| 10 |
+
'id' => 'edit_form',
|
| 11 |
+
'action' => $this->getData('action'),
|
| 12 |
+
'method' => 'post'
|
| 13 |
+
));
|
| 14 |
+
|
| 15 |
+
$fieldset = $form->addFieldset('base_fieldset',
|
| 16 |
+
array('legend'=>Mage::helper('catalog')->__('Attribute Properties'))
|
| 17 |
+
);
|
| 18 |
+
if ($model->getId()) {
|
| 19 |
+
$fieldset->addField('attribute_id', 'hidden', array(
|
| 20 |
+
'name' => 'attribute_id',
|
| 21 |
+
));
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
$this->_addElementTypes($fieldset);
|
| 25 |
+
|
| 26 |
+
$yesno = array(
|
| 27 |
+
array(
|
| 28 |
+
'value' => 0,
|
| 29 |
+
'label' => Mage::helper('catalog')->__('No')
|
| 30 |
+
),
|
| 31 |
+
array(
|
| 32 |
+
'value' => 1,
|
| 33 |
+
'label' => Mage::helper('catalog')->__('Yes')
|
| 34 |
+
));
|
| 35 |
+
|
| 36 |
+
$fieldset->addField('attribute_code', 'text', array(
|
| 37 |
+
'name' => 'attribute_code',
|
| 38 |
+
'label' => Mage::helper('catalog')->__('Attribute Code'),
|
| 39 |
+
'title' => Mage::helper('catalog')->__('Attribute Code'),
|
| 40 |
+
'note' => Mage::helper('catalog')->__('For internal use. Must be unique with no spaces'),
|
| 41 |
+
'class' => 'validate-code',
|
| 42 |
+
'required' => true,
|
| 43 |
+
));
|
| 44 |
+
|
| 45 |
+
$scopes = array(
|
| 46 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'),
|
| 47 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>Mage::helper('catalog')->__('Website'),
|
| 48 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'),
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
if ($model->getAttributeCode() == 'status' || $model->getAttributeCode() == 'tax_class_id') {
|
| 52 |
+
unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
$fieldset->addField('is_global', 'select', array(
|
| 56 |
+
'name' => 'is_global',
|
| 57 |
+
'label' => Mage::helper('catalog')->__('Scope'),
|
| 58 |
+
'title' => Mage::helper('catalog')->__('Scope'),
|
| 59 |
+
'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'),
|
| 60 |
+
'values'=> $scopes
|
| 61 |
+
));
|
| 62 |
+
|
| 63 |
+
$inputTypes = array(
|
| 64 |
+
array(
|
| 65 |
+
'value' => 'text',
|
| 66 |
+
'label' => Mage::helper('catalog')->__('Text Field')
|
| 67 |
+
),
|
| 68 |
+
array(
|
| 69 |
+
'value' => 'textarea',
|
| 70 |
+
'label' => Mage::helper('catalog')->__('Text Area')
|
| 71 |
+
),
|
| 72 |
+
array(
|
| 73 |
+
'value' => 'date',
|
| 74 |
+
'label' => Mage::helper('catalog')->__('Date')
|
| 75 |
+
),
|
| 76 |
+
array(
|
| 77 |
+
'value' => 'boolean',
|
| 78 |
+
'label' => Mage::helper('catalog')->__('Yes/No')
|
| 79 |
+
),
|
| 80 |
+
array(
|
| 81 |
+
'value' => 'multiselect',
|
| 82 |
+
'label' => Mage::helper('catalog')->__('Multiple Select')
|
| 83 |
+
),
|
| 84 |
+
array(
|
| 85 |
+
'value' => 'select',
|
| 86 |
+
'label' => Mage::helper('catalog')->__('Dropdown')
|
| 87 |
+
),
|
| 88 |
+
);
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
$response = new Varien_Object();
|
| 92 |
+
$response->setTypes(array());
|
| 93 |
+
//Mage::dispatchEvent('adminhtml_product_attribute_types', array('response'=>$response));
|
| 94 |
+
|
| 95 |
+
$_disabledTypes = array();
|
| 96 |
+
$_hiddenFields = array();
|
| 97 |
+
foreach ($response->getTypes() as $type) {
|
| 98 |
+
$inputTypes[] = $type;
|
| 99 |
+
if (isset($type['hide_fields'])) {
|
| 100 |
+
$_hiddenFields[$type['value']] = $type['hide_fields'];
|
| 101 |
+
}
|
| 102 |
+
if (isset($type['disabled_types'])) {
|
| 103 |
+
$_disabledTypes[$type['value']] = $type['disabled_types'];
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
Mage::register('attribute_type_hidden_fields', $_hiddenFields);
|
| 107 |
+
Mage::register('attribute_type_disabled_types', $_disabledTypes);
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
$fieldset->addField('frontend_input', 'select', array(
|
| 111 |
+
'name' => 'frontend_input',
|
| 112 |
+
'label' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'),
|
| 113 |
+
'title' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'),
|
| 114 |
+
'value' => 'text',
|
| 115 |
+
'values'=> $inputTypes
|
| 116 |
+
));
|
| 117 |
+
/****** champs cach�s dans le formulaire **********/
|
| 118 |
+
$fieldset->addField('entity_type_id', 'hidden', array(
|
| 119 |
+
'name' => 'entity_type_id',
|
| 120 |
+
'value' => Mage::getModel('eav/entity')->setType($this->getRequest ()->getParam ( 'type' ))->getTypeId()
|
| 121 |
+
));
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
$fieldset->addField('is_user_defined', 'hidden', array(
|
| 126 |
+
'name' => 'is_user_defined',
|
| 127 |
+
'value' => 1
|
| 128 |
+
));
|
| 129 |
+
|
| 130 |
+
$fieldset->addField('attribute_set_id', 'hidden', array(
|
| 131 |
+
'name' => 'attribute_set_id',
|
| 132 |
+
'value' => Mage::getModel('eav/entity')->setType($this->getRequest ()->getParam ( 'type' ))->getTypeId()
|
| 133 |
+
));
|
| 134 |
+
|
| 135 |
+
$fieldset->addField('attribute_group_id', 'hidden', array(
|
| 136 |
+
'name' => 'attribute_group_id',
|
| 137 |
+
'value' => Mage::getModel('eav/entity')->setType($this->getRequest ()->getParam ( 'type' ))->getTypeId()
|
| 138 |
+
));
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
/*******************************************************/
|
| 142 |
+
$fieldset->addField('is_unique', 'select', array(
|
| 143 |
+
'name' => 'is_unique',
|
| 144 |
+
'label' => Mage::helper('catalog')->__('Unique Value'),
|
| 145 |
+
'title' => Mage::helper('catalog')->__('Unique Value (not shared with other products)'),
|
| 146 |
+
'note' => Mage::helper('catalog')->__('Not shared with other products'),
|
| 147 |
+
'values' => $yesno,
|
| 148 |
+
));
|
| 149 |
+
|
| 150 |
+
$fieldset->addField('is_required', 'select', array(
|
| 151 |
+
'name' => 'is_required',
|
| 152 |
+
'label' => Mage::helper('catalog')->__('Values Required'),
|
| 153 |
+
'title' => Mage::helper('catalog')->__('Values Required'),
|
| 154 |
+
'values' => $yesno,
|
| 155 |
+
));
|
| 156 |
+
$fieldset->addField('is_visible', 'select', array(
|
| 157 |
+
'name' => 'is_visible',
|
| 158 |
+
'label' => Mage::helper('catalog')->__('Is Visible'),
|
| 159 |
+
'title' => Mage::helper('catalog')->__('Is Visible'),
|
| 160 |
+
'values' => $yesno,
|
| 161 |
+
));
|
| 162 |
+
$fieldset->addField('frontend_class', 'select', array(
|
| 163 |
+
'name' => 'frontend_class',
|
| 164 |
+
'label' => Mage::helper('catalog')->__('Input Validation for Store Owner'),
|
| 165 |
+
'title' => Mage::helper('catalog')->__('Input Validation for Store Owner'),
|
| 166 |
+
'values'=> array(
|
| 167 |
+
array(
|
| 168 |
+
'value' => '',
|
| 169 |
+
'label' => Mage::helper('catalog')->__('None')
|
| 170 |
+
),
|
| 171 |
+
array(
|
| 172 |
+
'value' => 'validate-number',
|
| 173 |
+
'label' => Mage::helper('catalog')->__('Decimal Number')
|
| 174 |
+
),
|
| 175 |
+
array(
|
| 176 |
+
'value' => 'validate-digits',
|
| 177 |
+
'label' => Mage::helper('catalog')->__('Integer Number')
|
| 178 |
+
),
|
| 179 |
+
array(
|
| 180 |
+
'value' => 'validate-email',
|
| 181 |
+
'label' => Mage::helper('catalog')->__('Email')
|
| 182 |
+
),
|
| 183 |
+
array(
|
| 184 |
+
'value' => 'validate-url',
|
| 185 |
+
'label' => Mage::helper('catalog')->__('Url')
|
| 186 |
+
),
|
| 187 |
+
array(
|
| 188 |
+
'value' => 'validate-alpha',
|
| 189 |
+
'label' => Mage::helper('catalog')->__('Letters')
|
| 190 |
+
),
|
| 191 |
+
array(
|
| 192 |
+
'value' => 'validate-alphanum',
|
| 193 |
+
'label' => Mage::helper('catalog')->__('Letters(a-zA-Z) or Numbers(0-9)')
|
| 194 |
+
),
|
| 195 |
+
)
|
| 196 |
+
));
|
| 197 |
+
|
| 198 |
+
// -----
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
// frontend properties fieldset
|
| 202 |
+
$fieldset = $form->addFieldset('front_fieldset',
|
| 203 |
+
array('legend'=>Mage::helper('catalog')->__('Frontend Properties')));
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
/* $fieldset->addField('position', 'text', array(
|
| 208 |
+
'name' => 'position',
|
| 209 |
+
'label' => Mage::helper('catalog')->__('Position'),
|
| 210 |
+
'title' => Mage::helper('catalog')->__('Position In Layered Navigation'),
|
| 211 |
+
'note' => Mage::helper('catalog')->__('Position of attribute in layered navigation block'),
|
| 212 |
+
'class' => 'validate-digits',
|
| 213 |
+
));*/
|
| 214 |
+
if($model->getId())
|
| 215 |
+
{
|
| 216 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
| 217 |
+
$readresult=$write->query("SELECT * from customer_form_attribute WHERE attribute_id=".$model->getId());
|
| 218 |
+
while ($row = $readresult->fetch() ) {
|
| 219 |
+
$customerForm[$row['form_code']] = 'checked';
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
/*$fieldset->addField('adminhtml_customer', 'checkbox', array(
|
| 223 |
+
'name' => 'customer_form[]',
|
| 224 |
+
'label' => Mage::helper('catalog')->__('Adminhtml Customer'),
|
| 225 |
+
'value' => 'adminhtml_customer',
|
| 226 |
+
'checked' => isset($customerForm['adminhtml_customer'])?$customerForm['adminhtml_customer']:'',
|
| 227 |
+
));*/
|
| 228 |
+
$fieldset->addField('customer_account_edit', 'checkbox', array(
|
| 229 |
+
'name' => 'customer_form[]',
|
| 230 |
+
'label' => Mage::helper('catalog')->__('Customer Account Edit'),
|
| 231 |
+
'value' => 'customer_account_edit',
|
| 232 |
+
'checked' => isset($customerForm['customer_account_edit'])?$customerForm['customer_account_edit']:'',
|
| 233 |
+
));
|
| 234 |
+
$fieldset->addField('adminhtml_customer_address', 'checkbox', array(
|
| 235 |
+
'name' => 'customer_form[]',
|
| 236 |
+
'label' => Mage::helper('catalog')->__('Adminhtml Customer Address'),
|
| 237 |
+
'value' => 'adminhtml_customer_address',
|
| 238 |
+
'checked' => isset($customerForm['adminhtml_customer_address'])?$customerForm['adminhtml_customer_address']:'',
|
| 239 |
+
));
|
| 240 |
+
$fieldset->addField('checkout_register', 'checkbox', array(
|
| 241 |
+
'name' => 'customer_form[]',
|
| 242 |
+
'label' => Mage::helper('catalog')->__('Checkout Register'),
|
| 243 |
+
'value' => 'checkout_register',
|
| 244 |
+
'checked' => isset($customerForm['checkout_register'])?$customerForm['checkout_register']:'',
|
| 245 |
+
));
|
| 246 |
+
$fieldset->addField('customer_account_create', 'checkbox', array(
|
| 247 |
+
'name' => 'customer_form[]',
|
| 248 |
+
'label' => Mage::helper('catalog')->__('Customer Account Create'),
|
| 249 |
+
'value' => 'customer_account_create',
|
| 250 |
+
'checked' => isset($customerForm['customer_account_create'])?$customerForm['customer_account_create']:'',
|
| 251 |
+
));
|
| 252 |
+
$fieldset->addField('customer_register_address', 'checkbox', array(
|
| 253 |
+
'name' => 'customer_form[]',
|
| 254 |
+
'label' => Mage::helper('catalog')->__('Customer Register Address'),
|
| 255 |
+
'value' => 'customer_register_address',
|
| 256 |
+
'checked' => isset($customerForm['customer_register_address'])?$customerForm['customer_register_address']:'',
|
| 257 |
+
));
|
| 258 |
+
$fieldset->addField('customer_address_edit', 'checkbox', array(
|
| 259 |
+
'name' => 'customer_form[]',
|
| 260 |
+
'label' => Mage::helper('catalog')->__('Customer Address Edit'),
|
| 261 |
+
'value' => 'customer_address_edit',
|
| 262 |
+
'checked' => isset($customerForm['customer_address_edit'])?$customerForm['customer_address_edit']:'',
|
| 263 |
+
));
|
| 264 |
+
|
| 265 |
+
$fieldset->addField('sort_order', 'text', array(
|
| 266 |
+
'name' => 'sort_order',
|
| 267 |
+
'label' => Mage::helper('catalog')->__('Sort Order'),
|
| 268 |
+
'title' => Mage::helper('catalog')->__('Order in form'),
|
| 269 |
+
//'note' => Mage::helper('catalog')->__('order of attribute in form edit/create. Leave blank for form bottom.'),
|
| 270 |
+
'class' => 'validate-digits',
|
| 271 |
+
'value' => $model->getAttributeSetInfo()
|
| 272 |
+
));
|
| 273 |
+
|
| 274 |
+
if ($model->getId())
|
| 275 |
+
{
|
| 276 |
+
$form->getElement('attribute_code')->setDisabled(1);
|
| 277 |
+
$form->getElement('frontend_input')->setDisabled(1);
|
| 278 |
+
|
| 279 |
+
if (isset($disableAttributeFields[$model->getAttributeCode()]))
|
| 280 |
+
{
|
| 281 |
+
foreach ($disableAttributeFields[$model->getAttributeCode()] as $field)
|
| 282 |
+
{
|
| 283 |
+
$form->getElement($field)->setDisabled(1);
|
| 284 |
+
}
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
/* if (!$model->getIsUserDefined() && $model->getId()) {
|
| 288 |
+
$form->getElement('is_unique')->setDisabled(1);
|
| 289 |
+
}
|
| 290 |
+
*/
|
| 291 |
+
//var_dump($model->getData());exit;
|
| 292 |
+
$form->addValues($model->getData());
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
$this->setForm($form);
|
| 297 |
+
|
| 298 |
+
return parent::_prepareForm();
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
protected function _getAdditionalElementTypes()
|
| 302 |
+
{
|
| 303 |
+
return array(
|
| 304 |
+
'apply' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_apply')
|
| 305 |
+
);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit/Tab/Options.php
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Address_Edit_Tab_Options extends Mage_Adminhtml_Block_Widget
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
public function __construct()
|
| 6 |
+
{
|
| 7 |
+
parent::__construct();
|
| 8 |
+
$this->setTemplate('attributemanager/options.phtml');
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
protected function _prepareLayout()
|
| 12 |
+
{
|
| 13 |
+
$this->setChild('delete_button',
|
| 14 |
+
$this->getLayout()->createBlock('adminhtml/widget_button')
|
| 15 |
+
->setData(array(
|
| 16 |
+
'label' => Mage::helper('catalog')->__('Delete'),
|
| 17 |
+
'class' => 'delete delete-option'
|
| 18 |
+
)));
|
| 19 |
+
|
| 20 |
+
$this->setChild('add_button',
|
| 21 |
+
$this->getLayout()->createBlock('adminhtml/widget_button')
|
| 22 |
+
->setData(array(
|
| 23 |
+
'label' => Mage::helper('catalog')->__('Add Option'),
|
| 24 |
+
'class' => 'add',
|
| 25 |
+
'id' => 'add_new_option_button'
|
| 26 |
+
)));
|
| 27 |
+
return parent::_prepareLayout();
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
public function getDeleteButtonHtml()
|
| 31 |
+
{
|
| 32 |
+
return $this->getChildHtml('delete_button');
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
public function getAddNewButtonHtml()
|
| 36 |
+
{
|
| 37 |
+
return $this->getChildHtml('add_button');
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public function getStores()
|
| 41 |
+
{
|
| 42 |
+
$stores = $this->getData('stores');
|
| 43 |
+
if (is_null($stores)) {
|
| 44 |
+
$stores = Mage::getModel('core/store')
|
| 45 |
+
->getResourceCollection()
|
| 46 |
+
->setLoadDefault(true)
|
| 47 |
+
->load();
|
| 48 |
+
$this->setData('stores', $stores);
|
| 49 |
+
}
|
| 50 |
+
return $stores;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
public function getOptionValues()
|
| 54 |
+
{
|
| 55 |
+
$attributeType = $this->getAttributeObject()->getFrontendInput();
|
| 56 |
+
$defaultValues = $this->getAttributeObject()->getDefaultValue();
|
| 57 |
+
if ($attributeType == 'select' || $attributeType == 'multiselect') {
|
| 58 |
+
$defaultValues = explode(',', $defaultValues);
|
| 59 |
+
} else {
|
| 60 |
+
$defaultValues = array();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
switch ($attributeType) {
|
| 64 |
+
case 'select':
|
| 65 |
+
$inputType = 'radio';
|
| 66 |
+
break;
|
| 67 |
+
case 'multiselect':
|
| 68 |
+
$inputType = 'checkbox';
|
| 69 |
+
break;
|
| 70 |
+
default:
|
| 71 |
+
$inputType = '';
|
| 72 |
+
break;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
$values = $this->getData('option_values');
|
| 76 |
+
if (is_null($values)) {
|
| 77 |
+
$values = array();
|
| 78 |
+
$optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
|
| 79 |
+
->setAttributeFilter($this->getAttributeObject()->getId())
|
| 80 |
+
->setPositionOrder('desc', true)
|
| 81 |
+
->load();
|
| 82 |
+
|
| 83 |
+
foreach ($optionCollection as $option) {
|
| 84 |
+
$value = array();
|
| 85 |
+
if (in_array($option->getId(), $defaultValues)) {
|
| 86 |
+
$value['checked'] = 'checked="checked"';
|
| 87 |
+
} else {
|
| 88 |
+
$value['checked'] = '';
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
$value['intype'] = $inputType;
|
| 92 |
+
$value['id'] = $option->getId();
|
| 93 |
+
$value['sort_order'] = $option->getSortOrder();
|
| 94 |
+
foreach ($this->getStores() as $store) {
|
| 95 |
+
$storeValues = $this->getStoreOptionValues($store->getId());
|
| 96 |
+
if (isset($storeValues[$option->getId()])) {
|
| 97 |
+
$value['store'.$store->getId()] = htmlspecialchars($storeValues[$option->getId()]);
|
| 98 |
+
}
|
| 99 |
+
else {
|
| 100 |
+
$value['store'.$store->getId()] = '';
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
$values[] = new Varien_Object($value);
|
| 104 |
+
}
|
| 105 |
+
$this->setData('option_values', $values);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return $values;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
public function getLabelValues()
|
| 112 |
+
{
|
| 113 |
+
$values = array();
|
| 114 |
+
$values[0] = $this->getAttributeObject()->getFrontend()->getLabel();
|
| 115 |
+
// it can be array and cause bug
|
| 116 |
+
$frontendLabel = $this->getAttributeObject()->getFrontend()->getLabel();
|
| 117 |
+
if (is_array($frontendLabel)) {
|
| 118 |
+
$frontendLabel = array_shift($frontendLabel);
|
| 119 |
+
}
|
| 120 |
+
$translations = Mage::getModel('core/translate_string')
|
| 121 |
+
->load(Mage_Catalog_Model_Entity_Attribute::MODULE_NAME.Mage_Core_Model_Translate::SCOPE_SEPARATOR.$frontendLabel)
|
| 122 |
+
->getStoreTranslations();
|
| 123 |
+
foreach ($this->getStores() as $store) {
|
| 124 |
+
if ($store->getId() != 0) {
|
| 125 |
+
$values[$store->getId()] = isset($translations[$store->getId()]) ? $translations[$store->getId()] : '';
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
return $values;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
public function getStoreOptionValues($storeId)
|
| 132 |
+
{
|
| 133 |
+
$values = $this->getData('store_option_values_'.$storeId);
|
| 134 |
+
if (is_null($values)) {
|
| 135 |
+
$values = array();
|
| 136 |
+
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
|
| 137 |
+
->setAttributeFilter($this->getAttributeObject()->getId())
|
| 138 |
+
->setStoreFilter($storeId, false)
|
| 139 |
+
->load();
|
| 140 |
+
foreach ($valuesCollection as $item) {
|
| 141 |
+
$values[$item->getId()] = $item->getValue();
|
| 142 |
+
}
|
| 143 |
+
$this->setData('store_option_values_'.$storeId, $values);
|
| 144 |
+
}
|
| 145 |
+
return $values;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
public function getAttributeObject()
|
| 149 |
+
{
|
| 150 |
+
return Mage::registry('attributemanager_data');
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Edit/Tabs.php
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Address_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
public function __construct()
|
| 6 |
+
{
|
| 7 |
+
parent::__construct();
|
| 8 |
+
$this->setId('attributemanager_tabs');
|
| 9 |
+
$this->setDestElementId('edit_form');
|
| 10 |
+
$this->setTitle(Mage::helper('catalog')->__('Attribute Information'));
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
protected function _beforeToHtml()
|
| 14 |
+
{
|
| 15 |
+
$model = Mage::registry('attributemanager_data');
|
| 16 |
+
|
| 17 |
+
$this->addTab('main', array(
|
| 18 |
+
'label' => Mage::helper('catalog')->__('Properties'),
|
| 19 |
+
'title' => Mage::helper('catalog')->__('Properties'),
|
| 20 |
+
'content' => $this->getLayout()->createBlock('attributemanager/adminhtml_address_edit_tab_main')->toHtml(),
|
| 21 |
+
'active' => true
|
| 22 |
+
));
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
$this->addTab('labels', array(
|
| 26 |
+
'label' => Mage::helper('catalog')->__('Manage Label / Options'),
|
| 27 |
+
'title' => Mage::helper('catalog')->__('Manage Label / Options'),
|
| 28 |
+
'content' => $this->getLayout()->createBlock('attributemanager/adminhtml_address_edit_tab_options')->toHtml(),
|
| 29 |
+
));
|
| 30 |
+
|
| 31 |
+
/*if ('select' == $model->getFrontendInput()) {
|
| 32 |
+
$this->addTab('options_section', array(
|
| 33 |
+
'label' => Mage::helper('catalog')->__('Options Control'),
|
| 34 |
+
'title' => Mage::helper('catalog')->__('Options Control'),
|
| 35 |
+
'content' => $this->getLayout()->createBlock('attributemanager/edit_tab_options')->toHtml(),
|
| 36 |
+
));
|
| 37 |
+
}*/
|
| 38 |
+
|
| 39 |
+
return parent::_beforeToHtml();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Address/Grid.php
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Address_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
| 3 |
+
{
|
| 4 |
+
public function __construct()
|
| 5 |
+
{
|
| 6 |
+
parent::__construct();
|
| 7 |
+
$this->setId('attributemanagergrid');
|
| 8 |
+
$this->setDefaultSort('attribute_code');
|
| 9 |
+
$this->setDefaultDir('ASC');
|
| 10 |
+
$this->setSaveParametersInSession(true);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
protected function _prepareCollection()
|
| 14 |
+
{
|
| 15 |
+
$type='customer_address';
|
| 16 |
+
$block='address';
|
| 17 |
+
$this->type =$type;
|
| 18 |
+
$this->block =$block;
|
| 19 |
+
$this->type=$type;
|
| 20 |
+
|
| 21 |
+
$collection = Mage::getResourceModel('eav/entity_attribute_collection')
|
| 22 |
+
->setEntityTypeFilter( Mage::getModel('eav/entity')->setType($type)->getTypeId() )
|
| 23 |
+
->addFieldToFilter("is_user_defined", 1);
|
| 24 |
+
|
| 25 |
+
$this->setCollection($collection);
|
| 26 |
+
return parent::_prepareCollection();
|
| 27 |
+
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
protected function _prepareColumns()
|
| 31 |
+
{
|
| 32 |
+
$this->addColumn('attribute_code', array(
|
| 33 |
+
'header'=>Mage::helper('catalog')->__('Attribute Code'),
|
| 34 |
+
'sortable'=>true,
|
| 35 |
+
'index'=>'attribute_code'
|
| 36 |
+
));
|
| 37 |
+
|
| 38 |
+
$this->addColumn('frontend_label', array(
|
| 39 |
+
'header'=>Mage::helper('catalog')->__('Attribute Label'),
|
| 40 |
+
'sortable'=>true,
|
| 41 |
+
'index'=>'frontend_label'
|
| 42 |
+
));
|
| 43 |
+
|
| 44 |
+
$this->addColumn('is_visible', array(
|
| 45 |
+
'header'=>Mage::helper('catalog')->__('Visible'),
|
| 46 |
+
'sortable'=>true,
|
| 47 |
+
'index'=>'is_visible_on_front',
|
| 48 |
+
'type' => 'options',
|
| 49 |
+
'options' => array(
|
| 50 |
+
'1' => Mage::helper('catalog')->__('Yes'),
|
| 51 |
+
'0' => Mage::helper('catalog')->__('No'),
|
| 52 |
+
),
|
| 53 |
+
'align' => 'center',
|
| 54 |
+
));
|
| 55 |
+
|
| 56 |
+
$this->addColumn('is_global', array(
|
| 57 |
+
'header'=>Mage::helper('catalog')->__('Scope'),
|
| 58 |
+
'sortable'=>true,
|
| 59 |
+
'index'=>'is_global',
|
| 60 |
+
'type' => 'options',
|
| 61 |
+
'options' => array(
|
| 62 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'),
|
| 63 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>Mage::helper('catalog')->__('Website'),
|
| 64 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'),
|
| 65 |
+
),
|
| 66 |
+
'align' => 'center',
|
| 67 |
+
));
|
| 68 |
+
|
| 69 |
+
$this->addColumn('is_required', array(
|
| 70 |
+
'header'=>Mage::helper('catalog')->__('Required'),
|
| 71 |
+
'sortable'=>true,
|
| 72 |
+
'index'=>'is_required',
|
| 73 |
+
'type' => 'options',
|
| 74 |
+
'options' => array(
|
| 75 |
+
'1' => Mage::helper('catalog')->__('Yes'),
|
| 76 |
+
'0' => Mage::helper('catalog')->__('No'),
|
| 77 |
+
),
|
| 78 |
+
'align' => 'center',
|
| 79 |
+
));
|
| 80 |
+
|
| 81 |
+
$this->addColumn('is_user_defined', array(
|
| 82 |
+
'header'=>Mage::helper('catalog')->__('System'),
|
| 83 |
+
'sortable'=>true,
|
| 84 |
+
'index'=>'is_user_defined',
|
| 85 |
+
'type' => 'options',
|
| 86 |
+
'align' => 'center',
|
| 87 |
+
'options' => array(
|
| 88 |
+
'0' => Mage::helper('catalog')->__('Yes'), // intended reverted use
|
| 89 |
+
'1' => Mage::helper('catalog')->__('No'), // intended reverted use
|
| 90 |
+
),
|
| 91 |
+
));
|
| 92 |
+
|
| 93 |
+
$this->addExportType('*/*/exportCsv'.$this->_block, Mage::helper('attributemanager')->__('CSV'));
|
| 94 |
+
$this->addExportType('*/*/exportXml'.$this->_block, Mage::helper('attributemanager')->__('XML'));
|
| 95 |
+
|
| 96 |
+
return parent::_prepareColumns();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
public function getRowUrl($row)
|
| 100 |
+
{
|
| 101 |
+
return $this->getUrl('*/*/edit', array('type' => $this->type,'attribute_id' => $row->getAttributeId()));
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
?>
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category.php
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Category extends Mage_Adminhtml_Block_Widget_Grid_Container
|
| 3 |
+
{
|
| 4 |
+
public function __construct()
|
| 5 |
+
{
|
| 6 |
+
$this->_controller = 'adminhtml_category';
|
| 7 |
+
$this->_blockGroup = 'attributemanager';
|
| 8 |
+
$this->_headerText = Mage::helper('attributemanager')->__('Manage Category Attribute');
|
| 9 |
+
$this->_addButtonLabel = Mage::helper('attributemanager')->__('Add New Attribute');
|
| 10 |
+
parent::__construct();
|
| 11 |
+
|
| 12 |
+
$this->_addButton('add', array(
|
| 13 |
+
'label' => $this->getAddButtonLabel(),
|
| 14 |
+
'onclick' => 'setLocation(\''.$this->getUrl('*/*/new', array('type' => 'catalog_category','attribute_id'=>0)).'\')',
|
| 15 |
+
'class' => 'add',
|
| 16 |
+
));
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
?>
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit.php
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Category_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
protected function _prepareLayout()
|
| 6 |
+
{
|
| 7 |
+
|
| 8 |
+
$this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_mode . '_form'));
|
| 9 |
+
return parent::_prepareLayout();
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
public function __construct()
|
| 13 |
+
{
|
| 14 |
+
|
| 15 |
+
$this->_objectId = 'attribute_id';
|
| 16 |
+
$this->_controller = 'adminhtml_category';
|
| 17 |
+
$this->_blockGroup = 'attributemanager';
|
| 18 |
+
|
| 19 |
+
parent::__construct();
|
| 20 |
+
|
| 21 |
+
if($this->getRequest()->getParam('popup')) {
|
| 22 |
+
$this->_removeButton('back');
|
| 23 |
+
$this->_addButton(
|
| 24 |
+
'close',
|
| 25 |
+
array(
|
| 26 |
+
'label' => Mage::helper('catalog')->__('Close Window'),
|
| 27 |
+
'class' => 'cancel',
|
| 28 |
+
'onclick' => 'window.close()',
|
| 29 |
+
'level' => -1
|
| 30 |
+
)
|
| 31 |
+
);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
$this->_updateButton('back', 'onclick', "setLocation('".$this->getUrl('*/*/category')."')");
|
| 35 |
+
|
| 36 |
+
$this->_updateButton('save', 'label', Mage::helper('catalog')->__('Save Attribute'));
|
| 37 |
+
$this->_addButton(
|
| 38 |
+
'save_and_edit_button',
|
| 39 |
+
array(
|
| 40 |
+
'label' => Mage::helper('catalog')->__('Save And Continue Edit'),
|
| 41 |
+
'onclick' => 'saveAndContinueEdit()',
|
| 42 |
+
'class' => 'save'
|
| 43 |
+
),
|
| 44 |
+
100
|
| 45 |
+
);
|
| 46 |
+
$this->_formScripts[] = "
|
| 47 |
+
function toggleEditor() {
|
| 48 |
+
if (tinyMCE.getInstanceById('company_content') == null) {
|
| 49 |
+
tinyMCE.execCommand('mceAddControl', false, 'company_content');
|
| 50 |
+
} else {
|
| 51 |
+
tinyMCE.execCommand('mceRemoveControl', false, 'company_content');
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function saveAndContinueEdit(){
|
| 56 |
+
editForm.submit($('edit_form').action+'back/edit/');
|
| 57 |
+
}
|
| 58 |
+
";
|
| 59 |
+
if (! Mage::registry('attributemanager_data')->getIsUserDefined()) {
|
| 60 |
+
$this->_removeButton('delete');
|
| 61 |
+
} else {
|
| 62 |
+
$this->_updateButton('delete', 'label', Mage::helper('catalog')->__('Delete Attribute'));
|
| 63 |
+
$this->_updateButton('delete', 'onclick', "deleteConfirm(
|
| 64 |
+
'".Mage::helper('adminhtml')->__('Are you sure you want to do this?')."',
|
| 65 |
+
'".$this->getUrl('*/*/delete/type/catalog_category/attribute_id/'.$this->getRequest()->getParam('attribute_id')
|
| 66 |
+
)."')");
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
public function getHeaderText()
|
| 71 |
+
{
|
| 72 |
+
$type="Category";
|
| 73 |
+
if (Mage::registry('attributemanager_data')->getId()) {
|
| 74 |
+
return Mage::helper('attributemanager')->__('Edit %s Attribute "%s"', $type, $this->htmlEscape(Mage::registry('attributemanager_data')->getFrontendLabel()));
|
| 75 |
+
}
|
| 76 |
+
else {
|
| 77 |
+
return Mage::helper('attributemanager')->__('New %s Attribute', $type);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
public function getValidationUrl()
|
| 83 |
+
{
|
| 84 |
+
return $this->getUrl('*/*/validate', array('_current'=>true));
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
public function getSaveUrl()
|
| 88 |
+
{
|
| 89 |
+
return $this->getUrl('*/*/save', array('_current'=>true, 'back'=>null));
|
| 90 |
+
}
|
| 91 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Form.php
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Hwg_Attributemanager_Block_Adminhtml_Category_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
protected function _prepareForm()
|
| 7 |
+
{
|
| 8 |
+
$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
|
| 9 |
+
|
| 10 |
+
$form->setUseContainer(true);
|
| 11 |
+
$this->setForm($form);
|
| 12 |
+
return parent::_prepareForm();
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tab/Front.php
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Category_Edit_Tab_Front extends Mage_Adminhtml_Block_Widget_Form
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
protected function _prepareForm()
|
| 6 |
+
{
|
| 7 |
+
$model = Mage::registry('attributemanager_data');
|
| 8 |
+
|
| 9 |
+
$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
|
| 10 |
+
|
| 11 |
+
$fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('catalog')->__('Frontend Properties')));
|
| 12 |
+
|
| 13 |
+
$yesno = array(
|
| 14 |
+
array(
|
| 15 |
+
'value' => 0,
|
| 16 |
+
'label' => Mage::helper('catalog')->__('No')
|
| 17 |
+
),
|
| 18 |
+
array(
|
| 19 |
+
'value' => 1,
|
| 20 |
+
'label' => Mage::helper('catalog')->__('Yes')
|
| 21 |
+
));
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
$fieldset->addField('is_searchable', 'select', array(
|
| 25 |
+
'name' => 'is_searchable',
|
| 26 |
+
'label' => Mage::helper('catalog')->__('Use in quick search'),
|
| 27 |
+
'title' => Mage::helper('catalog')->__('Use in quick search'),
|
| 28 |
+
'values' => $yesno,
|
| 29 |
+
));
|
| 30 |
+
|
| 31 |
+
$fieldset->addField('is_visible_in_advanced_search', 'select', array(
|
| 32 |
+
'name' => 'is_visible_in_advanced_search',
|
| 33 |
+
'label' => Mage::helper('catalog')->__('Use in advanced search'),
|
| 34 |
+
'title' => Mage::helper('catalog')->__('Use in advanced search'),
|
| 35 |
+
'values' => $yesno,
|
| 36 |
+
));
|
| 37 |
+
|
| 38 |
+
$fieldset->addField('is_comparable', 'select', array(
|
| 39 |
+
'name' => 'is_comparable',
|
| 40 |
+
'label' => Mage::helper('catalog')->__('Comparable on Front-end'),
|
| 41 |
+
'title' => Mage::helper('catalog')->__('Comparable on Front-end'),
|
| 42 |
+
'values' => $yesno,
|
| 43 |
+
));
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
$fieldset->addField('is_filterable', 'select', array(
|
| 47 |
+
'name' => 'is_filterable',
|
| 48 |
+
'label' => Mage::helper('catalog')->__("Use In Layered Navigation<br/>(Can be used only with catalog input type 'Dropdown')"),
|
| 49 |
+
'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown'),
|
| 50 |
+
'values' => array(
|
| 51 |
+
array('value' => '0', 'label' => Mage::helper('catalog')->__('No')),
|
| 52 |
+
array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')),
|
| 53 |
+
array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)')),
|
| 54 |
+
),
|
| 55 |
+
));
|
| 56 |
+
|
| 57 |
+
// if ($model->getIsUserDefined() || !$model->getId()) {
|
| 58 |
+
$fieldset->addField('is_visible_on_front', 'select', array(
|
| 59 |
+
'name' => 'is_visible_on_front',
|
| 60 |
+
'label' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'),
|
| 61 |
+
'title' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'),
|
| 62 |
+
'values' => $yesno,
|
| 63 |
+
));
|
| 64 |
+
// }
|
| 65 |
+
|
| 66 |
+
$form->setValues($model->getData());
|
| 67 |
+
|
| 68 |
+
$this->setForm($form);
|
| 69 |
+
|
| 70 |
+
return parent::_prepareForm();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tab/Main.php
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Hwg_Attributemanager_Block_Adminhtml_Category_Edit_Tab_Main extends Mage_Adminhtml_Block_Widget_Form
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
protected function _prepareForm()
|
| 7 |
+
{
|
| 8 |
+
$model = Mage::registry('attributemanager_data');
|
| 9 |
+
|
| 10 |
+
$form = new Varien_Data_Form(array(
|
| 11 |
+
'id' => 'edit_form',
|
| 12 |
+
'action' => $this->getData('action'),
|
| 13 |
+
'method' => 'post'
|
| 14 |
+
));
|
| 15 |
+
|
| 16 |
+
$fieldset = $form->addFieldset('base_fieldset',
|
| 17 |
+
array('legend'=>Mage::helper('catalog')->__('Attribute Properties'))
|
| 18 |
+
);
|
| 19 |
+
if ($model->getId()) {
|
| 20 |
+
$fieldset->addField('attribute_id', 'hidden', array(
|
| 21 |
+
'name' => 'attribute_id',
|
| 22 |
+
));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
$this->_addElementTypes($fieldset);
|
| 26 |
+
|
| 27 |
+
$yesno = array(
|
| 28 |
+
array(
|
| 29 |
+
'value' => 0,
|
| 30 |
+
'label' => Mage::helper('catalog')->__('No')
|
| 31 |
+
),
|
| 32 |
+
array(
|
| 33 |
+
'value' => 1,
|
| 34 |
+
'label' => Mage::helper('catalog')->__('Yes')
|
| 35 |
+
));
|
| 36 |
+
|
| 37 |
+
$fieldset->addField('attribute_code', 'text', array(
|
| 38 |
+
'name' => 'attribute_code',
|
| 39 |
+
'label' => Mage::helper('catalog')->__('Attribute Code'),
|
| 40 |
+
'title' => Mage::helper('catalog')->__('Attribute Code'),
|
| 41 |
+
'note' => Mage::helper('catalog')->__('For internal use. Must be unique with no spaces'),
|
| 42 |
+
'class' => 'validate-code',
|
| 43 |
+
'required' => true,
|
| 44 |
+
));
|
| 45 |
+
|
| 46 |
+
$scopes = array(
|
| 47 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'),
|
| 48 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>Mage::helper('catalog')->__('Website'),
|
| 49 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'),
|
| 50 |
+
);
|
| 51 |
+
|
| 52 |
+
if ($model->getAttributeCode() == 'status' || $model->getAttributeCode() == 'tax_class_id') {
|
| 53 |
+
unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
$fieldset->addField('is_global', 'select', array(
|
| 57 |
+
'name' => 'is_global',
|
| 58 |
+
'label' => Mage::helper('catalog')->__('Scope'),
|
| 59 |
+
'title' => Mage::helper('catalog')->__('Scope'),
|
| 60 |
+
'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'),
|
| 61 |
+
'values'=> $scopes
|
| 62 |
+
));
|
| 63 |
+
|
| 64 |
+
$inputTypes = array(
|
| 65 |
+
array(
|
| 66 |
+
'value' => 'text',
|
| 67 |
+
'label' => Mage::helper('catalog')->__('Text Field')
|
| 68 |
+
),
|
| 69 |
+
array(
|
| 70 |
+
'value' => 'textarea',
|
| 71 |
+
'label' => Mage::helper('catalog')->__('Text Area')
|
| 72 |
+
),
|
| 73 |
+
array(
|
| 74 |
+
'value' => 'date',
|
| 75 |
+
'label' => Mage::helper('catalog')->__('Date')
|
| 76 |
+
),
|
| 77 |
+
array(
|
| 78 |
+
'value' => 'boolean',
|
| 79 |
+
'label' => Mage::helper('catalog')->__('Yes/No')
|
| 80 |
+
),
|
| 81 |
+
array(
|
| 82 |
+
'value' => 'multiselect',
|
| 83 |
+
'label' => Mage::helper('catalog')->__('Multiple Select')
|
| 84 |
+
),
|
| 85 |
+
array(
|
| 86 |
+
'value' => 'select',
|
| 87 |
+
'label' => Mage::helper('catalog')->__('Dropdown')
|
| 88 |
+
),
|
| 89 |
+
);
|
| 90 |
+
if($this->getRequest ()->getParam ( 'type' )==="catalog_category"){
|
| 91 |
+
$inputTypes[]= array(
|
| 92 |
+
'value' => 'image',
|
| 93 |
+
'label' => Mage::helper('catalog')->__('Image')
|
| 94 |
+
|
| 95 |
+
);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
$response = new Varien_Object();
|
| 99 |
+
$response->setTypes(array());
|
| 100 |
+
//Mage::dispatchEvent('adminhtml_product_attribute_types', array('response'=>$response));
|
| 101 |
+
|
| 102 |
+
$_disabledTypes = array();
|
| 103 |
+
$_hiddenFields = array();
|
| 104 |
+
foreach ($response->getTypes() as $type) {
|
| 105 |
+
$inputTypes[] = $type;
|
| 106 |
+
if (isset($type['hide_fields'])) {
|
| 107 |
+
$_hiddenFields[$type['value']] = $type['hide_fields'];
|
| 108 |
+
}
|
| 109 |
+
if (isset($type['disabled_types'])) {
|
| 110 |
+
$_disabledTypes[$type['value']] = $type['disabled_types'];
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
Mage::register('attribute_type_hidden_fields', $_hiddenFields);
|
| 114 |
+
Mage::register('attribute_type_disabled_types', $_disabledTypes);
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
$fieldset->addField('frontend_input', 'select', array(
|
| 118 |
+
'name' => 'frontend_input',
|
| 119 |
+
'label' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'),
|
| 120 |
+
'title' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'),
|
| 121 |
+
'value' => 'text',
|
| 122 |
+
'values'=> $inputTypes
|
| 123 |
+
));
|
| 124 |
+
/****** champs cach�s dans le formulaire **********/
|
| 125 |
+
$fieldset->addField('entity_type_id', 'hidden', array(
|
| 126 |
+
'name' => 'entity_type_id',
|
| 127 |
+
'value' => Mage::getModel('eav/entity')->setType($this->getRequest ()->getParam ( 'type' ))->getTypeId()
|
| 128 |
+
));
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
$fieldset->addField('is_user_defined', 'hidden', array(
|
| 133 |
+
'name' => 'is_user_defined',
|
| 134 |
+
'value' => 1
|
| 135 |
+
));
|
| 136 |
+
|
| 137 |
+
$fieldset->addField('attribute_set_id', 'hidden', array(
|
| 138 |
+
'name' => 'attribute_set_id',
|
| 139 |
+
'value' => Mage::getModel('eav/entity')->setType($this->getRequest ()->getParam ( 'type' ))->getTypeId()
|
| 140 |
+
));
|
| 141 |
+
|
| 142 |
+
$fieldset->addField('attribute_group_id', 'hidden', array(
|
| 143 |
+
'name' => 'attribute_group_id',
|
| 144 |
+
'value' => Mage::getModel('eav/entity')->setType($this->getRequest ()->getParam ( 'type' ))->getTypeId()
|
| 145 |
+
));
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
/*******************************************************/
|
| 149 |
+
$fieldset->addField('is_unique', 'select', array(
|
| 150 |
+
'name' => 'is_unique',
|
| 151 |
+
'label' => Mage::helper('catalog')->__('Unique Value'),
|
| 152 |
+
'title' => Mage::helper('catalog')->__('Unique Value (not shared with other products)'),
|
| 153 |
+
'note' => Mage::helper('catalog')->__('Not shared with other products'),
|
| 154 |
+
'values' => $yesno,
|
| 155 |
+
));
|
| 156 |
+
|
| 157 |
+
$fieldset->addField('is_required', 'select', array(
|
| 158 |
+
'name' => 'is_required',
|
| 159 |
+
'label' => Mage::helper('catalog')->__('Values Required'),
|
| 160 |
+
'title' => Mage::helper('catalog')->__('Values Required'),
|
| 161 |
+
'values' => $yesno,
|
| 162 |
+
));
|
| 163 |
+
|
| 164 |
+
$fieldset->addField('frontend_class', 'select', array(
|
| 165 |
+
'name' => 'frontend_class',
|
| 166 |
+
'label' => Mage::helper('catalog')->__('Input Validation for Store Owner'),
|
| 167 |
+
'title' => Mage::helper('catalog')->__('Input Validation for Store Owner'),
|
| 168 |
+
'values'=> array(
|
| 169 |
+
array(
|
| 170 |
+
'value' => '',
|
| 171 |
+
'label' => Mage::helper('catalog')->__('None')
|
| 172 |
+
),
|
| 173 |
+
array(
|
| 174 |
+
'value' => 'validate-number',
|
| 175 |
+
'label' => Mage::helper('catalog')->__('Decimal Number')
|
| 176 |
+
),
|
| 177 |
+
array(
|
| 178 |
+
'value' => 'validate-digits',
|
| 179 |
+
'label' => Mage::helper('catalog')->__('Integer Number')
|
| 180 |
+
),
|
| 181 |
+
array(
|
| 182 |
+
'value' => 'validate-email',
|
| 183 |
+
'label' => Mage::helper('catalog')->__('Email')
|
| 184 |
+
),
|
| 185 |
+
array(
|
| 186 |
+
'value' => 'validate-url',
|
| 187 |
+
'label' => Mage::helper('catalog')->__('Url')
|
| 188 |
+
),
|
| 189 |
+
array(
|
| 190 |
+
'value' => 'validate-alpha',
|
| 191 |
+
'label' => Mage::helper('catalog')->__('Letters')
|
| 192 |
+
),
|
| 193 |
+
array(
|
| 194 |
+
'value' => 'validate-alphanum',
|
| 195 |
+
'label' => Mage::helper('catalog')->__('Letters(a-zA-Z) or Numbers(0-9)')
|
| 196 |
+
),
|
| 197 |
+
)
|
| 198 |
+
));
|
| 199 |
+
|
| 200 |
+
// -----
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
// frontend properties fieldset
|
| 204 |
+
$fieldset = $form->addFieldset('front_fieldset',
|
| 205 |
+
array('legend'=>Mage::helper('catalog')->__('Frontend Properties')));
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
$fieldset->addField('position', 'text', array(
|
| 210 |
+
'name' => 'position',
|
| 211 |
+
'label' => Mage::helper('catalog')->__('Position'),
|
| 212 |
+
'title' => Mage::helper('catalog')->__('Position In Layered Navigation'),
|
| 213 |
+
'note' => Mage::helper('catalog')->__('Position of attribute in layered navigation block'),
|
| 214 |
+
'class' => 'validate-digits',
|
| 215 |
+
));
|
| 216 |
+
|
| 217 |
+
if ($model->getIsUserDefined() || !$model->getId()) {
|
| 218 |
+
$fieldset->addField('is_visible_on_front', 'select', array(
|
| 219 |
+
'name' => 'is_visible_on_front',
|
| 220 |
+
'label' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'),
|
| 221 |
+
'title' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'),
|
| 222 |
+
'values' => $yesno,
|
| 223 |
+
));
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
$fieldset->addField('sort_order', 'text', array(
|
| 227 |
+
'name' => 'sort_order',
|
| 228 |
+
'label' => Mage::helper('catalog')->__('Order'),
|
| 229 |
+
'title' => Mage::helper('catalog')->__('Order in form'),
|
| 230 |
+
'note' => Mage::helper('catalog')->__('order of attribute in form edit/create. Leave blank for form bottom.'),
|
| 231 |
+
'class' => 'validate-digits',
|
| 232 |
+
'value' => $model->getAttributeSetInfo()
|
| 233 |
+
));
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
if ($model->getId()) {
|
| 237 |
+
$form->getElement('attribute_code')->setDisabled(1);
|
| 238 |
+
$form->getElement('frontend_input')->setDisabled(1);
|
| 239 |
+
|
| 240 |
+
if (isset($disableAttributeFields[$model->getAttributeCode()])) {
|
| 241 |
+
foreach ($disableAttributeFields[$model->getAttributeCode()] as $field) {
|
| 242 |
+
$form->getElement($field)->setDisabled(1);
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
}
|
| 246 |
+
/* if (!$model->getIsUserDefined() && $model->getId()) {
|
| 247 |
+
$form->getElement('is_unique')->setDisabled(1);
|
| 248 |
+
}
|
| 249 |
+
*/
|
| 250 |
+
//var_dump($model->getData());exit;
|
| 251 |
+
$form->addValues($model->getData());
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
$this->setForm($form);
|
| 256 |
+
|
| 257 |
+
return parent::_prepareForm();
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
protected function _getAdditionalElementTypes()
|
| 261 |
+
{
|
| 262 |
+
return array(
|
| 263 |
+
'apply' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_apply')
|
| 264 |
+
);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tab/Options.php
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Category_Edit_Tab_Options extends Mage_Adminhtml_Block_Widget
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
public function __construct()
|
| 6 |
+
{
|
| 7 |
+
parent::__construct();
|
| 8 |
+
$this->setTemplate('attributemanager/options.phtml');
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
protected function _prepareLayout()
|
| 12 |
+
{
|
| 13 |
+
$this->setChild('delete_button',
|
| 14 |
+
$this->getLayout()->createBlock('adminhtml/widget_button')
|
| 15 |
+
->setData(array(
|
| 16 |
+
'label' => Mage::helper('catalog')->__('Delete'),
|
| 17 |
+
'class' => 'delete delete-option'
|
| 18 |
+
)));
|
| 19 |
+
|
| 20 |
+
$this->setChild('add_button',
|
| 21 |
+
$this->getLayout()->createBlock('adminhtml/widget_button')
|
| 22 |
+
->setData(array(
|
| 23 |
+
'label' => Mage::helper('catalog')->__('Add Option'),
|
| 24 |
+
'class' => 'add',
|
| 25 |
+
'id' => 'add_new_option_button'
|
| 26 |
+
)));
|
| 27 |
+
return parent::_prepareLayout();
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
public function getDeleteButtonHtml()
|
| 31 |
+
{
|
| 32 |
+
return $this->getChildHtml('delete_button');
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
public function getAddNewButtonHtml()
|
| 36 |
+
{
|
| 37 |
+
return $this->getChildHtml('add_button');
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public function getStores()
|
| 41 |
+
{
|
| 42 |
+
$stores = $this->getData('stores');
|
| 43 |
+
if (is_null($stores)) {
|
| 44 |
+
$stores = Mage::getModel('core/store')
|
| 45 |
+
->getResourceCollection()
|
| 46 |
+
->setLoadDefault(true)
|
| 47 |
+
->load();
|
| 48 |
+
$this->setData('stores', $stores);
|
| 49 |
+
}
|
| 50 |
+
return $stores;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
public function getOptionValues()
|
| 54 |
+
{
|
| 55 |
+
$attributeType = $this->getAttributeObject()->getFrontendInput();
|
| 56 |
+
$defaultValues = $this->getAttributeObject()->getDefaultValue();
|
| 57 |
+
if ($attributeType == 'select' || $attributeType == 'multiselect') {
|
| 58 |
+
$defaultValues = explode(',', $defaultValues);
|
| 59 |
+
} else {
|
| 60 |
+
$defaultValues = array();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
switch ($attributeType) {
|
| 64 |
+
case 'select':
|
| 65 |
+
$inputType = 'radio';
|
| 66 |
+
break;
|
| 67 |
+
case 'multiselect':
|
| 68 |
+
$inputType = 'checkbox';
|
| 69 |
+
break;
|
| 70 |
+
default:
|
| 71 |
+
$inputType = '';
|
| 72 |
+
break;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
$values = $this->getData('option_values');
|
| 76 |
+
if (is_null($values)) {
|
| 77 |
+
$values = array();
|
| 78 |
+
$optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
|
| 79 |
+
->setAttributeFilter($this->getAttributeObject()->getId())
|
| 80 |
+
->setPositionOrder('desc', true)
|
| 81 |
+
->load();
|
| 82 |
+
|
| 83 |
+
foreach ($optionCollection as $option) {
|
| 84 |
+
$value = array();
|
| 85 |
+
if (in_array($option->getId(), $defaultValues)) {
|
| 86 |
+
$value['checked'] = 'checked="checked"';
|
| 87 |
+
} else {
|
| 88 |
+
$value['checked'] = '';
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
$value['intype'] = $inputType;
|
| 92 |
+
$value['id'] = $option->getId();
|
| 93 |
+
$value['sort_order'] = $option->getSortOrder();
|
| 94 |
+
foreach ($this->getStores() as $store) {
|
| 95 |
+
$storeValues = $this->getStoreOptionValues($store->getId());
|
| 96 |
+
if (isset($storeValues[$option->getId()])) {
|
| 97 |
+
$value['store'.$store->getId()] = htmlspecialchars($storeValues[$option->getId()]);
|
| 98 |
+
}
|
| 99 |
+
else {
|
| 100 |
+
$value['store'.$store->getId()] = '';
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
$values[] = new Varien_Object($value);
|
| 104 |
+
}
|
| 105 |
+
$this->setData('option_values', $values);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return $values;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
public function getLabelValues()
|
| 112 |
+
{
|
| 113 |
+
$values = array();
|
| 114 |
+
$values[0] = $this->getAttributeObject()->getFrontend()->getLabel();
|
| 115 |
+
// it can be array and cause bug
|
| 116 |
+
$frontendLabel = $this->getAttributeObject()->getFrontend()->getLabel();
|
| 117 |
+
if (is_array($frontendLabel)) {
|
| 118 |
+
$frontendLabel = array_shift($frontendLabel);
|
| 119 |
+
}
|
| 120 |
+
$translations = Mage::getModel('core/translate_string')
|
| 121 |
+
->load(Mage_Catalog_Model_Entity_Attribute::MODULE_NAME.Mage_Core_Model_Translate::SCOPE_SEPARATOR.$frontendLabel)
|
| 122 |
+
->getStoreTranslations();
|
| 123 |
+
foreach ($this->getStores() as $store) {
|
| 124 |
+
if ($store->getId() != 0) {
|
| 125 |
+
$values[$store->getId()] = isset($translations[$store->getId()]) ? $translations[$store->getId()] : '';
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
return $values;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
public function getStoreOptionValues($storeId)
|
| 132 |
+
{
|
| 133 |
+
$values = $this->getData('store_option_values_'.$storeId);
|
| 134 |
+
if (is_null($values)) {
|
| 135 |
+
$values = array();
|
| 136 |
+
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
|
| 137 |
+
->setAttributeFilter($this->getAttributeObject()->getId())
|
| 138 |
+
->setStoreFilter($storeId, false)
|
| 139 |
+
->load();
|
| 140 |
+
foreach ($valuesCollection as $item) {
|
| 141 |
+
$values[$item->getId()] = $item->getValue();
|
| 142 |
+
}
|
| 143 |
+
$this->setData('store_option_values_'.$storeId, $values);
|
| 144 |
+
}
|
| 145 |
+
return $values;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
public function getAttributeObject()
|
| 149 |
+
{
|
| 150 |
+
return Mage::registry('attributemanager_data');
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tab/System.php
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Category_Edit_Tab_System extends Mage_Adminhtml_Block_Widget_Form
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
protected function _prepareForm()
|
| 6 |
+
{
|
| 7 |
+
$model = Mage::registry('entity_attribute');
|
| 8 |
+
|
| 9 |
+
$form = new Varien_Data_Form();
|
| 10 |
+
$fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('catalog')->__('System Properties')));
|
| 11 |
+
|
| 12 |
+
if ($model->getAttributeId()) {
|
| 13 |
+
$fieldset->addField('attribute_id', 'hidden', array(
|
| 14 |
+
'name' => 'attribute_id',
|
| 15 |
+
));
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
$yesno = array(
|
| 19 |
+
array(
|
| 20 |
+
'value' => 0,
|
| 21 |
+
'label' => Mage::helper('catalog')->__('No')
|
| 22 |
+
),
|
| 23 |
+
array(
|
| 24 |
+
'value' => 1,
|
| 25 |
+
'label' => Mage::helper('catalog')->__('Yes')
|
| 26 |
+
));
|
| 27 |
+
|
| 28 |
+
/*$fieldset->addField('attribute_model', 'text', array(
|
| 29 |
+
'name' => 'attribute_model',
|
| 30 |
+
'label' => Mage::helper('catalog')->__('Attribute Model'),
|
| 31 |
+
'title' => Mage::helper('catalog')->__('Attribute Model'),
|
| 32 |
+
));
|
| 33 |
+
|
| 34 |
+
$fieldset->addField('backend_model', 'text', array(
|
| 35 |
+
'name' => 'backend_model',
|
| 36 |
+
'label' => Mage::helper('catalog')->__('Backend Model'),
|
| 37 |
+
'title' => Mage::helper('catalog')->__('Backend Model'),
|
| 38 |
+
));*/
|
| 39 |
+
|
| 40 |
+
$fieldset->addField('backend_type', 'select', array(
|
| 41 |
+
'name' => 'backend_type',
|
| 42 |
+
'label' => Mage::helper('catalog')->__('Data Type for Saving in Database'),
|
| 43 |
+
'title' => Mage::helper('catalog')->__('Data Type for Saving in Database'),
|
| 44 |
+
'options' => array(
|
| 45 |
+
'text' => Mage::helper('catalog')->__('Text'),
|
| 46 |
+
'varchar' => Mage::helper('catalog')->__('Varchar'),
|
| 47 |
+
'static' => Mage::helper('catalog')->__('Static'),
|
| 48 |
+
'datetime' => Mage::helper('catalog')->__('Datetime'),
|
| 49 |
+
'decimal' => Mage::helper('catalog')->__('Decimal'),
|
| 50 |
+
'int' => Mage::helper('catalog')->__('Integer'),
|
| 51 |
+
),
|
| 52 |
+
));
|
| 53 |
+
|
| 54 |
+
/*$fieldset->addField('backend_table', 'text', array(
|
| 55 |
+
'name' => 'backend_table',
|
| 56 |
+
'label' => Mage::helper('catalog')->__('Backend Table'),
|
| 57 |
+
'title' => Mage::helper('catalog')->__('Backend Table Title'),
|
| 58 |
+
));
|
| 59 |
+
|
| 60 |
+
$fieldset->addField('frontend_model', 'text', array(
|
| 61 |
+
'name' => 'frontend_model',
|
| 62 |
+
'label' => Mage::helper('catalog')->__('Frontend Model'),
|
| 63 |
+
'title' => Mage::helper('catalog')->__('Frontend Model'),
|
| 64 |
+
));*/
|
| 65 |
+
|
| 66 |
+
/*$fieldset->addField('is_visible', 'select', array(
|
| 67 |
+
'name' => 'is_visible',
|
| 68 |
+
'label' => Mage::helper('catalog')->__('Visible'),
|
| 69 |
+
'title' => Mage::helper('catalog')->__('Visible'),
|
| 70 |
+
'values' => $yesno,
|
| 71 |
+
));*/
|
| 72 |
+
|
| 73 |
+
/*$fieldset->addField('source_model', 'text', array(
|
| 74 |
+
'name' => 'source_model',
|
| 75 |
+
'label' => Mage::helper('catalog')->__('Source Model'),
|
| 76 |
+
'title' => Mage::helper('catalog')->__('Source Model'),
|
| 77 |
+
));*/
|
| 78 |
+
|
| 79 |
+
$fieldset->addField('is_global', 'select', array(
|
| 80 |
+
'name' => 'is_global',
|
| 81 |
+
'label' => Mage::helper('catalog')->__('Globally Editable'),
|
| 82 |
+
'title' => Mage::helper('catalog')->__('Globally Editable'),
|
| 83 |
+
'values'=> $yesno,
|
| 84 |
+
));
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
$form->setValues($model->getData());
|
| 89 |
+
|
| 90 |
+
if ($model->getAttributeId()) {
|
| 91 |
+
$form->getElement('backend_type')->setDisabled(1);
|
| 92 |
+
if ($model->getIsGlobal()) {
|
| 93 |
+
#$form->getElement('is_global')->setDisabled(1);
|
| 94 |
+
}
|
| 95 |
+
} else {
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
$this->setForm($form);
|
| 99 |
+
|
| 100 |
+
return parent::_prepareForm();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Edit/Tabs.php
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Hwg_Attributemanager_Block_Adminhtml_Category_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
public function __construct()
|
| 7 |
+
{
|
| 8 |
+
parent::__construct();
|
| 9 |
+
$this->setId('attributemanager_tabs');
|
| 10 |
+
$this->setDestElementId('edit_form');
|
| 11 |
+
$this->setTitle(Mage::helper('catalog')->__('Attribute Information'));
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
protected function _beforeToHtml()
|
| 15 |
+
{
|
| 16 |
+
$model = Mage::registry('attributemanager_data');
|
| 17 |
+
|
| 18 |
+
$this->addTab('main', array(
|
| 19 |
+
'label' => Mage::helper('catalog')->__('Properties'),
|
| 20 |
+
'title' => Mage::helper('catalog')->__('Properties'),
|
| 21 |
+
'content' => $this->getLayout()->createBlock('attributemanager/adminhtml_category_edit_tab_main')->toHtml(),
|
| 22 |
+
'active' => true
|
| 23 |
+
));
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
$this->addTab('labels', array(
|
| 27 |
+
'label' => Mage::helper('catalog')->__('Manage Label / Options'),
|
| 28 |
+
'title' => Mage::helper('catalog')->__('Manage Label / Options'),
|
| 29 |
+
'content' => $this->getLayout()->createBlock('attributemanager/adminhtml_category_edit_tab_options')->toHtml(),
|
| 30 |
+
));
|
| 31 |
+
|
| 32 |
+
/*if ('select' == $model->getFrontendInput()) {
|
| 33 |
+
$this->addTab('options_section', array(
|
| 34 |
+
'label' => Mage::helper('catalog')->__('Options Control'),
|
| 35 |
+
'title' => Mage::helper('catalog')->__('Options Control'),
|
| 36 |
+
'content' => $this->getLayout()->createBlock('attributemanager/edit_tab_options')->toHtml(),
|
| 37 |
+
));
|
| 38 |
+
}*/
|
| 39 |
+
|
| 40 |
+
return parent::_beforeToHtml();
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Category/Grid.php
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Category_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
| 3 |
+
{
|
| 4 |
+
public function __construct()
|
| 5 |
+
{
|
| 6 |
+
parent::__construct();
|
| 7 |
+
$this->setId('attributemanagergrid');
|
| 8 |
+
$this->setDefaultSort('attribute_code');
|
| 9 |
+
$this->setDefaultDir('ASC');
|
| 10 |
+
$this->setSaveParametersInSession(true);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
protected function _prepareCollection()
|
| 14 |
+
{
|
| 15 |
+
$type='catalog_category';
|
| 16 |
+
$this->type=$type;
|
| 17 |
+
$collection = Mage::getResourceModel('eav/entity_attribute_collection')
|
| 18 |
+
->setEntityTypeFilter( Mage::getModel('eav/entity')->setType($type)->getTypeId() )
|
| 19 |
+
->addFieldToFilter("is_user_defined", 1);
|
| 20 |
+
|
| 21 |
+
$this->setCollection($collection);
|
| 22 |
+
return parent::_prepareCollection();
|
| 23 |
+
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
protected function _prepareColumns()
|
| 27 |
+
{
|
| 28 |
+
$this->addColumn('attribute_code', array(
|
| 29 |
+
'header'=>Mage::helper('catalog')->__('Attribute Code'),
|
| 30 |
+
'sortable'=>true,
|
| 31 |
+
'index'=>'attribute_code'
|
| 32 |
+
));
|
| 33 |
+
|
| 34 |
+
$this->addColumn('frontend_label', array(
|
| 35 |
+
'header'=>Mage::helper('catalog')->__('Attribute Label'),
|
| 36 |
+
'sortable'=>true,
|
| 37 |
+
'index'=>'frontend_label'
|
| 38 |
+
));
|
| 39 |
+
|
| 40 |
+
$this->addColumn('is_visible', array(
|
| 41 |
+
'header'=>Mage::helper('catalog')->__('Visible'),
|
| 42 |
+
'sortable'=>true,
|
| 43 |
+
'index'=>'is_visible_on_front',
|
| 44 |
+
'type' => 'options',
|
| 45 |
+
'options' => array(
|
| 46 |
+
'1' => Mage::helper('catalog')->__('Yes'),
|
| 47 |
+
'0' => Mage::helper('catalog')->__('No'),
|
| 48 |
+
),
|
| 49 |
+
'align' => 'center',
|
| 50 |
+
));
|
| 51 |
+
|
| 52 |
+
$this->addColumn('is_global', array(
|
| 53 |
+
'header'=>Mage::helper('catalog')->__('Scope'),
|
| 54 |
+
'sortable'=>true,
|
| 55 |
+
'index'=>'is_global',
|
| 56 |
+
'type' => 'options',
|
| 57 |
+
'options' => array(
|
| 58 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'),
|
| 59 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>Mage::helper('catalog')->__('Website'),
|
| 60 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'),
|
| 61 |
+
),
|
| 62 |
+
'align' => 'center',
|
| 63 |
+
));
|
| 64 |
+
|
| 65 |
+
$this->addColumn('is_required', array(
|
| 66 |
+
'header'=>Mage::helper('catalog')->__('Required'),
|
| 67 |
+
'sortable'=>true,
|
| 68 |
+
'index'=>'is_required',
|
| 69 |
+
'type' => 'options',
|
| 70 |
+
'options' => array(
|
| 71 |
+
'1' => Mage::helper('catalog')->__('Yes'),
|
| 72 |
+
'0' => Mage::helper('catalog')->__('No'),
|
| 73 |
+
),
|
| 74 |
+
'align' => 'center',
|
| 75 |
+
));
|
| 76 |
+
|
| 77 |
+
$this->addColumn('is_user_defined', array(
|
| 78 |
+
'header'=>Mage::helper('catalog')->__('System'),
|
| 79 |
+
'sortable'=>true,
|
| 80 |
+
'index'=>'is_user_defined',
|
| 81 |
+
'type' => 'options',
|
| 82 |
+
'align' => 'center',
|
| 83 |
+
'options' => array(
|
| 84 |
+
'0' => Mage::helper('catalog')->__('Yes'), // intended reverted use
|
| 85 |
+
'1' => Mage::helper('catalog')->__('No'), // intended reverted use
|
| 86 |
+
),
|
| 87 |
+
));
|
| 88 |
+
|
| 89 |
+
$this->addExportType('*/*/exportCsv'.$this->_block, Mage::helper('attributemanager')->__('CSV'));
|
| 90 |
+
$this->addExportType('*/*/exportXml'.$this->_block, Mage::helper('attributemanager')->__('XML'));
|
| 91 |
+
|
| 92 |
+
return parent::_prepareColumns();
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
public function getRowUrl($row)
|
| 96 |
+
{
|
| 97 |
+
return $this->getUrl('*/*/edit', array('type' => $this->type,'attribute_id' => $row->getAttributeId()));
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
?>
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer.php
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Customer extends Mage_Adminhtml_Block_Widget_Grid_Container
|
| 3 |
+
{
|
| 4 |
+
public function __construct()
|
| 5 |
+
{
|
| 6 |
+
$this->_controller = 'adminhtml_customer';
|
| 7 |
+
$this->_blockGroup = 'attributemanager';
|
| 8 |
+
$this->_headerText = Mage::helper('attributemanager')->__('Manage Customer Attribute');
|
| 9 |
+
$this->_addButtonLabel = Mage::helper('attributemanager')->__('Add New Attribute');
|
| 10 |
+
parent::__construct();
|
| 11 |
+
|
| 12 |
+
$this->_addButton('add', array(
|
| 13 |
+
'label' => $this->getAddButtonLabel(),
|
| 14 |
+
'onclick' => 'setLocation(\''.$this->getUrl('*/*/new', array('type' => 'customer','attribute_id'=>0)).'\')',
|
| 15 |
+
'class' => 'add',
|
| 16 |
+
));
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
?>
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit.php
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Customer_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
protected function _prepareLayout()
|
| 6 |
+
{
|
| 7 |
+
|
| 8 |
+
$this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_mode . '_form'));
|
| 9 |
+
return parent::_prepareLayout();
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
public function __construct()
|
| 13 |
+
{
|
| 14 |
+
|
| 15 |
+
$this->_objectId = 'attribute_id';
|
| 16 |
+
$this->_controller = 'adminhtml_customer';
|
| 17 |
+
$this->_blockGroup = 'attributemanager';
|
| 18 |
+
|
| 19 |
+
parent::__construct();
|
| 20 |
+
|
| 21 |
+
if($this->getRequest()->getParam('popup')) {
|
| 22 |
+
$this->_removeButton('back');
|
| 23 |
+
$this->_addButton(
|
| 24 |
+
'close',
|
| 25 |
+
array(
|
| 26 |
+
'label' => Mage::helper('catalog')->__('Close Window'),
|
| 27 |
+
'class' => 'cancel',
|
| 28 |
+
'onclick' => 'window.close()',
|
| 29 |
+
'level' => -1
|
| 30 |
+
)
|
| 31 |
+
);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
$this->_updateButton('back', 'onclick', "setLocation('".$this->getUrl('*/*/customer')."')");
|
| 35 |
+
|
| 36 |
+
$this->_updateButton('save', 'label', Mage::helper('catalog')->__('Save Attribute'));
|
| 37 |
+
$this->_addButton(
|
| 38 |
+
'save_and_edit_button',
|
| 39 |
+
array(
|
| 40 |
+
'label' => Mage::helper('catalog')->__('Save And Continue Edit'),
|
| 41 |
+
'onclick' => 'saveAndContinueEdit()',
|
| 42 |
+
'class' => 'save'
|
| 43 |
+
),
|
| 44 |
+
100
|
| 45 |
+
);
|
| 46 |
+
$this->_formScripts[] = "
|
| 47 |
+
function toggleEditor() {
|
| 48 |
+
if (tinyMCE.getInstanceById('company_content') == null) {
|
| 49 |
+
tinyMCE.execCommand('mceAddControl', false, 'company_content');
|
| 50 |
+
} else {
|
| 51 |
+
tinyMCE.execCommand('mceRemoveControl', false, 'company_content');
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function saveAndContinueEdit(){
|
| 56 |
+
editForm.submit($('edit_form').action+'back/edit/');
|
| 57 |
+
}
|
| 58 |
+
";
|
| 59 |
+
if (! Mage::registry('attributemanager_data')->getIsUserDefined()) {
|
| 60 |
+
$this->_removeButton('delete');
|
| 61 |
+
} else {
|
| 62 |
+
$this->_updateButton('delete', 'label', Mage::helper('catalog')->__('Delete Attribute'));
|
| 63 |
+
$this->_updateButton('delete', 'onclick', "deleteConfirm(
|
| 64 |
+
'".Mage::helper('adminhtml')->__('Are you sure you want to do this?')."',
|
| 65 |
+
'".$this->getUrl('*/*/delete/type/'.$this->getRequest()->getParam('type').'/attribute_id/'.$this->getRequest()->getParam('attribute_id')
|
| 66 |
+
)."')");
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
public function getHeaderText()
|
| 71 |
+
{
|
| 72 |
+
$type="Customer";
|
| 73 |
+
if (Mage::registry('attributemanager_data')->getId()) {
|
| 74 |
+
return Mage::helper('attributemanager')->__('Edit %s Attribute "%s"', $type, $this->htmlEscape(Mage::registry('attributemanager_data')->getFrontendLabel()));
|
| 75 |
+
}
|
| 76 |
+
else {
|
| 77 |
+
return Mage::helper('attributemanager')->__('New %s Attribute', $type);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
public function getValidationUrl()
|
| 83 |
+
{
|
| 84 |
+
return $this->getUrl('*/*/validate', array('_current'=>true));
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
public function getSaveUrl()
|
| 88 |
+
{
|
| 89 |
+
return $this->getUrl('*/*/save', array('_current'=>true, 'back'=>null));
|
| 90 |
+
}
|
| 91 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Form.php
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Hwg_Attributemanager_Block_Adminhtml_Customer_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
protected function _prepareForm()
|
| 7 |
+
{
|
| 8 |
+
$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
|
| 9 |
+
|
| 10 |
+
$form->setUseContainer(true);
|
| 11 |
+
$this->setForm($form);
|
| 12 |
+
return parent::_prepareForm();
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tab/Front.php
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Customer_Edit_Tab_Front extends Mage_Adminhtml_Block_Widget_Form
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
protected function _prepareForm()
|
| 6 |
+
{
|
| 7 |
+
$model = Mage::registry('attributemanager_data');
|
| 8 |
+
|
| 9 |
+
$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
|
| 10 |
+
|
| 11 |
+
$fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('catalog')->__('Frontend Properties')));
|
| 12 |
+
|
| 13 |
+
$yesno = array(
|
| 14 |
+
array(
|
| 15 |
+
'value' => 0,
|
| 16 |
+
'label' => Mage::helper('catalog')->__('No')
|
| 17 |
+
),
|
| 18 |
+
array(
|
| 19 |
+
'value' => 1,
|
| 20 |
+
'label' => Mage::helper('catalog')->__('Yes')
|
| 21 |
+
));
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
$fieldset->addField('is_searchable', 'select', array(
|
| 25 |
+
'name' => 'is_searchable',
|
| 26 |
+
'label' => Mage::helper('catalog')->__('Use in quick search'),
|
| 27 |
+
'title' => Mage::helper('catalog')->__('Use in quick search'),
|
| 28 |
+
'values' => $yesno,
|
| 29 |
+
));
|
| 30 |
+
|
| 31 |
+
$fieldset->addField('is_visible_in_advanced_search', 'select', array(
|
| 32 |
+
'name' => 'is_visible_in_advanced_search',
|
| 33 |
+
'label' => Mage::helper('catalog')->__('Use in advanced search'),
|
| 34 |
+
'title' => Mage::helper('catalog')->__('Use in advanced search'),
|
| 35 |
+
'values' => $yesno,
|
| 36 |
+
));
|
| 37 |
+
|
| 38 |
+
$fieldset->addField('is_comparable', 'select', array(
|
| 39 |
+
'name' => 'is_comparable',
|
| 40 |
+
'label' => Mage::helper('catalog')->__('Comparable on Front-end'),
|
| 41 |
+
'title' => Mage::helper('catalog')->__('Comparable on Front-end'),
|
| 42 |
+
'values' => $yesno,
|
| 43 |
+
));
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
$fieldset->addField('is_filterable', 'select', array(
|
| 47 |
+
'name' => 'is_filterable',
|
| 48 |
+
'label' => Mage::helper('catalog')->__("Use In Layered Navigation<br/>(Can be used only with catalog input type 'Dropdown')"),
|
| 49 |
+
'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown'),
|
| 50 |
+
'values' => array(
|
| 51 |
+
array('value' => '0', 'label' => Mage::helper('catalog')->__('No')),
|
| 52 |
+
array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')),
|
| 53 |
+
array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)')),
|
| 54 |
+
),
|
| 55 |
+
));
|
| 56 |
+
|
| 57 |
+
// if ($model->getIsUserDefined() || !$model->getId()) {
|
| 58 |
+
$fieldset->addField('is_visible_on_front', 'select', array(
|
| 59 |
+
'name' => 'is_visible_on_front',
|
| 60 |
+
'label' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'),
|
| 61 |
+
'title' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'),
|
| 62 |
+
'values' => $yesno,
|
| 63 |
+
));
|
| 64 |
+
// }
|
| 65 |
+
|
| 66 |
+
$form->setValues($model->getData());
|
| 67 |
+
|
| 68 |
+
$this->setForm($form);
|
| 69 |
+
|
| 70 |
+
return parent::_prepareForm();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tab/Main.php
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Hwg_Attributemanager_Block_Adminhtml_Customer_Edit_Tab_Main extends Mage_Adminhtml_Block_Widget_Form
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
protected function _prepareForm()
|
| 7 |
+
{
|
| 8 |
+
$model = Mage::registry('attributemanager_data');
|
| 9 |
+
|
| 10 |
+
$form = new Varien_Data_Form(array(
|
| 11 |
+
'id' => 'edit_form',
|
| 12 |
+
'action' => $this->getData('action'),
|
| 13 |
+
'method' => 'post'
|
| 14 |
+
));
|
| 15 |
+
|
| 16 |
+
$fieldset = $form->addFieldset('base_fieldset',
|
| 17 |
+
array('legend'=>Mage::helper('catalog')->__('Attribute Properties'))
|
| 18 |
+
);
|
| 19 |
+
if ($model->getId()) {
|
| 20 |
+
$fieldset->addField('attribute_id', 'hidden', array(
|
| 21 |
+
'name' => 'attribute_id',
|
| 22 |
+
));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
$this->_addElementTypes($fieldset);
|
| 26 |
+
|
| 27 |
+
$yesno = array(
|
| 28 |
+
array(
|
| 29 |
+
'value' => 0,
|
| 30 |
+
'label' => Mage::helper('catalog')->__('No')
|
| 31 |
+
),
|
| 32 |
+
array(
|
| 33 |
+
'value' => 1,
|
| 34 |
+
'label' => Mage::helper('catalog')->__('Yes')
|
| 35 |
+
));
|
| 36 |
+
|
| 37 |
+
$fieldset->addField('attribute_code', 'text', array(
|
| 38 |
+
'name' => 'attribute_code',
|
| 39 |
+
'label' => Mage::helper('catalog')->__('Attribute Code'),
|
| 40 |
+
'title' => Mage::helper('catalog')->__('Attribute Code'),
|
| 41 |
+
'note' => Mage::helper('catalog')->__('For internal use. Must be unique with no spaces'),
|
| 42 |
+
'class' => 'validate-code',
|
| 43 |
+
'required' => true,
|
| 44 |
+
));
|
| 45 |
+
|
| 46 |
+
$scopes = array(
|
| 47 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'),
|
| 48 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>Mage::helper('catalog')->__('Website'),
|
| 49 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'),
|
| 50 |
+
);
|
| 51 |
+
|
| 52 |
+
if ($model->getAttributeCode() == 'status' || $model->getAttributeCode() == 'tax_class_id') {
|
| 53 |
+
unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
$fieldset->addField('is_global', 'select', array(
|
| 57 |
+
'name' => 'is_global',
|
| 58 |
+
'label' => Mage::helper('catalog')->__('Scope'),
|
| 59 |
+
'title' => Mage::helper('catalog')->__('Scope'),
|
| 60 |
+
'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'),
|
| 61 |
+
'values'=> $scopes
|
| 62 |
+
));
|
| 63 |
+
|
| 64 |
+
$inputTypes = array(
|
| 65 |
+
array(
|
| 66 |
+
'value' => 'text',
|
| 67 |
+
'label' => Mage::helper('catalog')->__('Text Field')
|
| 68 |
+
),
|
| 69 |
+
array(
|
| 70 |
+
'value' => 'textarea',
|
| 71 |
+
'label' => Mage::helper('catalog')->__('Text Area')
|
| 72 |
+
),
|
| 73 |
+
array(
|
| 74 |
+
'value' => 'date',
|
| 75 |
+
'label' => Mage::helper('catalog')->__('Date')
|
| 76 |
+
),
|
| 77 |
+
array(
|
| 78 |
+
'value' => 'boolean',
|
| 79 |
+
'label' => Mage::helper('catalog')->__('Yes/No')
|
| 80 |
+
),
|
| 81 |
+
array(
|
| 82 |
+
'value' => 'multiselect',
|
| 83 |
+
'label' => Mage::helper('catalog')->__('Multiple Select')
|
| 84 |
+
),
|
| 85 |
+
array(
|
| 86 |
+
'value' => 'select',
|
| 87 |
+
'label' => Mage::helper('catalog')->__('Dropdown')
|
| 88 |
+
),
|
| 89 |
+
);
|
| 90 |
+
if($this->getRequest ()->getParam ( 'type' )==="catalog_category"){
|
| 91 |
+
$inputTypes[]= array(
|
| 92 |
+
'value' => 'image',
|
| 93 |
+
'label' => Mage::helper('catalog')->__('Image')
|
| 94 |
+
|
| 95 |
+
);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
$response = new Varien_Object();
|
| 99 |
+
$response->setTypes(array());
|
| 100 |
+
//Mage::dispatchEvent('adminhtml_product_attribute_types', array('response'=>$response));
|
| 101 |
+
|
| 102 |
+
$_disabledTypes = array();
|
| 103 |
+
$_hiddenFields = array();
|
| 104 |
+
foreach ($response->getTypes() as $type) {
|
| 105 |
+
$inputTypes[] = $type;
|
| 106 |
+
if (isset($type['hide_fields'])) {
|
| 107 |
+
$_hiddenFields[$type['value']] = $type['hide_fields'];
|
| 108 |
+
}
|
| 109 |
+
if (isset($type['disabled_types'])) {
|
| 110 |
+
$_disabledTypes[$type['value']] = $type['disabled_types'];
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
Mage::register('attribute_type_hidden_fields', $_hiddenFields);
|
| 114 |
+
Mage::register('attribute_type_disabled_types', $_disabledTypes);
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
$fieldset->addField('frontend_input', 'select', array(
|
| 118 |
+
'name' => 'frontend_input',
|
| 119 |
+
'label' => Mage::helper('catalog')->__('Input Type for Store Owner'),
|
| 120 |
+
'title' => Mage::helper('catalog')->__('Input Type for Store Owner'),
|
| 121 |
+
'value' => 'text',
|
| 122 |
+
'values'=> $inputTypes
|
| 123 |
+
));
|
| 124 |
+
|
| 125 |
+
$fieldset->addField('entity_type_id', 'hidden', array(
|
| 126 |
+
'name' => 'entity_type_id',
|
| 127 |
+
'value' => Mage::getModel('eav/entity')->setType($this->getRequest ()->getParam ( 'type' ))->getTypeId()
|
| 128 |
+
));
|
| 129 |
+
|
| 130 |
+
$fieldset->addField('is_user_defined', 'hidden', array(
|
| 131 |
+
'name' => 'is_user_defined',
|
| 132 |
+
'value' => 1
|
| 133 |
+
));
|
| 134 |
+
|
| 135 |
+
$fieldset->addField('attribute_set_id', 'hidden', array(
|
| 136 |
+
'name' => 'attribute_set_id',
|
| 137 |
+
'value' => Mage::getModel('eav/entity')->setType($this->getRequest ()->getParam ( 'type' ))->getTypeId()
|
| 138 |
+
));
|
| 139 |
+
|
| 140 |
+
$fieldset->addField('attribute_group_id', 'hidden', array(
|
| 141 |
+
'name' => 'attribute_group_id',
|
| 142 |
+
'value' => Mage::getModel('eav/entity')->setType($this->getRequest ()->getParam ( 'type' ))->getTypeId()
|
| 143 |
+
));
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
/*******************************************************/
|
| 147 |
+
$fieldset->addField('is_unique', 'select', array(
|
| 148 |
+
'name' => 'is_unique',
|
| 149 |
+
'label' => Mage::helper('catalog')->__('Unique Value'),
|
| 150 |
+
'title' => Mage::helper('catalog')->__('Unique Value (not shared with other products)'),
|
| 151 |
+
'note' => Mage::helper('catalog')->__('Not shared with other products'),
|
| 152 |
+
'values' => $yesno,
|
| 153 |
+
));
|
| 154 |
+
|
| 155 |
+
$fieldset->addField('is_required', 'select', array(
|
| 156 |
+
'name' => 'is_required',
|
| 157 |
+
'label' => Mage::helper('catalog')->__('Values Required'),
|
| 158 |
+
'title' => Mage::helper('catalog')->__('Values Required'),
|
| 159 |
+
'values' => $yesno,
|
| 160 |
+
));
|
| 161 |
+
|
| 162 |
+
$fieldset->addField('is_visible', 'select', array(
|
| 163 |
+
'name' => 'is_visible',
|
| 164 |
+
'label' => Mage::helper('catalog')->__('Is Visible'),
|
| 165 |
+
'title' => Mage::helper('catalog')->__('Is Visible'),
|
| 166 |
+
'values' => $yesno,
|
| 167 |
+
));
|
| 168 |
+
|
| 169 |
+
$fieldset->addField('frontend_class', 'select', array(
|
| 170 |
+
'name' => 'frontend_class',
|
| 171 |
+
'label' => Mage::helper('catalog')->__('Input Validation for Store Owner'),
|
| 172 |
+
'title' => Mage::helper('catalog')->__('Input Validation for Store Owner'),
|
| 173 |
+
'values'=> array(
|
| 174 |
+
array(
|
| 175 |
+
'value' => '',
|
| 176 |
+
'label' => Mage::helper('catalog')->__('None')
|
| 177 |
+
),
|
| 178 |
+
array(
|
| 179 |
+
'value' => 'validate-number',
|
| 180 |
+
'label' => Mage::helper('catalog')->__('Decimal Number')
|
| 181 |
+
),
|
| 182 |
+
array(
|
| 183 |
+
'value' => 'validate-digits',
|
| 184 |
+
'label' => Mage::helper('catalog')->__('Integer Number')
|
| 185 |
+
),
|
| 186 |
+
array(
|
| 187 |
+
'value' => 'validate-email',
|
| 188 |
+
'label' => Mage::helper('catalog')->__('Email')
|
| 189 |
+
),
|
| 190 |
+
array(
|
| 191 |
+
'value' => 'validate-url',
|
| 192 |
+
'label' => Mage::helper('catalog')->__('Url')
|
| 193 |
+
),
|
| 194 |
+
array(
|
| 195 |
+
'value' => 'validate-alpha',
|
| 196 |
+
'label' => Mage::helper('catalog')->__('Letters')
|
| 197 |
+
),
|
| 198 |
+
array(
|
| 199 |
+
'value' => 'validate-alphanum',
|
| 200 |
+
'label' => Mage::helper('catalog')->__('Letters(a-zA-Z) or Numbers(0-9)')
|
| 201 |
+
),
|
| 202 |
+
)
|
| 203 |
+
));
|
| 204 |
+
|
| 205 |
+
$fieldset = $form->addFieldset('front_fieldset',
|
| 206 |
+
array('legend'=>Mage::helper('catalog')->__('Frontend Properties')));
|
| 207 |
+
|
| 208 |
+
if($model->getId())
|
| 209 |
+
{
|
| 210 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
| 211 |
+
$readresult=$write->query("SELECT * from customer_form_attribute WHERE attribute_id=".$model->getId());
|
| 212 |
+
while ($row = $readresult->fetch() ) {
|
| 213 |
+
$customerForm[$row['form_code']] = 'checked';
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
$fieldset->addField('adminhtml_customer', 'checkbox', array(
|
| 217 |
+
'name' => 'customer_form[]',
|
| 218 |
+
'label' => Mage::helper('catalog')->__('Adminhtml Customer'),
|
| 219 |
+
'value' => 'adminhtml_customer',
|
| 220 |
+
'checked' => isset($customerForm['adminhtml_customer'])?$customerForm['adminhtml_customer']:'',
|
| 221 |
+
));
|
| 222 |
+
$fieldset->addField('customer_account_create', 'checkbox', array(
|
| 223 |
+
'name' => 'customer_form[]',
|
| 224 |
+
'label' => Mage::helper('catalog')->__('Customer Account Create'),
|
| 225 |
+
'value' => 'customer_account_create',
|
| 226 |
+
'checked' => isset($customerForm['customer_account_create'])?$customerForm['customer_account_create']:'',
|
| 227 |
+
));
|
| 228 |
+
$fieldset->addField('customer_address_edit', 'checkbox', array(
|
| 229 |
+
'name' => 'customer_form[]',
|
| 230 |
+
'label' => Mage::helper('catalog')->__('Customer Address Edit'),
|
| 231 |
+
'value' => 'customer_address_edit',
|
| 232 |
+
'checked' => isset($customerForm['customer_address_edit'])?$customerForm['customer_address_edit']:'',
|
| 233 |
+
));
|
| 234 |
+
$fieldset->addField('checkout_register', 'checkbox', array(
|
| 235 |
+
'name' => 'customer_form[]',
|
| 236 |
+
'label' => Mage::helper('catalog')->__('Checkout Register'),
|
| 237 |
+
'value' => 'checkout_register',
|
| 238 |
+
'checked' => isset($customerForm['checkout_register'])?$customerForm['checkout_register']:'',
|
| 239 |
+
));
|
| 240 |
+
$fieldset->addField('sort_order', 'text', array(
|
| 241 |
+
'name' => 'sort_order',
|
| 242 |
+
'label' => Mage::helper('catalog')->__('Sort Order'),
|
| 243 |
+
'title' => Mage::helper('catalog')->__('Sort Order'),
|
| 244 |
+
'class' => 'validate-digits',
|
| 245 |
+
'value' => $model->getAttributeSetInfo()
|
| 246 |
+
));
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
if ($model->getId()) {
|
| 250 |
+
$form->getElement('attribute_code')->setDisabled(1);
|
| 251 |
+
$form->getElement('frontend_input')->setDisabled(1);
|
| 252 |
+
|
| 253 |
+
if (isset($disableAttributeFields[$model->getAttributeCode()])) {
|
| 254 |
+
foreach ($disableAttributeFields[$model->getAttributeCode()] as $field) {
|
| 255 |
+
$form->getElement($field)->setDisabled(1);
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
$form->addValues($model->getData());
|
| 261 |
+
|
| 262 |
+
$this->setForm($form);
|
| 263 |
+
|
| 264 |
+
return parent::_prepareForm();
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
protected function _getAdditionalElementTypes()
|
| 268 |
+
{
|
| 269 |
+
return array(
|
| 270 |
+
'apply' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_apply')
|
| 271 |
+
);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tab/Options.php
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Customer_Edit_Tab_Options extends Mage_Adminhtml_Block_Widget
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
public function __construct()
|
| 6 |
+
{
|
| 7 |
+
parent::__construct();
|
| 8 |
+
$this->setTemplate('attributemanager/options.phtml');
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
protected function _prepareLayout()
|
| 12 |
+
{
|
| 13 |
+
$this->setChild('delete_button',
|
| 14 |
+
$this->getLayout()->createBlock('adminhtml/widget_button')
|
| 15 |
+
->setData(array(
|
| 16 |
+
'label' => Mage::helper('catalog')->__('Delete'),
|
| 17 |
+
'class' => 'delete delete-option'
|
| 18 |
+
)));
|
| 19 |
+
|
| 20 |
+
$this->setChild('add_button',
|
| 21 |
+
$this->getLayout()->createBlock('adminhtml/widget_button')
|
| 22 |
+
->setData(array(
|
| 23 |
+
'label' => Mage::helper('catalog')->__('Add Option'),
|
| 24 |
+
'class' => 'add',
|
| 25 |
+
'id' => 'add_new_option_button'
|
| 26 |
+
)));
|
| 27 |
+
return parent::_prepareLayout();
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
public function getDeleteButtonHtml()
|
| 31 |
+
{
|
| 32 |
+
return $this->getChildHtml('delete_button');
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
public function getAddNewButtonHtml()
|
| 36 |
+
{
|
| 37 |
+
return $this->getChildHtml('add_button');
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public function getStores()
|
| 41 |
+
{
|
| 42 |
+
$stores = $this->getData('stores');
|
| 43 |
+
if (is_null($stores)) {
|
| 44 |
+
$stores = Mage::getModel('core/store')
|
| 45 |
+
->getResourceCollection()
|
| 46 |
+
->setLoadDefault(true)
|
| 47 |
+
->load();
|
| 48 |
+
$this->setData('stores', $stores);
|
| 49 |
+
}
|
| 50 |
+
return $stores;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
public function getOptionValues()
|
| 54 |
+
{
|
| 55 |
+
$attributeType = $this->getAttributeObject()->getFrontendInput();
|
| 56 |
+
$defaultValues = $this->getAttributeObject()->getDefaultValue();
|
| 57 |
+
if ($attributeType == 'select' || $attributeType == 'multiselect') {
|
| 58 |
+
$defaultValues = explode(',', $defaultValues);
|
| 59 |
+
} else {
|
| 60 |
+
$defaultValues = array();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
switch ($attributeType) {
|
| 64 |
+
case 'select':
|
| 65 |
+
$inputType = 'radio';
|
| 66 |
+
break;
|
| 67 |
+
case 'multiselect':
|
| 68 |
+
$inputType = 'checkbox';
|
| 69 |
+
break;
|
| 70 |
+
default:
|
| 71 |
+
$inputType = '';
|
| 72 |
+
break;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
$values = $this->getData('option_values');
|
| 76 |
+
if (is_null($values)) {
|
| 77 |
+
$values = array();
|
| 78 |
+
$optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
|
| 79 |
+
->setAttributeFilter($this->getAttributeObject()->getId())
|
| 80 |
+
->setPositionOrder('desc', true)
|
| 81 |
+
->load();
|
| 82 |
+
|
| 83 |
+
foreach ($optionCollection as $option) {
|
| 84 |
+
$value = array();
|
| 85 |
+
if (in_array($option->getId(), $defaultValues)) {
|
| 86 |
+
$value['checked'] = 'checked="checked"';
|
| 87 |
+
} else {
|
| 88 |
+
$value['checked'] = '';
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
$value['intype'] = $inputType;
|
| 92 |
+
$value['id'] = $option->getId();
|
| 93 |
+
$value['sort_order'] = $option->getSortOrder();
|
| 94 |
+
foreach ($this->getStores() as $store) {
|
| 95 |
+
$storeValues = $this->getStoreOptionValues($store->getId());
|
| 96 |
+
if (isset($storeValues[$option->getId()])) {
|
| 97 |
+
$value['store'.$store->getId()] = htmlspecialchars($storeValues[$option->getId()]);
|
| 98 |
+
}
|
| 99 |
+
else {
|
| 100 |
+
$value['store'.$store->getId()] = '';
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
$values[] = new Varien_Object($value);
|
| 104 |
+
}
|
| 105 |
+
$this->setData('option_values', $values);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return $values;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
public function getLabelValues()
|
| 112 |
+
{
|
| 113 |
+
$values = array();
|
| 114 |
+
$values[0] = $this->getAttributeObject()->getFrontend()->getLabel();
|
| 115 |
+
// it can be array and cause bug
|
| 116 |
+
$frontendLabel = $this->getAttributeObject()->getFrontend()->getLabel();
|
| 117 |
+
if (is_array($frontendLabel)) {
|
| 118 |
+
$frontendLabel = array_shift($frontendLabel);
|
| 119 |
+
}
|
| 120 |
+
$translations = Mage::getModel('core/translate_string')
|
| 121 |
+
->load(Mage_Catalog_Model_Entity_Attribute::MODULE_NAME.Mage_Core_Model_Translate::SCOPE_SEPARATOR.$frontendLabel)
|
| 122 |
+
->getStoreTranslations();
|
| 123 |
+
foreach ($this->getStores() as $store) {
|
| 124 |
+
if ($store->getId() != 0) {
|
| 125 |
+
$values[$store->getId()] = isset($translations[$store->getId()]) ? $translations[$store->getId()] : '';
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
return $values;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
public function getStoreOptionValues($storeId)
|
| 132 |
+
{
|
| 133 |
+
$values = $this->getData('store_option_values_'.$storeId);
|
| 134 |
+
if (is_null($values)) {
|
| 135 |
+
$values = array();
|
| 136 |
+
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
|
| 137 |
+
->setAttributeFilter($this->getAttributeObject()->getId())
|
| 138 |
+
->setStoreFilter($storeId, false)
|
| 139 |
+
->load();
|
| 140 |
+
foreach ($valuesCollection as $item) {
|
| 141 |
+
$values[$item->getId()] = $item->getValue();
|
| 142 |
+
}
|
| 143 |
+
$this->setData('store_option_values_'.$storeId, $values);
|
| 144 |
+
}
|
| 145 |
+
return $values;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
public function getAttributeObject()
|
| 149 |
+
{
|
| 150 |
+
return Mage::registry('attributemanager_data');
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tab/System.php
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Customer_Edit_Tab_System extends Mage_Adminhtml_Block_Widget_Form
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
protected function _prepareForm()
|
| 6 |
+
{
|
| 7 |
+
$model = Mage::registry('entity_attribute');
|
| 8 |
+
|
| 9 |
+
$form = new Varien_Data_Form();
|
| 10 |
+
$fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('catalog')->__('System Properties')));
|
| 11 |
+
|
| 12 |
+
if ($model->getAttributeId()) {
|
| 13 |
+
$fieldset->addField('attribute_id', 'hidden', array(
|
| 14 |
+
'name' => 'attribute_id',
|
| 15 |
+
));
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
$yesno = array(
|
| 19 |
+
array(
|
| 20 |
+
'value' => 0,
|
| 21 |
+
'label' => Mage::helper('catalog')->__('No')
|
| 22 |
+
),
|
| 23 |
+
array(
|
| 24 |
+
'value' => 1,
|
| 25 |
+
'label' => Mage::helper('catalog')->__('Yes')
|
| 26 |
+
));
|
| 27 |
+
|
| 28 |
+
/*$fieldset->addField('attribute_model', 'text', array(
|
| 29 |
+
'name' => 'attribute_model',
|
| 30 |
+
'label' => Mage::helper('catalog')->__('Attribute Model'),
|
| 31 |
+
'title' => Mage::helper('catalog')->__('Attribute Model'),
|
| 32 |
+
));
|
| 33 |
+
|
| 34 |
+
$fieldset->addField('backend_model', 'text', array(
|
| 35 |
+
'name' => 'backend_model',
|
| 36 |
+
'label' => Mage::helper('catalog')->__('Backend Model'),
|
| 37 |
+
'title' => Mage::helper('catalog')->__('Backend Model'),
|
| 38 |
+
));*/
|
| 39 |
+
|
| 40 |
+
$fieldset->addField('backend_type', 'select', array(
|
| 41 |
+
'name' => 'backend_type',
|
| 42 |
+
'label' => Mage::helper('catalog')->__('Data Type for Saving in Database'),
|
| 43 |
+
'title' => Mage::helper('catalog')->__('Data Type for Saving in Database'),
|
| 44 |
+
'options' => array(
|
| 45 |
+
'text' => Mage::helper('catalog')->__('Text'),
|
| 46 |
+
'varchar' => Mage::helper('catalog')->__('Varchar'),
|
| 47 |
+
'static' => Mage::helper('catalog')->__('Static'),
|
| 48 |
+
'datetime' => Mage::helper('catalog')->__('Datetime'),
|
| 49 |
+
'decimal' => Mage::helper('catalog')->__('Decimal'),
|
| 50 |
+
'int' => Mage::helper('catalog')->__('Integer'),
|
| 51 |
+
),
|
| 52 |
+
));
|
| 53 |
+
|
| 54 |
+
/*$fieldset->addField('backend_table', 'text', array(
|
| 55 |
+
'name' => 'backend_table',
|
| 56 |
+
'label' => Mage::helper('catalog')->__('Backend Table'),
|
| 57 |
+
'title' => Mage::helper('catalog')->__('Backend Table Title'),
|
| 58 |
+
));
|
| 59 |
+
|
| 60 |
+
$fieldset->addField('frontend_model', 'text', array(
|
| 61 |
+
'name' => 'frontend_model',
|
| 62 |
+
'label' => Mage::helper('catalog')->__('Frontend Model'),
|
| 63 |
+
'title' => Mage::helper('catalog')->__('Frontend Model'),
|
| 64 |
+
));*/
|
| 65 |
+
|
| 66 |
+
/*$fieldset->addField('is_visible', 'select', array(
|
| 67 |
+
'name' => 'is_visible',
|
| 68 |
+
'label' => Mage::helper('catalog')->__('Visible'),
|
| 69 |
+
'title' => Mage::helper('catalog')->__('Visible'),
|
| 70 |
+
'values' => $yesno,
|
| 71 |
+
));*/
|
| 72 |
+
|
| 73 |
+
/*$fieldset->addField('source_model', 'text', array(
|
| 74 |
+
'name' => 'source_model',
|
| 75 |
+
'label' => Mage::helper('catalog')->__('Source Model'),
|
| 76 |
+
'title' => Mage::helper('catalog')->__('Source Model'),
|
| 77 |
+
));*/
|
| 78 |
+
|
| 79 |
+
$fieldset->addField('is_global', 'select', array(
|
| 80 |
+
'name' => 'is_global',
|
| 81 |
+
'label' => Mage::helper('catalog')->__('Globally Editable'),
|
| 82 |
+
'title' => Mage::helper('catalog')->__('Globally Editable'),
|
| 83 |
+
'values'=> $yesno,
|
| 84 |
+
));
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
$form->setValues($model->getData());
|
| 89 |
+
|
| 90 |
+
if ($model->getAttributeId()) {
|
| 91 |
+
$form->getElement('backend_type')->setDisabled(1);
|
| 92 |
+
if ($model->getIsGlobal()) {
|
| 93 |
+
#$form->getElement('is_global')->setDisabled(1);
|
| 94 |
+
}
|
| 95 |
+
} else {
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
$this->setForm($form);
|
| 99 |
+
|
| 100 |
+
return parent::_prepareForm();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Edit/Tabs.php
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Hwg_Attributemanager_Block_Adminhtml_Customer_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
public function __construct()
|
| 7 |
+
{
|
| 8 |
+
parent::__construct();
|
| 9 |
+
$this->setId('attributemanager_tabs');
|
| 10 |
+
$this->setDestElementId('edit_form');
|
| 11 |
+
$this->setTitle(Mage::helper('catalog')->__('Attribute Information'));
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
protected function _beforeToHtml()
|
| 15 |
+
{
|
| 16 |
+
$model = Mage::registry('attributemanager_data');
|
| 17 |
+
|
| 18 |
+
$this->addTab('main', array(
|
| 19 |
+
'label' => Mage::helper('catalog')->__('Properties'),
|
| 20 |
+
'title' => Mage::helper('catalog')->__('Properties'),
|
| 21 |
+
'content' => $this->getLayout()->createBlock('attributemanager/adminhtml_customer_edit_tab_main')->toHtml(),
|
| 22 |
+
'active' => true
|
| 23 |
+
));
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
$this->addTab('labels', array(
|
| 27 |
+
'label' => Mage::helper('catalog')->__('Manage Label / Options'),
|
| 28 |
+
'title' => Mage::helper('catalog')->__('Manage Label / Options'),
|
| 29 |
+
'content' => $this->getLayout()->createBlock('attributemanager/adminhtml_customer_edit_tab_options')->toHtml(),
|
| 30 |
+
));
|
| 31 |
+
|
| 32 |
+
/*if ('select' == $model->getFrontendInput()) {
|
| 33 |
+
$this->addTab('options_section', array(
|
| 34 |
+
'label' => Mage::helper('catalog')->__('Options Control'),
|
| 35 |
+
'title' => Mage::helper('catalog')->__('Options Control'),
|
| 36 |
+
'content' => $this->getLayout()->createBlock('attributemanager/edit_tab_options')->toHtml(),
|
| 37 |
+
));
|
| 38 |
+
}*/
|
| 39 |
+
|
| 40 |
+
return parent::_beforeToHtml();
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
}
|
app/code/local/Hwg/Attributemanager/Block/Adminhtml/Customer/Grid.php
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Block_Adminhtml_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
| 3 |
+
{
|
| 4 |
+
public function __construct()
|
| 5 |
+
{
|
| 6 |
+
parent::__construct();
|
| 7 |
+
$this->setId('attributemanagergrid');
|
| 8 |
+
$this->setDefaultSort('attribute_code');
|
| 9 |
+
$this->setDefaultDir('ASC');
|
| 10 |
+
$this->setSaveParametersInSession(true);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
protected function _prepareCollection()
|
| 14 |
+
{
|
| 15 |
+
//$sUrl=$this->getUrl('*/*/*', array('_current'=>true));
|
| 16 |
+
|
| 17 |
+
$type='customer';
|
| 18 |
+
$block='customer';
|
| 19 |
+
$this->type =$type;
|
| 20 |
+
$this->block =$block;
|
| 21 |
+
// echo($this->type = $type);
|
| 22 |
+
// exit;
|
| 23 |
+
$collection = Mage::getResourceModel('eav/entity_attribute_collection')
|
| 24 |
+
->setEntityTypeFilter( Mage::getModel('eav/entity')->setType($type)->getTypeId() )
|
| 25 |
+
->addFieldToFilter("is_user_defined", 1);
|
| 26 |
+
|
| 27 |
+
$this->setCollection($collection);
|
| 28 |
+
return parent::_prepareCollection();
|
| 29 |
+
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
protected function _prepareColumns()
|
| 33 |
+
{
|
| 34 |
+
$this->addColumn('attribute_code', array(
|
| 35 |
+
'header'=>Mage::helper('catalog')->__('Attribute Code'),
|
| 36 |
+
'sortable'=>true,
|
| 37 |
+
'index'=>'attribute_code'
|
| 38 |
+
));
|
| 39 |
+
|
| 40 |
+
$this->addColumn('frontend_label', array(
|
| 41 |
+
'header'=>Mage::helper('catalog')->__('Attribute Label'),
|
| 42 |
+
'sortable'=>true,
|
| 43 |
+
'index'=>'frontend_label'
|
| 44 |
+
));
|
| 45 |
+
|
| 46 |
+
$this->addColumn('is_visible', array(
|
| 47 |
+
'header'=>Mage::helper('catalog')->__('Visible'),
|
| 48 |
+
'sortable'=>true,
|
| 49 |
+
'index'=>'is_visible_on_front',
|
| 50 |
+
'type' => 'options',
|
| 51 |
+
'options' => array(
|
| 52 |
+
'1' => Mage::helper('catalog')->__('Yes'),
|
| 53 |
+
'0' => Mage::helper('catalog')->__('No'),
|
| 54 |
+
),
|
| 55 |
+
'align' => 'center',
|
| 56 |
+
));
|
| 57 |
+
|
| 58 |
+
$this->addColumn('is_global', array(
|
| 59 |
+
'header'=>Mage::helper('catalog')->__('Scope'),
|
| 60 |
+
'sortable'=>true,
|
| 61 |
+
'index'=>'is_global',
|
| 62 |
+
'type' => 'options',
|
| 63 |
+
'options' => array(
|
| 64 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'),
|
| 65 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>Mage::helper('catalog')->__('Website'),
|
| 66 |
+
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'),
|
| 67 |
+
),
|
| 68 |
+
'align' => 'center',
|
| 69 |
+
));
|
| 70 |
+
|
| 71 |
+
$this->addColumn('is_required', array(
|
| 72 |
+
'header'=>Mage::helper('catalog')->__('Required'),
|
| 73 |
+
'sortable'=>true,
|
| 74 |
+
'index'=>'is_required',
|
| 75 |
+
'type' => 'options',
|
| 76 |
+
'options' => array(
|
| 77 |
+
'1' => Mage::helper('catalog')->__('Yes'),
|
| 78 |
+
'0' => Mage::helper('catalog')->__('No'),
|
| 79 |
+
),
|
| 80 |
+
'align' => 'center',
|
| 81 |
+
));
|
| 82 |
+
|
| 83 |
+
$this->addColumn('is_user_defined', array(
|
| 84 |
+
'header'=>Mage::helper('catalog')->__('System'),
|
| 85 |
+
'sortable'=>true,
|
| 86 |
+
'index'=>'is_user_defined',
|
| 87 |
+
'type' => 'options',
|
| 88 |
+
'align' => 'center',
|
| 89 |
+
'options' => array(
|
| 90 |
+
'0' => Mage::helper('catalog')->__('Yes'), // intended reverted use
|
| 91 |
+
'1' => Mage::helper('catalog')->__('No'), // intended reverted use
|
| 92 |
+
),
|
| 93 |
+
));
|
| 94 |
+
|
| 95 |
+
$this->addExportType('*/*/exportCsv/type/'.$this->_block, Mage::helper('attributemanager')->__('CSV'));
|
| 96 |
+
$this->addExportType('*/*/exportXml/type/'.$this->_block, Mage::helper('attributemanager')->__('XML'));
|
| 97 |
+
|
| 98 |
+
return parent::_prepareColumns();
|
| 99 |
+
}
|
| 100 |
+
public function getRowUrl($row)
|
| 101 |
+
{
|
| 102 |
+
return $this->getUrl('*/*/edit', array('type' => $this->type,'attribute_id' => $row->getAttributeId()));
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
?>
|
app/code/local/Hwg/Attributemanager/Helper/Data.php
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Hwg_Attributemanager_Helper_Data extends Mage_Core_Helper_Abstract
|
| 4 |
+
{
|
| 5 |
+
/**
|
| 6 |
+
* Selected products for massupdate
|
| 7 |
+
*
|
| 8 |
+
* @var Mage_Catalog_Model_Entity_Product_Collection
|
| 9 |
+
*/
|
| 10 |
+
protected $_categories;
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Array of categories that not available in selected store
|
| 14 |
+
*
|
| 15 |
+
* @var array
|
| 16 |
+
*/
|
| 17 |
+
protected $_categoriesNotInStore;
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Same attribtes for selected categories
|
| 21 |
+
*
|
| 22 |
+
* @var Mage_Eav_Model_Mysql4_Entity_Attribute_Collection
|
| 23 |
+
*/
|
| 24 |
+
protected $_attributes;
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Excluded from batch update attribute codes
|
| 29 |
+
*
|
| 30 |
+
* @var array
|
| 31 |
+
*/
|
| 32 |
+
protected $_excludedAttributes = array('url_key');
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Retrive product collection
|
| 36 |
+
*
|
| 37 |
+
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
|
| 38 |
+
*/
|
| 39 |
+
public function getCategories()
|
| 40 |
+
{
|
| 41 |
+
if (is_null($this->_categories)) {
|
| 42 |
+
$categoriesIds = $this->getCategoryIds();
|
| 43 |
+
|
| 44 |
+
if(!is_array($categoriesIds)) {
|
| 45 |
+
$categoriesIds = array(0);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
$this->_categories = Mage::getResourceModel('catalog/category_collection')
|
| 49 |
+
->setStoreId($this->getSelectedStoreId())
|
| 50 |
+
->addIdFilter($categoriesIds);
|
| 51 |
+
|
| 52 |
+
/*$this->load();
|
| 53 |
+
$this->addStoreNamesToResult();*/
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
return $this->_categories;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Retrive selected categories ids from post or session
|
| 61 |
+
*
|
| 62 |
+
* @return array|null
|
| 63 |
+
*/
|
| 64 |
+
public function getCategoryIds()
|
| 65 |
+
{
|
| 66 |
+
$session = Mage::getSingleton('adminhtml/session');
|
| 67 |
+
|
| 68 |
+
if ($this->_getRequest()->isPost() && $this->_getRequest()->getActionName()=='edit') {
|
| 69 |
+
$session->setCategoryIds($this->_getRequest()->getParam('category', null));
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
return $session->getCategoryIds();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Retrive selected store id
|
| 77 |
+
*
|
| 78 |
+
* @return integer
|
| 79 |
+
*/
|
| 80 |
+
public function getSelectedStoreId()
|
| 81 |
+
{
|
| 82 |
+
return (int) $this->_getRequest()->getParam('store', 0);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Retrive selected categories' attribute sets
|
| 87 |
+
*
|
| 88 |
+
* @return array
|
| 89 |
+
*/
|
| 90 |
+
public function getCategoriesSetIds()
|
| 91 |
+
{
|
| 92 |
+
return $this->getCategories()->getSetIds();
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* Retrive same attributes for selected categories without unique
|
| 97 |
+
*
|
| 98 |
+
* @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection
|
| 99 |
+
*/
|
| 100 |
+
public function getAttributes()
|
| 101 |
+
{
|
| 102 |
+
if (is_null($this->_attributes)) {
|
| 103 |
+
$this->_attributes = $this->getCategories()->getEntity()->getEntityType()->getAttributeCollection()
|
| 104 |
+
->addIsNotUniqueFilter()
|
| 105 |
+
->setInAllAttributeSetsFilter($this->getCategoriesSetIds());
|
| 106 |
+
|
| 107 |
+
foreach ($this->_excludedAttributes as $attributeCode) {
|
| 108 |
+
$this->_attributes->addFieldToFilter('attribute_code', array('neq'=>$attributeCode));
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
$this->_attributes->load();
|
| 112 |
+
foreach($this->_attributes as $attribute) {
|
| 113 |
+
$attribute->setEntity($this->getCategories()->getEntity());
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
return $this->_attributes;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* Retrive categories ids that not available for selected store
|
| 122 |
+
*
|
| 123 |
+
* @return array
|
| 124 |
+
*/
|
| 125 |
+
public function getCategoriesNotInStoreIds()
|
| 126 |
+
{
|
| 127 |
+
if (is_null($this->_categoriesNotInStore)) {
|
| 128 |
+
$this->_categoriesNotInStoreIds = array();
|
| 129 |
+
/*foreach ($this->getCategories() as $category) {
|
| 130 |
+
$stores = $category->getStores();
|
| 131 |
+
if (!isset($stores[$this->getSelectedStoreId()]) && $this->getSelectedStoreId() != 0) {
|
| 132 |
+
$this->_categoriesNotInStoreIds[] = $category->getId();
|
| 133 |
+
}
|
| 134 |
+
}*/
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
return $this->_categoriesNotInStoreIds;
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
?>
|
app/code/local/Hwg/Attributemanager/Model/Attributemanager.php
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Hwg_Attributemanager_Model_attributemanager extends Mage_Eav_Model_Entity_Attribute
|
| 4 |
+
{
|
| 5 |
+
public function _construct()
|
| 6 |
+
{
|
| 7 |
+
parent::_construct();
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
protected function _beforeSave()
|
| 11 |
+
{
|
| 12 |
+
if ( $this->getFrontendInput()=="image"){
|
| 13 |
+
$this->setBackendModel('catalog/category_attribute_backend_image');
|
| 14 |
+
$this->setBackendType('varchar');
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
if ( $this->getFrontendInput()=="date"){
|
| 18 |
+
$this->setBackendModel('eav/entity_attribute_backend_datetime');
|
| 19 |
+
$this->setBackendType('datetime');
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
if ( $this->getFrontendInput()=="textarea" ){
|
| 23 |
+
|
| 24 |
+
$this->setBackendType('text');
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
if ( $this->getFrontendInput()=="text" ){
|
| 28 |
+
|
| 29 |
+
$this->setBackendType('varchar');
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
if ( ($this->getFrontendInput()=="multiselect" || $this->getFrontendInput()=="select") ){
|
| 33 |
+
$this->setData('source_model', 'eav/entity_attribute_source_table');
|
| 34 |
+
$this->setBackendType('varchar');
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
if ($this->getFrontendInput()=="boolean"){
|
| 40 |
+
$this->setFrontendInput("select");
|
| 41 |
+
$this->setBackendType('int');
|
| 42 |
+
$this->setData('source_model', 'eav/entity_attribute_source_boolean');
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return parent::_beforeSave();
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
?>
|
app/code/local/Hwg/Attributemanager/controllers/Adminhtml/AddressController.php
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Adminhtml_AddressController extends Mage_Adminhtml_Controller_Action
|
| 3 |
+
{
|
| 4 |
+
protected $_customer_addressTypeId;
|
| 5 |
+
protected $_type;
|
| 6 |
+
protected $_block;
|
| 7 |
+
|
| 8 |
+
public function preDispatch()
|
| 9 |
+
{
|
| 10 |
+
parent::preDispatch();
|
| 11 |
+
$this->_customer_addressTypeId = Mage::getModel('eav/entity')->setType('customer_address')->getTypeId();
|
| 12 |
+
|
| 13 |
+
$this->_block = 'address';
|
| 14 |
+
$this->_type = 'customer_address';
|
| 15 |
+
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
protected function _initAction() {
|
| 19 |
+
$this->loadLayout()
|
| 20 |
+
->_setActiveMenu('attributemanager/attributemanager')
|
| 21 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Attribute Manager'), Mage::helper('adminhtml')->__('Attribute Manager'));
|
| 22 |
+
return $this;
|
| 23 |
+
}
|
| 24 |
+
public function addressAction()
|
| 25 |
+
{
|
| 26 |
+
$this->_initAction()->renderLayout();
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
public function editAction()
|
| 30 |
+
{
|
| 31 |
+
$id = $this->getRequest()->getParam('attribute_id');
|
| 32 |
+
$model = Mage::getModel('eav/entity_attribute')->load($id);
|
| 33 |
+
|
| 34 |
+
if(0!==$id){
|
| 35 |
+
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
|
| 36 |
+
$model->setData("sort_order",$db->fetchOne("select sort_order from eav_entity_attribute where attribute_id=$id"));
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if ($model->getId() || $id == 0) {
|
| 41 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
| 42 |
+
if (!empty($data)) {
|
| 43 |
+
$model->setData($data);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
Mage::register('attributemanager_data', $model);
|
| 47 |
+
|
| 48 |
+
$this->loadLayout();
|
| 49 |
+
$this->_setActiveMenu('attributemanager/attributemanager');
|
| 50 |
+
|
| 51 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
| 52 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
| 53 |
+
|
| 54 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
| 55 |
+
|
| 56 |
+
$this
|
| 57 |
+
->_addContent($this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_edit'))
|
| 58 |
+
->_addLeft($this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_edit_tabs'))
|
| 59 |
+
;
|
| 60 |
+
|
| 61 |
+
$this->renderLayout();
|
| 62 |
+
} else {
|
| 63 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('attributemanager')->__('Item does not exist'));
|
| 64 |
+
$this->_redirect('*/*/');
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
public function newAction() {
|
| 69 |
+
$this->_forward('edit');
|
| 70 |
+
}
|
| 71 |
+
public function saveAction() {
|
| 72 |
+
if ($data = $this->getRequest()->getPost()) {
|
| 73 |
+
|
| 74 |
+
$model = Mage::getModel('attributemanager/attributemanager');
|
| 75 |
+
$model->setData($data);
|
| 76 |
+
if( $this->getRequest()->getParam('attribute_id') > 0 ) {
|
| 77 |
+
|
| 78 |
+
$model->setId($this->getRequest()->getParam('attribute_id'));
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
try {
|
| 82 |
+
|
| 83 |
+
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
|
| 84 |
+
$model->setCreatedTime(now())
|
| 85 |
+
->setUpdateTime(now());
|
| 86 |
+
} else {
|
| 87 |
+
$model->setUpdateTime(now());
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
$model->save();
|
| 91 |
+
$id=$model->getId();
|
| 92 |
+
|
| 93 |
+
if($this->_block == 'customer' || $this->_block == 'address')
|
| 94 |
+
{
|
| 95 |
+
$attribute = Mage::getModel('eav/entity_attribute')->load($id);
|
| 96 |
+
|
| 97 |
+
Mage::getSingleton('eav/config')
|
| 98 |
+
->getAttribute($this->_type, $attribute->getAttributeCode())
|
| 99 |
+
->setData('used_in_forms', $data['customer_form'])
|
| 100 |
+
->save();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('attributemanager')->__('Item was successfully saved'));
|
| 104 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
| 105 |
+
|
| 106 |
+
if ($this->getRequest()->getParam('back')) {
|
| 107 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'), 'attribute_id' => $id));
|
| 108 |
+
return;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 112 |
+
return;
|
| 113 |
+
} catch (Exception $e) {
|
| 114 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 115 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
| 116 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'),'attribute_id' => $this->getRequest()->getParam('attribute_id')));
|
| 117 |
+
return;
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('attributemanager')->__('Unable to find item to save'));
|
| 121 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
public function deleteAction() {
|
| 125 |
+
if( $this->getRequest()->getParam('attribute_id') > 0 ) {
|
| 126 |
+
try {
|
| 127 |
+
$model = Mage::getModel('eav/entity_attribute');
|
| 128 |
+
|
| 129 |
+
$model->setId($this->getRequest()->getParam('attribute_id'))
|
| 130 |
+
->delete();
|
| 131 |
+
|
| 132 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
|
| 133 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 134 |
+
|
| 135 |
+
} catch (Exception $e) {
|
| 136 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 137 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'),'attribute_id' => $this->getRequest()->getParam('attribute_id')));
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
$this->_redirect('*/*/'.$this->_block.'/filter//');
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
public function massDeleteAction() {
|
| 144 |
+
$categoriesattributesIds = $this->getRequest()->getParam('attributemanager');
|
| 145 |
+
if(!is_array($categoriesattributesIds)) {
|
| 146 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
|
| 147 |
+
} else {
|
| 148 |
+
try {
|
| 149 |
+
foreach ($categoriesattributesIds as $categoriesattributesId) {
|
| 150 |
+
$categoriesattributes = Mage::getModel('eav/entity_attribute')->load($categoriesattributesId);
|
| 151 |
+
$categoriesattributes->delete();
|
| 152 |
+
}
|
| 153 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(
|
| 154 |
+
Mage::helper('adminhtml')->__(
|
| 155 |
+
'Total of %d record(s) were successfully deleted', count($categoriesattributesIds)
|
| 156 |
+
)
|
| 157 |
+
);
|
| 158 |
+
} catch (Exception $e) {
|
| 159 |
+
|
| 160 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
$this->_redirect('*/*/'.$this->_type);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
public function exportCsvAction()
|
| 167 |
+
{
|
| 168 |
+
$fileName = $this->_type.'attributes.csv';
|
| 169 |
+
$content = $this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_grid')
|
| 170 |
+
->getCsv();
|
| 171 |
+
|
| 172 |
+
$this->_sendUploadResponse($fileName, $content);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
public function exportXmlAction()
|
| 176 |
+
{
|
| 177 |
+
$fileName = $this->_type.'attributes.xml';
|
| 178 |
+
$content = $this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_grid')
|
| 179 |
+
->getXml();
|
| 180 |
+
|
| 181 |
+
$this->_sendUploadResponse($fileName, $content);
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
|
| 185 |
+
{
|
| 186 |
+
$response = $this->getResponse();
|
| 187 |
+
$response->setHeader('HTTP/1.1 200 OK','');
|
| 188 |
+
$response->setHeader('Pragma', 'public', true);
|
| 189 |
+
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
|
| 190 |
+
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
|
| 191 |
+
$response->setHeader('Last-Modified', date('r'));
|
| 192 |
+
$response->setHeader('Accept-Ranges', 'bytes');
|
| 193 |
+
$response->setHeader('Content-Length', strlen($content));
|
| 194 |
+
$response->setHeader('Content-type', $contentType);
|
| 195 |
+
$response->setBody($content);
|
| 196 |
+
$response->sendResponse();
|
| 197 |
+
die;
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
?>
|
app/code/local/Hwg/Attributemanager/controllers/Adminhtml/CategoryController.php
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Adminhtml_CategoryController extends Mage_Adminhtml_Controller_Action
|
| 3 |
+
{
|
| 4 |
+
protected $_categoryTypeId;
|
| 5 |
+
protected $_type;
|
| 6 |
+
protected $_block;
|
| 7 |
+
|
| 8 |
+
public function preDispatch()
|
| 9 |
+
{
|
| 10 |
+
parent::preDispatch();
|
| 11 |
+
$this->_categoryTypeId = Mage::getModel('eav/entity')->setType('catalog_category')->getTypeId();
|
| 12 |
+
|
| 13 |
+
$this->_block = 'category';
|
| 14 |
+
$this->_type = 'catalog_category';
|
| 15 |
+
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
protected function _initAction() {
|
| 19 |
+
$this->loadLayout()
|
| 20 |
+
->_setActiveMenu('attributemanager/attributemanager')
|
| 21 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Attribute Manager'), Mage::helper('adminhtml')->__('Attribute Manager'));
|
| 22 |
+
return $this;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
public function categoryAction() {
|
| 26 |
+
$this->_initAction()->renderLayout();
|
| 27 |
+
}
|
| 28 |
+
public function editAction()
|
| 29 |
+
{
|
| 30 |
+
$id = $this->getRequest()->getParam('attribute_id');
|
| 31 |
+
$model = Mage::getModel('eav/entity_attribute')->load($id);
|
| 32 |
+
|
| 33 |
+
if(0!==$id){
|
| 34 |
+
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
|
| 35 |
+
$model->setData("sort_order",$db->fetchOne("select sort_order from eav_entity_attribute where attribute_id=$id"));
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
if ($model->getId() || $id == 0) {
|
| 40 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
| 41 |
+
if (!empty($data)) {
|
| 42 |
+
$model->setData($data);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
Mage::register('attributemanager_data', $model);
|
| 46 |
+
|
| 47 |
+
$this->loadLayout();
|
| 48 |
+
$this->_setActiveMenu('attributemanager/attributemanager');
|
| 49 |
+
|
| 50 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
| 51 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
| 52 |
+
|
| 53 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
| 54 |
+
|
| 55 |
+
$this
|
| 56 |
+
->_addContent($this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_edit'))
|
| 57 |
+
->_addLeft($this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_edit_tabs'))
|
| 58 |
+
;
|
| 59 |
+
|
| 60 |
+
$this->renderLayout();
|
| 61 |
+
} else {
|
| 62 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('attributemanager')->__('Item does not exist'));
|
| 63 |
+
$this->_redirect('*/*/');
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
public function newAction() {
|
| 68 |
+
$this->_forward('edit');
|
| 69 |
+
}
|
| 70 |
+
public function saveAction() {
|
| 71 |
+
if ($data = $this->getRequest()->getPost()) {
|
| 72 |
+
|
| 73 |
+
$model = Mage::getModel('attributemanager/attributemanager');
|
| 74 |
+
$model->setData($data);
|
| 75 |
+
if( $this->getRequest()->getParam('attribute_id') > 0 ) {
|
| 76 |
+
|
| 77 |
+
$model->setId($this->getRequest()->getParam('attribute_id'));
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
try {
|
| 81 |
+
|
| 82 |
+
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
|
| 83 |
+
$model->setCreatedTime(now())
|
| 84 |
+
->setUpdateTime(now());
|
| 85 |
+
} else {
|
| 86 |
+
$model->setUpdateTime(now());
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
$model->save();
|
| 90 |
+
$id=$model->getId();
|
| 91 |
+
|
| 92 |
+
if($this->_block == 'customer' || $this->_block == 'address')
|
| 93 |
+
{
|
| 94 |
+
$attribute = Mage::getModel('eav/entity_attribute')->load($id);
|
| 95 |
+
|
| 96 |
+
Mage::getSingleton('eav/config')
|
| 97 |
+
->getAttribute($this->_type, $attribute->getAttributeCode())
|
| 98 |
+
->setData('used_in_forms', $data['customer_form'])
|
| 99 |
+
->save();
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('attributemanager')->__('Item was successfully saved'));
|
| 103 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
| 104 |
+
|
| 105 |
+
if ($this->getRequest()->getParam('back')) {
|
| 106 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'), 'attribute_id' => $id));
|
| 107 |
+
return;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 111 |
+
return;
|
| 112 |
+
} catch (Exception $e) {
|
| 113 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 114 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
| 115 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'),'attribute_id' => $this->getRequest()->getParam('attribute_id')));
|
| 116 |
+
return;
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('attributemanager')->__('Unable to find item to save'));
|
| 120 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
public function deleteAction() {
|
| 124 |
+
if( $this->getRequest()->getParam('attribute_id') > 0 ) {
|
| 125 |
+
try {
|
| 126 |
+
$model = Mage::getModel('eav/entity_attribute');
|
| 127 |
+
|
| 128 |
+
$model->setId($this->getRequest()->getParam('attribute_id'))
|
| 129 |
+
->delete();
|
| 130 |
+
|
| 131 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
|
| 132 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 133 |
+
|
| 134 |
+
} catch (Exception $e) {
|
| 135 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 136 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'),'attribute_id' => $this->getRequest()->getParam('attribute_id')));
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
$this->_redirect('*/*/'.$this->_block.'/filter//');
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
public function massDeleteAction() {
|
| 143 |
+
$categoriesattributesIds = $this->getRequest()->getParam('attributemanager');
|
| 144 |
+
if(!is_array($categoriesattributesIds)) {
|
| 145 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
|
| 146 |
+
} else {
|
| 147 |
+
try {
|
| 148 |
+
foreach ($categoriesattributesIds as $categoriesattributesId) {
|
| 149 |
+
$categoriesattributes = Mage::getModel('eav/entity_attribute')->load($categoriesattributesId);
|
| 150 |
+
$categoriesattributes->delete();
|
| 151 |
+
}
|
| 152 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(
|
| 153 |
+
Mage::helper('adminhtml')->__(
|
| 154 |
+
'Total of %d record(s) were successfully deleted', count($categoriesattributesIds)
|
| 155 |
+
)
|
| 156 |
+
);
|
| 157 |
+
} catch (Exception $e) {
|
| 158 |
+
|
| 159 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
$this->_redirect('*/*/'.$this->_type);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
public function exportCsvAction()
|
| 166 |
+
{
|
| 167 |
+
$fileName = $this->_type.'attributes.csv';
|
| 168 |
+
$content = $this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_grid')
|
| 169 |
+
->getCsv();
|
| 170 |
+
|
| 171 |
+
$this->_sendUploadResponse($fileName, $content);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
public function exportXmlAction()
|
| 175 |
+
{
|
| 176 |
+
$fileName = $this->_type.'attributes.xml';
|
| 177 |
+
$content = $this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_grid')
|
| 178 |
+
->getXml();
|
| 179 |
+
|
| 180 |
+
$this->_sendUploadResponse($fileName, $content);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
|
| 184 |
+
{
|
| 185 |
+
$response = $this->getResponse();
|
| 186 |
+
$response->setHeader('HTTP/1.1 200 OK','');
|
| 187 |
+
$response->setHeader('Pragma', 'public', true);
|
| 188 |
+
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
|
| 189 |
+
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
|
| 190 |
+
$response->setHeader('Last-Modified', date('r'));
|
| 191 |
+
$response->setHeader('Accept-Ranges', 'bytes');
|
| 192 |
+
$response->setHeader('Content-Length', strlen($content));
|
| 193 |
+
$response->setHeader('Content-type', $contentType);
|
| 194 |
+
$response->setBody($content);
|
| 195 |
+
$response->sendResponse();
|
| 196 |
+
die;
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
?>
|
app/code/local/Hwg/Attributemanager/controllers/Adminhtml/CustomerController.php
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
|
| 3 |
+
{
|
| 4 |
+
protected $_customerTypeId;
|
| 5 |
+
protected $_type;
|
| 6 |
+
protected $_block;
|
| 7 |
+
|
| 8 |
+
public function preDispatch()
|
| 9 |
+
{
|
| 10 |
+
parent::preDispatch();
|
| 11 |
+
$this->_customerTypeId = Mage::getModel('eav/entity')->setType('customer')->getTypeId();
|
| 12 |
+
|
| 13 |
+
$this->_block = 'customer';
|
| 14 |
+
$this->_type = 'customer';
|
| 15 |
+
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
protected function _initAction() {
|
| 19 |
+
$this->loadLayout()
|
| 20 |
+
->_setActiveMenu('attributemanager/attributemanager')
|
| 21 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Attribute Manager'), Mage::helper('adminhtml')->__('Attribute Manager'));
|
| 22 |
+
return $this;
|
| 23 |
+
}
|
| 24 |
+
public function customerAction()
|
| 25 |
+
{
|
| 26 |
+
$this->_initAction()->renderLayout();
|
| 27 |
+
}
|
| 28 |
+
public function editAction()
|
| 29 |
+
{
|
| 30 |
+
$id = $this->getRequest()->getParam('attribute_id');
|
| 31 |
+
$model = Mage::getModel('eav/entity_attribute')->load($id);
|
| 32 |
+
|
| 33 |
+
if(0!==$id){
|
| 34 |
+
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
|
| 35 |
+
$model->setData("sort_order",$db->fetchOne("select sort_order from eav_entity_attribute where attribute_id=$id"));
|
| 36 |
+
}
|
| 37 |
+
if ($model->getId() || $id == 0) {
|
| 38 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
| 39 |
+
if (!empty($data)) {
|
| 40 |
+
$model->setData($data);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
Mage::register('attributemanager_data', $model);
|
| 44 |
+
|
| 45 |
+
$this->loadLayout();
|
| 46 |
+
$this->_setActiveMenu('attributemanager/attributemanager');
|
| 47 |
+
|
| 48 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
| 49 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
| 50 |
+
|
| 51 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
| 52 |
+
|
| 53 |
+
$this
|
| 54 |
+
->_addContent($this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_edit'))
|
| 55 |
+
->_addLeft($this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_edit_tabs'))
|
| 56 |
+
;
|
| 57 |
+
|
| 58 |
+
$this->renderLayout();
|
| 59 |
+
} else {
|
| 60 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('attributemanager')->__('Item does not exist'));
|
| 61 |
+
$this->_redirect('*/*/');
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
public function newAction() {
|
| 66 |
+
$this->_forward('edit');
|
| 67 |
+
}
|
| 68 |
+
public function saveAction() {
|
| 69 |
+
if ($data = $this->getRequest()->getPost()) {
|
| 70 |
+
|
| 71 |
+
$model = Mage::getModel('attributemanager/attributemanager');
|
| 72 |
+
$model->setData($data);
|
| 73 |
+
if( $this->getRequest()->getParam('attribute_id') > 0 ) {
|
| 74 |
+
|
| 75 |
+
$model->setId($this->getRequest()->getParam('attribute_id'));
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
try {
|
| 79 |
+
|
| 80 |
+
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
|
| 81 |
+
$model->setCreatedTime(now())
|
| 82 |
+
->setUpdateTime(now());
|
| 83 |
+
} else {
|
| 84 |
+
$model->setUpdateTime(now());
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
$model->save();
|
| 88 |
+
$id=$model->getId();
|
| 89 |
+
|
| 90 |
+
if($this->_block == 'customer' || $this->_block == 'address')
|
| 91 |
+
{
|
| 92 |
+
$attribute = Mage::getModel('eav/entity_attribute')->load($id);
|
| 93 |
+
|
| 94 |
+
Mage::getSingleton('eav/config')
|
| 95 |
+
->getAttribute($this->_type, $attribute->getAttributeCode())
|
| 96 |
+
->setData('used_in_forms', $data['customer_form'])
|
| 97 |
+
->save();
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('attributemanager')->__('Item was successfully saved'));
|
| 101 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
| 102 |
+
|
| 103 |
+
if ($this->getRequest()->getParam('back')) {
|
| 104 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'), 'attribute_id' => $id));
|
| 105 |
+
return;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 109 |
+
return;
|
| 110 |
+
} catch (Exception $e) {
|
| 111 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 112 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
| 113 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'),'attribute_id' => $this->getRequest()->getParam('attribute_id')));
|
| 114 |
+
return;
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('attributemanager')->__('Unable to find item to save'));
|
| 118 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
public function deleteAction() {
|
| 122 |
+
if( $this->getRequest()->getParam('attribute_id') > 0 ) {
|
| 123 |
+
try {
|
| 124 |
+
$model = Mage::getModel('eav/entity_attribute');
|
| 125 |
+
|
| 126 |
+
$model->setId($this->getRequest()->getParam('attribute_id'))
|
| 127 |
+
->delete();
|
| 128 |
+
|
| 129 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
|
| 130 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 131 |
+
|
| 132 |
+
} catch (Exception $e) {
|
| 133 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 134 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'),'attribute_id' => $this->getRequest()->getParam('attribute_id')));
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
public function massDeleteAction() {
|
| 141 |
+
$categoriesattributesIds = $this->getRequest()->getParam('attributemanager');
|
| 142 |
+
if(!is_array($categoriesattributesIds)) {
|
| 143 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
|
| 144 |
+
} else {
|
| 145 |
+
try {
|
| 146 |
+
foreach ($categoriesattributesIds as $categoriesattributesId) {
|
| 147 |
+
$categoriesattributes = Mage::getModel('eav/entity_attribute')->load($categoriesattributesId);
|
| 148 |
+
$categoriesattributes->delete();
|
| 149 |
+
}
|
| 150 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(
|
| 151 |
+
Mage::helper('adminhtml')->__(
|
| 152 |
+
'Total of %d record(s) were successfully deleted', count($categoriesattributesIds)
|
| 153 |
+
)
|
| 154 |
+
);
|
| 155 |
+
} catch (Exception $e) {
|
| 156 |
+
|
| 157 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
$this->_redirect('*/*/'.$this->_type.'/filter//');
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
public function exportCsvAction()
|
| 164 |
+
{
|
| 165 |
+
$fileName = $this->_type.'attributes.csv';
|
| 166 |
+
$content = $this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_grid')
|
| 167 |
+
->getCsv();
|
| 168 |
+
|
| 169 |
+
$this->_sendUploadResponse($fileName, $content);
|
| 170 |
+
}
|
| 171 |
+
public function exportXmlAction()
|
| 172 |
+
{
|
| 173 |
+
$fileName = $this->_type.'attributes.xml';
|
| 174 |
+
$content = $this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_grid')
|
| 175 |
+
->getXml();
|
| 176 |
+
|
| 177 |
+
$this->_sendUploadResponse($fileName, $content);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
|
| 181 |
+
{
|
| 182 |
+
$response = $this->getResponse();
|
| 183 |
+
$response->setHeader('HTTP/1.1 200 OK','');
|
| 184 |
+
$response->setHeader('Pragma', 'public', true);
|
| 185 |
+
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
|
| 186 |
+
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
|
| 187 |
+
$response->setHeader('Last-Modified', date('r'));
|
| 188 |
+
$response->setHeader('Accept-Ranges', 'bytes');
|
| 189 |
+
$response->setHeader('Content-Length', strlen($content));
|
| 190 |
+
$response->setHeader('Content-type', $contentType);
|
| 191 |
+
$response->setBody($content);
|
| 192 |
+
$response->sendResponse();
|
| 193 |
+
die;
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
?>
|
app/code/local/Hwg/Attributemanager/controllers/Adminhtml/IndexController.php
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Hwg_Attributemanager_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
|
| 3 |
+
{
|
| 4 |
+
protected $_customerTypeId;
|
| 5 |
+
protected $_categoryTypeId;
|
| 6 |
+
protected $_customer_addressTypeId;
|
| 7 |
+
protected $_type;
|
| 8 |
+
protected $_block;
|
| 9 |
+
|
| 10 |
+
public function preDispatch()
|
| 11 |
+
{
|
| 12 |
+
parent::preDispatch();
|
| 13 |
+
$this->_customerTypeId = Mage::getModel('eav/entity')->setType('customer')->getTypeId();
|
| 14 |
+
$this->_categoryTypeId = Mage::getModel('eav/entity')->setType('catalog_category')->getTypeId();
|
| 15 |
+
$this->_customer_addressTypeId = Mage::getModel('eav/entity')->setType('customer_address')->getTypeId();
|
| 16 |
+
|
| 17 |
+
if ($this->getRequest ()->getParam ( 'type' ))
|
| 18 |
+
{
|
| 19 |
+
switch ($this->getRequest ()->getParam ( 'type' ))
|
| 20 |
+
{
|
| 21 |
+
case "catalog_category" :
|
| 22 |
+
$this->_block = 'category';
|
| 23 |
+
$this->_type = 'catalog_category';
|
| 24 |
+
break;
|
| 25 |
+
|
| 26 |
+
case "customer" :
|
| 27 |
+
$this->_block = 'customer';
|
| 28 |
+
$this->_type = 'customer';
|
| 29 |
+
break;
|
| 30 |
+
|
| 31 |
+
case "customer_address" :
|
| 32 |
+
$this->_block = 'address';
|
| 33 |
+
$this->_type = 'customer_address';
|
| 34 |
+
break;
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
protected function _initAction() {
|
| 40 |
+
$this->loadLayout()
|
| 41 |
+
->_setActiveMenu('attributemanager/attributemanager')
|
| 42 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Attribute Manager'), Mage::helper('adminhtml')->__('Attribute Manager'));
|
| 43 |
+
return $this;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
public function categoryAction() {
|
| 47 |
+
$this->_initAction()->renderLayout();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
public function customerAction()
|
| 51 |
+
{
|
| 52 |
+
$this->_initAction()->renderLayout();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
public function addressAction()
|
| 56 |
+
{
|
| 57 |
+
$this->_initAction()->renderLayout();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
public function editAction()
|
| 61 |
+
{
|
| 62 |
+
$id = $this->getRequest()->getParam('attribute_id');
|
| 63 |
+
$model = Mage::getModel('eav/entity_attribute')->load($id);
|
| 64 |
+
|
| 65 |
+
if(0!==$id){
|
| 66 |
+
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
|
| 67 |
+
$model->setData("sort_order",$db->fetchOne("select sort_order from eav_entity_attribute where attribute_id=$id"));
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
if ($model->getId() || $id == 0) {
|
| 72 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
| 73 |
+
if (!empty($data)) {
|
| 74 |
+
$model->setData($data);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
Mage::register('attributemanager_data', $model);
|
| 78 |
+
|
| 79 |
+
$this->loadLayout();
|
| 80 |
+
$this->_setActiveMenu('attributemanager/attributemanager');
|
| 81 |
+
|
| 82 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
| 83 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
| 84 |
+
|
| 85 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
| 86 |
+
|
| 87 |
+
$this
|
| 88 |
+
->_addContent($this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_edit'))
|
| 89 |
+
->_addLeft($this->getLayout()->createBlock('attributemanager/adminhtml_'.$this->_block.'_edit_tabs'))
|
| 90 |
+
;
|
| 91 |
+
|
| 92 |
+
$this->renderLayout();
|
| 93 |
+
} else {
|
| 94 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('attributemanager')->__('Item does not exist'));
|
| 95 |
+
$this->_redirect('*/*/');
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
public function newAction() {
|
| 100 |
+
$this->_forward('edit');
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
public function validateAction()
|
| 104 |
+
{
|
| 105 |
+
$response = new Varien_Object();
|
| 106 |
+
$response->setError(false);
|
| 107 |
+
|
| 108 |
+
$attributeCode = $this->getRequest()->getParam('type');
|
| 109 |
+
$attributeId = $this->getRequest()->getParam('attribute_id');
|
| 110 |
+
switch ($attributeCode){
|
| 111 |
+
case "catalog_category":
|
| 112 |
+
$this->_entityTypeId=$this->_categoryTypeId;
|
| 113 |
+
break;
|
| 114 |
+
|
| 115 |
+
case "customer":
|
| 116 |
+
$this->_entityTypeId=$this->_customerTypeId;
|
| 117 |
+
break;
|
| 118 |
+
|
| 119 |
+
case "customer_address":
|
| 120 |
+
$this->_entityTypeId=$this->_customer_addressTypeId;
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
$attribute = Mage::getModel('eav/entity_attribute')
|
| 124 |
+
->loadByCode($this->_entityTypeId, $attributeCode);
|
| 125 |
+
|
| 126 |
+
if ($attribute->getId() && !$attributeId) {
|
| 127 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('Attribute with the same code already exists'));
|
| 128 |
+
$this->_initLayoutMessages('adminhtml/session');
|
| 129 |
+
$response->setError(true);
|
| 130 |
+
$response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
$this->getResponse()->setBody($response->toJson());
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
public function saveAction() {
|
| 137 |
+
if ($data = $this->getRequest()->getPost()) {
|
| 138 |
+
|
| 139 |
+
$model = Mage::getModel('attributemanager/attributemanager');
|
| 140 |
+
$model->setData($data);
|
| 141 |
+
if( $this->getRequest()->getParam('attribute_id') > 0 ) {
|
| 142 |
+
|
| 143 |
+
$model->setId($this->getRequest()->getParam('attribute_id'));
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
try {
|
| 147 |
+
|
| 148 |
+
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
|
| 149 |
+
$model->setCreatedTime(now())
|
| 150 |
+
->setUpdateTime(now());
|
| 151 |
+
} else {
|
| 152 |
+
$model->setUpdateTime(now());
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
$model->save();
|
| 156 |
+
$id=$model->getId();
|
| 157 |
+
|
| 158 |
+
if($this->_block == 'customer' || $this->_block == 'address')
|
| 159 |
+
{
|
| 160 |
+
$attribute = Mage::getModel('eav/entity_attribute')->load($id);
|
| 161 |
+
|
| 162 |
+
Mage::getSingleton('eav/config')
|
| 163 |
+
->getAttribute($this->_type, $attribute->getAttributeCode())
|
| 164 |
+
->setData('used_in_forms', $data['customer_form'])
|
| 165 |
+
->save();
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('attributemanager')->__('Item was successfully saved'));
|
| 169 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
| 170 |
+
|
| 171 |
+
if ($this->getRequest()->getParam('back')) {
|
| 172 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'), 'attribute_id' => $id));
|
| 173 |
+
return;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 177 |
+
return;
|
| 178 |
+
} catch (Exception $e) {
|
| 179 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 180 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
| 181 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'),'attribute_id' => $this->getRequest()->getParam('attribute_id')));
|
| 182 |
+
return;
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('attributemanager')->__('Unable to find item to save'));
|
| 186 |
+
$this->_redirect('*/*/'.$this->_block);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
public function deleteAction() {
|
| 190 |
+
if( $this->getRequest()->getParam('attribute_id') > 0 ) {
|
| 191 |
+
try {
|
| 192 |
+
$model = Mage::getModel('eav/entity_attribute');
|
| 193 |
+
|
| 194 |
+
$model->setId($this->getRequest()->getParam('attribute_id'))
|
| 195 |
+
->delete();
|
| 196 |
+
|
| 197 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
|
| 198 |
+
$this->_redirect('*/*/'.$this->_type.'/filter//');
|
| 199 |
+
} catch (Exception $e) {
|
| 200 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 201 |
+
$this->_redirect('*/*/edit', array('type'=>$this->getRequest()->getParam('type'),'attribute_id' => $this->getRequest()->getParam('attribute_id')));
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
$this->_redirect('*/*/'.$this->_type.'/filter//');
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
public function massDeleteAction() {
|
| 208 |
+
$categoriesattributesIds = $this->getRequest()->getParam('attributemanager');
|
| 209 |
+
if(!is_array($categoriesattributesIds)) {
|
| 210 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
|
| 211 |
+
} else {
|
| 212 |
+
try {
|
| 213 |
+
foreach ($categoriesattributesIds as $categoriesattributesId) {
|
| 214 |
+
$categoriesattributes = Mage::getModel('eav/entity_attribute')->load($categoriesattributesId);
|
| 215 |
+
$categoriesattributes->delete();
|
| 216 |
+
}
|
| 217 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(
|
| 218 |
+
Mage::helper('adminhtml')->__(
|
| 219 |
+
'Total of %d record(s) were successfully deleted', count($categoriesattributesIds)
|
| 220 |
+
)
|
| 221 |
+
);
|
| 222 |
+
} catch (Exception $e) {
|
| 223 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
$this->_redirect('*/*/'.$this->_type.'/filter//');
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
public function exportCsvAction()
|
| 230 |
+
{
|
| 231 |
+
$fileName = $this->_type.'attributes.csv';
|
| 232 |
+
$content = $this->getLayout()->createBlock('attributemanager/grid')
|
| 233 |
+
->getCsv();
|
| 234 |
+
|
| 235 |
+
$this->_sendUploadResponse($fileName, $content);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
public function exportXmlAction()
|
| 239 |
+
{
|
| 240 |
+
$fileName = $this->_type.'attributes.xml';
|
| 241 |
+
$content = $this->getLayout()->createBlock('attributemanager/grid')
|
| 242 |
+
->getXml();
|
| 243 |
+
|
| 244 |
+
$this->_sendUploadResponse($fileName, $content);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
|
| 248 |
+
{
|
| 249 |
+
$response = $this->getResponse();
|
| 250 |
+
$response->setHeader('HTTP/1.1 200 OK','');
|
| 251 |
+
$response->setHeader('Pragma', 'public', true);
|
| 252 |
+
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
|
| 253 |
+
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
|
| 254 |
+
$response->setHeader('Last-Modified', date('r'));
|
| 255 |
+
$response->setHeader('Accept-Ranges', 'bytes');
|
| 256 |
+
$response->setHeader('Content-Length', strlen($content));
|
| 257 |
+
$response->setHeader('Content-type', $contentType);
|
| 258 |
+
$response->setBody($content);
|
| 259 |
+
$response->sendResponse();
|
| 260 |
+
die;
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
?>
|
app/code/local/Hwg/Attributemanager/etc/config.xml
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Hwg_Attributemanager>
|
| 5 |
+
<version>0.1.0</version>
|
| 6 |
+
</Hwg_Attributemanager>
|
| 7 |
+
</modules>
|
| 8 |
+
<admin>
|
| 9 |
+
<routers>
|
| 10 |
+
<attributemanager>
|
| 11 |
+
<use>admin</use>
|
| 12 |
+
<args>
|
| 13 |
+
<module>Hwg_Attributemanager</module>
|
| 14 |
+
<frontName>attributemanager</frontName>
|
| 15 |
+
</args>
|
| 16 |
+
</attributemanager>
|
| 17 |
+
</routers>
|
| 18 |
+
</admin>
|
| 19 |
+
<default>
|
| 20 |
+
<config_vars></config_vars>
|
| 21 |
+
</default>
|
| 22 |
+
<adminhtml>
|
| 23 |
+
<menu>
|
| 24 |
+
<attributemanager module="attributemanager">
|
| 25 |
+
<title>Attribute Manager</title>
|
| 26 |
+
<sort_order>70</sort_order>
|
| 27 |
+
<children>
|
| 28 |
+
<category_manager module="attributemanager">
|
| 29 |
+
<title>Category Attribute</title>
|
| 30 |
+
<sort_order>10</sort_order>
|
| 31 |
+
<action>attributemanager/adminhtml_category/category</action>
|
| 32 |
+
</category_manager>
|
| 33 |
+
<customer_manager module="attributemanager">
|
| 34 |
+
<title>Customer Attribute</title>
|
| 35 |
+
<sort_order>20</sort_order>
|
| 36 |
+
<action>attributemanager/adminhtml_customer/customer</action>
|
| 37 |
+
</customer_manager>
|
| 38 |
+
<customer_address_manager module="attributemanager">
|
| 39 |
+
<title>Customer Address Attribute</title>
|
| 40 |
+
<sort_order>30</sort_order>
|
| 41 |
+
<action>attributemanager/adminhtml_address/address</action>
|
| 42 |
+
</customer_address_manager>
|
| 43 |
+
</children>
|
| 44 |
+
</attributemanager>
|
| 45 |
+
</menu>
|
| 46 |
+
<acl>
|
| 47 |
+
<resources>
|
| 48 |
+
<all>
|
| 49 |
+
<title>Allow Everything</title>
|
| 50 |
+
</all>
|
| 51 |
+
<admin>
|
| 52 |
+
<children>
|
| 53 |
+
<Hwg_Attributemanager>
|
| 54 |
+
<title>Attributemanager Module</title>
|
| 55 |
+
<sort_order>10</sort_order>
|
| 56 |
+
</Hwg_Attributemanager>
|
| 57 |
+
</children>
|
| 58 |
+
</admin>
|
| 59 |
+
</resources>
|
| 60 |
+
</acl>
|
| 61 |
+
<layout>
|
| 62 |
+
<updates>
|
| 63 |
+
<attributemanager>
|
| 64 |
+
<file>attributemanager.xml</file>
|
| 65 |
+
</attributemanager>
|
| 66 |
+
</updates>
|
| 67 |
+
</layout>
|
| 68 |
+
</adminhtml>
|
| 69 |
+
|
| 70 |
+
<global>
|
| 71 |
+
<models>
|
| 72 |
+
<attributemanager>
|
| 73 |
+
<class>Hwg_Attributemanager_Model</class>
|
| 74 |
+
</attributemanager>
|
| 75 |
+
</models>
|
| 76 |
+
<blocks>
|
| 77 |
+
<attributemanager>
|
| 78 |
+
<class>Hwg_Attributemanager_Block</class>
|
| 79 |
+
</attributemanager>
|
| 80 |
+
</blocks>
|
| 81 |
+
<helpers>
|
| 82 |
+
<attributemanager>
|
| 83 |
+
<class>Hwg_Attributemanager_Helper</class>
|
| 84 |
+
</attributemanager>
|
| 85 |
+
</helpers>
|
| 86 |
+
</global>
|
| 87 |
+
</config>
|
app/design/adminhtml/default/default/layout/attributemanager.xml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" ?>
|
| 2 |
+
<layout version="0.1.0">
|
| 3 |
+
<attributemanager_adminhtml_category_category>
|
| 4 |
+
<reference name="content">
|
| 5 |
+
<block type="attributemanager/adminhtml_category" name="attributemanager_category" />
|
| 6 |
+
</reference>
|
| 7 |
+
</attributemanager_adminhtml_category_category>
|
| 8 |
+
|
| 9 |
+
<attributemanager_adminhtml_customer_customer>
|
| 10 |
+
<reference name="content">
|
| 11 |
+
<block type="attributemanager/adminhtml_customer" name="attributemanager_customer" />
|
| 12 |
+
</reference>
|
| 13 |
+
</attributemanager_adminhtml_customer_customer>
|
| 14 |
+
|
| 15 |
+
<attributemanager_adminhtml_address_address>
|
| 16 |
+
<reference name="content">
|
| 17 |
+
<block type="attributemanager/adminhtml_address" name="attributemanager_address" />
|
| 18 |
+
</reference>
|
| 19 |
+
</attributemanager_adminhtml_address_address>
|
| 20 |
+
</layout>
|
app/etc/modules/Hwg_Attributemanager.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Hwg_Attributemanager>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>local</codePool>
|
| 7 |
+
</Hwg_Attributemanager>
|
| 8 |
+
</modules>
|
| 9 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Hwg_Attributemanager</name>
|
| 4 |
+
<version>0.1.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">GPL</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Create custom attribute for customer, category, customer address</summary>
|
| 10 |
+
<description>Using this extension you can create custom attributes for customer, category, customer address.</description>
|
| 11 |
+
<notes>First version</notes>
|
| 12 |
+
<authors><author><name>Sanjay Modasia</name><user>sanjaymodasia</user><email>sanjaymodasia@gmail.com</email></author></authors>
|
| 13 |
+
<date>2012-05-18</date>
|
| 14 |
+
<time>06:22:58</time>
|
| 15 |
+
<contents><target name="magelocal"><dir name="Hwg"><dir name="Attributemanager"><dir name="Block"><dir name="Adminhtml"><dir name="Address"><dir name="Edit"><file name="Form.php" hash="b6cd8384a5380850d810adfebdd9f714"/><dir name="Tab"><file name="Main.php" hash="98fb53f1ac8315077891829ea76c6732"/><file name="Options.php" hash="9b802dbcf80251e45a5f77ece9895033"/></dir><file name="Tabs.php" hash="b010124cc527cc0bda16b062e0ec12d9"/></dir><file name="Edit.php" hash="2940e471a524dd278e2f909b79721c75"/><file name="Grid.php" hash="3d6b4941dcfe3acdf8612ec18797d1a9"/></dir><file name="Address.php" hash="0ee9142d47a055ce80b9abba1edd2a10"/><dir name="Category"><dir name="Edit"><file name="Form.php" hash="117173cba42eb72725c2bac6717eaae4"/><dir name="Tab"><file name="Front.php" hash="1adeab8c8bbf9c45f8d81d5453a9fa63"/><file name="Main.php" hash="7065c6806abba244b42c8533b5328f45"/><file name="Options.php" hash="f54573f629266fb215ca2a2ff79690b1"/><file name="System.php" hash="a0297869e9aa6df54611e61946764606"/></dir><file name="Tabs.php" hash="175dc93f524d62fac852a3c88d5cd3fa"/></dir><file name="Edit.php" hash="fb74624c5cfaf545f5789dce62b5e36e"/><file name="Grid.php" hash="5e5fea8d4ed79f3712708198c53d41dc"/></dir><file name="Category.php" hash="103e8d55704b9237af218c18eec51359"/><dir name="Customer"><dir name="Edit"><file name="Form.php" hash="518c24ba092cb60841db93b6a9b33658"/><dir name="Tab"><file name="Front.php" hash="29754c79c4b9fdf247fc4be78bb762f8"/><file name="Main.php" hash="20fac1539bce94c150d606f36700a474"/><file name="Options.php" hash="cc77c662c69e297eb53f6bc9abb446b9"/><file name="System.php" hash="133a65f79ced3e244347a4c0d6495854"/></dir><file name="Tabs.php" hash="2b4a7cea518b27bc46135dbc3bfce96d"/></dir><file name="Edit.php" hash="8dfc17823c78e8e576dea75ddf98e124"/><file name="Grid.php" hash="d86c4c106a8660b2481a2a9e613a8154"/></dir><file name="Customer.php" hash="fdbe66aa1b6cbbaaa92239bf5cfb92b7"/></dir></dir><dir name="Helper"><file name="Data.php" hash="b3ac459c1fcaa696433aeafede13747e"/></dir><dir name="Model"><file name="Attributemanager.php" hash="e54514153c723943ceb0835bdf18000d"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="AddressController.php" hash="ba611cc4d765379ecfcda2e171b659e6"/><file name="CategoryController.php" hash="5f7e8f5f9513365f9e34728f9789f63a"/><file name="CustomerController.php" hash="b57ebc46709ecd78b255c3957d5b9e6a"/><file name="IndexController.php" hash="272f19208e8da306b445c5e83037e9d8"/></dir></dir><dir name="etc"><file name="config.xml" hash="fc071f2cfae029187dce63f728192b6a"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="attributemanager.xml" hash="616f27b876b35df290befde732c98638"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Hwg_Attributemanager.xml" hash="c88f9e812a4f29ebf61e76602792c539"/></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
+
</package>
|
