--- import type { ContentsDto } from "../data/internals/ContentsDtoT"; import type { Localized } from "../data/internals/LocalizedT"; import type { Product } from "../data/models/multis/Product"; import { getAssetById, getBrandsByIds, getMarketplacesByIds, getOffersByListingId } from "../data/api-client"; import path from "node:path"; import * as core from "../data/core/client"; import { renderMarkdown } from "../lib/rendering"; import { SCHEMAS } from "../data/models/schemas"; import type { Listing } from "../data/models/multis/Listing"; import type { Offer } from "../data/models/multis/Offer"; import type { Marketplace } from "../data/models/multis/Marketplace"; import ImageCarousel from "./ImageCarousel.astro"; import type { AmazonMarketplaceConnection } from "../data/models/components/AmazonMarketplaceConnection"; import { getSellersByIds } from "../data/api-client"; import { DateTime } from "luxon"; import type { Multilingual, SquidexEditable } from "./SharedProperties"; interface Props extends Multilingual, SquidexEditable { productDto: ContentsDto, } let category={ } as unknown as any;let site={ } as unknown as any const formatAsCurrency = (amount: number) => amount.toLocaleString(locale, { style: 'currency', currency: 'USD' }); const { productDto, editToken, locale } = Astro.props; const product = productDto.items[0].data!; let amazonConnectorSchemaId = (await core.client.schemas.getSchema({ schema: 'product-marketplace-connection-amazon' })).id; let brandDto = (await getBrandsByIds(product.brand.iv[0])); let possibleAmazonConnectors = product.marketplaceConnections.iv.filter((connection) => connection.connection.schemaId === amazonConnectorSchemaId); let amazonConnector = possibleAmazonConnectors.length > 0 ? possibleAmazonConnectors[0].connection as AmazonMarketplaceConnection : undefined; const listingsDto = await core.getContentsUsingJsonQuery(SCHEMAS.LISTINGS, JSON.stringify({ filter: { path: "data.product.iv", op: "eq", value: productDto.items[0].id, } })); const listingOffersDtos = listingsDto.items.map(async (listingDto) => await core.getContentsUsingJsonQuery(SCHEMAS.OFFERS, JSON.stringify({ filter: { path: "data.listing.iv", op: "eq", value: listingDto.id } }))); // listingsDto.items.forEach(async (listing) => { // let marketplaceId = listing.data?.marketplace.iv[0]!; // const marketplaceDto = await core.getContentsByIds(SCHEMAS.MARKETPLACES, marketplaceId); // const marketplace = marketplaceDto.items[0].data!; // pushDisclaimer({ renderedText: renderMarkdown(marketplace.disclaimer[locale]), marketplaceEditToken: marketplaceDto.items[0].editToken! }); // }); let productListingImages: string[] = []; for (let listingDto of listingsDto.items) { for (let assetId of listingDto.data?.marketplaceImages?.iv||[]) { let assetDto = await getAssetById(assetId); let assetUrl = path.posix.join('/img', assetDto.links['content'] .href .split('/') .reverse() .filter((_value, index, array) => index < (array.length - index - 2)) .reverse() .join('/')); productListingImages.push(assetUrl); } } let i18n: { [key: string]: Localized } = { 'Brand:': { 'en-US': "Brand:", 'es-US': "Marca :", 'fr-CA': "Marque :", }, 'New from': { 'en-US': "New from", 'es-US': "Nuevo desde", 'fr-CA': "Nouveau depuis", }, 'Used from': { 'en-US': "Used from", 'es-US': "Usado desde", 'fr-CA': "Utilisé depuis", }, 'on': { 'en-US': "on", 'es-US': "en", 'fr-CA': "sur", }, 'Price information updated as of': { 'en-US': "Price information updated as of", 'es-US': "Información de precio actualizada a partir de", 'fr-CA': "Information sur le prix mise à jour jusqu\'à", }, 'Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon.com at the time of purchase will apply to the purchase of this product.': { 'en-US': "Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon.com at the time of purchase will apply to the purchase of this product.", 'es-US': "Precios de los productos y disponibilidad son exactos a la fecha/hora indicada y están sujetos a cambios. Cualquier información sobre precios y disponibilidad que se muestre en Amazon.com al momento del pago se aplicará a la compra de este producto.", 'fr-CA': "Les prix des produits et la disponibilité sont exacts à la date/heure indiquée et peuvent varier. Toute information sur les prix et la disponibilité affichés sur Amazon.com au moment de l'achat s'appliqueront à l'achat de ce produit." } } ---
{ productListingImages.length == 1 && {product.productName[locale]} } { productListingImages.length > 1 && { return { src: productUrl }; } )||[]} /> }

{product?.productName[locale]}

{ brandDto && brandDto.items.length && // }

{ product?.description && }