-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy Loading for Prices #201
Open
htuzel
wants to merge
42
commits into
develop
Choose a base branch
from
poc/promotional-prices
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 39 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
e4b9a79
feat: Add promotionalPrices attribute to Algolia product configuration
htuzel 6dc76de
Logic changed for indexing promo end date and start date.
htuzel 1371dba
feat: Remove unnecessary start and end date fields in promotionalPrices
htuzel 91b3440
Improved logic
htuzel 731dfb1
Lazy load and refactoring for promotional prices
htuzel f442ad6
linter errors
htuzel 4d7c720
unit test mockups
htuzel 53ab58e
small refactoring for name convention
htuzel 822fced
small refactorings
htuzel caf44d7
promotions
htuzel 268c995
Prevented duplicate price fetching and double update issue
htuzel c69bf86
removed console.log
htuzel 6e8c05f
Some refactorings
htuzel 9747efe
rulebased promotion logic removed
htuzel ea60034
Update cartridges/bm_algolia/cartridge/templates/resources/algolia.pr…
htuzel e370584
Update cartridges/int_algolia/cartridge/scripts/algolia/model/algolia…
htuzel 42b4126
removed unnecessery imports
htuzel 0e6eef7
som eimprovements
htuzel 9919e16
linter fix
htuzel 869aee8
Lazy load logic is improved
htuzel b0f9b8a
lazy load reverted
htuzel 96d9519
lazy load remaining parts & refactoring
htuzel f97107f
Update cartridges/int_algolia/cartridge/scripts/algolia/model/algolia…
htuzel 66018c9
CR fixes
htuzel 3a6a018
Merge branch 'poc/promotional-prices' of https://github.com/algolia/a…
htuzel 5cfe908
Update cartridges/int_algolia_sfra/cartridge/static/default/js/algoli…
htuzel 79e8745
Merge branch 'develop' into poc/promotional-prices
htuzel 475bdf8
Fixed linter errors and made some improvements
htuzel aa8b4b0
Updated code according to reviews
htuzel 7220478
Revert "lazy load reverted"
htuzel 362a97d
Revert "lazy load remaining parts & refactoring"
htuzel 5753b66
Merge branch 'develop' into poc/promotional-prices
htuzel f49695b
Fixed typo for preference name
htuzel 592363a
Removed console log
htuzel 09eae82
Fixed Constant value
htuzel 923799c
Removed unneccesery comment
htuzel 0594fa7
Apply suggestions from code review
htuzel 6bdb32d
Refactoring for reviews
htuzel 8ac0263
Removed unnecessery file
htuzel 1321415
Improved list price logic according to defaul behaviour of cartridge
htuzel 6d7f657
Refactoring for getPriceHTML function
htuzel 5bb400a
fixed linter errors
htuzel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
cartridges/int_algolia_sfra/cartridge/controllers/Algolia.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict'; | ||
|
||
var server = require('server'); | ||
|
||
var cache = require('*/cartridge/scripts/middleware/cache'); | ||
|
||
server.get('Price', cache.applyShortPromotionSensitiveCache, function (req, res, next) { | ||
var PromotionMgr = require('dw/campaign/PromotionMgr'); | ||
var ProductMgr = require('dw/catalog/ProductMgr'); | ||
var ProductFactory = require('*/cartridge/scripts/factories/product'); | ||
|
||
var params = req.querystring; | ||
var productIds = params.pids; | ||
var productIdsArr = productIds.split(','); | ||
|
||
var productsArr = []; | ||
for (var i = 0; i < productIdsArr.length; i++) { | ||
var product = ProductFactory.get( | ||
{ | ||
pid: productIdsArr[i] | ||
} | ||
); | ||
|
||
//find the minimum price and the promotion | ||
var minPrice = Number.MAX_VALUE; | ||
var activePromotion = null; | ||
|
||
var promotions = product.promotions || []; | ||
var apiProduct = ProductMgr.getProduct(product.id); | ||
|
||
for (var j = 0; j < promotions.length; j++) { | ||
var promotion = promotions[j] | ||
var apiPromotion = PromotionMgr.getPromotion(promotion.id); | ||
var promotionPrice = apiPromotion.getPromotionalPrice(apiProduct); | ||
|
||
if (promotionPrice.value && promotionPrice.value < minPrice ) { | ||
minPrice = promotionPrice.value; | ||
activePromotion = promotion; | ||
} | ||
} | ||
|
||
if (activePromotion) { | ||
product.activePromotion = { | ||
price: minPrice, | ||
promotion: activePromotion | ||
}; | ||
} | ||
|
||
productsArr.push(product); | ||
} | ||
|
||
res.json({ | ||
products : productsArr | ||
}); | ||
next(); | ||
}); | ||
|
||
module.exports = server.exports(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,5 +153,4 @@ | |
</attribute-group> | ||
</group-definitions> | ||
</custom-type> | ||
|
||
</metadata> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -200,6 +200,14 @@ Setting this preference replaces the first two segments, the final index name be | |||||
<default-value>false</default-value> | ||||||
</attribute-definition> | ||||||
|
||||||
<attribute-definition attribute-id="Algolia_EnablePricingLazyLoad"> | ||||||
<display-name xml:lang="x-default">Enables Pricing Lazy Load</display-name> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<description xml:lang="x-default">It fetches prices from SFCC not Algolia</description> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<type>boolean</type> | ||||||
<mandatory-flag>false</mandatory-flag> | ||||||
<externally-managed-flag>false</externally-managed-flag> | ||||||
</attribute-definition> | ||||||
|
||||||
<attribute-definition attribute-id="Algolia_EnableSSR"> | ||||||
<display-name xml:lang="x-default">Enable SSR</display-name> | ||||||
<description xml:lang="x-default">Enables server-side rendering for CLP search results. Helps with SEO as CLP pages are no longer rendered with empty containers that are to be filled by client-side code, but increases page load times a tiny bit (which can be countered with page caching).</description> | ||||||
|
@@ -265,6 +273,7 @@ Setting this preference replaces the first two segments, the final index name be | |||||
<attribute attribute-id="Algolia_EnableSSR"/> | ||||||
<attribute attribute-id="Algolia_EnableContentSearch"/> | ||||||
<attribute attribute-id="Algolia_EnableRecommend"/> | ||||||
<attribute attribute-id="Algolia_EnablePricingLazyLoad"/> | ||||||
</attribute-group> | ||||||
</group-definitions> | ||||||
|
||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure all this is needed? You are using the ProductFactory, which already sets the best active promotion in the
sales
price: https://github.com/SalesforceCommerceCloud/storefront-reference-architecture/blob/3a99a7990e70756eb21b775c73e7680a984be0d3/cartridges/app_storefront_base/cartridge/scripts/factories/price.js#L84I've debugged and I confirm that I see the promotion price.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But in this case, we don't know which promotion is applied for this price. There may be multiple promotions, and we need to know which promotion is causing this price and display call out message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SFRA systematically uses the first promotion: https://github.com/SalesforceCommerceCloud/storefront-reference-architecture/blob/3a99a7990e70756eb21b775c73e7680a984be0d3/cartridges/app_storefront_base/cartridge/scripts/helpers/pricing.js#L46
So we actually know. But this is an good reason to compute it ourselves, as technically there could be a better price than the one present in the
sales
price.