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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function isOnline(product) {
if (config.includeOfflineProducts === true) {
return true;
}
return product.online;
return product.isOnline();
}

/**
Expand All @@ -36,7 +36,7 @@ function isSearchable(product) {
if (config.includeNotSearchableProducts === true) {
return true;
}
return product.searchable;
return product.isSearchable();
}

/**
Expand Down Expand Up @@ -65,7 +65,10 @@ function isInclude(product) {
// Do not include Option products
// if (product.optionProduct) return false;
// Do not include bundled product
if (product.bundled && !(product.priceModel && product.priceModel.price && product.priceModel.price.available)) return false;
if (product.isBundled()) {
var priceModel = product.getPriceModel();
if (!(priceModel && priceModel.getPrice() && priceModel.getPrice().isAvailable())) return false;
}

// Check online status
if (!isOnline(product)) return false;
Expand Down Expand Up @@ -100,7 +103,7 @@ function isInStock(product, threshold) {

// even if one variant is in stock, we consider the product as in stock
if (product.isMaster() || product.isVariationGroup()) {
const variantsIt = product.variants.iterator();
const variantsIt = product.getVariants().iterator();

while (variantsIt.hasNext()) {
let variant = variantsIt.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,13 @@ function generateAttributeSlicedRecords(parameters) {
let variationModel = parameters.baseProduct.getVariationModel();
let variationAttribute = variationModel.getProductVariationAttribute(parameters.variationAttributeID);
if (!variationAttribute) {
algoliaLogger.info('No ' + parameters.variationAttributeID + ' attribute found for product ' + parameters.baseProduct.ID);
algoliaLogger.info('No ' + parameters.variationAttributeID + ' attribute found for product ' + parameters.baseProduct.getID());
return algoliaRecordsPerLocale;
}
let variationValues = variationModel.getAllValues(variationAttribute).iterator();
while (variationValues.hasNext()) {
let variationValue = variationValues.next();
variationModel.setSelectedAttributeValue(variationAttribute.ID, variationValue.ID);
variationModel.setSelectedAttributeValue(variationAttribute.getID(), variationValue.getID());
let baseModel = new AlgoliaLocalizedProduct({
product: parameters.baseProduct,
locale: 'default',
Expand All @@ -766,7 +766,7 @@ function generateAttributeSlicedRecords(parameters) {
variantAttributes: parameters.variantAttributes,
baseModel: baseModel,
variationModel: variationModel,
variationValueID: variationValue.ID,
variationValueID: variationValue.getID(),
});
algoliaRecordsPerLocale[locale].push(localizedVariationGroup);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getColorVariations(product, locale) {
);
if (!hasOrderableVariants) {
logger.info(
'Product ' + product.ID + ' has no orderable variant for color ' + colorValue.value
'Product ' + product.getID() + ' has no orderable variant for color ' + colorValue.getValue()
);
continue;
}
Expand All @@ -46,15 +46,15 @@ function getColorVariations(product, locale) {
variationURL: URLUtils.url(
'Product-Show',
'pid',
product.ID,
product.getID(),
variationModel.getHtmlName(colorVariationAttribute), // returns 'dwvar_' + product.ID + '_color',
colorValue.value
colorValue.getValue()
).toString(),
color: colorValue.displayValue,
color: colorValue.getDisplayValue(),
};

if (IS_PWA) {
variationObject.colorCode = colorValue.value; // Required to create product detail page URL in PWA
variationObject.colorCode = colorValue.getValue(); // Required to create product detail page URL in PWA
}

colorVariations.push(variationObject);
Expand All @@ -73,7 +73,7 @@ function getColorVariations(product, locale) {
function getColorVariationImagesGroup(variationModel, colorAttributeValue) {
var imageGroupsArr = [];

variationModel.setSelectedAttributeValue('color', colorAttributeValue.ID);
variationModel.setSelectedAttributeValue('color', colorAttributeValue.getID());

['large', 'small', 'swatch'].forEach(function (viewtype) {
var imagesList = variationModel.getImages(viewtype);
Expand Down Expand Up @@ -111,9 +111,10 @@ function getImageGroups(imagesList, viewtype) {
title: {},
};

image.alt = imagesList[i].alt;
image.dis_base_link = imagesList[i].absURL.toString();
image.title = imagesList[i].title;
var mediaFile = imagesList.get(i);
image.alt = mediaFile.getAlt();
image.dis_base_link = mediaFile.getAbsURL().toString();
image.title = mediaFile.getTitle();

result.images.push(image);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getCategoryUrl(category) {
* @returns {string} - Final ID of the category
*/
function getCategoryId(catalogId, category) {
return catalogId + '/' + category.ID;
return catalogId + '/' + category.getID();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function getPromotionalPrice(product) {
// find the lowest price
if (promoPrices.length > 0) {
lowestPromoPrice = promoPrices.reduce(function (a, b) {
return Math.min(a.value, b.value);
return a.getValue() <= b.getValue() ? a : b;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The original code typecast the Money object into a number, which can lead to issues downstream (e.g. when trying to call .getValue() or .getCurrencyCode() on it).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

good catch 👍

});
}
return lowestPromoPrice;
Expand Down Expand Up @@ -109,7 +109,7 @@ function getPromotionalPrices(product, campaigns) {
if (price === dw.value.Money.NOT_AVAILABLE) {
return null;
}
let promoId = promotion.ID;
let promoId = promotion.getID();
return {
price: price.getValue(),
promoId: promoId
Expand Down Expand Up @@ -244,7 +244,7 @@ var aggregatedValueHandlers = {
},
defaultVariantID: function(product) {
const defaultVariant = product.getVariationModel().getDefaultVariant();
return defaultVariant ? defaultVariant.ID : null;
return defaultVariant ? defaultVariant.getID() : null;
},
categories: function (product) {
var productCategories = product.getOnlineCategories();
Expand Down Expand Up @@ -279,19 +279,19 @@ var aggregatedValueHandlers = {
},
primary_category_id: function (product) {
var result = null;
if (empty(product.primaryCategory)) {
if (empty(product.getPrimaryCategory())) {
var primaryCategory = product.isVariant() ? product.getMasterProduct().getPrimaryCategory() : null;
result = empty(primaryCategory) ? null : primaryCategory.ID;
result = empty(primaryCategory) ? null : primaryCategory.getID();
} else {
result = product.getPrimaryCategory().getID();
}
return result;
},
__primary_category: function (product) {
var res = {};
var primaryCategory = product.primaryCategory;
var primaryCategory = product.getPrimaryCategory();
if (empty(primaryCategory)) {
primaryCategory = product.isVariant() ? product.masterProduct.primaryCategory : null;
primaryCategory = product.isVariant() ? product.getMasterProduct().getPrimaryCategory() : null;
if (empty(primaryCategory)) {
return null;
}
Expand All @@ -306,7 +306,7 @@ var aggregatedValueHandlers = {
var variationModel = parameters.variationModel || product.getVariationModel();
var colorAttribute = variationModel.getProductVariationAttribute('color');
return (colorAttribute && variationModel.getSelectedValue(colorAttribute))
? variationModel.getSelectedValue(colorAttribute).displayValue
? variationModel.getSelectedValue(colorAttribute).getDisplayValue()
: product.custom.color; // this is a workaround to retrieve color values which are otherwise not returned properly by the API via the variation model, likely due to an SFCC bug. It either returns the color value that `getSelectedValue()` couldn't or `null` as before.

},
Expand All @@ -319,7 +319,7 @@ var aggregatedValueHandlers = {
if (product.isMaster() || product.isVariationGroup()) {
return modelHelper.getColorVariations(product);
}
const masterProduct = product.getVariationModel().master;
const masterProduct = product.getVariationModel().getMaster();
if (!masterProduct) {
return null;
}
Expand All @@ -329,7 +329,7 @@ var aggregatedValueHandlers = {
var variationModel = parameters.variationModel || product.getVariationModel();
var sizeAttribute = variationModel.getProductVariationAttribute('size');
return (sizeAttribute && variationModel.getSelectedValue(sizeAttribute))
? variationModel.getSelectedValue(sizeAttribute).displayValue
? variationModel.getSelectedValue(sizeAttribute).getDisplayValue()
: product.custom.size; // this is a workaround to retrieve size values which are otherwise not returned properly by the API via the variation model, likely due to an SFCC bug. It either returns the size value that `getSelectedValue()` couldn't or `null` as before.
},
refinementSize: function (product) {
Expand All @@ -346,12 +346,12 @@ var aggregatedValueHandlers = {
var currentCurrency = currentSession.getCurrency();

for (var k = 0; k < siteCurrenciesSize; k += 1) {
var currency = Currency.getCurrency(siteCurrencies[k]);
var currency = Currency.getCurrency(siteCurrencies.get(k));
currentSession.setCurrency(currency);
var price = product.productSet ? product.priceModel.minPrice : product.priceModel.price;
if (price.available) {
var price = product.isProductSet() ? product.getPriceModel().getMinPrice() : product.getPriceModel().getPrice();
if (price.isAvailable()) {
if (!productPrice) { productPrice = {}; }
productPrice[price.currencyCode] = price.value;
productPrice[price.getCurrencyCode()] = price.getValue();
}
}
currentSession.setCurrency(currentCurrency);
Expand All @@ -364,19 +364,22 @@ var aggregatedValueHandlers = {

while (sitePriceBooks.hasNext()) {
var pricebook = sitePriceBooks.next();
if (siteCurrencies.indexOf(pricebook.currencyCode) < 0) {
var pricebookCurrencyCode = pricebook.getCurrencyCode();
if (siteCurrencies.indexOf(pricebookCurrencyCode) < 0) {
continue;
}
var priceInfo = product.priceModel.getPriceBookPriceInfo(pricebook.ID);
var priceInfo = product.getPriceModel().getPriceBookPriceInfo(pricebook.getID());
if (priceInfo) {
if (!pricebooks[pricebook.currencyCode]) {
pricebooks[pricebook.currencyCode] = [];
if (!pricebooks[pricebookCurrencyCode]) {
pricebooks[pricebookCurrencyCode] = [];
}
pricebooks[pricebook.currencyCode].push({
price: priceInfo.price.value,
onlineFrom: priceInfo.onlineFrom ? priceInfo.onlineFrom.getTime() : undefined,
onlineTo: priceInfo.onlineTo ? priceInfo.onlineTo.getTime() : undefined,
pricebookID: pricebook.ID,
var onlineFrom = priceInfo.getOnlineFrom();
var onlineTo = priceInfo.getOnlineTo();
pricebooks[pricebookCurrencyCode].push({
price: priceInfo.getPrice().getValue(),
onlineFrom: onlineFrom ? onlineFrom.getTime() : undefined,
onlineTo: onlineTo ? onlineTo.getTime() : undefined,
pricebookID: pricebook.getID(),
});
}
}
Expand Down Expand Up @@ -416,7 +419,7 @@ var aggregatedValueHandlers = {
},
url: function (product) {
// Get product page url for the current locale
var productPageUrl = URLUtils.url('Product-Show', 'pid', product.ID);
var productPageUrl = URLUtils.url('Product-Show', 'pid', product.getID());
return productPageUrl ? productPageUrl.toString() : null;
},
promotionalPrice: function (product) {
Expand All @@ -428,7 +431,7 @@ var aggregatedValueHandlers = {
var currentCurrency = currentSession.getCurrency();

for (var k = 0; k < siteCurrenciesSize; k += 1) {
var currency = Currency.getCurrency(siteCurrencies[k]);
var currency = Currency.getCurrency(siteCurrencies.get(k));
currentSession.setCurrency(currency);
var price = getPromotionalPrice(product);
if (price) {
Expand All @@ -448,13 +451,13 @@ var aggregatedValueHandlers = {
var currentCurrency = currentSession.getCurrency();
var campaigns = PromotionMgr.getCampaigns().toArray();
for (var k = 0; k < siteCurrenciesSize; k += 1) {
var currency = Currency.getCurrency(siteCurrencies[k]);
var currency = Currency.getCurrency(siteCurrencies.get(k));
currentSession.setCurrency(currency);
var promotionObjects = getPromotionalPrices(product, campaigns);

if (promotionObjects.length > 0) {
if (!promotionalPrices) { promotionalPrices = {}; }
promotionalPrices[siteCurrencies[k]] = promotionObjects;
promotionalPrices[siteCurrencies.get(k)] = promotionObjects;
}
}
currentSession.setCurrency(currentCurrency);
Expand All @@ -469,7 +472,7 @@ var aggregatedValueHandlers = {
if (parameters.variationModel) {
variantsIt = parameters.variationModel.getSelectedVariants().iterator();
} else {
variantsIt = product.variants.iterator();
variantsIt = product.getVariants().iterator();
}

while (variantsIt.hasNext()) {
Expand Down Expand Up @@ -512,7 +515,7 @@ var aggregatedValueHandlers = {
}
},
_tags: function(product) {
return ['id:' + product.ID];
return ['id:' + product.getID()];
},
storeAvailability: function(product) {
var storeArray = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ function getProductType(product) {
function getAppropriateProduct(product, recordModel) {
const productType = getProductType(product);
if (recordModel === RECORD_MODEL_TYPES.MASTER_LEVEL && productType !== 'Master') {
return product.masterProduct; // @TODO: refactor to be safer: only Variants and Variation Groups have the `masterProduct` property, add checks
return product.getMasterProduct(); // @TODO: refactor to be safer: only Variants and Variation Groups have the `masterProduct` property, add checks
} else if (recordModel === RECORD_MODEL_TYPES.MASTER_LEVEL && (productType === 'Master' || productType === 'Variation Group')) {
return product;
} else if (recordModel !== RECORD_MODEL_TYPES.MASTER_LEVEL && (productType === 'Master' || productType === 'Variation Group')) {
return product.variationModel.defaultVariant;
return product.getVariationModel().getDefaultVariant();
} else if (recordModel !== RECORD_MODEL_TYPES.MASTER_LEVEL && productType === 'Variant') {
return product;
}
Expand All @@ -51,7 +51,7 @@ function getAnchorProductIDs(slotcontent) {
} else {
for (let i = 0; i < slotcontent.content.length; i++) {
let product = slotcontent.content[i];
productIDs.push(product.ID);
productIDs.push(product.getID());
}
}

Expand All @@ -71,7 +71,7 @@ function getAnchorProductIDs(slotcontent) {
var appropriateProduct = getAppropriateProduct(product, recordModel);

if (appropriateProduct) {
anchorProductIDsArr.push(appropriateProduct.ID);
anchorProductIDsArr.push(appropriateProduct.getID());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ exports.process = function(content, parameters, stepExecution) {
var baseModel = new AlgoliaLocalizedContent({ content: content, locale: 'default', attributeList: nonLocalizedAttributes, includedContent: includedContent });

for (let l = 0; l < siteLocales.size(); ++l) {
var locale = siteLocales[l];
var locale = siteLocales.get(l);
var indexName = jobHelper.toTmp(algoliaData.calculateIndexName('contents', locale));
let localizedContent = new AlgoliaLocalizedContent({ content: content, locale: locale, attributeList: attributesToSend, baseModel: baseModel, includedContent: includedContent });
let splits = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ exports.process = function(cpObj, parameters, stepExecution) {
// This variant will be processed when we handle its master product, skip it for now.
return [];
}
if (product.master) {
if (product.isMaster()) {
let inStock = productFilter.isInStock(product, ALGOLIA_IN_STOCK_THRESHOLD);

if ((inStock || INDEX_OUT_OF_STOCK) &&
Expand Down Expand Up @@ -417,13 +417,13 @@ exports.process = function(cpObj, parameters, stepExecution) {
return [];
}

if (product.master) {
if (product.isMaster()) {
let variationModel = product.getVariationModel();
let variationAttribute = variationModel.getProductVariationAttribute(variationAttributeForAttributeSlicedRecordModel);

// masters that DON'T have the specified variation attribute -- treat them as regular masters
if (!variationAttribute) {
logger.info('Specified variation attribute "' + variationAttributeForAttributeSlicedRecordModel + '" not found for master product "' + product.ID + '", falling back to master-type record.');
logger.info('Specified variation attribute "' + variationAttributeForAttributeSlicedRecordModel + '" not found for master product "' + product.getID() + '", falling back to master-type record.');

let inStock = productFilter.isInStock(product, ALGOLIA_IN_STOCK_THRESHOLD);

Expand Down Expand Up @@ -528,7 +528,7 @@ exports.process = function(cpObj, parameters, stepExecution) {
});

// Check if we need a delete operation because of product filter because delta jobs are record updates not a full reindex
let variants = product.variants;
let variants = product.getVariants();
if (variants && variants.size() > 0) {
for (let v = 0; v < variants.size(); ++v) {
let variant = variants[v];
Expand Down
Loading
Loading