magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.5k stars 9.3k forks source link

Custom attribute(Customer Address type) not saved when Create New Order from admin #10805

Closed ronakChauhanKrish closed 3 years ago

ronakChauhanKrish commented 7 years ago

Preconditions

  1. Magento 2.1.7
  2. Identified on PHP 7.0.9-1

Steps to reproduce

  1. Create Customer address attribute using installdata script as below: `$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

    $customerSetup->addAttribute('customer_address', 'suburb', [
        'label' => 'Suburb',
        'input' => 'text',
        'type' => 'varchar',
        'source' => '',
        'required' => true,
        'position' => 70,
        'visible' => true,
        'system' => false,
        'is_used_in_grid' => false,
        'is_visible_in_grid' => false,
        'is_filterable_in_grid' => false,
        'is_searchable_in_grid' => false,
        'backend' => ''
    ]);
    
    $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'suburb')
        ->addData(['used_in_forms' => [
            'adminhtml_customer_address',
            'customer_address_edit',
            'customer_register_address'
        ]]);
    $attribute->save();`
  2. Open Admin >> Sales >> Order >> Create New Order
  3. Select Store >> Address Information >> Fill address with our Custom attribute(Suburb)
  4. Select Payment Method and Shipping Method
  5. Submit Order

Expected result

  1. Suburb should be saved same as other customer address attributes
  2. As we have already filled value in Custom attribute field(Suburb) It should not generate any required field value PHP error.
  3. Even if We have already save value in Customer >> Address then It must be visible on Create new Order >> Billing Address/ Shipping Address form

Actual result

  1. new order orders operations sales magento admin

  2. new order orders operations sales magento admin 1

  3. Value not saved while other attributes saved and retrieved as well.

marcinfr commented 7 years ago

im on it

marcinfr commented 7 years ago

It is not saved, because order address values are stored in "quote_address" and "sales_order_address" tables. By creating new customer address attribute, columns are not automatically created in the above tables. There are more steps to add new address attribute in correct way:

  1. create customer address attribute
  2. create new columns in quote_address and sales_order_address:
    $salesSetup = $this->salesSetupFactory->create(['setup' => $setup]);
    $salesSetup->addAttribute('order_address', 'suburb', ['type' => 'text']);
    $quoteSetup = $this->quoteSetupFactory->create(['setup' => $setup]);
    $quoteSetup->addAttribute('quote_address', 'suburb', ['type' => 'text']);
  3. add fieldset in xml file to copy new field value from quote address to order address
    <fieldset id="sales_convert_quote_address">
     <field name="suburb">
          <aspect name="to_order_address" />
     </field>
    </fieldset>
  4. create new setter method in order address class:
    public function setSuburb($suburb)
    {
     return $this->setData('suburb', $suburb);
    }
magento-engcom-team commented 7 years ago

@ronakChauhanKrish thank you for your bug report. We've created internal ticket MAGETWO-75304 to track progress on the issue

mallafreDG commented 6 years ago

I am working on it at #mm17es

mallafreDG commented 6 years ago

Reproduced the same error in Magento 2.2.1 with PHP 7.0.25

magento-engcom-team commented 5 years ago

Hi @engcom-backlog-nazar. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

magento-engcom-team commented 5 years ago

@engcom-backlog-nazar Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-97682, MAGETWO-97683 were created

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

yohanespradono commented 7 months ago

is this fixed on 2.4.6? apparently i am still getting this issue. my custom address attributes are set to order address object field "custom_attributes" instead of extension_attributes. And then \Magento\Quote\Model\Quote\Address\ToOrderAddress::convert() doesn't convert custom_attributes. I understand that order_address is not eav entity and custom_attributes are related to eav. That's why ToOrderAddress ignores it completely and only pickup extension_attributes.