Skip to content

Conversation

@nmalevanec
Copy link
Contributor

Original Pull Request

#16915

  • fix default value check in case of type conversion;
  • add boolean attribute default value assignment;

Description

Fixed Issues

  1. Creating custom customer attribute with default value 0 will cause not saving value for customer entity #14510: Creating custom customer attribute with default value 0 will cause not saving value for customer entity

Manual testing scenarios

Steps to

  1. Create attribute with type "boolean" and default value via Data Install.

         $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
         $eavSetup->addAttribute(
             \Magento\Catalog\Model\Product::ENTITY,
             'custom_product',
             [
                 'type' => 'int',
                 'label' => 'Custom Product',
                 'input' => 'boolean',
                 'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
                 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
                 'backend' => \Magento\Catalog\Model\Product\Attribute\Backend\Boolean::class,
                 'visible' => true,
                 'required' => true,
                 'user_defined' => false,
                 'default' => '0',
                 'searchable' => false,
                 'filterable' => false,
                 'comparable' => false,
                 'visible_on_front' => false,
                 'used_in_product_listing' => true,
                 'unique' => false,
             ]
         );
    
         $entityTypeId = $eavSetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
         $attributeSetId = $eavSetup->getDefaultAttributeSetId($entityTypeId);
         $attributeGroupId = $eavSetup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
         $this->attributeManagement->assign(
             \Magento\Catalog\Model\Product::ENTITY,
             $attributeSetId,
             $attributeGroupId,
             'custom_product',
             100
         );
    
  2. Open Swagger.

  3. Create new product with REST API via CATALOGPRODUCTREPOSITORYV1. Attribute 'custom_product' should be missed.
    { "product": { "status": 2, "visibility": 4, "type_id": "simple", "sku": "testattr", "name": "TEST ATTR", "attribute_set_id": 4, "price": 0.5, "weight": 0.0, "extension_attributes": { "stock_item": { "qty": 0, "is_in_stock": true, "use_config_backorders": false, "backorders": 1, "use_config_manage_stock": false } }, "custom_attributes": [ { "attribute_code": "description", "value": "" }, { "attribute_code": "short_description", "value": "" }, { "attribute_code": "weight", "value": "" } ] } }

  4. Check a product attribute 'custom_product' value in DB.

Expected result

  1. Default attribute value '0' was set for attribute 'custom_product'.

Actual result

  1. No value was set for attribute ' custom_product' was set.

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)

… will cause not saving value for customer entity.
@magento-engcom-team
Copy link
Contributor

Hi @nmalevanec. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-3673 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

Hi @nmalevanec. Thank you for your contribution.
We will aim to release these changes as part of 2.3.1.
Please check the release notes for final confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants