generated from ecomplus/storefront-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed 'template/pages/' changes from 111420a..6e1fc53
6e1fc53 Update with @ecomplus/storefront-template v2.0.0-beta.237 git-subtree-dir: template/pages git-subtree-split: 6e1fc5312698cbef9a6c13b6f00e46a91f3a924e
- Loading branch information
1 parent
409f0bc
commit 50fc567
Showing
2 changed files
with
93 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<% | ||
const { shuffle, autoplay } = opt | ||
let shelfTabs | ||
if (opt.collection_ids) { | ||
const collections = opt.collection_ids | ||
const promises = collections.map((collectionInfo) => new Promise(async (resolve) => { | ||
let search, title | ||
if (collectionInfo) { | ||
const [_id, resource, name] = collectionInfo.split(':') | ||
title = name | ||
if (resource === 'categories') { | ||
search = new _.EcomSearch().setCategoryIds([_id]) | ||
} else if (resource === 'brands') { | ||
search = new _.EcomSearch().setBrandIds([_id]) | ||
} else { | ||
let res | ||
try { | ||
res = await _.ecomClient.store({ | ||
url: `/collections/${_id}.json` | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
if (res) { | ||
const collection = res.data | ||
const productIds = collection.products | ||
if (Array.isArray(productIds) && productIds.length) { | ||
search = new _.EcomSearch().setProductIds(productIds.slice(0, 8)) | ||
} | ||
if (!title) { | ||
title = collection.name | ||
} | ||
} | ||
} | ||
} | ||
if (search) { | ||
if (opt.sort) { | ||
search.setSortOrder(opt.sort) | ||
} | ||
if (opt.limit > 0) { | ||
search.setPageSize(opt.limit) | ||
} | ||
if (opt.page >= 2) { | ||
search.setPageNumber(opt.page) | ||
} | ||
return search.fetch().then(() => { | ||
resolve({ | ||
title, | ||
items: search.getItems() | ||
}) | ||
}) | ||
} | ||
resolve(null) | ||
})) | ||
shelfTabs = (await Promise.all(promises)) | ||
.filter((result) => Boolean(result && result.items.length)) | ||
} | ||
%> | ||
|
||
<% if (shelfTabs && shelfTabs.length) { %> | ||
<div class="shelfs-nav my-lg-5"> | ||
<% if (opt.shelfs_title) { %> | ||
<h3 class="shelfs-nav__title"> | ||
<%= opt.shelfs_title %> | ||
</h3> | ||
<% } %> | ||
<ul class="shelfs-nav__tabs"> | ||
<% for (let i = 0; i < shelfTabs.length; i++) { %> | ||
<li class="shelfs-nav__tab<%= i === 0 ? ' active' : '' %>" data-tab="<%= i %>"> | ||
<h4><%= shelfTabs[i].title %></h4> | ||
</li> | ||
<% } %> | ||
</ul> | ||
<% for (let i = 0; i < shelfTabs.length; i++) { %> | ||
<div class="collection-shelf" data-shelf="<%= i %>" | ||
style="display: <%= i === 0 ? 'block' : 'none' %>"> | ||
<%- await include('@/sections/inc/products-carousel', { | ||
_, opt: { | ||
items: shelfTabs[i].items, | ||
collection: null, | ||
title: '', | ||
link: '', | ||
shuffle, | ||
headless: true, | ||
autoplay | ||
} | ||
}) %> | ||
</div> | ||
<% } %> | ||
</div> | ||
<% } %> |