@misiki/gocommerce-connector 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/{index-BaFtBtaA.d.cts → index-DOlNI60Y.d.cts} +11 -21
- package/dist/{index-BaFtBtaA.d.ts → index-DOlNI60Y.d.ts} +11 -21
- package/dist/index.cjs +20 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +20 -3
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +20 -3
- package/dist/services/index.js.map +1 -1
- package/package.json +1 -1
package/dist/services/index.cjs
CHANGED
|
@@ -1574,7 +1574,23 @@ function attributesFrom(p) {
|
|
|
1574
1574
|
return Object.keys(out).length ? out : void 0;
|
|
1575
1575
|
}
|
|
1576
1576
|
var counts = (values) => Object.fromEntries((values ?? []).map((v) => [v.value, v.count]));
|
|
1577
|
-
function
|
|
1577
|
+
function categoryFacets(counted, tree) {
|
|
1578
|
+
const byId = new Map(tree.map((c) => [c.id, c]));
|
|
1579
|
+
const totals = /* @__PURE__ */ new Map();
|
|
1580
|
+
for (const { id: id2, count } of counted) {
|
|
1581
|
+
for (let c = byId.get(id2); c; c = c.parent_id === null ? void 0 : byId.get(c.parent_id)) {
|
|
1582
|
+
totals.set(c.id, (totals.get(c.id) ?? 0) + count);
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
const kept = tree.filter((c) => totals.has(c.id)).sort((a, b) => a.position - b.position || a.id - b.id);
|
|
1586
|
+
const parentOf = (c) => c.parent_id !== null && byId.has(c.parent_id) ? c.parent_id : null;
|
|
1587
|
+
const under = (parent) => kept.filter((c) => parentOf(c) === parent).flatMap((c) => [{ name: c.title, slug: c.slug, count: totals.get(c.id), depth: c.depth }, ...under(c.id)]);
|
|
1588
|
+
return [
|
|
1589
|
+
...under(null),
|
|
1590
|
+
...counted.filter((c) => !byId.has(c.id)).map((c) => ({ name: c.title, slug: c.slug, count: c.count, depth: 0 }))
|
|
1591
|
+
];
|
|
1592
|
+
}
|
|
1593
|
+
function toStorefrontFacets(f, tree = []) {
|
|
1578
1594
|
if (!f) return { priceStat: {}, categories: [], tags: [], allFilters: {} };
|
|
1579
1595
|
const allFilters = {};
|
|
1580
1596
|
const group = (key, values) => {
|
|
@@ -1585,7 +1601,7 @@ function toStorefrontFacets(f) {
|
|
|
1585
1601
|
for (const [handle, values] of Object.entries(f.attributes ?? {})) group(`attributes.${handle}`, values);
|
|
1586
1602
|
return {
|
|
1587
1603
|
priceStat: f.price ? { min: toMajor(f.price.min), max: toMajor(f.price.max) } : {},
|
|
1588
|
-
categories: (f.categories ?? []
|
|
1604
|
+
categories: categoryFacets(f.categories ?? [], tree),
|
|
1589
1605
|
tags: (f.tags ?? []).map((t) => ({ name: t.value, count: t.count })),
|
|
1590
1606
|
allFilters
|
|
1591
1607
|
};
|
|
@@ -1618,13 +1634,14 @@ var SearchService = class extends CatalogService {
|
|
|
1618
1634
|
productTypes: listParam(p, "product_type"),
|
|
1619
1635
|
facets: true
|
|
1620
1636
|
});
|
|
1637
|
+
const tree = res.facets?.categories?.length ? await this.facts.categories().catch(() => []) : [];
|
|
1621
1638
|
return {
|
|
1622
1639
|
data: res.data,
|
|
1623
1640
|
count: res.count,
|
|
1624
1641
|
totalPages: res.noOfPage,
|
|
1625
1642
|
page: res.page,
|
|
1626
1643
|
categoryHierarchy: res.categoryHierarchy,
|
|
1627
|
-
facets: toStorefrontFacets(res.facets)
|
|
1644
|
+
facets: toStorefrontFacets(res.facets, tree)
|
|
1628
1645
|
};
|
|
1629
1646
|
} catch (err) {
|
|
1630
1647
|
if (err?.status === 404) return this.emptyResult();
|