更改签出步骤时,属性在类Magento \ Quote \ Api \ Data \ AddressInterface中没有相应的setter


18

1-我将eav属性添加到customer_address

$attributesInfo = [
    'reference' => [
         'label' => 'Reference',
         'type' => 'varchar',
         'input' => 'text',
         'position' => 100,
         'visible' => true,
         'required' => false,
    ],
];

foreach ($attributesInfo as $attributeCode => $attributeParams) {
    $customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams);
}

2-我在模块中添加了extension属性

<extension_attributes for="Magento\Quote\Api\Data\AddressInterface">
    <attribute code="reference" type="string"/>
</extension_attributes>

在我的requirejs-config.js中,我覆盖了一些JavaScript文件以添加参考字段

var config = {
"map": {
    "*": {
        "Magento_Checkout/js/model/shipping-save-processor/default" : "Agr_Checkout/js/shipping-save-processor-default-override",
        "Magento_Customer/js/model/customer/address" : "Agr_Checkout/js/model/customer/address",
        "Magento_Checkout/js/model/address-converter" : "Agr_Checkout/js/model/address-converter",
        "Magento_Checkout/js/model/new-customer-address" : "Agr_Checkout/js/model/new-customer-address"
    }
}

3-我确认参考字段正在发送地址

在此处输入图片说明

4-当我发送运输信息时(单击“下一步”),我收到此错误:“属性“参考”在类“ Magento \ Quote \ Api \ Data \ AddressInterface”中没有相应的设置器。”

在此处输入图片说明

我已经做过:-清理并冲洗magento缓存-运行setup:upgrade-运行setup:di:compile

我做错了什么?


以下答案有效吗?
Stevie G

我通过硬sql插入解决了问题,执行了一个用于使用address_id进行更新de reference的脚本,我知道这是错误的,但是我有些着急,我将进行测试,稍后再提供反馈。
allamgr

我不认为您应该受到指责...显然,您只能在Enterprise中添加custom_attributes,到目前为止,我还没有找到解决此问题的“可轻松自定义的结帐”方法。
LM_Fielding

关于任何更新?
Magento2 Devloper

@allamgr我的新客户地址属性也面临着同样的问题,您对此是否有解决方案?你能和我分享你对此的想法吗?prnt.sc/iovkp2
Nagarajuķ

Answers:


1

在eav设置或升级脚本中设置属性的效果最佳,并且会自动添加到您要求添加到的表单中。

    class InstallData implements InstallDataInterface
    {
        private $_eavSetupFactory;
        private $_eavConfig;
        private $_attributeResource;
        protected $_logger;

        public function __construct(EavSetupFactory $eavSetupFactory, Config $eavConfig, Attribute $attributeResource, Monolog $logger)
        {
            $this->_eavSetupFactory = $eavSetupFactory;
            $this->_eavConfig = $eavConfig;
            $this->_attributeResource = $attributeResource;
            $this->_logger = $logger;
        }

        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
            $eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]);
            $addressAttributes = [
        'attribute1' => [
            'type' => 'int',
            'label' => 'attribute1',
            'input' => 'text',
            'unique' => true,
            'required' => false,
            'visible' => true,
            'user_defined' => false,
            'position' => 100,
            'system' => false,
            'adminhtml_only' => 0
        ],
        'attribute2' => [
            'type' => 'int',
            'label' => 'attribute2',
            'input' => 'text',
            'required' => false,
            'visible' => true,
            'user_defined' => false,
            'position' => 110,
            'system' => false,
            'adminhtml_only' => 1
        ]
    ];

    $usedInFormsAddress = [
            'adminhtml_customer_address',
            'customer_address_edit',
            'customer_register_address'
        ];

    foreach ($addressAttributes as $code => $options) {
        $eavSetup->addAttribute(
            'customer_address',
            $code,
            $options
        );

        try {
            $attribute = $this->_eavConfig->getAttribute('customer_address', $code);
            $attribute->setData(
                'used_in_forms',
                $usedInFormsAddress
            );
            $this->_attributeResource->save($attribute);
        } catch (LocalizedException $exception) {
            $this->_logger->critical($exception->getMessage());
        } catch (Exception $exception) {
            $this->_logger->critical($exception->getMessage());
        }
    }

在此处输入图片说明

此代码将添加到表格中,不会有任何问题保存或进入下一步

$usedInFormsAddress = [
            'adminhtml_customer_address',
            'customer_address_edit',
            'customer_register_address'
        ];

try {
            $attribute = $this->_eavConfig->getAttribute('customer_address', $code);
            $attribute->setData(
                'used_in_forms',
                $usedInFormsAddress
            );
            $this->_attributeResource->save($attribute);
        } catch (LocalizedException $exception) {
            $this->_logger->critical($exception->getMessage());
        } catch (Exception $exception) {
            $this->_logger->critical($exception->getMessage());
        }

0

尝试通过自定义属性进行设置。

例:

...
 custom_attribute: [{"attribute_code": "reference", "value": "Your value"}]
...

您是否曾经尝试过这项工作,还是只是一个实验?
LM_Fielding

我成功了
Phoenix128_RiccardoT

有社区版吗?我将不胜感激,即使您能展示如何做到这一点,也可以得到赏金。
LM_Fielding

1
它与Magento2 Enterprise Edition一起使用,是一个自定义的独立前端结帐程序。我必须搜索该代码。这是一项古老的工作。
Phoenix128_RiccardoT

如果找到它,请告诉我,但我认为它不可用。
LM_Fielding

0

如何在请求中传递属性?您可以像这样检查浏览器控制台

{
    ...
    extension_attributes: {
         reference: "value"
    }
}

这是正确的。您可以删除var文件夹和生成的文件夹 var / cache var / page_cache var / view_proceed和generate /

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.