Magento2:类别中的自定义图像属性不保存?

时间:2018-01-17 07:34:41

标签: magento2

我已经在类别中创建了自定义图像属性,并且图像已成功上传,但它已保存数据库。任何人都可以在下面的代码中指导我的问题。

路径: - /app/code/Catattribute/Catthumbnail/Setup/InstallData.php

namespace Catattribute\Catthumbnail\Setup;

 use Magento\Eav\Setup\EavSetup;
 use Magento\Eav\Setup\EavSetupFactory;
 use Magento\Framework\Module\Setup\Migration;
 use Magento\Framework\Setup\InstallDataInterface;
 use Magento\Framework\Setup\ModuleContextInterface;
 use Magento\Framework\Setup\ModuleDataSetupInterface;
 use Magento\Catalog\Setup\CategorySetupFactory;

 class InstallData implements InstallDataInterface
  {
private $eavSetupFactory;
public function __construct(CategorySetupFactory $categorySetupFactory)
{
    $this->categorySetupFactory = $categorySetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    $installer = $setup;
    $setup->startSetup();

    $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
    $entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Category::ENTITY);
    $attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
    $categorySetup->removeAttribute(
        \Magento\Catalog\Model\Category::ENTITY, 'image_thumb' );
    $categorySetup->addAttribute(
        \Magento\Catalog\Model\Category::ENTITY, 'image_thumb', [
            'type' => 'varchar',
            'label' => 'Thumbnail Image',
            'input' => 'image',
            'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image',
            'required' => false,
            'sort_order' => 5,
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'group' => 'General Information',
        ]
    );
    $setup->endSetup();
}
}

路径: - /app/code/Catattribute/Catthumbnail/view/adminhtml/ui_component/category_form.xml

<?xml version="1.0" encoding="UTF-8"?>
  <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="content">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true">Content</item>
            <item name="collapsible" xsi:type="boolean">true</item>
            <item name="sortOrder" xsi:type="number">10</item>
        </item>
    </argument>
    <field name="image_thumb">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">string</item>
                <item name="source" xsi:type="string">category</item>
                <item name="label" xsi:type="string" translate="true">Thumbnail Image</item>
                <item name="visible" xsi:type="boolean">true</item>
                <item name="formElement" xsi:type="string">fileUploader</item>
                <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
                <item name="previewTmpl" xsi:type="string">Magento_Catalog/image-preview</item>
                <item name="required" xsi:type="boolean">false</item>
                <item name="sortOrder" xsi:type="number">40</item>
                <item name="uploaderConfig" xsi:type="array">
                    <item name="url" xsi:type="url" path="catthumbnail/category_thumb/upload"/>
                </item>
            </item>
        </argument>
    </field>
</fieldset>
</form>

0 个答案:

没有答案