dimaportenko / magento-react-native

React Native mobile app for Magento 2.x
MIT License
297 stars 158 forks source link

Products #154

Closed sidneylopes closed 4 years ago

sidneylopes commented 4 years ago

Is there any way for me to not show unavailable products?

dimaportenko commented 4 years ago

@sidneylopes yes, you can. if you take a look function getSearchCreteriaForCategoryAndChild in src/magento/lib/admin/index.js file, there is

    const searchCriteria = {
      groups: [
        [{
          field: 'visibility',
          value: '4',
          conditionType: 'eq',
        }],
        [{
          field: 'status',
          value: '1',
          conditionType: 'eq',
        }],
      ],
    };

which is filtering products by visibility and status so you can modify filters whatever you need.

here are the docs on how to use Magento search criteria https://devdocs.magento.com/guides/v2.4/rest/performing-searches.html

sidneylopes commented 4 years ago

thanks, problem solved

sidneylopes commented 4 years ago

hey, I still have a problem. I need to hide the products that aren't in stock, but I am having trouble. Here is a part of the JSON of a product, the parameter that I need is "is_in_stock" in "stock_item":

"items": [ { "id": 5, "sku": "22-0001", "name": "Antena Chapa Ku Mini Parabólica 60cm - Bedin Sat", "attribute_set_id": 4, "price": 85.32, "status": 1, "visibility": 4, "type_id": "simple", "created_at": "2020-03-30 21:54:35", "updated_at": "2020-11-09 18:26:18", "weight": 0.888, "extension_attributes": { "website_ids": [ 1, 2 ], "category_links": [ { "position": 0, "category_id": "33" }, { "position": 0, "category_id": "48" }, { "position": 0, "category_id": "2" } ], "stock_item": { "item_id": 3, "product_id": 5, "stock_id": 1, "qty": 1468, "is_in_stock": true, "is_qty_decimal": false, "show_default_notification_message": false, "use_config_min_qty": true, "min_qty": 5, "use_config_min_sale_qty": 1, "min_sale_qty": 1, "use_config_max_sale_qty": true, "max_sale_qty": 10000, "use_config_backorders": true, "backorders": 0, "use_config_notify_stock_qty": true, "notify_stock_qty": 5, "use_config_qty_increments": true, "qty_increments": 0, "use_config_enable_qty_inc": true, "enable_qty_increments": false, "use_config_manage_stock": true, "manage_stock": true, "low_stock_date": null, "is_decimal_divided": false, "stock_status_changed_auto": 0 } },

dimaportenko commented 4 years ago

Did you read the docs? here are the docs on how to use Magento search criteria https://devdocs.magento.com/guides/v2.4/rest/performing-searches.html

sidneylopes commented 4 years ago

yup, but still couldn't solve my problem

dimaportenko commented 4 years ago

why?

sidneylopes commented 4 years ago

I'm trying to use "is_in_stock" as a filter, but all the products disappear.

dimaportenko commented 4 years ago

Can share what exactly you are trying to do?

sidneylopes commented 4 years ago

const searchCriteria = { groups: [ [{ field: 'visibility', value: '4', conditionType: 'eq', }], [{ field: 'status', value: '1', conditionType: 'eq', }], [{ field: 'website_id', value: '1', conditionType: 'eq', }], [{ field: 'is_in_stock', value: true, conditionType: 'eq', }], ], };const searchCriteria = { groups: [ [{ field: 'visibility', value: '4', conditionType: 'eq', }], [{ field: 'status', value: '1', conditionType: 'eq', }], [{ field: 'website_id', value: '1', conditionType: 'eq', }], [{ field: 'is_in_stock', value: true, conditionType: 'eq', }], ], };

sidneylopes commented 4 years ago

the "website_id" works, but the "is_in_stock" doesn't

dimaportenko commented 4 years ago

@sidneylopes try to google about this issue. From what I can read field you trying to filter should be presented in Magento database https://magento.stackexchange.com/questions/158062/magento-2-api-filter-orders-by-extension-attribute