Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed missing 'size' and 'type' props on a third-party category images #11541

Conversation

vovayatsyuk
Copy link
Member

Description

Fixes hardcoded 'image' key when processing ImageBackendModel attribute.

Manual testing scenarios

  1. In order to test the issue, you need to create custom ImageBackendModel attribute and add it to the category edit form
  2. Upload third-party image (leave the image field empty) and save category
  3. Third-party image will not have required 'size' and 'type' properties during page rendering
  4. The main image will have 'size' and 'type' properties of third-party image

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@orlangur orlangur self-assigned this Oct 18, 2017
@orlangur
Copy link
Contributor

@vovayatsyuk thanks for your contribution!

In order to speed up testing and PR processing, could you please provide code snippet used to create custom image attribute?

@vovayatsyuk
Copy link
Member Author

  1. This is a code to create an attribute. You can use it in any action without writing an upgrade:

    $setup = $this->_objectManager->get(\Magento\Framework\Setup\ModuleDataSetupInterface::class);
    $categorySetupFactory = $this->_objectManager->get(\Magento\Catalog\Setup\CategorySetupFactory::class);
    $setup->startSetup();
    $categorySetup = $categorySetupFactory->create(['setup' => $setup]);
    $categorySetup->addAttribute(
        \Magento\Catalog\Model\Category::ENTITY,
        'thumbnail_test',
        [
            'type' => 'varchar',
            'label' => 'Thumbnail test',
            'input' => 'image',
            'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image',
            'required' => false,
            'sort_order' => 4,
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'group' => 'General Information',
        ]
    );
    $setup->endSetup();
  2. Add this code to Magento/Catalog/view/adminhtml/ui_component/category_form.xml above the image field:

    <field name="thumbnail_test" sortOrder="30" formElement="fileUploader">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="source" xsi:type="string">category</item>
            </item>
        </argument>
        <settings>
            <elementTmpl>ui/form/element/uploader/uploader</elementTmpl>
            <dataType>string</dataType>
            <label translate="true">Category Thumbnail</label>
            <visible>true</visible>
            <required>false</required>
        </settings>
        <formElements>
            <fileUploader>
                <settings>
                    <required>false</required>
                    <uploaderConfig>
                        <param xsi:type="url" name="url" path="catalog/category_image/upload"/>
                    </uploaderConfig>
                    <previewTmpl>Magento_Catalog/image-preview</previewTmpl>
                </settings>
            </fileUploader>
        </formElements>
    </field>
  3. Now you will be able to upload thumbnail from the category page, save category, and reproduce the bug:

image

@orlangur
Copy link
Contributor

Excellent 👍

@orlangur orlangur added this to the October 2017 milestone Oct 19, 2017
@magento-engcom-team magento-engcom-team changed the base branch from develop to 2.3-develop October 20, 2017 15:32
@okorshenko okorshenko modified the milestones: October 2017, November 2017 Nov 1, 2017
@okorshenko okorshenko merged commit 51f743c into magento:2.3-develop Nov 10, 2017
okorshenko pushed a commit that referenced this pull request Nov 10, 2017
vovayatsyuk pushed a commit to vovayatsyuk/magento2 that referenced this pull request Nov 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants