You are viewing an old revision of this post, from July 1, 2020 @ 20:02:05. See below for differences between this version and the current revision.

Magento – Delete Empty Null Attribute Options

By default, if you enter attribute options in the back end, you can't add an empty option to the attribute. Maybe these empty options were added via a custom script. Here is the custom script that helps you to remove the empty options of the attributes

1.Create store_root/shell/empty.php file with code snippet:

<?php
require_once 'abstract.php';
class Empty_Attribute_Remover extends Mage_Shell_Abstract
{
    public function run()
    {
        $attribute                  = Mage::getModel('catalog/resource_eav_attribute')
          ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'some_attribute_code');

        $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
            ->setAttributeFilter($attribute->getAttributeId())
            ->setPositionOrder('desc', true)
            ->load();
        foreach($optionCollection as $option){
            //remove if options value is empty
            if ($option->getValue()=='') {
                $option->delete();
            }
        }
    }
}

$shell = new Empty_Attribute_Remover();
$shell->run();

2.Run this PHP script to remove empty options of the attribute with some_attribute_code:

php -f shell/empty.php

Revisions

  • July 1, 2020 @ 20:02:07 [Current Revision] by Sharing Solution
  • July 1, 2020 @ 20:02:05 by Sharing Solution

Revision Differences

There are no differences between the July 1, 2020 @ 20:02:05 revision and the current revision. (Maybe only post meta information was changed.)

No comments yet.

Leave a Reply