Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Refactor catalog module #2890

Merged
merged 90 commits into from
Jul 1, 2019
Merged

Conversation

patzick
Copy link
Collaborator

@patzick patzick commented May 13, 2019

Short description and why it's useful

This is WIP and should be for now treated as POC. PR created at early stage to show concept.

things to complete this PR

  • resolve problem with URL dispatcher. After page refresh there is 14 beforeEach invocations, and finally it removes query params from path
  • add support for multiple filter
  • move created logic in filters to GenericSelector
  • [OPTIONAL] add support for filters from path params, not only query params
  • refactor names - this will be done at the end with team, for now i'm naming things as i believe they should be named
  • add upgrade notes
  • add ending comparison to ensure that we didn't missed any functionalities

Additional TODO to complete this PR

  • display filters when navigate directly to product page
  • display proper images variants on color filter
  • improve filters on product page to work old way
  • refactor module name

Which environment this relates to

Check your case. In case of any doubts please read about Release Cycle

  • Test version (https://test.storefrontcloud.io) - this is a new feature or improvement for Vue Storefront. I've created branch from develop branch and want to merge it back to develop
  • RC version (https://next.storefrontcloud.io) - this is a stabilisation fix for Release Candidate of Vue Storefront. I've created branch from release branch and want to merge it back to release
  • Stable version (https://demo.storefrontcloud.io) - this is an important fix for current stable version. I've created branch from hotfix or master branch and want to merge it back to hotfix

Upgrade Notes and Changelog

  • No upgrade steps required (100% backward compatibility and no breaking changes)
  • I've updated the Upgrade notes and Changelog on how to port existing VS sites with this new feature

IMPORTANT NOTICE - Remember to update CHANGELOG.md with description of your change

core/modules/catalog-magento/store/category/actions.ts Outdated Show resolved Hide resolved
core/modules/catalog-magento/store/category/actions.ts Outdated Show resolved Hide resolved
core/modules/catalog-magento/store/category/actions.ts Outdated Show resolved Hide resolved
core/modules/catalog-magento/store/category/actions.ts Outdated Show resolved Hide resolved
core/modules/catalog-magento/store/category/actions.ts Outdated Show resolved Hide resolved
core/modules/catalog-magento/store/category/getters.ts Outdated Show resolved Hide resolved
core/modules/catalog/components/CategorySort.ts Outdated Show resolved Hide resolved
src/themes/default/pages/Category.vue Show resolved Hide resolved
src/themes/default/pages/Category.vue Outdated Show resolved Hide resolved
src/themes/default/pages/Category.vue Show resolved Hide resolved
@pkarw
Copy link
Collaborator

pkarw commented May 13, 2019

I think it's good step, right direction. The considerations:

  • we need more strict coding standards for vuex + convention to apply over all the catalog modules and probably the other modules as well,
  • it's not clear to the developer - using the Category.vue from where to get filters, pagination, sorting options and products - the Category.vue interface should be more self-explanatory based on Vuex getters + computed attributes

@patzick patzick requested review from pkarw and filrak June 26, 2019 14:20
@patzick
Copy link
Collaborator Author

patzick commented Jun 26, 2019

I'll need add docs and info what's changed, but this can be reviewed.
Version is deployed under: https://theme20.storefrontcloud.io/

@pkarw
Copy link
Collaborator

pkarw commented Jun 26, 2019

@patzick there is a check missing if the category is available in the offline mode - I can enter it and there is no even basic data like category title: https://www.dropbox.com/s/te3xe9fzl2bv2i9/Screenshot%202019-06-26%2022.07.23.png?dl=0

on demo - when you enter category that hasn't been visited before you get notification that this product is not availble in the offline mode + you can't just enter it. We should have some better sollution than this "broken" category page like it's right now

@pkarw
Copy link
Collaborator

pkarw commented Jun 26, 2019

Moreover, I see that currently we're not setting the category data into local cache (categoriesCollection). Not sure about the consequences of this behavior for the offline mode (I can imagine some issues regarding the breadcrumbs on the product page or some other problems when we won't cache the category (?)). I don't say we must have it but just please test it out and do some code-review what will happen in the offline mode in this situation please. The cool thing about caching is we're pre-caching categories for later (the same we can potentially do with the categoriesMap and hierarchy - storing them in local cache could save us with some addional calls).

UPDATE: What's pretty interesting even with the setItem on demo - the cache is not being populated (categories collection), However, please do check the offlne mode scenarios

Copy link
Collaborator

@pkarw pkarw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really cool one! I had some questions regarding categoriesMap (to make sure we won't duplicate data), categoryHierarchy (if it's really needed) and mostly about the offline mode (caching/exception handling).

BUT I must admit it works perfectly well for most scenarios I've tested :D That's great, the code is very coherent - I like it.

getCategories: (state) => state.categories,
getCategoryProducts: (state) => state.products,
getAvailableFilters: state => state.availableFilters,
calculateCurrentCategory: (state, getters, rootState) => (route) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say get is easier to get :D

core/modules/catalog-magento/store/category/getters.ts Outdated Show resolved Hide resolved
core/modules/catalog/components/CategorySort.ts Outdated Show resolved Hide resolved
src/themes/default/pages/Category.vue Show resolved Hide resolved
core/modules/catalog-magento/store/category/actions.ts Outdated Show resolved Hide resolved
await dispatch('loadCategoryFilters', searchCategory)
const searchQuery = getters.getCurrentFiltersFrom(route[products.routerFiltersSource])
let filterQr = buildFilterProductsQuery(searchCategory, searchQuery.filters)
const searchResult = await quickSearchByQuery({ query: filterQr, sort: searchQuery.sort })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if'we re using the config.entites.products.includeFields ... as it was done with the progressive caching approach: https://github.com/DivanteLtd/vue-storefront/blob/70543b3cfa379971220f6514348fe0386a108878/core/modules/catalog/store/category/actions.ts#L240

It seems like not. Moreover, we're not running these 2 calls with the doublecheck (if it gains the performance) as it was originally done. It should work exact the same way

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, the stock prefetching mechanism is also not ported to this refactored version: https://github.com/DivanteLtd/vue-storefront/blob/70543b3cfa379971220f6514348fe0386a108878/core/modules/catalog/store/category/actions.ts#L267

Without prefetching the stocks - when the config.products. filterUnavailableVariants is set to true - it will take forever to fetch the stocks on demand on the product page

return 0
}

export const _prepareCategoryHierarchyMap = (category: Category|ChildrenData) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest you to reconsider if this is really needed. Potentially it will be huuuge object (take wonect.com for an example) - building it, passing thru INITIAL_STATE - not sure if it makes sense. shouldn't we create this kind of mapping just for the current category (we do have category.path which consist the ids of category accestors as far as I remember) (?)

@@ -0,0 +1,3 @@
export async function afterRegistration ({ Vue, config, store, isServer }) {
if (isServer) await store.dispatch('category-next/_prepareCategoriesHierarchyMap')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't liek to have such a pre-caching mechanism for the whole category tree in the module init :(

core/modules/catalog-next/store/category/actions.ts Outdated Show resolved Hide resolved
}
return filters
},
getAvailableFilters: state => state.availableFilters,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this interface :)

@pkarw
Copy link
Collaborator

pkarw commented Jun 26, 2019

OK one more thing - we're not caching the products when browsing in the CSR (elasticCache collection is not being populated); we're also not having the progressive caching (taking the limites set of product fields for the listing + second request for caching). This should be re-considered

@@ -0,0 +1,5 @@
import { CategoryService } from './CategoryService';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set sideEffects: false for this in package.json

return 0
}

export const _prepareCategoryPathIds = (category: Category): string[] => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ indicates private fn yet you export it, why?

import chunk from 'lodash-es/chunk'

const actions: ActionTree<CategoryState, RootState> = {
async loadCategoryProducts ({ commit, getters, dispatch, rootState }, { route, category } = {}) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho products should be cached by default. No additional work should be required to do this

@patzick patzick merged commit dd1f755 into vuestorefront:develop Jul 1, 2019
@patzick patzick deleted the magento-catalog branch July 1, 2019 09:45
@patzick patzick mentioned this pull request Aug 27, 2019
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants