@behio/storefront-sdk 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -480,7 +480,12 @@ Every API method returns a Promise. Types are fully auto-completed.
|
|
|
480
480
|
|
|
481
481
|
```typescript
|
|
482
482
|
// Catalog
|
|
483
|
-
const products = await shop.catalog.getProducts({
|
|
483
|
+
const products = await shop.catalog.getProducts({
|
|
484
|
+
limit: 20,
|
|
485
|
+
sort: 'newest',
|
|
486
|
+
categories: ['electronics', 'books'], // array filters sent as repeated query params
|
|
487
|
+
hasDiscount: true,
|
|
488
|
+
});
|
|
484
489
|
const product = await shop.catalog.getProduct('my-product-slug');
|
|
485
490
|
const { categories } = await shop.catalog.getCategories();
|
|
486
491
|
|
|
@@ -545,20 +550,80 @@ const { data, isLoading, error } = useShopInfo();
|
|
|
545
550
|
```
|
|
546
551
|
|
|
547
552
|
### useProducts
|
|
553
|
+
|
|
554
|
+
Supports **both** traditional pagination and infinite scroll from one hook.
|
|
555
|
+
|
|
548
556
|
```typescript
|
|
549
|
-
const {
|
|
557
|
+
const {
|
|
558
|
+
items, // flat array (all pages merged) — for infinite scroll
|
|
559
|
+
data, // PaginatedResponse (current page) — for traditional pagination
|
|
560
|
+
total, totalPages, currentPage, limit,
|
|
561
|
+
|
|
562
|
+
// Traditional pagination
|
|
563
|
+
page, setPage,
|
|
564
|
+
|
|
565
|
+
// Infinite scroll
|
|
566
|
+
loadMore, hasMore, isLoadingMore,
|
|
567
|
+
|
|
568
|
+
// State
|
|
569
|
+
isLoading, isFetching, error, isError, refetch,
|
|
570
|
+
} = useProducts({
|
|
550
571
|
page: 1,
|
|
551
572
|
limit: 24,
|
|
552
|
-
|
|
553
|
-
|
|
573
|
+
|
|
574
|
+
// Scalar filters
|
|
575
|
+
category: 'electronics', // single category slug
|
|
576
|
+
label: 'new', // single label slug
|
|
554
577
|
priceMin: 100,
|
|
555
578
|
priceMax: 5000,
|
|
556
|
-
|
|
579
|
+
currency: 'CZK',
|
|
580
|
+
locale: 'cs',
|
|
581
|
+
sort: 'price_asc', // or ProductSort.PRICE_ASC
|
|
557
582
|
inStock: true,
|
|
558
583
|
search: 'keyboard',
|
|
559
584
|
customFields: { material: 'aluminum' },
|
|
585
|
+
|
|
586
|
+
// Array filters — sent as repeated query params (?ids=a&ids=b)
|
|
587
|
+
ids: ['prod_1', 'prod_2'], // filter to specific IDs
|
|
588
|
+
slugs: ['red-shoes', 'blue-hat'], // filter to specific slugs
|
|
589
|
+
categories: ['electronics', 'books'], // OR logic (in ANY of these)
|
|
590
|
+
labels: ['sale', 'new'], // AND logic (must have ALL)
|
|
591
|
+
excludeIds: ['prod_999'], // exclude specific IDs (e.g. related products)
|
|
592
|
+
excludeCategories: ['archive'], // exclude products in these categories
|
|
593
|
+
|
|
594
|
+
// Boolean / time filters
|
|
595
|
+
hasDiscount: true, // only products with compareAtPrice
|
|
596
|
+
isFeatured: true, // only featured products
|
|
597
|
+
createdAfter: Date.now() - 7 * 864e5, // created in last 7 days (epoch ms)
|
|
598
|
+
|
|
599
|
+
// Hook options
|
|
600
|
+
enabled: true, // skip fetch until true
|
|
601
|
+
initialData: prefetchedData, // SSR hydration
|
|
560
602
|
});
|
|
561
|
-
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
**Infinite scroll example:**
|
|
606
|
+
```tsx
|
|
607
|
+
const { items, loadMore, hasMore, isLoadingMore } = useProducts({ limit: 24 });
|
|
608
|
+
|
|
609
|
+
return (
|
|
610
|
+
<>
|
|
611
|
+
{items.map(p => <ProductCard key={p.id} product={p} />)}
|
|
612
|
+
{hasMore && <button onClick={loadMore} disabled={isLoadingMore}>Load more</button>}
|
|
613
|
+
</>
|
|
614
|
+
);
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
**Traditional pagination example:**
|
|
618
|
+
```tsx
|
|
619
|
+
const { data, page, setPage, totalPages } = useProducts({ limit: 24 });
|
|
620
|
+
|
|
621
|
+
return (
|
|
622
|
+
<>
|
|
623
|
+
{data?.items.map(p => <ProductCard key={p.id} product={p} />)}
|
|
624
|
+
<Pagination page={page} total={totalPages} onChange={setPage} />
|
|
625
|
+
</>
|
|
626
|
+
);
|
|
562
627
|
```
|
|
563
628
|
|
|
564
629
|
### useProduct
|