Skip to content

Commit

Permalink
Add changeProductCategory and price poc extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Apr 15, 2023
1 parent 9524fce commit dbec6ad
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 1 deletion.
23 changes: 23 additions & 0 deletions extensions/changeProductCategory.ts
Original file line number Diff line number Diff line change
@@ -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<Product> => ({
category,
});
export default function addProductPrice(
product: Product | Product[] | null,
{ newCategory }: Props,
): Partial<Product> | Partial<Product>[] | null {
if (product === null) {
return product;
}
const withCategory = changeCategory(newCategory);
if (Array.isArray(product)) {
return product.map(withCategory);
}
return withCategory(product);
}
22 changes: 22 additions & 0 deletions extensions/changeProductPrice.ts
Original file line number Diff line number Diff line change
@@ -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<Product> => ({
offers: p?.offers ? { ...p.offers, lowPrice: price } : undefined,
});
export default function addProductPrice(
product: Product | Product[] | null,
{ newPrice }: Props,
): Partial<Product> | Partial<Product>[] | null {
if (product === null) {
return product;
}
const withPrice = addPrice(newPrice);
if (Array.isArray(product)) {
return product.map(withPrice);
}
return withPrice(product);
}
2 changes: 1 addition & 1 deletion import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"imports": {
"deco-sites/fashion/": "./",
"deco-sites/std/": "https://denopkg.com/deco-sites/[email protected]/",
"$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/[email protected]/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
Expand Down
10 changes: 10 additions & 0 deletions live.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
149 changes: 149 additions & 0 deletions schemas.gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -5435,6 +5553,17 @@
}
]
},
"loaders": {
"title": "loaders",
"anyOf": [
{
"$ref": "#/definitions/Resolvable"
},
{
"$ref": "#/definitions/JGxpdmUvbG9hZGVycy9hZGRFeHRlbnNpb25zLnRz"
}
]
},
"islands": {
"title": "islands",
"anyOf": [
Expand Down Expand Up @@ -5633,6 +5762,20 @@
}
]
},
"extensions": {
"title": "extensions",
"anyOf": [
{
"$ref": "#/definitions/Resolvable"
},
{
"$ref": "#/definitions/ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdENhdGVnb3J5LnRz"
},
{
"$ref": "#/definitions/ZGVjby1zaXRlcy9mYXNoaW9uL2V4dGVuc2lvbnMvY2hhbmdlUHJvZHVjdFByaWNlLnRz"
}
]
},
"state": {
"type": "object",
"required": [
Expand Down Expand Up @@ -5663,6 +5806,9 @@
{
"$ref": "#/root/accounts"
},
{
"$ref": "#/root/loaders"
},
{
"$ref": "#/root/islands"
},
Expand All @@ -5680,6 +5826,9 @@
},
{
"$ref": "#/root/flags"
},
{
"$ref": "#/root/extensions"
}
]
}
Expand Down

0 comments on commit dbec6ad

Please sign in to comment.