dimaportenko / magento-react-native

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

Product filter #156

Closed sidneylopes closed 4 years ago

sidneylopes commented 4 years ago

I managed to filter the products, and to show only the ones from the right store. How would I show only the right categories?

dimaportenko commented 4 years ago

Add categories you want to the search criteria of request.

sidneylopes commented 4 years ago

where is that?

dimaportenko commented 4 years ago

I managed to filter the products, where did you filter products?

sidneylopes commented 4 years ago

in the getSearchCreteriaForCategoryAndChild function

dimaportenko commented 4 years ago
src/magento/lib/admin/index.js
getSearchCreteriaForCategoryAndChild: (category, pageSize = 10, offset = 1, sortOrder, filter)

it takes category as a parameter

sidneylopes commented 4 years ago

could you give me an example of how you would filter categories?

dimaportenko commented 4 years ago

@sidneylopes check src/actions/RestActions.js

export const getProductsForCategoryOrChild = (category, offset, sortOrder, filter) => async (dispatch) => {
  if (offset) {
    dispatch({ type: MAGENTO_LOAD_MORE_CATEGORY_PRODUCTS, payload: true });
  }

  if (!offset && (typeof sortOrder === 'number' || typeof filter !== 'undefined')) {
    dispatch({ type: MAGENTO_RESET_CATEGORY_PRODUCTS });
  }

  try {
    const payload = await magento.admin
      .getSearchCreteriaForCategoryAndChild(category, 10, offset, sortOrder, filter);
    dispatch({ type: MAGENTO_GET_CATEGORY_PRODUCTS, payload });
    dispatch({ type: MAGENTO_LOAD_MORE_CATEGORY_PRODUCTS, payload: false });
    updateConfigurableProductsPrices(payload.items, dispatch);
  } catch (e) {
    logError(e);
  }
};
sidneylopes commented 4 years ago

but isn't that function for filtering products? I need to filter categories. let's suppose that I only want a category that has an Id of 20. How would I filter that?

dimaportenko commented 4 years ago

Ok, this issue about product filter, isn't it? so I supposed you are asking about filter products by categories.

Also, you are asking a lot of questions I don't have in my mind I need to find an answer for you. So probably you can do it yourself. What did you try and where you stuck with it?

sidneylopes commented 4 years ago

I already managed to filter the products, and the categories work, but I have 2 sites and in one of them, some categories aren't supposed to show up. I tried to filter them using a searchCriteria for their Ids, but it didn't work. I have no idea on how to do this.

dimaportenko commented 4 years ago

Please share what you tried.