8

I am thinking to update is_required data to "1" for existing "Region" attribute code.

select * From eav_attribute where attribute_id = '28'

However, I am wondering what is the practice here. Is it simply creating SQL statement and update that specific record in setup script fine? Or perhaps there may be a better way.

  • Which region attribute? for order or address? – Bijal Bhavsar Jan 24 '14 at 10:43
  • for order and address =) – Leongelis Jan 27 '14 at 3:24
  • ok I have already added code in below answer :) – Bijal Bhavsar Jan 28 '14 at 5:53
11

Create sql script to update region attribute

$installer->startSetup();
/*** Update customer address attributes*/
$installer->updateAttribute('customer_address', 'region', 'is_required', true); 

/*** Update order address attributes*/
$installer->updateAttribute('order_address', 'region', 'is_required', true);  
$installer->endSetup();

I hope above code will help

  • Can you please explain it in deep with example. – Ami Kamboj Jun 20 '14 at 10:13
4

I am writing this updates is simply sharing my research and hope could help someone out there.

config.xml

<config>
    <modules>
        <Package_Module>
            <version>0.0.2</version>
        </Package_Module>
    </modules>
    <global>
        <resources>
            <module_setup>
                <setup>
                    <module>Package_Module</module>
                    <!-- 
                     Create a Switchable Installer Script 
                     This class is incredibly handy in case you need different setup classes 
                     -->
                    <class>Package_Module_Model_Resource_Setup</class> 
                </setup>
            </module_setup>
        </resources>
    </global>
<config>

Custom Setup Class: Package_Module_Model_Resource_Setup

class Package_Module_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
{
    public function getCatalogResourceSetup()
    {
        return new Mage_Catalog_Model_Resource_Setup('module_setup');
    }
    public function getCustomerResourceSetup()
    {
        return new Mage_Customer_Model_Resource_Setup('module_setup');
    }
    public function getCustomerEntitySetup() 
    {
        return new Mage_Customer_Model_Entity_Setup('module_setup');
    }
}

Upgrade Script: mysql4-upgrade-0.0.1-0.0.2.php

<?php
/* @var $installer Package_Module_Model_Resource_Setup */
$installer = $this->getCustomerEntitySetup();

$installer->startSetup();
/*** Update customer address attributes*/
$installer->updateAttribute('customer_address', 'region', 'is_required', 1);

$installer->endSetup();

Hereby a great article that shared about 'Switchable Installer Script'. Source link: inchoo.net

0

Create sql update script and run updateAttribute function.

$installer = $this;
$installer->startSetup();
$installer->updateAttribute('entity_type', 'your_attribute_id', 'required', 1);
$installer->endSetup();

With this function you can update any attribute's property.

0

I was trying some scripts found, but the attribute still was required. The correct parameter is 'is_required' and not 'required'. $installer->updateAttribute('entity_type', 'your_attribute_id', 'is_required', 1);

0

Below code will update attribute using sql script

$installer = $this;
$this->updateAttribute('customer_address', 'region', 'is_required' ,1); 
0

you can find definition of updateAttribute() function in file app\code\core\Mage\Eav\Model\Entity\setup.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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