Domanda

Vorrei aggiungere un attributo personalizzato al modello Sales_Quote_Address in Magento.Ho cercato su Google per alcune ore ora, e non riesco a trovare un modo di farlo.È possibile?Oppure devo impostare l'attributo sul Sales_Order stesso e afferrarlo da lì in seguito?

Grazie

È stato utile?

Soluzione

Allora, ecco cosa ho finito per fare:

$installer = $this;
$installer->startSetup();
/* @var $addressHelper Mage_Customer_Helper_Address */
$addressHelper = Mage::helper('customer/address');
$store         = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);

/* @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
// update customer address user defined attributes data
$attributes = array(
    'attribute_name'           => array(
        'label'    => 'Attribute label',
        'backend_type'     => 'int',
        'frontend_input'    => 'select',
        'is_user_defined'   => 0,
        'is_system'         => 0,
        'is_visible'        => 0,
        'sort_order'        => 140,
        'is_required'       => 0,
        'multiline_count'   => 0
    ),
);

foreach ($attributes as $attributeCode => $data) {
    $attribute = $eavConfig->getAttribute('customer_address', $attributeCode);
    $attribute->setWebsite($store->getWebsite());
    $attribute->addData($data);
    $usedInForms = array(
        'adminhtml_customer_address',
        'customer_address_edit',
        'customer_register_address'
    );
    $attribute->setData('used_in_forms', $usedInForms);
    $attribute->save();
}

    $installer->run("
            ALTER TABLE {$this->getTable('sales_flat_quote_address')} ADD COLUMN `column_name` TINYINT(4) DEFAULT NULL;
            ALTER TABLE {$this->getTable('sales_flat_order_address')} ADD COLUMN `column_name` TINYINT(4) DEFAULT NULL;
            ");
    $installer->endSetup();
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top