首页 > 解决方案 > 将自定义产品属性添加到订单 API

问题描述

我通过添加了一个自定义属性InstallData.php

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
        $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'hts_code',
            [
                'type' => 'text',
                'backend' => '',
                'frontend' => '',
                'label' => 'HTS Code',
                'input' => 'text',
                'class' => '',
                'source' => '',
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
                'visible' => true,
                'required' => false,
                'user_defined' => false,
                'default' => '',
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => true,
                'unique' => false,
                'apply_to' => ''
            ]
        );
    }

它显示在每个产品的后端,可以设置,没有问题。当我通过 REST API 查询产品时,它也可见。到目前为止很棒。

现在,我需要将此属性添加到 Order API 端点,因此当查询 Order 时,属性名称和值是可见的。

我按照这里的示例https://magento.stackexchange.com/a/316609/38767但它不起作用。

对于 Magento 2.3,如何将此自定义属性添加到 Order API?

标签: apimagentomagento2

解决方案


推荐阅读