Skip to content

Instantly share code, notes, and snippets.

@moleman
Created February 2, 2012 11:27
Show Gist options
  • Save moleman/1723022 to your computer and use it in GitHub Desktop.
Save moleman/1723022 to your computer and use it in GitHub Desktop.
Magento - snippets
$attributeSetName = 'Editorial Product';
// active_from
$entityTypeId = Mage::getModel('eav/entity')
->setType('catalog_product')
->getTypeId();
$setId = $installer->getAttributeSet($entityTypeId, $attributeSetName, 'attribute_set_id');
// Add attribute set if it does not exists
if($setId === null) {
$installer->addAttributeSet($entityTypeId, $attributeSetName);
$setId = $installer->getAttributeSet($entityTypeId, $attributeSetName, 'attribute_set_id');
}
$groupId = $this->_generalGroupName;
$attributeId = $this->getAttribute($entityTypeId, 'active_from', 'attribute_id');;
if($entityTypeId !== null && $setId !== null && $attributeId !== null) {
$installer->addAttributeToSet($entityTypeId, $setId, $groupId, $attributeId);
}
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
// update General Group
$installer->updateAttributeGroup($entityTypeId, $attributeSetId, $attributeGroupId, 'attribute_group_name', 'General Information');
$installer->updateAttributeGroup($entityTypeId, $attributeSetId, $attributeGroupId, 'sort_order', '10');
$groups = array(
'display' => array(
'name' => 'Display Settings',
'sort' => 20,
'id' => null
),
'design' => array(
'name' => 'Custom Design',
'sort' => 30,
'id' => null
)
);
foreach ($groups as $k => $groupProp) {
$installer->addAttributeGroup($entityTypeId, $attributeSetId, $groupProp['name'], $groupProp['sort']);
$groups[$k]['id'] = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, $groupProp['name']);
}
config.xml
<frontend>
<events>
<controller_action_layout_generate_xml_before>
<observers>
<rimpachidecategories>
<type>singleton</type>
<class>rimpachidecategories/observer</class>
<method>onControllerActionLayoutGenerateXmlBefore</method>
</rimpachidecategories>
</observers>
</controller_action_layout_generate_xml_before>
</events>
</frontend>
method:
/**
* Method that will be called when the controller_action_layout_generate_xml_before event is fired.
* Adds layout update that removes catalog.topnav depending on if the hide categories attribute is
* toggle on the logged in customer object.
*
* @see Mage_Core_Controller_Varien_Action::generateLayoutXml()
* @param Varien_Event_Observer $observer
*/
public function onControllerActionLayoutGenerateXmlBefore($observer)
{
/* @var $action Mage_Core_Controller_Varien_Action */
$action = $observer->getEvent()->getAction();
/* @var $layout Mage_Core_Model_Layout */
$layout = $observer->getEvent()->getLayout();
/* @var $session Mage_Customer_Model_Session */
$session = Mage::getSingleton('customer/session');
if (!is_null($session) && $session->isLoggedIn() === true &&
$session->getCustomer()->getData('ic_hide_toggle'))
{
$layout->getUpdate()->
addUpdate('<reference name="top.menu"><remove name="catalog.topnav" /></reference>');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment