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

[VNDA] Feat: create addItems action #889

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions vnda/actions/cart/addItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { HttpError } from "../../../utils/http.ts";
import cartLoader, { Cart } from "../../loaders/cart.ts";
import { AppContext } from "../../mod.ts";
import { getCartCookie } from "../../utils/cart.ts";

interface Item {
itemId: string;
quantity: number;
attributes?: Record<string, string>;
}

export interface Props {
items: Item[];
}

const action = async (
props: Props,
req: Request,
ctx: AppContext,
): Promise<Cart> => {
const { api } = ctx;
const { items } = props;
const cartId = getCartCookie(req.headers);

if (!cartId) {
throw new HttpError(400, "Missing cart cookie");
}

await api["POST /api/v2/carts/:cartId/items/bulk"]({ cartId }, {
body: {
items: items.map((item) => ({
sku: item.itemId,
quantity: item.quantity,
customizations: item.attributes
? Object.entries(item.attributes).map(([key, value]) => ({
[key]: value,
}))
: undefined,
})),
},
});

return cartLoader({}, req, ctx);
};

export default action;
18 changes: 10 additions & 8 deletions vnda/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// This file is automatically updated during development when running `dev.ts`.

import * as $$$$$$$$$0 from "./actions/cart/addItem.ts";
import * as $$$$$$$$$1 from "./actions/cart/simulation.ts";
import * as $$$$$$$$$2 from "./actions/cart/updateCart.ts";
import * as $$$$$$$$$3 from "./actions/cart/updateItem.ts";
import * as $$$$$$$$$4 from "./actions/notifyme.ts";
import * as $$$$$$$$$1 from "./actions/cart/addItems.ts";
import * as $$$$$$$$$2 from "./actions/cart/simulation.ts";
import * as $$$$$$$$$3 from "./actions/cart/updateCart.ts";
import * as $$$$$$$$$4 from "./actions/cart/updateItem.ts";
import * as $$$$$$$$$5 from "./actions/notifyme.ts";
import * as $$$$0 from "./handlers/sitemap.ts";
import * as $$$0 from "./loaders/cart.ts";
import * as $$$1 from "./loaders/extensions/price/list.ts";
Expand All @@ -33,10 +34,11 @@ const manifest = {
},
"actions": {
"vnda/actions/cart/addItem.ts": $$$$$$$$$0,
"vnda/actions/cart/simulation.ts": $$$$$$$$$1,
"vnda/actions/cart/updateCart.ts": $$$$$$$$$2,
"vnda/actions/cart/updateItem.ts": $$$$$$$$$3,
"vnda/actions/notifyme.ts": $$$$$$$$$4,
"vnda/actions/cart/addItems.ts": $$$$$$$$$1,
"vnda/actions/cart/simulation.ts": $$$$$$$$$2,
"vnda/actions/cart/updateCart.ts": $$$$$$$$$3,
"vnda/actions/cart/updateItem.ts": $$$$$$$$$4,
"vnda/actions/notifyme.ts": $$$$$$$$$5,
},
"name": "vnda",
"baseUrl": import.meta.url,
Expand Down
26 changes: 20 additions & 6 deletions vnda/utils/openapi/vnda.openapi.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,16 +1036,30 @@ store_coupon_code?: string
*/
"POST /api/v2/carts/:cartId/items/bulk": {
body: {
/**
* Itens do carrinho
*/
items?: {
/**
* Código SKU da variante do produto
*/
sku: string
/**
* Unidades do produto
*/
quantity: number
extra?: {

}
place_id?: number
/**
* Itens do carrinho
* [Personalização](http://ajuda.vnda.com.br/pt-BR/articles/1763398-funcionalidades-produtos-personalizados) do produto
*/
items?: any[][]
customizations?: {
/**
* Adicione a customização de acordo com a [personalização](http://ajuda.vnda.com.br/pt-BR/articles/1763398-funcionalidades-produtos-personalizados) incluídas no Admin da loja.
* Se por exemplo a customização do produto é a cor, o parâmetro para a requisição deve ser `Color` ao invés de `CUstomization`.
* Saiba mais sobre como utilizar esse parâmetro pelo exemplo de requsição localizado na seção de **Request Example** (ao lado do código da requisição).
*/
Customization?: string
}[]
}[]
minItems?: 0
}
response: CartItem[]
Expand Down
70 changes: 23 additions & 47 deletions vnda/utils/openapi/vnda.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5109,27 +5109,11 @@
"schema": {
"type": "object",
"properties": {
"sku": {
"type": "string"
},
"quantity": {
"type": "integer",
"minimum": 0,
"exclusiveMinimum": true
},
"extra": {
"type": "object"
},
"place_id": {
"type": "integer",
"minimum": 0,
"exclusiveMinimum": true
},
"items": {
"type": "array",
"description": "Itens do carrinho",
"items": {
"type": "array",
"type": "object",
"properties": {
"sku": {
"type": "string",
Expand All @@ -5156,39 +5140,31 @@
"sku",
"quantity"
]
},
"example": {
"itemcustomizado": {
"items": {
"value": [
{
"sku": "variante.sku1",
"quantity": 1,
"customizations": [
{
"Color": "Black"
}
]
},
{
"sku": "variante.sku2",
"quantity": 10,
"customizations": [
{
"Color": "Red"
}
]
}
]
}
}
}
}
},
"required": [
"sku",
"quantity"
]
"example": {
"items": [
{
"sku": "teste",
"quantity": 1,
"customizations": [
{
"Color": "Black"
}
]
},
{
"sku": "variante.sku2",
"quantity": 10,
"customizations": [
{
"Color": "Red"
}
]
}
]
}
}
}
}
Expand Down
Loading