Skip to content

Commit

Permalink
Merge branch 'main' of github.com:hlxsites/aem-boilerplate-commerce i…
Browse files Browse the repository at this point in the history
…nto recommendations
  • Loading branch information
herzog31 committed Mar 5, 2024
2 parents c6f2fb1 + a30adf1 commit 671c4b4
Show file tree
Hide file tree
Showing 36 changed files with 10,057 additions and 19,587 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ helix-importer-ui
scripts/preact.js
scripts/htm.js
scripts/acdl
tools/picker
tools/picker
scripts/widgets
9 changes: 2 additions & 7 deletions .github/workflows/cleanup-on-create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 18
- name: Uninstall dependencies
run: |
npm uninstall --save-dev semantic-release @semantic-release/git @semantic-release/changelog @semantic-release/exec
node-version: 20
- name: Remove Helper Files
run: |
rm -rf \
.github/workflows/cleanup-on-create.yaml \
.github/workflows/semantic-release.yaml \
.releaserc.cjs \
CHANGELOG.md
- name: Initialize README
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Build
on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run lint
17 changes: 0 additions & 17 deletions .github/workflows/run-tests.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/semantic-release.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions .releaserc.cjs

This file was deleted.

58 changes: 0 additions & 58 deletions CHANGELOG.md

This file was deleted.

