2 Comments

Magento attribute change backend_type from varchar to text

Javascript - Read script js only if radio is checked
Simple product not display in categories [closed]

My product attribute exceeded the 255 character limit of varchar, so I came across the solution to change its backend_type to text.

Should this operation be considered safe (in the terms that it will not break anything, or leave garbage in the database)?

Related Posts

  • Search not working correctly (0)
    My search option not working property. I notice that if my SKU has dot and don't start with character then operation not give back items. For example: SKU: "123123" work fine SKU: "123.123" can't find product SKU: "a123.123" work fine SKU: "123.123a" can't find I […]
  • How to limit characters in system.xml for textarea in magento (3)
    I want to restrict textarea characters length to 150 characters, My system.xml code is below : ... <orderPlaceMessage translate="label"> <label>Message for order place: </label> <frontend_type>textarea</frontend_type> […]
  • getAttributeText in a safe way / test if attribute exist in product first (4)
    If I call getAttributeText on a non existing attribute, eg: $product->getAttributeText('some-non-existing-field'); I get the fatal error: Fatal error: Call to a member function getSource() on a non-object Which I can't even try-catch because its fatal. Different magento […]
  • getAttributeText in a safe way / test if attribute exist in product first (4)
    If I call getAttributeText on a non existing attribute, eg: $product->getAttributeText('some-non-existing-field'); I get the fatal error: Fatal error: Call to a member function getSource() on a non-object Which I can't even try-catch because its fatal. Different magento […]
  • Data-Migration-Tool doesn't migrate utf-8 characters (Magento 2) (1)
    I use the second step of migration with data-migration-tool 2.0.2 in plain Magento 2.0.4. php bin/magento migrate:data {config.xml} Its successfully completed. But it doesn't migrate utf-8 characters from older Magento1-database to my Magento2-database. Both databases have the […]
  • adding a image/logo to attribute (0)
    I am trying to use this extension as it adds a image to a attribute which i can display on the product page versus just attribute text Extension Link https://github.com/aligent/magento-attribute-option-image however when i try to add a image via admin i get this error I am […]
  • Alt tag is not working properly if you enter a special character (0)
    When I create a new product in the backend, I upload images for it. Every image can have the alt tag set up. If I want to add the text "this product doesn't have a hood" (without quotes), I don't see the whole text in the frontend. I guess because of the character ' (apostrophe). I […]
  • Alt tag is not working properly if you enter a special character (0)
    When I create a new product in the backend, I upload images for it. Every image can have the alt tag set up. If I want to add the text "this product doesn't have a hood" (without quotes), I don't see the whole text in the frontend. I guess because of the character ' (apostrophe). I […]
  • adding a image/logo to attribute (0)
    I am trying to use this extension as it adds a image to a attribute which i can display on the product page versus just attribute text Extension Link https://github.com/aligent/magento-attribute-option-image however when i try to add a image via admin i get this error I am […]
  • How disable attribute in second site (1)
    I have configured 2 sites. Have attribute named 'label'. How to remove it on second site and leave it on default (first) site?
Javascript - Read script js only if radio is checked
Simple product not display in categories [closed]

2 Comments on this article

  • User November 12, 2016

    If you change the backend_type Magento will also change the EAV table.

    It will use catalog_product_entity_text instead of catalog_product_entity_varchar.

    You will have to move all the records for that attribute to the new table.
    If you do not do this operation you may create orphans records and db inconsistencies.

    You may try with an insert from select. Best if you write down a small PHP script.

    WARNING: Make a full DB backup before you try this.

    Reply

  • User November 12, 2016

    I created shell script using method proposed by RicardoT, if anyone would need it:

    <?php
    include 'abstract.php';
    
    class Mage_Shell_Extend_Attributes extends Mage_Shell_Abstract
    {
        protected $_entityTypeId = 4; // Product
    
        public function __construct() {
            parent::__construct();
            Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
        }
    
        public function run() {
            $this->_alterAttribute('ATTRIBUTE_CODE');
        }
    
        protected function _alterAttribute($code) {
            $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($code, 'attribute_code');
            $attribute->setData('backend_type', 'text')
                ->save();
    
            $write = Mage::getSingleton('core/resource')->getConnection('core_write');
            $query = '
                    INSERT INTO catalog_product_entity_text
                        (entity_type_id, attribute_id, entity_id, store_id, value)
                    SELECT
                        entity_type_id, attribute_id, entity_id, store_id, value from catalog_product_entity_varchar
                    WHERE
                        attribute_id='.$attribute->getId().' AND entity_type_id='.$this->_entityTypeId.';
    
                    DELETE FROM catalog_product_entity_varchar WHERE attribute_id='.$attribute->getId().' AND entity_type_id = '.$this->_entityTypeId.'
                ';
            $result = $write->query($query);
            echo "Processed attribute '".$code."' n";
        }
    }
    
    $app = new Mage_Shell_Extend_Attributes();
    $app->run();
    

    Reply

Add a comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax