1

I've create a custom module that create two custom attributes for the order.

etc.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Companyname_modulename>
      <version>1.0.1</version>
    </Companyname_modulename>
  </modules>

  <global>
    <helpers>
      <modulename>
        <class>Companyname_modulename_Helper</class>
      </modulename>
    </helpers>
    <models>
      <modulename>
          <class>Companyname_modulename_Model</class>
          <resourceModel>modulename_mysql4</resourceModel>
      </modulename>
    </models>
    <fieldsets>
        <sales_convert_quote>                           
           <custom_field_one><to_order>*</to_order></custom_field_one>
        </sales_convert_quote>

        <sales_convert_order>                                              
            <custom_field_one><to_quote>*</to_quote></custom_field_one>
        </sales_convert_order>
    </fieldsets>
    <resources>
      <modulename_setup>
        <setup>
          <module>Companyname_modulename</module>
          <class>Mage_Sales_Model_Mysql4_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </modulename_setup>
      <modulename_write>
        <connection>
          <use>core_write</use>
        </connection>
      </modulename_write>
      <modulename_read>
        <connection>
          <use>core_read</use>
        </connection>
      </modulename_read>
    </resources>
  </global>
</config>

SQL Script

<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('order', 'custom_field_one', array(
    'type'            => 'varchar',
    'backend_type'    => 'varchar',
    'frontend_input'  => 'varchar',
    'is_user_defined' => true,
    'label'           => 'Custom Field One',
    'visible'         => true,
    'required'        => false,
    'user_defined'    => false,
    'searchable'      => false,
    'filterable'      => false,
    'comparable'      => false,
    'default'         => ''
));

$installer->addAttribute('quote', 'custom_filed_one', array(
    'type'            => 'varchar',
    'backend_type'    => 'varchar',
    'frontend_input'  => 'varchar',
    'is_user_defined' => true,
    'label'           => 'Custom Field One',
    'visible'         => true,
    'required'        => false,
    'user_defined'    => false,
    'searchable'      => false,
    'filterable'      => false,
    'comparable'      => false,
    'default'         => ''
));

$installer->addAttribute('order', 'custom_field_two', array(
    'type'            => 'varchar',
    'backend_type'    => 'varchar',
    'frontend_input'  => 'varchar',
    'is_user_defined' => true,
    'label'           => 'Custom Field Two',
    'visible'         => true,
    'required'        => false,
    'user_defined'    => false,
    'searchable'      => false,
    'filterable'      => false,
    'comparable'      => false,
    'default'         => ''
));

$installer->addAttribute('quote', 'custom_field_two', array(
    'type'            => 'varchar',
    'backend_type'    => 'varchar',
    'frontend_input'  => 'varchar',
    'is_user_defined' => true,
    'label'           => 'Custom Field Two',
    'visible'         => true,
    'required'        => false,
    'user_defined'    => false,
    'searchable'      => false,
    'filterable'      => false,
    'comparable'      => false,
    'default'         => ''
));

$installer->endSetup();

Then when save a value into this two custom attributes the value not saving ex:

Load the quote by customer ID:

$quote = Mage::getModel('sales/quote') ->loadByCustomer($customerId);

Save value in custom attributes:

$quote->setCustomFieldOne("ValueOne");
$quote->setCustomFieldtwo("ValueTwo");

The custom_field_one attribute is saved But the custom_filed_two attribute not saving any suggestions please?

0

It's may be because you have spelt the field name incorrectly:

custom_filed_one

setCustomFieldOne()

 $installer->addAttribute('quote', 'custom_filed_one', array(....


 $quote->setCustomFieldOne("ValueOne");

ok so you said typo in comment, the next thing I would look at is your xml file.

If you're following this example:

https://chillydraji.wordpress.com/2014/03/03/how-to-create-new-attribute-to-order-in-magento/

then you haven't updated the fieldset in the xml to customfield instead of deliverydate.

  • it's spelt like above in my question – mahmoudismail Dec 12 '17 at 9:49
  • yes that is what I mean. you two different spellings: filed and field. – BAF Dec 12 '17 at 9:50
  • Ah sorry this is a typo. All is Correct but it's not working. – mahmoudismail Dec 12 '17 at 9:53
  • ok, I have updated answer - I think it's the xml file issue, didn't notice before you haven't defined your custom fields - you are using the fields from the example. – BAF Dec 12 '17 at 9:59
  • That's right, my problem is in xml file, the second custom attribute not defined. – mahmoudismail Dec 12 '17 at 10:24

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.