1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,3 @@ One of the maintainers will look at the pull request within one week. Feedback o
The project's committers will release to the [Adobe organization on npmjs.org](https://www.npmjs.com/org/adobe).
Please contact the [Adobe Open Source Advisory Board](https://git.corp.adobe.com/OpenSourceAdvisoryBoard/discuss/issues) to get access to the npmjs organization.

The release process is fully automated using `semantic-release`, increasing the version numbers, etc. based on the contents of the commit messages found.
26 changes: 21 additions & 5 deletions blocks/enrichment/enrichment.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export default async function decorate(block) {
}

if (type === 'category') {
const categoryId = document.querySelector('.block.product-list-page')?.dataset?.category;
const plpBlock = document.querySelector('.block.product-list-page');
if (!plpBlock) return;

let categoryId = plpBlock.dataset?.category;
if (!categoryId) {
categoryId = readBlockConfig(plpBlock).category;
}
if (!categoryId) return;
filters.categories = categoryId;
}
Expand All @@ -33,11 +39,21 @@ export default async function decorate(block) {
(await Promise.all(matchingFragments.map((path) => loadFragment(path))))
.filter((fragment) => fragment)
.forEach((fragment) => {
const section = fragment.querySelector(':scope .section');
if (section) {
block.closest('.section').classList.add(...section.classList);
const sections = fragment.querySelectorAll(':scope .section');

// If only single section, replace block with content of section
if (sections.length === 1) {
block.closest('.section').classList.add(...sections[0].classList);
const wrapper = block.closest('.enrichment-wrapper');
section.childNodes.forEach((child) => wrapper.parentNode.insertBefore(child, wrapper));
Array.from(sections[0].children)
.forEach((child) => wrapper.parentNode.insertBefore(child, wrapper));
} else if (sections.length > 1) {
// If multiple sections, insert them after section of block
const blockSection = block.closest('.section');
Array.from(sections)
.reverse()
.forEach((section) => blockSection
.parentNode.insertBefore(section, blockSection.nextSibling));
}
});

Expand Down
25 changes: 22 additions & 3 deletions blocks/header/header.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* stylelint-disable selector-class-pattern */

/* header and nav layout */
header .nav-wrapper {
background-color: var(--background-color);
Expand Down Expand Up @@ -273,7 +275,7 @@ header nav .nav-tools {
gap: 10px;
}

header nav .nav-tools button {
header nav .nav-tools > button, header nav .nav-tools .minicart-wrapper > button {
color: var(--color-brand-700);
background: transparent;
padding: 5px 10px;
Expand All @@ -296,12 +298,13 @@ header nav .nav-tools button.nav-search-button {

header .nav-search-input {
position: absolute;
z-index: 99;
top: var(--nav-height);
box-shadow: var(--shape-shadow-2);
background: var(--color-neutral-50);
left: 0;
right: 0;
padding: 10px;
z-index: 1;
padding: 20px;
}

header .nav-search-input.hidden {
Expand All @@ -310,4 +313,20 @@ header .nav-search-input.hidden {

header .nav-search-input input {
width: 100%;
padding: 5px;
}

header .nav-search-input .search_autocomplete .popover-container {
width: 100%;
}

@media (width >= 1024px) {
header .nav-search-input {
left: unset;
right: 20px;
}

header .nav-search-input input {
min-width: 400px;
}
}
10 changes: 8 additions & 2 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,18 @@ export default async function decorate(block) {
});

// Search
const searchInput = document.createRange().createContextualFragment('<div class="nav-search-input hidden"><form action="/search" method="GET"><input type="search" name="q" placeholder="Search" /></form></div>');
const searchInput = document.createRange().createContextualFragment(`<div class="nav-search-input hidden">
<form id="search_mini_form" action="/search" method="GET">
<input id="search" type="search" name="q" placeholder="Search" />
<div id="search_autocomplete" class="search-autocomplete"></div>
</form>
</div>`);
document.body.querySelector('header').append(searchInput);

const searchButton = document.createRange().createContextualFragment('<button type="button" class="nav-search-button">Search</button>');
navTools.append(searchButton);
navTools.querySelector('.nav-search-button').addEventListener('click', () => {
navTools.querySelector('.nav-search-button').addEventListener('click', async () => {
await import('./searchbar.js');
document.querySelector('header .nav-search-input').classList.toggle('hidden');
});

Expand Down
48 changes: 48 additions & 0 deletions blocks/header/searchbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { loadScript } from '../../scripts/aem.js';
import { getConfigValue } from '../../scripts/configs.js';

(async () => {
const widgetProd = '/scripts/widgets/LiveSearchAutocomplete.js';
await loadScript(widgetProd);

const storeDetails = {
environmentId: await getConfigValue('commerce-environment-id'),
environmentType: (await getConfigValue('commerce-environment-id')).includes('sandbox') ? 'testing' : '',
apiKey: await getConfigValue('commerce-x-api-key'),
websiteCode: await getConfigValue('commerce-website-code'),
storeCode: await getConfigValue('commerce-store-code'),
storeViewCode: await getConfigValue('commerce-store-view-code'),
config: {
pageSize: 8,
perPageConfig: {
pageSizeOptions: '12,24,36',
defaultPageSizeOption: '24',
},
minQueryLength: '2',
currencySymbol: '$',
currencyRate: '1',
displayOutOfStock: true,
allowAllProducts: false,
},
context: {
customerGroup: await getConfigValue('commerce-customer-group'),
},
route: ({ sku }) => `/products/missing-url-key/${sku}`, // TODO: We need urlKey as parameter as well!
searchRoute: {
route: '/search',
query: 'q',
},
};

await new Promise((resolve) => {
const interval = setInterval(() => {
if (window.LiveSearchAutocomplete) {
clearInterval(interval);
resolve();
}
}, 200);
});

// eslint-disable-next-line no-new
new window.LiveSearchAutocomplete(storeDetails);
})();
5 changes: 1 addition & 4 deletions blocks/product-details/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ class ProductDetailPage extends Component {
if (Object.keys(this.state.selection).length === (this.state.product.options?.length || 0)) {
const optionsUIDs = Object.values(this.state.selection).map((option) => option.id);
const { cartApi } = await import('../../scripts/minicart/api.js');
console.debug('onAddToCart', {
sku: this.state.product.sku, optionsUIDs, quantity: this.state.selectedQuantity ?? 1,
});
cartApi.addToCart(this.state.product.sku, optionsUIDs, this.state.selectedQuantity ?? 1);
cartApi.addToCart(this.state.product.sku, optionsUIDs, this.state.selectedQuantity ?? 1, 'product-detail');
}
};

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 671c4b4

Please sign in to comment.