9

I have created custom product multiselect attribute successfully.

But when i edit the product in admin and selecting some options(countries) of my multiselect attribute and if i click save its saved successfully.

but when i open same product again its not showing before selected options.that means its not saving my custom product attribute to product model.

can you Please help anyone.I'm very tired.and i tried lot of hours.then i'm placing here.

etc/config.xml file

<config>
    <modules>
        <Exinent_Shiplimit>
            <version>0.1.0</version>
        </Exinent_Shiplimit>
    </modules>

    <global>
    <models>
       <checkout>
         <rewrite>
           <type_onepage>Exinent_Shiplimit_Model_Checkout_Type_Onepage</type_onepage>
         </rewrite>
        </checkout>
      </models>
    <resources>
            <exinent_shiplimit_setup>
                <setup>
                    <module>Exinent_Shiplimit</module>
                    <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
                </setup>
            </exinent_shiplimit_setup>
        </resources>
    </global>
    </config>

app\code\local\Exinent\Shiplimit\sql\exinent_shiplimit_setup\mysql4-install-0.1.0.php

<?php 
$installer = $this;
/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */

$installer->startSetup();
$installer->addAttribute(
    'catalog_product',
    'custom_countries', 
    array(
        'group'             => 'General',
        'type'              => 'varchar',
        'backend'           => '',
        'user_defined' => '1',
        'frontend'          => '',
        'label'             => 'Shipping Restricted Countries',
        'input'             => 'multiselect',
        'source'            => 'Mage_Catalog_Model_Product_Attribute_Source_Countryofmanufacture',
        'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE

    )
);

$installer->updateAttribute('catalog_product', 'custom_countries', 'backend_model', '');
$installer->endSetup();
?>

1 Answer 1

16

You're setting the backend_model to '' it should be 'eav/entity_attribute_backend_array'

And you'll want to define the type as text not varchar, since varchar will have lower limit than what is required of the source model.

Take a look around the eav_attribute table for reference.

Hope this helps.

6
  • I think it is just 'backend' instead of 'backend_model'
    – Aphroz
    Commented Mar 14, 2015 at 8:28
  • 4
    If you are using addAttribute in setup scripts, it's "backend". In all other cases (updateAttribute or directly in the database), it's "backend_model". Commented Jun 17, 2016 at 12:26
  • 1
    perfect answer with nice explanation!!! +1 :) Commented Mar 6, 2018 at 11:39
  • How to set value programatically? Commented Feb 1, 2019 at 4:34
  • @jafarpinjar which value are you trying to set specifically?
    – B00MER
    Commented Feb 6, 2019 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.