Skip to content

Product repository getList() fails to return a product if 'visibility' attribute not present #8783

Closed
@ByteCreation

Description

@ByteCreation

Preconditions

  1. Magneto 2.1.4
  2. PHP 7.0.x
  3. MySQL 5.7.x

Steps to reproduce

  1. Create a new product type that does not include the attribute 'visibility'
  2. Add a new product to the catalog of the product type mentioned in point 1
  3. Request the new product via the product repository getList() method

Expected result

  1. The requested product is returned

Actual result

  1. Nothing is returned

Further information

When running the same query via a collection (instead of the product repository getList() method), it works as expected and returns the product.

The following example code assumes you have products in your catalog. One or more of these products has a product type that does not have the 'visibility' attribute present.

The following code should return all products in the catalog. However, it fails to include anything with a product type that does not have the 'visibility' attribute present.

<?php
$repo = $this->objectManager->get('Magento\Catalog\Model\ProductRepository');
$search_criteria = $this->objectManager->create('Magento\Framework\Api\SearchCriteriaInterface');

$result = $repo->getList($search_criteria);
$products = $result->getItems();

foreach($products as $product)
{
    echo '<pre>';
    var_dump($product->getData());
    echo '</pre>';
}

The following makes the same assumptions as the previous example. It should return all products in the catalog. It works as expected and returns all products, including those with the product type that does not have the 'visibility' attribute present.

<?php
$collection = $this->objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');

$collection = $collection->create();
$collection->addAttributeToSelect('*');
$products = $collection->getItems();

foreach($products as $product)
{
    echo '<pre>';
    var_dump($product->getData());
    echo '</pre>';
}

Dump of a product's attributes that result in the bug where the product repository getList() method does not work as expected. As can be seen below, the attribute 'visibility' is not present at all on this product type.

array(18) {
  ["entity_id"]=>
  string(1) "6"
  ["attribute_set_id"]=>
  string(1) "4"
  ["type_id"]=>
  string(11) "new_product_type_one"
  ["sku"]=>
  string(8) "s-000023"
  ["has_options"]=>
  string(1) "0"
  ["required_options"]=>
  string(1) "0"
  ["created_at"]=>
  string(19) "2017-03-03 10:42:27"
  ["updated_at"]=>
  string(19) "2017-03-03 13:20:05"
  ["is_salable"]=>
  string(1) "0"
  ["status"]=>
  string(1) "1"
  ["name"]=>
  string(13) "New product"
  ["meta_title"]=>
  string(13) "New product"
  ["meta_description"]=>
  string(14) "New product"
  ["options_container"]=>
  string(10) "container2"
  ["url_key"]=>
  string(13) "new-product"
  ["meta_keyword"]=>
  string(13) "New product"
  ["custom_attribute_one"]=>
  string(1) "1"
  ["custom_attribute_two"]=>
  string(1) "2"
}

Dump of a product's attributes that work as expected with the product repository getList() method. As can be seen below, the only difference is that the attribute 'visibility' is present.

array(19) {
  ["entity_id"]=>
  string(1) "3"
  ["attribute_set_id"]=>
  string(1) "4"
  ["type_id"]=>
  string(11) "new_product_type_two"
  ["sku"]=>
  string(8) "s-000001"
  ["has_options"]=>
  string(1) "0"
  ["required_options"]=>
  string(1) "0"
  ["created_at"]=>
  string(19) "2017-01-26 10:30:22"
  ["updated_at"]=>
  string(19) "2017-03-03 13:20:05"
  ["status"]=>
  string(1) "1"
  ["visibility"]=>
  string(1) "4"
  ["is_salable"]=>
  string(1) "0"
  ["name"]=>
  string(4) "New product"
  ["meta_title"]=>
  string(4) "New product"
  ["meta_description"]=>
  string(5) "New product "
  ["options_container"]=>
  string(10) "container2"
  ["url_key"]=>
  string(4) "new-product"
  ["meta_keyword"]=>
  string(4) "New product"
  ["custom_attribute_one"]=>
  string(2) "1"
  ["custom_attribute_two"]=>
  string(3) "2"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed 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 passedReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releasenon-issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions