From dbec6adeec49e899140f58324d07ecbe3a5a9a8d Mon Sep 17 00:00:00 2001 From: Marcos Candeia Date: Fri, 14 Apr 2023 21:53:13 -0300 Subject: [PATCH] Add changeProductCategory and price poc extensions Signed-off-by: Marcos Candeia --- extensions/changeProductCategory.ts | 23 +++++ extensions/changeProductPrice.ts | 22 ++++ import_map.json | 2 +- live.gen.ts | 10 ++ schemas.gen.json | 149 ++++++++++++++++++++++++++++ 5 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 extensions/changeProductCategory.ts create mode 100644 extensions/changeProductPrice.ts diff --git a/extensions/changeProductCategory.ts b/extensions/changeProductCategory.ts new file mode 100644 index 00000000..3566fa63 --- /dev/null +++ b/extensions/changeProductCategory.ts @@ -0,0 +1,23 @@ +import { Product } from "deco-sites/std/commerce/types.ts"; + +export interface Props { + newCategory: string; +} + +const changeCategory = + (category: string) => (_p: Product): Partial => ({ + category, + }); +export default function addProductPrice( + product: Product | Product[] | null, + { newCategory }: Props, +): Partial | Partial[] | null { + if (product === null) { + return product; + } + const withCategory = changeCategory(newCategory); + if (Array.isArray(product)) { + return product.map(withCategory); + } + return withCategory(product); +} diff --git a/extensions/changeProductPrice.ts b/extensions/changeProductPrice.ts new file mode 100644 index 00000000..bb2ceec6 --- /dev/null +++ b/extensions/changeProductPrice.ts @@ -0,0 +1,22 @@ +import { Product } from "deco-sites/std/commerce/types.ts"; + +export interface Props { + newPrice: number; +} + +const addPrice = (price: number) => (p: Product): Partial => ({ + offers: p?.offers ? { ...p.offers, lowPrice: price } : undefined, +}); +export default function addProductPrice( + product: Product | Product[] | null, + { newPrice }: Props, +): Partial | Partial[] | null { + if (product === null) { + return product; + } + const withPrice = addPrice(newPrice); + if (Array.isArray(product)) { + return product.map(withPrice); + } + return withPrice(product); +} diff --git a/import_map.json b/import_map.json index 33d7471e..bdca347a 100644 --- a/import_map.json +++ b/import_map.json @@ -2,7 +2,7 @@ "imports": { "deco-sites/fashion/": "./", "deco-sites/std/": "https://denopkg.com/deco-sites/std@1.0.0-rc.14/", - "$live/": "https://denopkg.com/deco-cx/live@1.0.0-rc.53/", + "$live/": "https://denopkg.com/deco-cx/live@8fce34de9523cb7b7d7f316a356c709ba606e152/", "$fresh/": "https://deno.land/x/fresh@1.1.5/", "preact": "https://esm.sh/preact@10.13.2", "preact/": "https://esm.sh/preact@10.13.2/", diff --git a/live.gen.ts b/live.gen.ts index c1916ee0..157375a5 100644 --- a/live.gen.ts +++ b/live.gen.ts @@ -32,6 +32,8 @@ import * as $$$$$$$$11 from "./sections/ProductDetails.tsx"; import * as $$$$$$$$12 from "./sections/Highlights.tsx"; import * as $$$$$$$$13 from "./sections/WhatsApp.tsx"; import * as $$$$$$$$14 from "./sections/Carousel.tsx"; +import * as $$$$$$$$$$$0 from "./extensions/changeProductCategory.ts"; +import * as $$$$$$$$$$$1 from "./extensions/changeProductPrice.ts"; import * as $live_middleware from "$live/routes/_middleware.ts"; import * as $live_workbench from "$live/routes/live/workbench.ts"; import * as $live_invoke from "$live/routes/live/invoke/index.ts"; @@ -40,6 +42,7 @@ import * as $live_inspect from "$live/routes/live/inspect.ts"; import * as $live_meta from "$live/routes/live/_meta.ts"; import * as $live_previews from "$live/routes/live/previews/[...block].tsx"; import * as $live_catchall from "$live/routes/[...catchall].tsx"; +import * as i1$0 from "$live/loaders/addExtensions.ts"; import * as i2$$$$0 from "$live/handlers/routesSelection.ts"; import * as i2$$$$1 from "$live/handlers/router.ts"; import * as i2$$$$2 from "$live/handlers/devPage.ts"; @@ -141,6 +144,13 @@ const manifest = { "deco-sites/std/sections/configVTEX.global.tsx": i2$$$7, "deco-sites/std/sections/SEOPDP.tsx": i2$$$8, }, + "extensions": { + "deco-sites/fashion/extensions/changeProductCategory.ts": $$$$$$$$$$$0, + "deco-sites/fashion/extensions/changeProductPrice.ts": $$$$$$$$$$$1, + }, + "loaders": { + "$live/loaders/addExtensions.ts": i1$0, + }, "handlers": { "$live/handlers/routesSelection.ts": i2$$$$0, "$live/handlers/router.ts": i2$$$$1, diff --git a/schemas.gen.json b/schemas.gen.json index 110dded0..f32135e8 100644 --- a/schemas.gen.json +++ b/schemas.gen.json @@ -2287,6 +2287,35 @@ ], "title": "deco-sites/std/commerce/occ/client.ts@ConfigOCC" }, + "ZGVjby1jeC9saXZlL2Jsb2Nrcy9leHRlbnNpb24udHM=@Extension": { + "$ref": "#/root/extensions", + "title": "Extension" + }, + "ZGVjby1jeC9saXZlL2Jsb2Nrcy9leHRlbnNpb24udHM=@Extension[]": { + "type": "array", + "items": { + "$ref": "#/definitions/ZGVjby1jeC9saXZlL2Jsb2Nrcy9leHRlbnNpb24udHM=@Extension" + }, + "title": "Extension[]" + }, + "ZGVjby1jeC9saXZlL2xvYWRlcnMvYWRkRXh0ZW5zaW9ucy50cw==@Props": { + "type": "object", + "properties": { + "data": { + "$ref": "#/root/functions", + "title": "Data" + }, + "extensions": { + "$ref": "#/definitions/ZGVjby1jeC9saXZlL2Jsb2Nrcy9leHRlbnNpb24udHM=@Extension[]", + "title": "Extensions" + } + }, + "required": [ + "data", + "extensions" + ], + "title": "deco-cx/live/loaders/addExtensions.ts@Props" + }, "ZGVjby1zaXRlcy9zdGQvY29tbWVyY2UvdnRleC90eXBlcy50cw==@SKU": { "type": "object", "properties": { @@ -3881,6 +3910,32 @@ "required": [], "title": "deco-cx/live/flags/everyone.ts@EveryoneConfig" }, + "ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdENhdGVnb3J5LnRz@Props": { + "type": "object", + "properties": { + "newCategory": { + "type": "string", + "title": "New Category" + } + }, + "required": [ + "newCategory" + ], + "title": "deco-sites/fashion/extensions/changeProductCategory.ts@Props" + }, + "ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdFByaWNlLnRz@Props": { + "type": "object", + "properties": { + "newPrice": { + "type": "number", + "title": "New Price" + } + }, + "required": [ + "newPrice" + ], + "title": "deco-sites/fashion/extensions/changeProductPrice.ts@Props" + }, "ZGVjby1zaXRlcy9zdGQvZnVuY3Rpb25zL3Z0ZXhDb25maWcudHM=": { "title": "deco-sites/std/functions/vtexConfig.ts", "type": "object", @@ -4334,6 +4389,27 @@ } } }, + "JGxpdmUvbG9hZGVycy9hZGRFeHRlbnNpb25zLnRz": { + "title": "$live/loaders/addExtensions.ts", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ZGVjby1jeC9saXZlL2xvYWRlcnMvYWRkRXh0ZW5zaW9ucy50cw==@Props" + } + ], + "required": [ + "__resolveType" + ], + "properties": { + "__resolveType": { + "type": "string", + "enum": [ + "$live/loaders/addExtensions.ts" + ], + "default": "$live/loaders/addExtensions.ts" + } + } + }, "Li9pc2xhbmRzL1dpc2hsaXN0QnV0dG9uLnRzeA==": { "title": "./islands/WishlistButton.tsx", "type": "object", @@ -5319,6 +5395,48 @@ } } }, + "ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdENhdGVnb3J5LnRz": { + "title": "deco-sites/fashion/extensions/changeProductCategory.ts", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdENhdGVnb3J5LnRz@Props" + } + ], + "required": [ + "__resolveType" + ], + "properties": { + "__resolveType": { + "type": "string", + "enum": [ + "deco-sites/fashion/extensions/changeProductCategory.ts" + ], + "default": "deco-sites/fashion/extensions/changeProductCategory.ts" + } + } + }, + "ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdFByaWNlLnRz": { + "title": "deco-sites/fashion/extensions/changeProductPrice.ts", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdFByaWNlLnRz@Props" + } + ], + "required": [ + "__resolveType" + ], + "properties": { + "__resolveType": { + "type": "string", + "enum": [ + "deco-sites/fashion/extensions/changeProductPrice.ts" + ], + "default": "deco-sites/fashion/extensions/changeProductPrice.ts" + } + } + }, "ZGVjby1jeC9saXZlL3JvdXRlcy9fbWlkZGxld2FyZS50cw==@MiddlewareConfig": { "type": "object", "properties": { @@ -5435,6 +5553,17 @@ } ] }, + "loaders": { + "title": "loaders", + "anyOf": [ + { + "$ref": "#/definitions/Resolvable" + }, + { + "$ref": "#/definitions/JGxpdmUvbG9hZGVycy9hZGRFeHRlbnNpb25zLnRz" + } + ] + }, "islands": { "title": "islands", "anyOf": [ @@ -5633,6 +5762,20 @@ } ] }, + "extensions": { + "title": "extensions", + "anyOf": [ + { + "$ref": "#/definitions/Resolvable" + }, + { + "$ref": "#/definitions/ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdENhdGVnb3J5LnRz" + }, + { + "$ref": "#/definitions/ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdFByaWNlLnRz" + } + ] + }, "state": { "type": "object", "required": [ @@ -5663,6 +5806,9 @@ { "$ref": "#/root/accounts" }, + { + "$ref": "#/root/loaders" + }, { "$ref": "#/root/islands" }, @@ -5680,6 +5826,9 @@ }, { "$ref": "#/root/flags" + }, + { + "$ref": "#/root/extensions" } ] }