Search code examples
magentomagento-rest-api

Empty product list for guest requests


I am trying to read Magento product list via REST API using guest account. My Magento instance responds to GET /api/rest/products/1 as expected, with:

<?xml version="1.0"?>
<magento_api>
  <entity_id>1</entity_id>
  <type_id>simple</type_id>
  <sku>simple_sku</sku>
  <name>simple</name>
  <meta_title/>
  <meta_description/>
  <description>description</description>
  <short_description>short description</short_description>
  <meta_keyword/>
  <tier_price/>
  <is_in_stock>0</is_in_stock>
  <regular_price_with_tax>100</regular_price_with_tax>
  <regular_price_without_tax>100</regular_price_without_tax>
  <final_price_with_tax>100</final_price_with_tax>
  <final_price_without_tax>100</final_price_without_tax>
  <is_saleable>0</is_saleable>
  <image_url>http://localhost/media/catalog/product/cache/0/image/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/image.jpg</image_url>
  <url>http://localhost/index.php/catalog/product/view/id/1/s/simple/</url>
  <buy_now_url>http://localhost/index.php/checkout/cart/add/uenc/aHR0cDovL2xvY2FsaG9zdC9hcGkvcmVzdC9wcm9kdWN0cy8x/product/1/form_key/6DQ0mBsIua4HpuGN/</buy_now_url>
  <total_reviews_count>0</total_reviews_count>
  <has_custom_options/>
</magento_api>

However, asking the same Magento instance for a list of products using GET /api/rest/products returns empty result, when I would expect a list containing that product:

<?xml version="1.0"?>
<magento_api/>

The result is populated correctly when calling as oauth authenticated user, but I need it working for guest account.

Guest REST role has been configured to get "All" resource access and "All" attributes. I have this behaviour for Magento versions 1.9.0.1 and 1.9.1.0, for both formats: xml and json, (json returning []). Also changing "All" guest settings to manually selected checkboxes didn't solve this issue.


Solution

  • Thanks to this blog post, I found out that Magento doesn't show out of stock products for guest role in REST API. To change this behaviour, edit setting System > Configuration > Catalog > Inventory > Stock options > Display out of stock products

    Reason for that behaviour could be, that guests shouldn't see unavailable products because they cannot order or do anything with them. At the same time admin can see them, because they are potentially edible for him (if admin role has been granted that permission).