Feb 21, 2012 -
You’re developing a Magento importer and you want to clean your DB after some tests? Here you have:
require_once dirname(__FILE__) . '/app/Mage.php';
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$resource = Mage::getSingleton('core/resource');
$db_read = $resource->getConnection('core_read');
$attribute_sets = $db_read->fetchCol("SELECT attribute_set_id FROM " . $resource->getTableName("eav_attribute_set") . " WHERE attribute_set_id<> 4 AND entity_type_id=4");
foreach ($attribute_sets as $attribute_set_id) {
try {
Mage::getModel("eav/entity_attribute_set")->load($attribute_set_id)->delete();
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
}
Note that only products’ attribute sets are deleted, those are often generated automatically during imports.
Filed in: PHP
Tags: Magento, PHP
Feb 21, 2012 -
You’re developing a Magento importer and you want to clean your DB after some tests? Here you have:
require_once dirname(__FILE__) . '/app/Mage.php';
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$resource = Mage::getSingleton('core/resource');
$db_read = $resource->getConnection('core_read');
$categories = $db_read->fetchCol("SELECT entity_id FROM " . $resource->getTableName("catalog_category_entity") . " WHERE entity_id>1 ORDER BY entity_id DESC");
foreach ($categories as $category_id) {
try {
Mage::getModel("catalog/category")->load($category_id)->delete();
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
}
Filed in: PHP
Tags: Magento, PHP
Feb 8, 2012 -
I’ve run into a few posts about this thing but none of them was working out of the box so I took all the info and glued them together so…
if you’ve to create a custom attribute for a Magento category but you don’t have a module (and its installer script) simply create a php file in the project’s root with this code:
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute = array(
'type' => 'int',
'label'=> 'Your attribute label',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => "",
'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'your_attribute_code', $attribute);
$installer->endSetup();
This attribute is a “text”, more info may come in comments if you need.
Filed in: PHP
Tags: Magento, PHP