-
Notifications
You must be signed in to change notification settings - Fork 187
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
initial Klevu integration #1854
Open
jerrypena1
wants to merge
1
commit into
bigcommerce:integrations/klevu
Choose a base branch
from
klevu-dev:integrations/klevu
base: integrations/klevu
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.
+341
−9
Open
Changes from all commits
Commits
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
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 |
---|---|---|
@@ -1,3 +1,21 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
/* KLEVU STYLES */ | ||
klevu-init { | ||
@apply w-full; | ||
} | ||
klevu-quicksearch::part(quicksearch-content) { | ||
@apply w-full overflow-auto; | ||
} | ||
klevu-quicksearch::part(textfield-input) { | ||
@apply rounded-none h-12 w-full appearance-none border-2 border-gray-200 px-12 py-3 text-base placeholder:text-gray-500 hover:border-primary focus-visible:border-primary focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-primary/20 disabled:bg-gray-100 disabled:hover:border-gray-200; | ||
} | ||
|
||
klevu-merchandising::part(product-addtocart), klevu-search-landing-page::part(product-addtocart), klevu-quicksearch::part(product-addtocart) { | ||
display: none !important; | ||
visibility: 0 !important; | ||
height: 0 !important; | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use client'; | ||
|
||
import { removeEdgesAndNodes } from '@bigcommerce/catalyst-client'; | ||
import { KlevuMerchandising } from '@klevu/ui-react'; | ||
import React from 'react'; | ||
|
||
import { KlevuInitWrapper } from '~/components/ui/klevu/init'; | ||
|
||
|
||
|
||
export default function KlevuCategory({ category }) { | ||
const catBreadcrumbs = removeEdgesAndNodes(category.breadcrumbs); | ||
const getCategoryPath = () => { | ||
try { | ||
let categoryPath = ''; | ||
|
||
if (catBreadcrumbs.length) { | ||
catBreadcrumbs.forEach((cat) => { | ||
if (cat.name) { | ||
categoryPath += (categoryPath !== '' ? ';' : '') + cat.name; | ||
} | ||
}); | ||
} | ||
|
||
return categoryPath ?? category.name; | ||
} catch (error) { | ||
return category.name; | ||
} | ||
}; | ||
|
||
return ( | ||
<KlevuInitWrapper> | ||
<KlevuMerchandising category={getCategoryPath()} categoryTitle={category.name} /> | ||
</KlevuInitWrapper> | ||
); | ||
}; |
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,33 @@ | ||
'use client' | ||
|
||
import { KlevuInit } from '@klevu/ui-react'; | ||
import React from 'react'; | ||
|
||
export function KlevuInitWrapper({ children }) { | ||
|
||
return ( | ||
<KlevuInit | ||
apiKey="klevu-172166885635617473" | ||
settings={{ | ||
generateProductUrl: function generateProductUrl(product) { | ||
const url = URL.parse(product.url); | ||
|
||
return url.pathname; | ||
}, | ||
onItemClick: function onItemClick(product, event) { | ||
console.log(product,event); | ||
}, | ||
renderPrice: function renderPrice(amount, currency) { | ||
|
||
return new Intl.NumberFormat(undefined, { | ||
style: 'currency', | ||
currency, | ||
}).format(parseFloat(amount)); | ||
}, | ||
}} | ||
url="https://uscs33v2.ksearchnet.com/cs/v2/search" | ||
> | ||
{children} | ||
</KlevuInit> | ||
); | ||
} |
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,37 @@ | ||
'use client'; | ||
|
||
import { KlevuQuicksearch } from '@klevu/ui-react'; | ||
import { useRouter } from 'next/navigation'; | ||
import React from 'react'; | ||
|
||
import { KlevuInitWrapper } from '~/components/ui/klevu/init'; | ||
|
||
export default function KlevuQuickSearch() { | ||
const { push } = useRouter(); | ||
|
||
const handleQuickSearchEvent = (event) => { | ||
if (event.detail !== '') { | ||
push(`/search/?term=${event.detail}`); | ||
} | ||
}; | ||
|
||
const wheelHandler = (event) => { | ||
event.stopPropagation(); | ||
|
||
return false; | ||
}; | ||
|
||
return ( | ||
<div className="col-span-4 flex lg:col-span-3" onWheel={wheelHandler}> | ||
<KlevuInitWrapper> | ||
<KlevuQuicksearch | ||
fallback-term="" | ||
onKlevuSearch={handleQuickSearchEvent} | ||
popup-anchor="bottom-start" | ||
search-categories="true" | ||
search-cms-cages="true" | ||
/> | ||
</KlevuInitWrapper> | ||
</div> | ||
); | ||
}; |
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,14 @@ | ||
'use client'; | ||
|
||
import { KlevuSearchLandingPage } from '@klevu/ui-react'; | ||
import React from 'react'; | ||
|
||
import { KlevuInitWrapper } from '~/components/ui/klevu/init'; | ||
|
||
export default function KlevuSearch({ term }) { | ||
return ( | ||
<KlevuInitWrapper> | ||
<KlevuSearchLandingPage term={term} /> | ||
</KlevuInitWrapper> | ||
); | ||
} |
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
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.
My only review comment is to do with this file - and I think you probably already saw it coming from what you mentioned in your README 🙂
Is there any chance we can replace the hard coded
apiKey
andurl
with aNEXT_PUBLIC_
environment variable? This will help with developers wanting to swap out keys, but will also help with the OCC deployment - we can programmatically add these variables potentially during deployment.This is my only change requested, this PR looks good for approval after this!