fix: product component needed fix due to breaking api change
This commit is contained in:
parent
dbac314256
commit
8e64c8a8b1
|
@ -1,5 +1,5 @@
|
|||
import type { Command } from "commander";
|
||||
import { askAiProductSubCategoryEvalQuestionsSet1, askAiProductSubCategoryEvalQuestionsSet2, askAiTopLevelProductCategoryEvalQuestions, generateAIProductDescription, generateAITagsForProduct, getAddNewBrandDtoByName, getAddNewOfferDto, getAddNewProductDtoByProduct, getAddNewProductListingDtoByProduct, getAddNewProductSubCategoryDto, getAddNewSellerDtoByName, getAllAssetsInFolder, getAllTopLevelProductCategories, getAmazonMarketplaceConnectionSchemaDto, getAmazonMarketplaceDto, getBrandDtoByName, getMarketplaceConnectionSchemaDto, getSellerDtoByName, isValidASIN, lookupAmazonASINs, removeQuotes, translateAmazonDescription_from_en_US_to_es_US, translateAmazonDescription_from_en_US_to_fr_CA, translateProductDescription_from_en_US_to_es_US, translateProductDescription_from_en_US_to_fr_CA, translateProductName_from_en_US_to_es_US, translateProductName_from_en_US_to_fr_CA, translateTags_from_en_US_to_es_US, translateTags_from_en_US_to_fr_CA, trimPeriods, uploadDownloadedImageToSquidexAsAsset, upsertAssetFolder } from "../common/catalog-helpers";
|
||||
import { askAiProductSubCategoryEvalQuestionsSet1, askAiProductSubCategoryEvalQuestionsSet2, askAiTopLevelProductCategoryEvalQuestions, doesProductAlreadyExist, generateAIProductDescription, generateAITagsForProduct, getAddNewBrandDtoByName, getAddNewOfferDto, getAddNewProductDtoByProduct, getAddNewProductListingDtoByProduct, getAddNewProductSubCategoryDto, getAddNewSellerDtoByName, getAllAssetsInFolder, getAllTopLevelProductCategories, getAmazonMarketplaceConnectionSchemaDto, getAmazonMarketplaceDto, getBrandDtoByName, getMarketplaceConnectionSchemaDto, getSellerDtoByName, isValidASIN, lookupAmazonASINs, removeQuotes, translateAmazonDescription_from_en_US_to_es_US, translateAmazonDescription_from_en_US_to_fr_CA, translateProductDescription_from_en_US_to_es_US, translateProductDescription_from_en_US_to_fr_CA, translateProductName_from_en_US_to_es_US, translateProductName_from_en_US_to_fr_CA, translateTags_from_en_US_to_es_US, translateTags_from_en_US_to_fr_CA, trimPeriods, uploadDownloadedImageToSquidexAsAsset, upsertAssetFolder } from "../common/catalog-helpers";
|
||||
import type { Localized } from "../../../data/internals/LocalizedT";
|
||||
import type { NonLocalized } from "../../../data/internals/NonLocalizedT";
|
||||
import { getProductCategoriesByIds, performSyncLocalizedSlugs } from "../../../data/api-client";
|
||||
|
@ -51,13 +51,13 @@ export const amazonProcureASINsCommand = (amazonCommand: Command) => {
|
|||
|
||||
apiResponse.ItemsResult!.Items!.forEach(async (amazonItem) => {
|
||||
let asin = amazonItem.ASIN!;
|
||||
log(`Mock data override: product enrollment is for ASIN ${asin}.`);
|
||||
// log(`Mock data override: product enrollment is for ASIN ${asin}.`);
|
||||
|
||||
// enable this if we're saving data:
|
||||
// if (await doesProductAlreadyExist(asin)) {
|
||||
// error(`error: Product with ASIN already exists in the application.`);
|
||||
// return;
|
||||
// }
|
||||
if (await doesProductAlreadyExist(asin)) {
|
||||
error(`error: Product with ASIN already exists in the application.`);
|
||||
return;
|
||||
}
|
||||
|
||||
log(`Amazon PA API Response contains ASIN: ${asin}.`);
|
||||
const amazonProductName_en_US = amazonItem.ItemInfo?.Title?.DisplayValue!;
|
||||
|
|
|
@ -477,14 +477,11 @@ export async function getAllAssetsInFolder(assetFolderId: string) {
|
|||
|
||||
export async function uploadDownloadedImageToSquidexAsAsset(downloadUrl: string, assetFolderId: string) {
|
||||
let url = new URL(downloadUrl);
|
||||
let filename = url.pathname.substring(downloadUrl.lastIndexOf('/')+1);//.replace(/[A-Z0-9\.-_]*, '$0');
|
||||
let response = await axios.get(downloadUrl, { timeout: TIMEOUT_IN_SECONDS * 1000, responseType: 'arraybuffer' });
|
||||
let blob = new Blob(response.data, {type: mimeLookup(filename) as string});
|
||||
let form = new FormData();
|
||||
form.append('fileName', filename);
|
||||
form.append('file', blob, filename);
|
||||
form.append('parentId', assetFolderId);
|
||||
let assetDto = await client.assets.postAsset({ file: blob, name: filename, url: filename, parentId: assetFolderId }, { body: form });
|
||||
let filename = url.pathname.substring(url.pathname.lastIndexOf('/')+1);
|
||||
let res = await fetch(downloadUrl);
|
||||
let ab = await res.arrayBuffer();
|
||||
let file = new File([ab], filename, { type: mimeLookup(filename) as string });
|
||||
let assetDto = await client.assets.postAsset({ file, parentId: assetFolderId });
|
||||
assetDto = await client.assets.putAsset(assetDto.id, { metadata: { ...assetDto.metadata, 'amazon-url': downloadUrl }, tags: ['amazon', 'product'] });
|
||||
return assetDto;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ const formatAsCurrency = (amount: number) => amount.toLocaleString(locale, { sty
|
|||
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 amazonConnectorSchemaId = (await core.client.schemas.getSchema('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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user