Ciao a tutti sto cercando di creare un custom module in magento 1.9 per l'inserimento del codice fiscale per quanto riguarda il cliente sia nel form del pannello di amministrazione che per i form del frontend, ho provato ma non funziona, ovvero il module risulta attivo tra quelli presenti, ma non aggiunge l'attributo desiderato: i codici sono i seguenti
local/Groundon/Customer/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Groundon_Customer>
<version>0.1.0</version>
</Groundon_Customer>
</modules>
<global>
<helpers>
<groundon_customer>
<class>Groundon_Customer_Helper</class>
</groundon_customer>
</helpers>
<resources>
<groundon_customer_setup>
<setup>
<module>Groundon_Customer</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
</groundon_customer_setup>
</resources>
</global>
</config>
local/Groundon/Customer/Helper/Data.php
<?php
class Groundon_Customer_Helper_Data extends Mage_Core_Helper_Abstract
{
}
local/Groundon/Customer/sql/groundon_customer_setup/install-0.1.0.php
<?php
$installer=$this;
$installer->startSetup();
$setup=new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute("customer","codice_fiscale",array(
"type" => "varchar",
"label" => "Codice Fiscale",
"input" => "text",
"visible" => true,
"required" => false,
"global" =>true,
"is_system" =>0,
"position" =>105,
));
$attributo=Mage::getSingleton('eav/config')->getAttribute('customer', 'codice_fiscale');
$attributo->setData('used_in_forms', array(
'adminhtml_customer',
'checkout_register',
'customer_account_create',
'customer_account_edit',
));
$attributo->save();
$installer->endSetup();
etc/modules/Groundon_Customer.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Groundon_Customer>
<active>true</active>
<codePool>local</codePool>
<depends><Mage_Customer/></depends>
</Groundon_Customer>
</modules>
</config>
Non riesco a trovare la soluzione del problema, per favore qualcuno riesce a darmi una mano.
Grazie in anticipo
Solved! Go to Solution.
Hi @gtwolf
Kindly refer below example for create customer attribute:
Create custom module add install script at below path:
app/code/local/Your/Customattribute/sql/your_customattribute_setup/install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute("customer", "customattribute", array(
"type" => "varchar",
"backend" => "",
"label" => "Custom Attribute",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => "Custom Attribute"
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "customattribute");
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'customattribute',
'999' //sort_order
);
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
//$used_in_forms[]="checkout_register";
//$used_in_forms[]="customer_account_create";
//$used_in_forms[]="customer_account_edit";
//$used_in_forms[]="adminhtml_checkout";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
;
$attribute->save();
$installer->endSetup();
Create config.xml
/app/code/local/Your/Customattribute/etc/config.xml
and add below code:
<?xml version="1.0"?>
<config>
<modules>
<Your_Customattribute>
<version>0.1.0</version>
</Your_Customattribute>
</modules>
<global>
<resources>
<Your_Customattribute_setup>
<setup>
<module>Your_Customattribute</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</Your_Customattribute_setup>
<Your_Customattribute_write>
<connection>
<use>core_write</use>
</connection>
</Your_Customattribute_write>
<Your_Customattribute_read>
<connection>
<use>core_read</use>
</connection>
</Your_Customattribute_read>
</resources>
</global>
</config>Create Your_Customattribute.xml and add below code:
<?xml version="1.0"?> <config> <modules> <Your_Customattribute> <active>true</active> <codePool>local</codePool> <version>0.1.0</version> </Your_Customattribute> </modules> </config>
Then to retrieve custom attribute use below code:
$customer = Mage::getModel('customer/customer')->load($custid);$customer->getCustomattribute();$customer->setCustomattribute($yourjson);
It may help you!
Problem Solved? Please click on 'Kudos' & Accept as Solution!
Hi @gtwolf
Kindly refer below example for create customer attribute:
Create custom module add install script at below path:
app/code/local/Your/Customattribute/sql/your_customattribute_setup/install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute("customer", "customattribute", array(
"type" => "varchar",
"backend" => "",
"label" => "Custom Attribute",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => "Custom Attribute"
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "customattribute");
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'customattribute',
'999' //sort_order
);
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
//$used_in_forms[]="checkout_register";
//$used_in_forms[]="customer_account_create";
//$used_in_forms[]="customer_account_edit";
//$used_in_forms[]="adminhtml_checkout";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
;
$attribute->save();
$installer->endSetup();
Create config.xml
/app/code/local/Your/Customattribute/etc/config.xml
and add below code:
<?xml version="1.0"?>
<config>
<modules>
<Your_Customattribute>
<version>0.1.0</version>
</Your_Customattribute>
</modules>
<global>
<resources>
<Your_Customattribute_setup>
<setup>
<module>Your_Customattribute</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</Your_Customattribute_setup>
<Your_Customattribute_write>
<connection>
<use>core_write</use>
</connection>
</Your_Customattribute_write>
<Your_Customattribute_read>
<connection>
<use>core_read</use>
</connection>
</Your_Customattribute_read>
</resources>
</global>
</config>Create Your_Customattribute.xml and add below code:
<?xml version="1.0"?> <config> <modules> <Your_Customattribute> <active>true</active> <codePool>local</codePool> <version>0.1.0</version> </Your_Customattribute> </modules> </config>
Then to retrieve custom attribute use below code:
$customer = Mage::getModel('customer/customer')->load($custid);$customer->getCustomattribute();$customer->setCustomattribute($yourjson);
It may help you!
Problem Solved? Please click on 'Kudos' & Accept as Solution!
Volevo chiederti un ultima cosa, è normale che dopo averlo aggiunto il modulo va disattivato dopo che l'attributo è stato aggiunto altrimenti mi da un errore sul database?