Grouping an Array by an Object in The Arrays Object -> Vue Storefront

52 Views Asked by At

Im new at VueSTorefront and i have a Problem at my Project. I want to Display the Products in the Cart in an Accordion gruped by their type. For this i want to group this Array by their Producttype so i have an Array->Object with the producttype and an Array with Products which have this Producttype. Can someone Help me on this Issue? im struggeling a long time on this issue.

Structure of first Array

1

There are 1 best solutions below

0
On

To resolve this you need to first, manipulate your array into creating a new sorted object, which will sort by the type you want.

Then you need the cart to manipulate a getter to return the same result you want. What I recommend is to "fork" the official getter, or do a merged object with the new getter and the old one.

import { Xgetter } from '@vue-storefront/INTEGRATION;

export default {
...Xgetter,
newGetter: () => ,
};

And finally, you can use your exported getter.