Skip to content

Unable to get product attribute value for store-view scope type in product collection loaded for a specific store. #18374

Closed
@milindsingh

Description

@milindsingh

Preconditions

  1. Product has a user defined attribute with scope : store-view. Created via:
`/** @var \Magento\Eav\Setup\EavSetup $eavSetup */`
`
$eavSetup->addAttribute(
                    'catalog_product',
                   'ced_profile_id',
                    [
                        'group' => $groupName,
                        'note' => 'Profile Id',
                        'input' => 'text',
                        'type' => 'varchar',
                        'label' => 'Profile Id ',
                        'backend' => '',
                        'visible' => 1,
                        'required' => 0,
                        'sort_order' => 1,
                        'user_defined' => 1,
                        'comparable' => 0,
                        'visible_on_front' => 0,
                        'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                    ]
                );
`
 
  1. Magento is setup with 2 store configuration. [Default Store & My Store]
  2. Attribute ced_profile_id has value 'blank' in All Store Views ( i.e. for Admin store ID - 0), and value '2' for Default Store ( i.e. ID - 1).
  3. On loading product collection with following code:
    $storeId = 1; \** @var Magento\Catalog\Model\ResourceModel\Product\Collection $collection **\ $collection->setStoreId($storeId); $collection->addAttributeToSelect(['ced_profile_id']); $products = $collection->getData();
  4. Environment:
  • Magento CE 2.2.5
  • PHP 7.09
  • MYSQL 5.7

Steps to reproduce

  1. Create a store-wise user-defined attribute.
  2. Have blank value for admin store (i.e. all store views, ID - 0). and Have 'some value' for Default Store i.e. ID - 1.
  3. Load Product collection by setting store id - 1, will get no values for default store - 1 for store -wise user defined attributes.

Expected result

1.$products have 2 attribute for 'ced_profile_id'.

Actual result

  1. $products have null attribute for 'ced_profile_id'.
  2. The Product collection final get SQL query search for Null value in admin store, while there is no row in admin store entity table for blank values. Add a row with null value for admin store and I am able to get the default store values.
    2018-10-04-132110_1366x768_scrot
    In above image, entity_id 2,3,4 have null values for admin store - 0 and collection can get the default store values.
    While entity_id 1 don't have a row in catalog_product_entity_varchar, hence I am not able to get values in product collection for store id 1 i.e. Default Store .

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CatalogFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions