-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: added pricebook support for variants and product level records #208
Open
htuzel
wants to merge
6
commits into
develop
Choose a base branch
from
feat/SFCC-299
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 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d167ec
feat: added pricebook support for variants and product level records
htuzel 483a3e3
refactor: Code made more modular
htuzel ef82b4b
Merge branch 'develop' into feat/SFCC-299
htuzel e442320
fix: price book online check logic put back
htuzel 10fa545
Merge branch 'feat/SFCC-299' of https://github.com/algolia/algoliasea…
htuzel fd736da
revert: Caused some issues and put some logic back
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,9 +287,9 @@ function enableInstantSearch(config) { | |
<div class="price"> | ||
${isPricingLazyLoad && html`<span class="price-placeholder" data-product-id="${productId}"></span>`} | ||
${!isPricingLazyLoad && html` | ||
${ (hit.displayPrice < hit.price || (hit.promotionalPrice && hit.promotionalPrice < hit.price)) && html` | ||
${ (hit.displayPrice < hit.price || (hit.promotionalPrice && hit.promotionalPrice < hit.price) || (hit.highestPriceBookPrice && hit.highestPriceBookPrice > hit.displayPrice)) && html` | ||
<span class="strike-through list"> | ||
<span class="value"> ${hit.currencySymbol} ${hit.price} </span> | ||
<span class="value"> ${hit.currencySymbol} ${((hit.promotionalPrice && hit.promotionalPrice < hit.price) || (hit.displayPrice < hit.price)) ? hit.price : hit.highestPriceBookPrice} </span> | ||
</span> | ||
`} | ||
<span class="sales"> | ||
|
@@ -332,29 +332,7 @@ function enableInstantSearch(config) { | |
if (item.price && item.price[algoliaData.currencyCode] !== null) { | ||
item.price = item.price[algoliaData.currencyCode] | ||
} | ||
// If no promotionalPrice, use the pricebooks to display the strikeout price | ||
if (!item.promotionalPrice && | ||
item.pricebooks && | ||
item.pricebooks[algoliaData.currencyCode] && | ||
item.pricebooks[algoliaData.currencyCode].length > 0 | ||
) { | ||
const prices = item.pricebooks[algoliaData.currencyCode].filter(pricebook => { | ||
if (pricebook.onlineFrom && pricebook.onlineFrom > Date.now()) { | ||
return false; | ||
} | ||
if (pricebook.onlineTo && pricebook.onlineTo < Date.now()) { | ||
return false; | ||
} | ||
htuzel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true; | ||
}).map(pricebook => pricebook.price); | ||
const maxPrice = prices.reduce((acc, currentValue) => { | ||
return Math.max(acc, currentValue); | ||
}); | ||
if (maxPrice > item.price) { | ||
item.promotionalPrice = item.price; | ||
item.price = maxPrice; | ||
} | ||
} | ||
|
||
// currency symbol | ||
item.currencySymbol = algoliaData.currencySymbol; | ||
item.quickShowUrl = algoliaData.quickViewUrlBase + '?pid=' + (item.masterID || item.objectID); | ||
|
@@ -386,6 +364,10 @@ function enableInstantSearch(config) { | |
item.displayPrice = price; | ||
item.calloutMsg = calloutMsg; | ||
|
||
item.highestPriceBookPrice = item.pricebooks && item.pricebooks[algoliaData.currencyCode] && item.pricebooks[algoliaData.currencyCode].length > 0 ? item.pricebooks[algoliaData.currencyCode].reduce((max, pricebook) => { | ||
return Math.max(max, pricebook.price); | ||
}, 0) : undefined; | ||
|
||
// Master-level indexing | ||
if (item.variants) { | ||
item.variants.forEach(variant => { | ||
|
@@ -457,6 +439,10 @@ function enableInstantSearch(config) { | |
|
||
item.displayPrice = variantPrice; | ||
item.calloutMsg = variantCalloutMsg; | ||
|
||
item.highestPriceBookPrice = selectedVariant.pricebooks && selectedVariant.pricebooks[algoliaData.currencyCode] && selectedVariant.pricebooks[algoliaData.currencyCode].length > 0 ? selectedVariant.pricebooks[algoliaData.currencyCode].reduce((max, pricebook) => { | ||
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. This doesn't makes things more clear: a 262 characters line with a ternary check at the end that triggers a function is quite hard to process. |
||
return Math.max(max, pricebook.price); | ||
}, 0) : undefined; | ||
} | ||
} | ||
return item; | ||
|
@@ -792,8 +778,20 @@ function calculateDisplayPrice(item) { | |
} | ||
} | ||
|
||
if (item.pricebooks && item.pricebooks[algoliaData.currencyCode] && item.pricebooks[algoliaData.currencyCode].length > 0) { | ||
|
||
const lowestPrice = item.pricebooks[algoliaData.currencyCode].reduce((min, pricebook) => { | ||
return Math.min(min, pricebook.price); | ||
}, Infinity); | ||
|
||
return { | ||
price: lowestPrice, | ||
calloutMsg: '', | ||
} | ||
} | ||
|
||
return { | ||
price: item.price, | ||
price: algoliaData.recordModel === 'master-level' ? (variant.price[algoliaData.currencyCode] ? variant.price[algoliaData.currencyCode] : variant.price) : item.price, | ||
calloutMsg: '', | ||
} | ||
} |
Oops, something went wrong.
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.
You've made things more clear with the
calculateDisplayPrice
function, but you have complexified this part.It's a good occasion to improve the
transformItem
function and generate prices ready to be displayed:strikeout
price if there is onedisplayPrice
So the HTML doesn't need such complex logic