Skip to content

[Forwardport] Creating custom customer attribute with default value 0 will cause not saving value for customer entity #18718

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

Closed

Conversation

gelanivishal
Copy link
Contributor

@gelanivishal gelanivishal commented Oct 20, 2018

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)

@magento-engcom-team
Copy link
Contributor

Hi @gelanivishal. 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 $VERSION instance - deploy vanilla Magento instance

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

Copy link
Member

@slavvka slavvka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gelanivishal please reimplement the solution according to my comment

@@ -0,0 +1,58 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gelanivishal Thank you for up-porting the issue but for 2.3 this solution should be modified since there we introduced Declarative Schema and you shouldn't use UpgradeData scripts together with setup_version of modules. Please reimplement that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavvka I have performed changes as requested.

@@ -142,7 +142,7 @@ public function apply()
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => '0',
'default' => null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gelanivishal Thank you but that's not correct since this change won't apply to already installed instances of Magento. You need to create another named patch.

@slavvka
Copy link
Member

slavvka commented Nov 8, 2018

Hey @gelanivishal are you going to proceed with this PR?

@slavvka
Copy link
Member

slavvka commented Nov 14, 2018

@gelanivishal I am closing this PR due to non-activity. Please feel free to reopen it once you decide to proceed with it.

@slavvka slavvka closed this Nov 14, 2018
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.

3 participants