Skip to content

Commit

Permalink
use the dynamic locale prop (#957)
Browse files Browse the repository at this point in the history
* create sales channel loaders

* remove unused props

* feat: use the dynamic locale prop

* fix: remove console.log

---------

Co-authored-by: guitavano <[email protected]>
  • Loading branch information
marcoferreiradev and guitavano authored Dec 3, 2024
1 parent 341e6c3 commit f0e4ca5
Show file tree
Hide file tree
Showing 12 changed files with 3,804 additions and 3,779 deletions.
11 changes: 11 additions & 0 deletions shopify/utils/storefront/storefront.graphql.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7789,6 +7789,17 @@ export type AddItemToCartMutationVariables = Exact<{

export type AddItemToCartMutation = { payload?: { cart?: { id: string, checkoutUrl: any, totalQuantity: number, lines: { nodes: Array<{ id: string, quantity: number, merchandise: { id: string, title: string, image?: { url: any, altText?: string | null } | null, product: { title: string, onlineStoreUrl?: any | null, handle: string }, price: { amount: any, currencyCode: CurrencyCode } }, discountAllocations: Array<{ code: string, discountedAmount: { amount: any, currencyCode: CurrencyCode } } | {}>, cost: { totalAmount: { amount: any, currencyCode: CurrencyCode }, subtotalAmount: { amount: any, currencyCode: CurrencyCode }, amountPerQuantity: { amount: any, currencyCode: CurrencyCode }, compareAtAmountPerQuantity?: { amount: any, currencyCode: CurrencyCode } | null } } | { id: string, quantity: number, merchandise: { id: string, title: string, image?: { url: any, altText?: string | null } | null, product: { title: string, onlineStoreUrl?: any | null, handle: string }, price: { amount: any, currencyCode: CurrencyCode } }, discountAllocations: Array<{ code: string, discountedAmount: { amount: any, currencyCode: CurrencyCode } } | {}>, cost: { totalAmount: { amount: any, currencyCode: CurrencyCode }, subtotalAmount: { amount: any, currencyCode: CurrencyCode }, amountPerQuantity: { amount: any, currencyCode: CurrencyCode }, compareAtAmountPerQuantity?: { amount: any, currencyCode: CurrencyCode } | null } }> }, cost: { totalTaxAmount?: { amount: any, currencyCode: CurrencyCode } | null, subtotalAmount: { amount: any, currencyCode: CurrencyCode }, totalAmount: { amount: any, currencyCode: CurrencyCode }, checkoutChargeAmount: { amount: any, currencyCode: CurrencyCode } }, discountCodes: Array<{ code: string, applicable: boolean }>, discountAllocations: Array<{ discountedAmount: { amount: any, currencyCode: CurrencyCode } } | { discountedAmount: { amount: any, currencyCode: CurrencyCode } } | { discountedAmount: { amount: any, currencyCode: CurrencyCode } }> } | null } | null };

export type RegisterAccountMutationVariables = Exact<{
email: Scalars['String']['input'];
password: Scalars['String']['input'];
firstName?: InputMaybe<Scalars['String']['input']>;
lastName?: InputMaybe<Scalars['String']['input']>;
acceptsMarketing?: InputMaybe<Scalars['Boolean']['input']>;
}>;


export type RegisterAccountMutation = { customerCreate?: { customer?: { id: string } | null, customerUserErrors: Array<{ code?: CustomerErrorCode | null, message: string }> } | null };

export type AddCouponMutationVariables = Exact<{
cartId: Scalars['ID']['input'];
discountCodes: Array<Scalars['String']['input']> | Scalars['String']['input'];
Expand Down
4 changes: 3 additions & 1 deletion vtex/loaders/intelligentSearch/productDetailsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const loader = async (
? slug?.toLowerCase()
: defaultPaths?.possiblePaths[0];
const segment = getSegmentFromBag(ctx);
const locale = segment?.payload?.cultureInfo ??
ctx.defaultSegment?.cultureInfo ?? "pt-BR";

const pageTypePromise = vcsDeprecated
["GET /api/catalog_system/pub/portal/pagetype/:term"](
Expand Down Expand Up @@ -90,7 +92,7 @@ const loader = async (
}

const facets = withDefaultFacets([], ctx);
const params = withDefaultParams({ query, count: 1 });
const params = withDefaultParams({ query, count: 1, locale });

const { products: [product] } = await vcsDeprecated
["GET /api/io/_v/api/intelligent-search/product_search/*facets"]({
Expand Down
4 changes: 3 additions & 1 deletion vtex/loaders/intelligentSearch/productList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ const loader = async (
const { vcsDeprecated } = ctx;
const { url } = req;
const segment = getSegmentFromBag(ctx);
const locale = segment?.payload?.cultureInfo ??
ctx.defaultSegment?.cultureInfo ?? "pt-BR";

const { selectedFacets, ...args } = fromProps({ props });
const params = withDefaultParams(args);
const params = withDefaultParams({ ...args, locale });
const facets = withDefaultFacets(selectedFacets, ctx);

const { products: vtexProducts } = await vcsDeprecated
Expand Down
5 changes: 4 additions & 1 deletion vtex/loaders/intelligentSearch/productListingPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ const loader = async (
if (!isInSeachFormat && !pathQuery) {
return null;
}
const params = withDefaultParams({ ...searchArgs, page });
const locale = segment?.payload?.cultureInfo ??
ctx.defaultSegment?.cultureInfo ?? "pt-BR";

const params = withDefaultParams({ ...searchArgs, page, locale });
// search products on VTEX. Feel free to change any of these parameters
const [productsResult, facetsResult] = await Promise.all([
vcsDeprecated
Expand Down
3 changes: 2 additions & 1 deletion vtex/loaders/intelligentSearch/suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ const loaders = async (
const { vcsDeprecated } = ctx;
const { url } = req;
const { count, query } = props;
const locale = "pt-BR"; // config!.defaultLocale; // TODO
const segment = getSegmentFromBag(ctx);
const locale = segment?.payload?.cultureInfo ??
ctx.defaultSegment?.cultureInfo ?? "pt-BR";

const suggestions = () =>
vcsDeprecated["GET /api/io/_v/api/intelligent-search/search_suggestions"]({
Expand Down
4 changes: 3 additions & 1 deletion vtex/loaders/intelligentSearch/topsearches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default async function (
_req: Request,
ctx: AppContext,
): Promise<Suggestion> {
const locale = "pt-BR"; // config!.defaultLocale; // TODO
const segment = getSegmentFromBag(ctx);
const locale = segment?.payload?.cultureInfo ??
ctx.defaultSegment?.cultureInfo ?? "pt-BR";

return await ctx.vcsDeprecated
["GET /api/io/_v/api/intelligent-search/top_searches"]({
Expand Down
22 changes: 22 additions & 0 deletions vtex/loaders/logistics/getSalesChannelById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { AppContext } from "../../mod.ts";
import { SalesChannel } from "../../utils/types.ts";

interface Props {
id: string;
}

export default async function loader(
props: Props,
_req: Request,
ctx: AppContext,
): Promise<SalesChannel> {
const { vcs } = ctx;

const salesChannel = await vcs
["GET /api/catalog_system/pub/saleschannel/:salesChannelId"]({
salesChannelId: props.id,
})
.then((r) => r.json());

return salesChannel;
}
16 changes: 16 additions & 0 deletions vtex/loaders/logistics/listSalesChannelById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { AppContext } from "../../mod.ts";
import { SalesChannel } from "../../utils/types.ts";

export default async function loader(
_props: unknown,
_req: Request,
ctx: AppContext,
): Promise<SalesChannel[]> {
const { vcs } = ctx;

const salesChannel = await vcs
["GET /api/catalog_system/pvt/saleschannel/list"]({})
.then((r) => r.json());

return salesChannel;
}
84 changes: 44 additions & 40 deletions vtex/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,28 @@ import * as $$$13 from "./loaders/legacy/productList.ts";
import * as $$$14 from "./loaders/legacy/productListingPage.ts";
import * as $$$15 from "./loaders/legacy/relatedProductsLoader.ts";
import * as $$$16 from "./loaders/legacy/suggestions.ts";
import * as $$$17 from "./loaders/logistics/listPickupPoints.ts";
import * as $$$18 from "./loaders/logistics/listPickupPointsByLocation.ts";
import * as $$$19 from "./loaders/logistics/listStockByStore.ts";
import * as $$$20 from "./loaders/masterdata/searchDocuments.ts";
import * as $$$21 from "./loaders/navbar.ts";
import * as $$$22 from "./loaders/options/productIdByTerm.ts";
import * as $$$23 from "./loaders/orders/list.ts";
import * as $$$24 from "./loaders/paths/PDPDefaultPath.ts";
import * as $$$25 from "./loaders/paths/PLPDefaultPath.ts";
import * as $$$26 from "./loaders/product/extend.ts";
import * as $$$27 from "./loaders/product/extensions/detailsPage.ts";
import * as $$$28 from "./loaders/product/extensions/list.ts";
import * as $$$29 from "./loaders/product/extensions/listingPage.ts";
import * as $$$30 from "./loaders/product/extensions/suggestions.ts";
import * as $$$31 from "./loaders/product/wishlist.ts";
import * as $$$32 from "./loaders/proxy.ts";
import * as $$$33 from "./loaders/user.ts";
import * as $$$34 from "./loaders/wishlist.ts";
import * as $$$35 from "./loaders/workflow/product.ts";
import * as $$$36 from "./loaders/workflow/products.ts";
import * as $$$17 from "./loaders/logistics/getSalesChannelById.ts";
import * as $$$18 from "./loaders/logistics/listPickupPoints.ts";
import * as $$$19 from "./loaders/logistics/listPickupPointsByLocation.ts";
import * as $$$20 from "./loaders/logistics/listSalesChannelById.ts";
import * as $$$21 from "./loaders/logistics/listStockByStore.ts";
import * as $$$22 from "./loaders/masterdata/searchDocuments.ts";
import * as $$$23 from "./loaders/navbar.ts";
import * as $$$24 from "./loaders/options/productIdByTerm.ts";
import * as $$$25 from "./loaders/orders/list.ts";
import * as $$$26 from "./loaders/paths/PDPDefaultPath.ts";
import * as $$$27 from "./loaders/paths/PLPDefaultPath.ts";
import * as $$$28 from "./loaders/product/extend.ts";
import * as $$$29 from "./loaders/product/extensions/detailsPage.ts";
import * as $$$30 from "./loaders/product/extensions/list.ts";
import * as $$$31 from "./loaders/product/extensions/listingPage.ts";
import * as $$$32 from "./loaders/product/extensions/suggestions.ts";
import * as $$$33 from "./loaders/product/wishlist.ts";
import * as $$$34 from "./loaders/proxy.ts";
import * as $$$35 from "./loaders/user.ts";
import * as $$$36 from "./loaders/wishlist.ts";
import * as $$$37 from "./loaders/workflow/product.ts";
import * as $$$38 from "./loaders/workflow/products.ts";
import * as $$$$$$0 from "./sections/Analytics/Vtex.tsx";
import * as $$$$$$$$$$0 from "./workflows/events.ts";
import * as $$$$$$$$$$1 from "./workflows/product/index.ts";
Expand All @@ -87,26 +89,28 @@ const manifest = {
"vtex/loaders/legacy/productListingPage.ts": $$$14,
"vtex/loaders/legacy/relatedProductsLoader.ts": $$$15,
"vtex/loaders/legacy/suggestions.ts": $$$16,
"vtex/loaders/logistics/listPickupPoints.ts": $$$17,
"vtex/loaders/logistics/listPickupPointsByLocation.ts": $$$18,
"vtex/loaders/logistics/listStockByStore.ts": $$$19,
"vtex/loaders/masterdata/searchDocuments.ts": $$$20,
"vtex/loaders/navbar.ts": $$$21,
"vtex/loaders/options/productIdByTerm.ts": $$$22,
"vtex/loaders/orders/list.ts": $$$23,
"vtex/loaders/paths/PDPDefaultPath.ts": $$$24,
"vtex/loaders/paths/PLPDefaultPath.ts": $$$25,
"vtex/loaders/product/extend.ts": $$$26,
"vtex/loaders/product/extensions/detailsPage.ts": $$$27,
"vtex/loaders/product/extensions/list.ts": $$$28,
"vtex/loaders/product/extensions/listingPage.ts": $$$29,
"vtex/loaders/product/extensions/suggestions.ts": $$$30,
"vtex/loaders/product/wishlist.ts": $$$31,
"vtex/loaders/proxy.ts": $$$32,
"vtex/loaders/user.ts": $$$33,
"vtex/loaders/wishlist.ts": $$$34,
"vtex/loaders/workflow/product.ts": $$$35,
"vtex/loaders/workflow/products.ts": $$$36,
"vtex/loaders/logistics/getSalesChannelById.ts": $$$17,
"vtex/loaders/logistics/listPickupPoints.ts": $$$18,
"vtex/loaders/logistics/listPickupPointsByLocation.ts": $$$19,
"vtex/loaders/logistics/listSalesChannelById.ts": $$$20,
"vtex/loaders/logistics/listStockByStore.ts": $$$21,
"vtex/loaders/masterdata/searchDocuments.ts": $$$22,
"vtex/loaders/navbar.ts": $$$23,
"vtex/loaders/options/productIdByTerm.ts": $$$24,
"vtex/loaders/orders/list.ts": $$$25,
"vtex/loaders/paths/PDPDefaultPath.ts": $$$26,
"vtex/loaders/paths/PLPDefaultPath.ts": $$$27,
"vtex/loaders/product/extend.ts": $$$28,
"vtex/loaders/product/extensions/detailsPage.ts": $$$29,
"vtex/loaders/product/extensions/list.ts": $$$30,
"vtex/loaders/product/extensions/listingPage.ts": $$$31,
"vtex/loaders/product/extensions/suggestions.ts": $$$32,
"vtex/loaders/product/wishlist.ts": $$$33,
"vtex/loaders/proxy.ts": $$$34,
"vtex/loaders/user.ts": $$$35,
"vtex/loaders/wishlist.ts": $$$36,
"vtex/loaders/workflow/product.ts": $$$37,
"vtex/loaders/workflow/products.ts": $$$38,
},
"handlers": {
"vtex/handlers/sitemap.ts": $$$$0,
Expand Down
3 changes: 2 additions & 1 deletion vtex/utils/intelligentSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ export const withDefaultParams = ({
count = 12,
sort = "",
fuzzy = "auto",
// locale,
locale = "pt-BR",
hideUnavailableItems,
}: Partial<Params>) => ({
page: page + 1,
count,
query,
sort,
fuzzy,
locale,
// locale: locale ?? ctx.configVTEX!.defaultLocale,
hideUnavailableItems: hideUnavailableItems ?? false,
});
Expand Down
Loading

0 comments on commit f0e4ca5

Please sign in to comment.