自定义属性未显示在一步结帐地址列表中

时间:2017-11-15 05:46:50

标签: php magento magento2 magento2.2

显示自定义属性“省”.Value保存在“customer_address”,“quote_address”和“sales_order_address”表中。

设置> Upgrade.php     受保护的函数_addAttributes($ setup)     {

    $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

    $customerSetup->addAttribute('customer_address', 'province', [
        'label' => 'Province',
        'input' => 'text',
        'type' => 'varchar',
        'source' => '',
        'required' => false,
        'position' => 333,
        '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' => '',
        'comment' => 'Province'
    ]);


    $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'province')
        ->addData(['used_in_forms' => [
            'customer_register_address',
            'customer_account_create',
            'adminhtml_customer_address',
            'customer_account_edit',
            'adminhtml_customer',
            'adminhtml_checkout',
            'checkout_register',
        ]]);
    $attribute->save();

    $setup->getConnection()->addColumn(
        $setup->getTable('quote_address'),
        'province',
        [
            'type' => 'text',
            'length' => 255,
            'comment' => 'Province'
        ]
    );

    $setup->getConnection()->addColumn(
        $setup->getTable('sales_order_address'),
        'province',
        [
            'type' => 'text',
            'length' => 255,
            'comment' => 'Province'
        ]
    );

    $setup->endSetup();
}

fieldset.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
    <fieldset id="customer_address">
        <field name="province">
           <aspect name="to_quote_address" />
        </field>
    </fieldset>
    <fieldset id="sales_convert_quote_address">
        <field name="extension_attributes">
            <aspect name="to_customer_address" />
            <aspect name="to_order_address" />
        </field>
    </fieldset>
    <fieldset id="sales_convert_order_address">
        <field name="extension_attributes">
             <aspect name="to_quote_address" />
        </field>
    </fieldset>
</scope>

创建观察者以在集合中添加属性:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

<event name="sales_quote_address_save_after">
  <observer name="iversa_customaddress_observer_address" instance="Iversa\CustomAddress\Observer\Address" />
</event>
<event name="sales_order_address_save_after">
    <observer name="iversa_customaddress_observer_address" instance="Iversa\CustomAddress\Observer\Order\Address" shared="false" />
</event>
<event name="sales_quote_address_collection_load_before">
    <observer name="iversa_customaddress_observer_addresscollectionload" instance="Iversa\CustomAddress\Observer\AddressCollectionLoad" shared="false" />
</event>
<event name="sales_order_address_collection_load_before">
    <observer name="iversa_customaddress_observer_order_addresscollectionload" instance="Iversa\CustomAddress\Observer\Order\AddressCollectionLoad" shared="false" />
</event>
</config>

我已提及https://web4pro.net/blog-news/magento-2-add-custom-attribute-customers-address/http://devdocs.magento.com/guides/v2.1/howdoi/checkout/checkout_new_field.html来显示magento2 onstepcheckout地址中的值。 Also refer screenshot for the same.

0 个答案:

没有答案