Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
38 changes: 33 additions & 5 deletions transformers/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,28 @@ function transformVariantValues(masterSku, variationValues) {
}

/**
* Transforms a Salesforce product to an ACO product.
* Builds the bundles array for an ACO parent bundle product.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the comment for transformProduct was removed during this update. Can you add it back?

*
* @param {SalesforceProduct} product - The Salesforce product.
* @returns {import('@adobe-commerce/aco-ts-sdk').FeedProduct} The ACO product.
* @param {{ id: string; name: string; quantity: number }[]} bundledProducts - Array of bundled product objects
* @returns {object[]} Array of bundle group objects for ACO
*/
function buildAcoBundles(bundledProducts) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use const arrow functions instead of the function syntax. Right now this file has a mix of both and we should standardize.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standarized to const

if (!Array.isArray(bundledProducts) || bundledProducts.length === 0) return [];
return bundledProducts.map(bp => ({
group: bp.name,
required: true,
multiSelect: false,
defaultItemSkus: [bp.id],
items: [
{
sku: bp.id,
qty: bp.quantity,
userDefinedQty: false,
},
],
}));
}

const transformProduct = product => {
const acoProduct = {
sku: product.id,
Expand Down Expand Up @@ -166,7 +183,6 @@ const transformProduct = product => {
...transformCustomAttributes(product.customAttributes),
],
images: transformImages(product.images),
// TODO: Add bundle product support
};

//add configurations
Expand All @@ -182,11 +198,23 @@ const transformProduct = product => {
sku: masterSku,
},
];

//attributes
acoProduct.attributes.push(...transformVariantValues(masterSku, product.variationValues));
}

// Handle parent bundle product (type BUNDLE) using correct bundles array structure
if (product.type === 'BUNDLE' && Array.isArray(product.bundledProducts) && product.bundledProducts.length > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you can just do this:

if (product.type === 'BUNDLE' && product.bundledProducts?.length)

acoProduct.bundles = buildAcoBundles(product.bundledProducts);
}

// Handle bundled products (child) for BUNDLED type
if (product.type === 'BUNDLED' && Array.isArray(product.bundles) && product.bundles.length > 0) {
acoProduct.links = product.bundles.map(bundleSku => ({
type: 'in_bundle',
sku: bundleSku,
}));
}

// @ts-ignore
return acoProduct;
};
Expand Down
8 changes: 8 additions & 0 deletions types/salesforce.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ declare interface SalesforceProduct {
variants?: SalesforceProductVariant[];
variationValues?: SalesforceProductVariationValues;
master?: SalesforceProductMaster;
bundles?: string[]; // Array of bundled product IDs for BUNDLE type
bundledProducts?: BundledProduct[]; // Array of bundled products with details for a parent bundle product
}

declare interface SalesforceProductPrice {
Expand Down Expand Up @@ -164,3 +166,9 @@ declare interface SalesforceProductVariationValues {
declare interface SalesforceProductMaster {
id: string;
}

declare interface BundledProduct {
id: string;
name: string;
quantity: number;
}