Description
Preconditions
- Magneto 2.1.4
- PHP 7.0.x
- MySQL 5.7.x
Steps to reproduce
- Create a new product type that does not include the attribute 'visibility'
- Add a new product to the catalog of the product type mentioned in point 1
- Request the new product via the product repository getList() method
Expected result
- The requested product is returned
Actual result
- 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"
}