create-abcart-theme 0.0.0-stage → 0.10.1
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/CHANGELOG.md +127 -0
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +64 -2
- package/bin/create-abcart-theme.mjs +4 -0
- package/package.json +47 -4
- package/src/args.mjs +113 -0
- package/src/banner.mjs +21 -0
- package/src/cli.mjs +119 -0
- package/src/create.mjs +82 -0
- package/src/package-manager.mjs +32 -0
- package/src/style.mjs +17 -0
- package/templates/default/.agents/skills/shopify-theme-asset-collector/SKILL.md +125 -0
- package/templates/default/.agents/skills/shopify-theme-asset-collector/scripts/collect_public_assets.py +370 -0
- package/templates/default/.agents/skills/wocart-docs/SKILL.md +146 -0
- package/templates/default/.agents/skills/wocart-theme-from-design/SKILL.md +58 -0
- package/templates/default/.agents/skills/wocart-theme-from-design/references/inputs-and-rights.md +47 -0
- package/templates/default/.agents/skills/wocart-theme-from-design/references/layout-rtl-and-phone.md +36 -0
- package/templates/default/.agents/skills/wocart-theme-from-design/references/measure-the-design.md +60 -0
- package/templates/default/.agents/skills/wocart-theme-from-design/references/tokens-sections-content.md +103 -0
- package/templates/default/.agents/skills/wocart-theme-from-design/references/verify-and-report.md +102 -0
- package/templates/default/.agents/skills/wocart-theme-from-design/scripts/compare-design.cjs +230 -0
- package/templates/default/.agents/skills/wocart-theme-from-design/scripts/qa-pages.cjs +219 -0
- package/templates/default/.dev.vars.example +12 -0
- package/templates/default/AGENTS.md +240 -0
- package/templates/default/README.md +184 -0
- package/templates/default/_gitignore +11 -0
- package/templates/default/astro.config.mjs +85 -0
- package/templates/default/package.json +36 -0
- package/templates/default/public/fonts/OFL.txt +96 -0
- package/templates/default/public/fonts/alexandria-arabic.woff2 +0 -0
- package/templates/default/public/fonts/fraunces-latin.woff2 +0 -0
- package/templates/default/src/actions/index.ts +22 -0
- package/templates/default/src/components/cart/AddToCartButton.astro +45 -0
- package/templates/default/src/components/cart/CartDrawer.astro +47 -0
- package/templates/default/src/components/cart/CartSummary.astro +11 -0
- package/templates/default/src/components/cart/FreeShipping.astro +7 -0
- package/templates/default/src/components/checkout/CheckoutMain.astro +29 -0
- package/templates/default/src/components/checkout/OrderForm.astro +280 -0
- package/templates/default/src/components/checkout/ThankYouMain.astro +68 -0
- package/templates/default/src/components/landing/LandingImages.astro +51 -0
- package/templates/default/src/components/landing/LandingOrder.astro +46 -0
- package/templates/default/src/components/landing/LandingProduct.astro +41 -0
- package/templates/default/src/components/listing/ListingMain.astro +93 -0
- package/templates/default/src/components/listing/PageMain.astro +52 -0
- package/templates/default/src/components/listing/Pagination.astro +31 -0
- package/templates/default/src/components/listing/SortControl.astro +35 -0
- package/templates/default/src/components/product/BuyBox.astro +96 -0
- package/templates/default/src/components/product/Description.astro +24 -0
- package/templates/default/src/components/product/Gallery.astro +66 -0
- package/templates/default/src/components/product/MobileBuyBar.astro +29 -0
- package/templates/default/src/components/product/OfferChoice.astro +66 -0
- package/templates/default/src/components/product/ProductMain.astro +40 -0
- package/templates/default/src/components/product/ProductReviews.astro +72 -0
- package/templates/default/src/components/product/RelatedProducts.astro +30 -0
- package/templates/default/src/components/product/blocks/BenefitsBlock.astro +13 -0
- package/templates/default/src/components/product/blocks/CollapsibleBlock.astro +20 -0
- package/templates/default/src/components/product/blocks/DescriptionBlock.astro +19 -0
- package/templates/default/src/components/product/blocks/DetailsBlock.astro +33 -0
- package/templates/default/src/components/product/blocks/GalleryBlock.astro +12 -0
- package/templates/default/src/components/product/blocks/OrderBlock.astro +30 -0
- package/templates/default/src/components/product/blocks/PriceBlock.astro +23 -0
- package/templates/default/src/components/product/blocks/RatingBlock.astro +16 -0
- package/templates/default/src/components/product/blocks/StockBlock.astro +22 -0
- package/templates/default/src/components/product/blocks/TextBlock.astro +11 -0
- package/templates/default/src/components/product/blocks/TitleBlock.astro +20 -0
- package/templates/default/src/components/reviews/ReviewCard.astro +46 -0
- package/templates/default/src/components/reviews/ReviewForm.astro +113 -0
- package/templates/default/src/components/reviews/VoiceNote.astro +60 -0
- package/templates/default/src/components/sections/CollectionCards.astro +65 -0
- package/templates/default/src/components/sections/Countdown.astro +57 -0
- package/templates/default/src/components/sections/Faq.astro +44 -0
- package/templates/default/src/components/sections/FeaturedProduct.astro +71 -0
- package/templates/default/src/components/sections/Hero.astro +99 -0
- package/templates/default/src/components/sections/ImageBanner.astro +46 -0
- package/templates/default/src/components/sections/ProductGrid.astro +47 -0
- package/templates/default/src/components/sections/RichText.astro +35 -0
- package/templates/default/src/components/sections/Steps.astro +46 -0
- package/templates/default/src/components/sections/Testimonials.astro +57 -0
- package/templates/default/src/components/shell/Footer.astro +80 -0
- package/templates/default/src/components/shell/Header.astro +89 -0
- package/templates/default/src/components/shell/LanguageMenu.astro +33 -0
- package/templates/default/src/components/shell/MobileMenu.astro +65 -0
- package/templates/default/src/components/shell/SearchDialog.astro +19 -0
- package/templates/default/src/components/shell/TopBar.astro +54 -0
- package/templates/default/src/components/shell/WhatsAppWidget.astro +111 -0
- package/templates/default/src/components/store/ContactMain.astro +79 -0
- package/templates/default/src/components/store/SearchMain.astro +56 -0
- package/templates/default/src/components/store/TrackOrderMain.astro +161 -0
- package/templates/default/src/components/surface/Area.astro +20 -0
- package/templates/default/src/components/surface/PreviewBridge.astro +24 -0
- package/templates/default/src/components/surface/Sections.astro +35 -0
- package/templates/default/src/components/ui/Breadcrumbs.astro +36 -0
- package/templates/default/src/components/ui/Button.astro +45 -0
- package/templates/default/src/components/ui/EditorPlaceholder.astro +24 -0
- package/templates/default/src/components/ui/Icon.astro +93 -0
- package/templates/default/src/components/ui/Logo.astro +36 -0
- package/templates/default/src/components/ui/Photo.astro +46 -0
- package/templates/default/src/components/ui/Price.astro +24 -0
- package/templates/default/src/components/ui/ProductCard.astro +41 -0
- package/templates/default/src/components/ui/Rating.astro +22 -0
- package/templates/default/src/components/ui/Section.astro +34 -0
- package/templates/default/src/components/ui/SectionHeading.astro +19 -0
- package/templates/default/src/env.d.ts +23 -0
- package/templates/default/src/layouts/StoreLayout.astro +145 -0
- package/templates/default/src/lib/browser-copy.ts +37 -0
- package/templates/default/src/lib/context.ts +89 -0
- package/templates/default/src/lib/coupon-notice.ts +47 -0
- package/templates/default/src/lib/i18n.ts +32 -0
- package/templates/default/src/lib/images.ts +38 -0
- package/templates/default/src/lib/listing-query.ts +41 -0
- package/templates/default/src/lib/money.ts +16 -0
- package/templates/default/src/lib/motion.ts +16 -0
- package/templates/default/src/lib/nav.ts +26 -0
- package/templates/default/src/lib/offer-tiles.ts +105 -0
- package/templates/default/src/lib/order-outcome.ts +66 -0
- package/templates/default/src/lib/otp-message.ts +21 -0
- package/templates/default/src/lib/products.ts +38 -0
- package/templates/default/src/lib/review-refusals.ts +31 -0
- package/templates/default/src/lib/store.ts +31 -0
- package/templates/default/src/lib/whatsapp.ts +29 -0
- package/templates/default/src/middleware.ts +23 -0
- package/templates/default/src/pages/404.astro +22 -0
- package/templates/default/src/pages/api/abandoned/convert.ts +4 -0
- package/templates/default/src/pages/api/abandoned/upsert.ts +4 -0
- package/templates/default/src/pages/api/cart/validate.ts +4 -0
- package/templates/default/src/pages/api/communes/[wilayaId].ts +4 -0
- package/templates/default/src/pages/api/otp/send.ts +4 -0
- package/templates/default/src/pages/api/otp/verify.ts +4 -0
- package/templates/default/src/pages/api/reviews/[productId].ts +3 -0
- package/templates/default/src/pages/api/reviews/eligibility.ts +3 -0
- package/templates/default/src/pages/api/reviews/submit.ts +3 -0
- package/templates/default/src/pages/api/reviews/upload.ts +3 -0
- package/templates/default/src/pages/category/[slug].astro +20 -0
- package/templates/default/src/pages/checkout.astro +25 -0
- package/templates/default/src/pages/collections/[handle].astro +20 -0
- package/templates/default/src/pages/contact.astro +17 -0
- package/templates/default/src/pages/index.astro +9 -0
- package/templates/default/src/pages/lp/[slug].astro +47 -0
- package/templates/default/src/pages/pages/[slug].astro +16 -0
- package/templates/default/src/pages/products/[handle].astro +37 -0
- package/templates/default/src/pages/products/index.astro +15 -0
- package/templates/default/src/pages/robots.txt.ts +9 -0
- package/templates/default/src/pages/search.astro +19 -0
- package/templates/default/src/pages/sitemap.xml.ts +12 -0
- package/templates/default/src/pages/thank-you.astro +33 -0
- package/templates/default/src/pages/track-order.astro +17 -0
- package/templates/default/src/pages/wocart-preview.astro +43 -0
- package/templates/default/src/pages/wocart-revalidate.ts +10 -0
- package/templates/default/src/pages/wocart-styles.css.ts +5 -0
- package/templates/default/src/pages/wocart-theme.json.ts +5 -0
- package/templates/default/src/scripts/cart.ts +371 -0
- package/templates/default/src/scripts/checkout/coupon.ts +96 -0
- package/templates/default/src/scripts/checkout/delivery.ts +86 -0
- package/templates/default/src/scripts/checkout/form.ts +54 -0
- package/templates/default/src/scripts/checkout/otp.ts +106 -0
- package/templates/default/src/scripts/checkout/picker.ts +169 -0
- package/templates/default/src/scripts/checkout/quote.ts +169 -0
- package/templates/default/src/scripts/checkout/submit.ts +113 -0
- package/templates/default/src/scripts/checkout/tracking.ts +74 -0
- package/templates/default/src/scripts/countdown.ts +29 -0
- package/templates/default/src/scripts/events.ts +4 -0
- package/templates/default/src/scripts/hero.ts +49 -0
- package/templates/default/src/scripts/listing.ts +13 -0
- package/templates/default/src/scripts/order-form.ts +100 -0
- package/templates/default/src/scripts/product.ts +306 -0
- package/templates/default/src/scripts/public-config.ts +79 -0
- package/templates/default/src/scripts/reviews.ts +358 -0
- package/templates/default/src/scripts/site.ts +131 -0
- package/templates/default/src/scripts/thank-you.ts +11 -0
- package/templates/default/src/scripts/voice-note.ts +94 -0
- package/templates/default/src/styles/base.css +1030 -0
- package/templates/default/src/styles/checkout.css +1111 -0
- package/templates/default/src/styles/global.css +12 -0
- package/templates/default/src/styles/product.css +871 -0
- package/templates/default/src/styles/reviews.css +533 -0
- package/templates/default/src/styles/sections.css +931 -0
- package/templates/default/src/styles/shell.css +970 -0
- package/templates/default/src/styles/tokens.css +583 -0
- package/templates/default/src/theme/api-routes.ts +10 -0
- package/templates/default/src/theme/content/catalog.ts +117 -0
- package/templates/default/src/theme/content/checkout.ts +168 -0
- package/templates/default/src/theme/content/editor.ts +21 -0
- package/templates/default/src/theme/content/index.ts +45 -0
- package/templates/default/src/theme/content/reviews.ts +76 -0
- package/templates/default/src/theme/content/shell.ts +59 -0
- package/templates/default/src/theme/content/types.ts +12 -0
- package/templates/default/src/theme/documents/catalog.json +11 -0
- package/templates/default/src/theme/documents/category.json +11 -0
- package/templates/default/src/theme/documents/checkout.json +11 -0
- package/templates/default/src/theme/documents/collection.json +11 -0
- package/templates/default/src/theme/documents/contact.json +11 -0
- package/templates/default/src/theme/documents/footer.area.json +11 -0
- package/templates/default/src/theme/documents/header.area.json +16 -0
- package/templates/default/src/theme/documents/home.json +313 -0
- package/templates/default/src/theme/documents/landing.json +8 -0
- package/templates/default/src/theme/documents/page.json +11 -0
- package/templates/default/src/theme/documents/product.json +125 -0
- package/templates/default/src/theme/documents/search.json +11 -0
- package/templates/default/src/theme/documents/thank-you.json +11 -0
- package/templates/default/src/theme/documents/track-order.json +11 -0
- package/templates/default/src/theme/fields.ts +61 -0
- package/templates/default/src/theme/key.ts +11 -0
- package/templates/default/src/theme/labels.ts +231 -0
- package/templates/default/src/theme/locales.ts +11 -0
- package/templates/default/src/theme/palette.ts +14 -0
- package/templates/default/src/theme/sections/collection-cards.ts +65 -0
- package/templates/default/src/theme/sections/faq.ts +74 -0
- package/templates/default/src/theme/sections/featured-product.ts +42 -0
- package/templates/default/src/theme/sections/hero.ts +47 -0
- package/templates/default/src/theme/sections/image-banner.ts +25 -0
- package/templates/default/src/theme/sections/index.ts +40 -0
- package/templates/default/src/theme/sections/landing.ts +150 -0
- package/templates/default/src/theme/sections/listing.ts +84 -0
- package/templates/default/src/theme/sections/product-grid.ts +42 -0
- package/templates/default/src/theme/sections/product.ts +297 -0
- package/templates/default/src/theme/sections/rich-text.ts +39 -0
- package/templates/default/src/theme/sections/shared.ts +54 -0
- package/templates/default/src/theme/sections/shell.ts +85 -0
- package/templates/default/src/theme/sections/store-pages.ts +101 -0
- package/templates/default/src/theme/sections/testimonials.ts +61 -0
- package/templates/default/src/theme/sections/thank-you.ts +35 -0
- package/templates/default/src/theme/settings.ts +124 -0
- package/templates/default/src/theme/theme.ts +65 -0
- package/templates/default/tests/fixtures/canvas-tote.json +62 -0
- package/templates/default/tests/fixtures/linen-shirt.json +128 -0
- package/templates/default/tests/unit/checkout.test.ts +241 -0
- package/templates/default/tests/unit/contract.test.ts +169 -0
- package/templates/default/tests/unit/contrast.test.ts +68 -0
- package/templates/default/tests/unit/copy.test.ts +101 -0
- package/templates/default/tests/unit/design-values.test.ts +95 -0
- package/templates/default/tests/unit/editability.test.ts +180 -0
- package/templates/default/tests/unit/fixtures.ts +91 -0
- package/templates/default/tests/unit/footer.test.ts +54 -0
- package/templates/default/tests/unit/guards.test.ts +340 -0
- package/templates/default/tests/unit/images.test.ts +26 -0
- package/templates/default/tests/unit/landing.test.ts +151 -0
- package/templates/default/tests/unit/languages.test.ts +42 -0
- package/templates/default/tests/unit/middleware.test.ts +53 -0
- package/templates/default/tests/unit/offer-tiles.test.ts +75 -0
- package/templates/default/tests/unit/render.ts +38 -0
- package/templates/default/tests/unit/reviews.test.ts +25 -0
- package/templates/default/tests/unit/rules.test.ts +59 -0
- package/templates/default/tests/unit/source.ts +75 -0
- package/templates/default/tests/unit/store-pages.test.ts +147 -0
- package/templates/default/tests/unit/studio.test.ts +202 -0
- package/templates/default/tests/unit/testimonials.test.ts +52 -0
- package/templates/default/tests/unit/thank-you.test.ts +52 -0
- package/templates/default/tests/unit/tracking.test.ts +29 -0
- package/templates/default/tests/unit/voice-note.test.ts +42 -0
- package/templates/default/tsconfig.json +13 -0
- package/templates/default/vitest.config.ts +15 -0
- package/templates/default/wrangler.jsonc +17 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A landing page — an ad's destination, each page with its own document: the
|
|
3
|
+
* page's images (all, or a range, so sections can sit between them), its one
|
|
4
|
+
* order form, and the sections that help an Algerian shopper decide to order
|
|
5
|
+
* cash on delivery — the product's name and price, a countdown to the end of
|
|
6
|
+
* the offer, how ordering works, and the theme's content sections. Presets
|
|
7
|
+
* hold the words merchants reach for first, in ar/fr/en, ready to edit.
|
|
8
|
+
*/
|
|
9
|
+
import { defineComponent, type FieldDefinition } from "@abcart/theme";
|
|
10
|
+
import { ACCENT_SCHEME, alignField, headingFields, iconField, schemeField, sectionStyle, styleField } from "../fields";
|
|
11
|
+
import { FIELD, GROUP, HELP, OPTION, SECTION } from "../labels";
|
|
12
|
+
import { routeLanding } from "./shared";
|
|
13
|
+
import LandingImages from "@/components/landing/LandingImages.astro";
|
|
14
|
+
import LandingOrder from "@/components/landing/LandingOrder.astro";
|
|
15
|
+
import LandingProduct from "@/components/landing/LandingProduct.astro";
|
|
16
|
+
import Countdown from "@/components/sections/Countdown.astro";
|
|
17
|
+
import Steps from "@/components/sections/Steps.astro";
|
|
18
|
+
|
|
19
|
+
const l = (ar: string, fr: string, en: string) => ({ ar, fr, en });
|
|
20
|
+
const ON_LANDING = { surfaces: ["landing"] };
|
|
21
|
+
const step = (id: string, icon: string, title: ReturnType<typeof l>, text: ReturnType<typeof l>) => ({ id, props: { icon, title, text } });
|
|
22
|
+
|
|
23
|
+
export const landingImages = defineComponent({
|
|
24
|
+
type: "landing-images",
|
|
25
|
+
component: LandingImages,
|
|
26
|
+
label: SECTION.landingImages,
|
|
27
|
+
group: GROUP.landing,
|
|
28
|
+
placement: "section",
|
|
29
|
+
capabilities: ON_LANDING,
|
|
30
|
+
fields: [
|
|
31
|
+
{ key: "first", kind: "number", label: FIELD.firstImage, description: HELP.firstImage, default: 1, min: 1, max: 40, step: 1 },
|
|
32
|
+
{ key: "count", kind: "number", label: FIELD.imageCount, description: HELP.imageCount, default: 0, min: 0, max: 40, step: 1 },
|
|
33
|
+
schemeField(),
|
|
34
|
+
styleField(sectionStyle("none", "narrow")),
|
|
35
|
+
],
|
|
36
|
+
load: async (input) => ({ landing: await routeLanding(input) }),
|
|
37
|
+
presets: [
|
|
38
|
+
{ key: "opening", label: l("الصور الأولى", "Premières images", "Opening images"), props: { first: 1, count: 3 } },
|
|
39
|
+
{ key: "rest", label: l("بقية الصور", "Images suivantes", "The other images"), props: { first: 4, count: 0 } },
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const landingOrder = defineComponent({
|
|
44
|
+
type: "landing-order",
|
|
45
|
+
component: LandingOrder,
|
|
46
|
+
label: SECTION.landingOrder,
|
|
47
|
+
group: GROUP.landing,
|
|
48
|
+
placement: "section",
|
|
49
|
+
role: "order-form",
|
|
50
|
+
capabilities: { ...ON_LANDING, insertable: false },
|
|
51
|
+
fields: [
|
|
52
|
+
{ key: "title", kind: "text", label: FIELD.title, contentKey: "product.completeOrder" },
|
|
53
|
+
{ key: "showAssurances", kind: "boolean", label: FIELD.showAssurances, default: true },
|
|
54
|
+
{ key: "mobileBar", kind: "boolean", label: FIELD.mobileBar, default: true },
|
|
55
|
+
schemeField(),
|
|
56
|
+
styleField(sectionStyle("tight", "narrow")),
|
|
57
|
+
],
|
|
58
|
+
load: async (input) => ({ landing: await routeLanding(input) }),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const landingProduct = defineComponent({
|
|
62
|
+
type: "landing-product",
|
|
63
|
+
component: LandingProduct,
|
|
64
|
+
label: SECTION.landingProduct,
|
|
65
|
+
group: GROUP.landing,
|
|
66
|
+
placement: "section",
|
|
67
|
+
capabilities: ON_LANDING,
|
|
68
|
+
fields: [{ key: "showRating", kind: "boolean", label: FIELD.showRating, default: true }, schemeField(), styleField(sectionStyle("tight", "narrow"))],
|
|
69
|
+
presets: [
|
|
70
|
+
{
|
|
71
|
+
key: "no-rating",
|
|
72
|
+
label: { ar: "بدون التقييم", fr: "Sans la note", en: "Without the rating" },
|
|
73
|
+
props: { showRating: false },
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
load: async (input) => ({ landing: await routeLanding(input) }),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const endsFields = [
|
|
80
|
+
{
|
|
81
|
+
key: "mode",
|
|
82
|
+
kind: "select",
|
|
83
|
+
label: FIELD.countdownEnds, description: HELP.countdownMode,
|
|
84
|
+
options: ["midnight", "date"],
|
|
85
|
+
optionLabels: { midnight: OPTION.midnight, date: OPTION.onDate },
|
|
86
|
+
default: "midnight",
|
|
87
|
+
display: "segmented",
|
|
88
|
+
},
|
|
89
|
+
{ key: "endsOn", kind: "text", label: FIELD.endsOn, description: HELP.endsOn, visibleIf: { field: "mode", equals: "date" } },
|
|
90
|
+
{ key: "endsAt", kind: "text", label: FIELD.endsAt, description: HELP.endsAt, visibleIf: { field: "mode", equals: "date" } },
|
|
91
|
+
] as const satisfies readonly FieldDefinition[];
|
|
92
|
+
|
|
93
|
+
export const countdown = defineComponent({
|
|
94
|
+
type: "countdown",
|
|
95
|
+
component: Countdown,
|
|
96
|
+
label: SECTION.countdown,
|
|
97
|
+
group: GROUP.content,
|
|
98
|
+
placement: "section",
|
|
99
|
+
capabilities: { surfaces: ["landing", "home", "product", "page"] },
|
|
100
|
+
fields: [{ key: "title", kind: "text", label: FIELD.title, contentKey: "countdown.title" }, ...endsFields, schemeField(ACCENT_SCHEME), styleField(sectionStyle("tight", "narrow"))],
|
|
101
|
+
presets: [{ key: "today", label: l("عرض اليوم فقط", "Offre du jour", "Today only"), props: { mode: "midnight" } }],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const steps = defineComponent({
|
|
105
|
+
type: "steps",
|
|
106
|
+
component: Steps,
|
|
107
|
+
label: SECTION.steps,
|
|
108
|
+
group: GROUP.content,
|
|
109
|
+
placement: "section",
|
|
110
|
+
capabilities: { surfaces: ["landing", "home", "product", "page"] },
|
|
111
|
+
fields: [
|
|
112
|
+
...headingFields("landing.steps"),
|
|
113
|
+
alignField,
|
|
114
|
+
{
|
|
115
|
+
key: "steps",
|
|
116
|
+
kind: "list",
|
|
117
|
+
label: FIELD.steps,
|
|
118
|
+
itemLabel: "title",
|
|
119
|
+
max: 4,
|
|
120
|
+
fields: [iconField("check"), { key: "title", kind: "text", label: FIELD.title }, { key: "text", kind: "text", label: FIELD.text }],
|
|
121
|
+
default: [
|
|
122
|
+
step("order", "check", l("املأ الاستمارة", "Remplissez le formulaire", "Fill in the form"), l("الاسم، الهاتف والولاية فقط.", "Nom, téléphone et wilaya, rien de plus.", "Name, phone and wilaya, nothing more.")),
|
|
123
|
+
step("confirm", "package", l("يؤكد المتجر طلبك", "La boutique confirme", "The store confirms"), l("يؤكد المتجر طلبك قبل إرساله.", "La boutique confirme votre commande avant de l'expédier.", "The store confirms your order before shipping it.")),
|
|
124
|
+
step("deliver", "truck", l("تستلم وتدفع", "Vous recevez et payez", "Receive it, then pay"), l("تدفع نقدًا عند استلام الطلب.", "Vous payez en espèces à la livraison.", "You pay in cash on delivery.")),
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
schemeField(),
|
|
128
|
+
styleField(sectionStyle("normal", "content")),
|
|
129
|
+
],
|
|
130
|
+
presets: [
|
|
131
|
+
{
|
|
132
|
+
key: "two-steps",
|
|
133
|
+
label: { ar: "خطوتان", fr: "Deux étapes", en: "Two steps" },
|
|
134
|
+
props: {
|
|
135
|
+
steps: [
|
|
136
|
+
{ id: "order", props: { icon: "check", title: { ar: "اطلب", fr: "Commandez", en: "Order" }, text: { ar: "الاسم والهاتف والولاية فقط.", fr: "Nom, téléphone et wilaya, rien de plus.", en: "Name, phone and wilaya, nothing more." } } },
|
|
137
|
+
{ id: "pay", props: { icon: "cash", title: { ar: "استلم وادفع", fr: "Recevez et payez", en: "Receive and pay" }, text: { ar: "تدفع نقدًا عند استلام طلبك.", fr: "Vous payez en espèces à la livraison.", en: "You pay in cash on delivery." } } },
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
export const landingComponents = {
|
|
145
|
+
"landing-images": landingImages,
|
|
146
|
+
"landing-order": landingOrder,
|
|
147
|
+
"landing-product": landingProduct,
|
|
148
|
+
countdown,
|
|
149
|
+
steps,
|
|
150
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The listing pages — all products, a category, a collection — share one
|
|
3
|
+
* section, and the text pages have theirs. Each route names its own kind
|
|
4
|
+
* (`surface`) and resource, so a collection or category that does not exist
|
|
5
|
+
* shows nothing, never every product in its place.
|
|
6
|
+
*/
|
|
7
|
+
import { defineComponent } from "@abcart/theme";
|
|
8
|
+
import { storefrontPath, type ProductPage, type StorePagePublic } from "@abcart/storefront";
|
|
9
|
+
import { alignField, schemeField, sectionStyle, styleField } from "../fields";
|
|
10
|
+
import { FIELD, GROUP, SECTION } from "../labels";
|
|
11
|
+
import ListingMain, { type ListingView } from "@/components/listing/ListingMain.astro";
|
|
12
|
+
import PageMain from "@/components/listing/PageMain.astro";
|
|
13
|
+
import { LISTING_PAGE_SIZE, requestedPage, requestedSort } from "@/lib/listing-query";
|
|
14
|
+
|
|
15
|
+
export const listingMain = defineComponent({
|
|
16
|
+
type: "listing-main",
|
|
17
|
+
component: ListingMain,
|
|
18
|
+
label: SECTION.listingMain,
|
|
19
|
+
group: GROUP.listing,
|
|
20
|
+
placement: "section",
|
|
21
|
+
capabilities: { surfaces: ["collection", "category", "catalog"], insertable: false },
|
|
22
|
+
fields: [
|
|
23
|
+
alignField,
|
|
24
|
+
{ key: "showBreadcrumbs", kind: "boolean", label: FIELD.showBreadcrumbs, default: true },
|
|
25
|
+
{ key: "showDescription", kind: "boolean", label: FIELD.showDescription, default: true },
|
|
26
|
+
{ key: "showCount", kind: "boolean", label: FIELD.showCount, default: true },
|
|
27
|
+
{ key: "showSort", kind: "boolean", label: FIELD.showSort, default: true },
|
|
28
|
+
{ key: "showCategoryNav", kind: "boolean", label: FIELD.showCategoryNav, default: true },
|
|
29
|
+
{ key: "columns", kind: "number", label: FIELD.columns, min: 2, max: 5, step: 1, default: 4, display: "slider" },
|
|
30
|
+
schemeField(),
|
|
31
|
+
styleField(sectionStyle("tight")),
|
|
32
|
+
],
|
|
33
|
+
load: async ({ storefront, reads, context }): Promise<{ view: ListingView | null }> => {
|
|
34
|
+
const params = context.params ?? {};
|
|
35
|
+
const page = requestedPage(params.page);
|
|
36
|
+
const sort = requestedSort(params.sort);
|
|
37
|
+
const window = { limit: LISTING_PAGE_SIZE, offset: (page - 1) * LISTING_PAGE_SIZE, sort };
|
|
38
|
+
const categories = await reads.get("categories", () => storefront.categories.list());
|
|
39
|
+
const view = (result: ProductPage, rest: Omit<ListingView, "products" | "hasNext" | "total" | "page" | "sort" | "categories">): ListingView => ({
|
|
40
|
+
...rest,
|
|
41
|
+
products: result.items,
|
|
42
|
+
hasNext: result.hasNext,
|
|
43
|
+
total: result.total,
|
|
44
|
+
page,
|
|
45
|
+
sort,
|
|
46
|
+
categories,
|
|
47
|
+
});
|
|
48
|
+
if (params.surface === "collection") {
|
|
49
|
+
const handle = params.handle ?? "";
|
|
50
|
+
const collection = handle ? await reads.get(`collection:${handle}`, () => storefront.collections.get(handle)) : null;
|
|
51
|
+
if (!collection) return { view: null };
|
|
52
|
+
const result = await storefront.products.page({ collection: handle, ...window });
|
|
53
|
+
return { view: view(result, { kind: "collection", title: collection.title, description: collection.description, path: storefrontPath("collection", { handle }), active: null }) };
|
|
54
|
+
}
|
|
55
|
+
if (params.surface === "category") {
|
|
56
|
+
const category = categories.find((candidate) => candidate.slug === params.slug);
|
|
57
|
+
if (!category) return { view: null };
|
|
58
|
+
const result = await storefront.products.page({ categoryId: category.id, ...window });
|
|
59
|
+
return { view: view(result, { kind: "category", title: category.name, description: category.description, path: storefrontPath("category", { slug: category.slug }), active: category.slug }) };
|
|
60
|
+
}
|
|
61
|
+
if (params.surface !== "catalog") return { view: null };
|
|
62
|
+
const result = await storefront.products.page(window);
|
|
63
|
+
return { view: view(result, { kind: "catalog", title: context.content["nav.shop"] ?? "", description: context.content["collection.subtitle"] ?? null, path: storefrontPath("catalog"), active: null }) };
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const pageMain = defineComponent({
|
|
68
|
+
type: "page-main",
|
|
69
|
+
component: PageMain,
|
|
70
|
+
label: SECTION.pageMain,
|
|
71
|
+
group: GROUP.page,
|
|
72
|
+
placement: "section",
|
|
73
|
+
capabilities: { surfaces: ["page"], insertable: false },
|
|
74
|
+
fields: [
|
|
75
|
+
{ key: "showBreadcrumbs", kind: "boolean", label: FIELD.showBreadcrumbs, default: true },
|
|
76
|
+
{ key: "showHelp", kind: "boolean", label: FIELD.showHelp, default: true },
|
|
77
|
+
schemeField(),
|
|
78
|
+
styleField(sectionStyle("normal", "content")),
|
|
79
|
+
],
|
|
80
|
+
load: async ({ storefront, reads, context }): Promise<{ page: StorePagePublic | null }> => {
|
|
81
|
+
const slug = context.params?.slug ?? "";
|
|
82
|
+
return { page: slug ? await reads.get(`page:${slug}`, () => storefront.pages.get(slug)) : null };
|
|
83
|
+
},
|
|
84
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Products of one collection, as a grid or a row that scrolls. */
|
|
2
|
+
import { defineComponent } from "@abcart/theme";
|
|
3
|
+
import type { ProductList } from "@abcart/storefront";
|
|
4
|
+
import ProductGrid from "@/components/sections/ProductGrid.astro";
|
|
5
|
+
import { alignField, headingFields, schemeField, styleField } from "../fields";
|
|
6
|
+
import { FIELD, GROUP, OPTION, SECTION, HELP } from "../labels";
|
|
7
|
+
import { ANYWHERE, columnsField, l } from "./shared";
|
|
8
|
+
|
|
9
|
+
export const productGrid = defineComponent({
|
|
10
|
+
type: "product-grid",
|
|
11
|
+
component: ProductGrid,
|
|
12
|
+
label: SECTION.productGrid,
|
|
13
|
+
group: GROUP.products,
|
|
14
|
+
placement: "section",
|
|
15
|
+
capabilities: ANYWHERE,
|
|
16
|
+
fields: [
|
|
17
|
+
...headingFields("home.products"),
|
|
18
|
+
alignField,
|
|
19
|
+
{ key: "collection", kind: "collection", label: FIELD.collection, default: "best-sellers" },
|
|
20
|
+
{ key: "limit", kind: "number", label: FIELD.limit, description: HELP.productsShown, default: 8, min: 2, max: 24, step: 1, display: "slider" },
|
|
21
|
+
columnsField,
|
|
22
|
+
{
|
|
23
|
+
key: "layout",
|
|
24
|
+
kind: "select",
|
|
25
|
+
label: FIELD.layout, description: HELP.gridLayout,
|
|
26
|
+
options: ["grid", "carousel"],
|
|
27
|
+
optionLabels: { grid: OPTION.grid, carousel: OPTION.carousel },
|
|
28
|
+
default: "grid",
|
|
29
|
+
display: "segmented",
|
|
30
|
+
},
|
|
31
|
+
{ key: "showViewAll", kind: "boolean", label: FIELD.showViewAll, default: true },
|
|
32
|
+
schemeField(),
|
|
33
|
+
styleField(),
|
|
34
|
+
],
|
|
35
|
+
load: async ({ storefront, props, reads }): Promise<{ products: ProductList[] }> => ({
|
|
36
|
+
products: await reads.get(`products:${props.collection}:${props.limit}`, () => storefront.products.list({ collection: props.collection, limit: props.limit })),
|
|
37
|
+
}),
|
|
38
|
+
presets: [
|
|
39
|
+
{ key: "new-arrivals", label: l("وصل حديثًا", "Nouveautés", "New arrivals"), props: { collection: "new-arrivals", layout: "carousel", title: { ar: "وصل", fr: "Nouveautés", en: "New" }, accent: { ar: "حديثًا", fr: "du moment", en: "arrivals" } } },
|
|
40
|
+
{ key: "featured", label: l("منتجات مختارة", "Sélection", "Featured picks"), props: { collection: "featured", limit: 4 } },
|
|
41
|
+
],
|
|
42
|
+
});
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The product template: the product itself — its photos, always there, and a
|
|
3
|
+
* column of blocks the merchant arranges around the order form, which can
|
|
4
|
+
* move but never leave — then its reviews and products like it.
|
|
5
|
+
*/
|
|
6
|
+
import { defineComponent, type LoadContext } from "@abcart/theme";
|
|
7
|
+
import { routeProduct } from "./shared";
|
|
8
|
+
import { iconField, schemeField, styleField } from "../fields";
|
|
9
|
+
import { BLOCK, FIELD, GROUP, HELP, OPTION, SECTION } from "../labels";
|
|
10
|
+
import ProductMain from "@/components/product/ProductMain.astro";
|
|
11
|
+
import ProductReviews from "@/components/product/ProductReviews.astro";
|
|
12
|
+
import RelatedProducts from "@/components/product/RelatedProducts.astro";
|
|
13
|
+
import GalleryBlock from "@/components/product/blocks/GalleryBlock.astro";
|
|
14
|
+
import RatingBlock from "@/components/product/blocks/RatingBlock.astro";
|
|
15
|
+
import TitleBlock from "@/components/product/blocks/TitleBlock.astro";
|
|
16
|
+
import PriceBlock from "@/components/product/blocks/PriceBlock.astro";
|
|
17
|
+
import StockBlock from "@/components/product/blocks/StockBlock.astro";
|
|
18
|
+
import OrderBlock from "@/components/product/blocks/OrderBlock.astro";
|
|
19
|
+
import BenefitsBlock from "@/components/product/blocks/BenefitsBlock.astro";
|
|
20
|
+
import DescriptionBlock from "@/components/product/blocks/DescriptionBlock.astro";
|
|
21
|
+
import CollapsibleBlock from "@/components/product/blocks/CollapsibleBlock.astro";
|
|
22
|
+
import DetailsBlock from "@/components/product/blocks/DetailsBlock.astro";
|
|
23
|
+
import TextBlock from "@/components/product/blocks/TextBlock.astro";
|
|
24
|
+
|
|
25
|
+
const ON_PRODUCT = { surfaces: ["product"] };
|
|
26
|
+
|
|
27
|
+
const load = async (input: LoadContext) => ({ product: await routeProduct(input) });
|
|
28
|
+
|
|
29
|
+
const productGallery = defineComponent({
|
|
30
|
+
type: "product-gallery",
|
|
31
|
+
component: GalleryBlock,
|
|
32
|
+
label: BLOCK.gallery,
|
|
33
|
+
group: GROUP.product,
|
|
34
|
+
placement: "block",
|
|
35
|
+
capabilities: { insertable: false, ...ON_PRODUCT },
|
|
36
|
+
fields: [
|
|
37
|
+
{
|
|
38
|
+
key: "thumbnails",
|
|
39
|
+
kind: "select",
|
|
40
|
+
label: FIELD.thumbnails, description: HELP.thumbnails,
|
|
41
|
+
options: ["side", "below"],
|
|
42
|
+
optionLabels: { side: OPTION.side, below: OPTION.below },
|
|
43
|
+
default: "side",
|
|
44
|
+
display: "segmented",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
load,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const productRating = defineComponent({
|
|
51
|
+
type: "product-rating",
|
|
52
|
+
component: RatingBlock,
|
|
53
|
+
label: BLOCK.rating,
|
|
54
|
+
group: GROUP.product,
|
|
55
|
+
placement: "block",
|
|
56
|
+
capabilities: ON_PRODUCT,
|
|
57
|
+
load,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const productTitle = defineComponent({
|
|
61
|
+
type: "product-title",
|
|
62
|
+
component: TitleBlock,
|
|
63
|
+
label: BLOCK.title,
|
|
64
|
+
group: GROUP.product,
|
|
65
|
+
placement: "block",
|
|
66
|
+
capabilities: ON_PRODUCT,
|
|
67
|
+
fields: [{ key: "showCategory", kind: "boolean", label: FIELD.showCategory, default: true }],
|
|
68
|
+
load,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const productPrice = defineComponent({
|
|
72
|
+
type: "product-price",
|
|
73
|
+
component: PriceBlock,
|
|
74
|
+
label: BLOCK.price,
|
|
75
|
+
group: GROUP.product,
|
|
76
|
+
placement: "block",
|
|
77
|
+
capabilities: ON_PRODUCT,
|
|
78
|
+
fields: [{ key: "showSaving", kind: "boolean", label: FIELD.showSaving, default: true }],
|
|
79
|
+
load,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const productStock = defineComponent({
|
|
83
|
+
type: "product-stock",
|
|
84
|
+
component: StockBlock,
|
|
85
|
+
label: BLOCK.stock,
|
|
86
|
+
group: GROUP.product,
|
|
87
|
+
placement: "block",
|
|
88
|
+
capabilities: ON_PRODUCT,
|
|
89
|
+
fields: [{ key: "showLowStock", kind: "boolean", label: FIELD.showLowStock, default: true }],
|
|
90
|
+
load,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The options, the offers and the cash-on-delivery form whose fields are the
|
|
95
|
+
* store's checkout form, set in the merchant dashboard; the theme only lays
|
|
96
|
+
* it out. Every product page holds exactly one.
|
|
97
|
+
*/
|
|
98
|
+
const productOrder = defineComponent({
|
|
99
|
+
type: "product-order",
|
|
100
|
+
component: OrderBlock,
|
|
101
|
+
label: BLOCK.order,
|
|
102
|
+
group: GROUP.product,
|
|
103
|
+
placement: "block",
|
|
104
|
+
role: "order-form",
|
|
105
|
+
capabilities: { insertable: false, ...ON_PRODUCT },
|
|
106
|
+
fields: [
|
|
107
|
+
{ key: "showAssurances", kind: "boolean", label: FIELD.showAssurances, default: true },
|
|
108
|
+
{ key: "scheme", kind: "colorScheme", label: FIELD.formScheme, description: HELP.formScheme },
|
|
109
|
+
],
|
|
110
|
+
load,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const productBenefits = defineComponent({
|
|
114
|
+
type: "product-benefits",
|
|
115
|
+
component: BenefitsBlock,
|
|
116
|
+
label: BLOCK.benefits,
|
|
117
|
+
group: GROUP.product,
|
|
118
|
+
placement: "block",
|
|
119
|
+
capabilities: ON_PRODUCT,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const productDescription = defineComponent({
|
|
123
|
+
type: "product-description",
|
|
124
|
+
component: DescriptionBlock,
|
|
125
|
+
label: BLOCK.description,
|
|
126
|
+
group: GROUP.product,
|
|
127
|
+
placement: "block",
|
|
128
|
+
capabilities: ON_PRODUCT,
|
|
129
|
+
fields: [
|
|
130
|
+
{ key: "title", kind: "text", label: FIELD.title, contentKey: "product.description" },
|
|
131
|
+
{ key: "open", kind: "boolean", label: FIELD.open, default: true },
|
|
132
|
+
],
|
|
133
|
+
load,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const productCollapsible = defineComponent({
|
|
137
|
+
type: "product-collapsible",
|
|
138
|
+
component: CollapsibleBlock,
|
|
139
|
+
label: BLOCK.collapsible,
|
|
140
|
+
group: GROUP.product,
|
|
141
|
+
placement: "block",
|
|
142
|
+
capabilities: ON_PRODUCT,
|
|
143
|
+
fields: [
|
|
144
|
+
{ key: "title", kind: "text", label: FIELD.title },
|
|
145
|
+
{ key: "body", kind: "richtext", label: FIELD.body, formats: ["bold", "italic", "link", "list"] },
|
|
146
|
+
iconField("truck"),
|
|
147
|
+
{ key: "open", kind: "boolean", label: FIELD.open, default: false },
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const productDetails = defineComponent({
|
|
152
|
+
type: "product-details",
|
|
153
|
+
component: DetailsBlock,
|
|
154
|
+
label: BLOCK.details,
|
|
155
|
+
group: GROUP.product,
|
|
156
|
+
placement: "block",
|
|
157
|
+
capabilities: ON_PRODUCT,
|
|
158
|
+
fields: [
|
|
159
|
+
{ key: "title", kind: "text", label: FIELD.title, contentKey: "product.details" },
|
|
160
|
+
{ key: "open", kind: "boolean", label: FIELD.open, default: false },
|
|
161
|
+
],
|
|
162
|
+
load,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const productText = defineComponent({
|
|
166
|
+
type: "product-text",
|
|
167
|
+
component: TextBlock,
|
|
168
|
+
label: BLOCK.text,
|
|
169
|
+
group: GROUP.product,
|
|
170
|
+
placement: "block",
|
|
171
|
+
capabilities: ON_PRODUCT,
|
|
172
|
+
fields: [{ key: "text", kind: "richtext", label: FIELD.text, formats: ["bold", "italic", "link"], inline: true }],
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const INFO_BLOCKS = [
|
|
176
|
+
"product-rating",
|
|
177
|
+
"product-title",
|
|
178
|
+
"product-price",
|
|
179
|
+
"product-stock",
|
|
180
|
+
"product-order",
|
|
181
|
+
"product-benefits",
|
|
182
|
+
"product-description",
|
|
183
|
+
"product-collapsible",
|
|
184
|
+
"product-details",
|
|
185
|
+
"product-text",
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
const productMain = defineComponent({
|
|
189
|
+
type: "product-main",
|
|
190
|
+
component: ProductMain,
|
|
191
|
+
label: SECTION.productMain,
|
|
192
|
+
group: GROUP.product,
|
|
193
|
+
placement: "section",
|
|
194
|
+
capabilities: { insertable: false, ...ON_PRODUCT },
|
|
195
|
+
fixed: [{ name: "gallery", type: "product-gallery", label: BLOCK.gallery }],
|
|
196
|
+
slots: [{ name: "info", allow: INFO_BLOCKS, max: 16, required: [{ type: "product-order", max: 1 }] }],
|
|
197
|
+
fields: [schemeField(), styleField({ spacing: { paddingBlockStart: { base: "s0", md: "s5" }, paddingBlockEnd: { base: "s6", lg: "s8" } }, size: { width: { base: "wide" } } })],
|
|
198
|
+
load,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const productReviews = defineComponent({
|
|
202
|
+
type: "product-reviews",
|
|
203
|
+
component: ProductReviews,
|
|
204
|
+
label: SECTION.productReviews,
|
|
205
|
+
group: GROUP.product,
|
|
206
|
+
placement: "section",
|
|
207
|
+
capabilities: { surfaces: ["product", "landing"] },
|
|
208
|
+
fields: [
|
|
209
|
+
{ key: "title", kind: "text", label: FIELD.title, contentKey: "product.reviews" },
|
|
210
|
+
{ key: "showForm", kind: "boolean", label: FIELD.showForm, default: true },
|
|
211
|
+
schemeField(),
|
|
212
|
+
styleField(),
|
|
213
|
+
],
|
|
214
|
+
presets: [
|
|
215
|
+
{
|
|
216
|
+
key: "read-only",
|
|
217
|
+
label: { ar: "آراء فقط", fr: "Avis seulement", en: "Reviews only" },
|
|
218
|
+
props: { showForm: false },
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
load: async (input) => {
|
|
222
|
+
const product = await routeProduct(input);
|
|
223
|
+
const empty = { rows: [], total: 0 };
|
|
224
|
+
if (!product || !input.context.store.reviewsEnabled) return { product, reviews: empty };
|
|
225
|
+
return { product, reviews: await input.reads.get(`reviews:${product.id}`, () => input.storefront.products.reviews.list(product.id, { limit: 6 })) };
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const relatedProducts = defineComponent({
|
|
230
|
+
type: "related-products",
|
|
231
|
+
component: RelatedProducts,
|
|
232
|
+
label: SECTION.relatedProducts,
|
|
233
|
+
group: GROUP.product,
|
|
234
|
+
placement: "section",
|
|
235
|
+
capabilities: ON_PRODUCT,
|
|
236
|
+
fields: [
|
|
237
|
+
{ key: "title", kind: "text", label: FIELD.title, contentKey: "product.related" },
|
|
238
|
+
{
|
|
239
|
+
key: "source",
|
|
240
|
+
kind: "select",
|
|
241
|
+
label: FIELD.source, description: HELP.relatedSource,
|
|
242
|
+
options: ["category", "collection"],
|
|
243
|
+
optionLabels: { category: OPTION.sameCategory, collection: FIELD.collection },
|
|
244
|
+
default: "category",
|
|
245
|
+
display: "segmented",
|
|
246
|
+
},
|
|
247
|
+
{ key: "collection", kind: "collection", label: FIELD.collection, default: "best-sellers", visibleIf: { field: "source", equals: "collection" } },
|
|
248
|
+
{ key: "limit", kind: "number", label: FIELD.limit, description: HELP.productsShown, default: 4, min: 2, max: 12, step: 1, display: "slider" },
|
|
249
|
+
{ key: "columns", kind: "number", label: FIELD.columns, min: 2, max: 5, step: 1, default: 4, display: "slider" },
|
|
250
|
+
schemeField(),
|
|
251
|
+
styleField(),
|
|
252
|
+
],
|
|
253
|
+
// Products like this one: its category's, else the chosen collection's —
|
|
254
|
+
// never the product itself. A product without a category falls back to the collection.
|
|
255
|
+
presets: [
|
|
256
|
+
{
|
|
257
|
+
key: "same-collection",
|
|
258
|
+
label: { ar: "من نفس المجموعة", fr: "Même collection", en: "Same collection" },
|
|
259
|
+
props: {
|
|
260
|
+
title: { ar: "من نفس المجموعة", fr: "Dans la même collection", en: "From the same collection" },
|
|
261
|
+
source: "collection",
|
|
262
|
+
collection: "best-sellers",
|
|
263
|
+
limit: 8,
|
|
264
|
+
columns: 4,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
load: async (input) => {
|
|
269
|
+
const { storefront, props, reads } = input;
|
|
270
|
+
const product = await routeProduct(input);
|
|
271
|
+
if (!product) return { products: [] };
|
|
272
|
+
const others = (rows: { id: string }[]) => rows.filter((row) => row.id !== product.id);
|
|
273
|
+
const byCategory = props.source === "category" && product.category
|
|
274
|
+
? others(await reads.get(`related:category:${product.category.id}`, () => storefront.products.list({ categoryId: product.category!.id, limit: props.limit + 1 })))
|
|
275
|
+
: [];
|
|
276
|
+
const fromCollection = byCategory.length > 0 ? [] : others(await reads.get(`related:collection:${props.collection}`, () => storefront.products.list({ collection: props.collection, limit: props.limit + 1 })));
|
|
277
|
+
return { products: [...byCategory, ...fromCollection].slice(0, props.limit) };
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
export const productComponents = {
|
|
282
|
+
"product-main": productMain,
|
|
283
|
+
"product-gallery": productGallery,
|
|
284
|
+
"product-rating": productRating,
|
|
285
|
+
"product-title": productTitle,
|
|
286
|
+
"product-price": productPrice,
|
|
287
|
+
"product-stock": productStock,
|
|
288
|
+
"product-order": productOrder,
|
|
289
|
+
"product-benefits": productBenefits,
|
|
290
|
+
"product-description": productDescription,
|
|
291
|
+
"product-collapsible": productCollapsible,
|
|
292
|
+
"product-details": productDetails,
|
|
293
|
+
"product-text": productText,
|
|
294
|
+
"product-reviews": productReviews,
|
|
295
|
+
"related-products": relatedProducts,
|
|
296
|
+
};
|
|
297
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** A title, formatted text and an optional button: the store's own words anywhere. */
|
|
2
|
+
import { defineComponent } from "@abcart/theme";
|
|
3
|
+
import RichText from "@/components/sections/RichText.astro";
|
|
4
|
+
import { MUTED_SCHEME, alignField, paragraphs, schemeField, sectionStyle, styleField } from "../fields";
|
|
5
|
+
import { FIELD, GROUP, SECTION } from "../labels";
|
|
6
|
+
import { WITH_LANDING, l } from "./shared";
|
|
7
|
+
|
|
8
|
+
export const richText = defineComponent({
|
|
9
|
+
type: "rich-text",
|
|
10
|
+
component: RichText,
|
|
11
|
+
label: SECTION.richText,
|
|
12
|
+
group: GROUP.content,
|
|
13
|
+
placement: "section",
|
|
14
|
+
capabilities: WITH_LANDING,
|
|
15
|
+
fields: [
|
|
16
|
+
{ key: "title", kind: "text", label: FIELD.title },
|
|
17
|
+
{ key: "body", kind: "richtext", label: FIELD.body, formats: ["bold", "italic", "underline", "link", "list", "heading"] },
|
|
18
|
+
{ key: "ctaLabel", kind: "text", label: FIELD.buttonLabel },
|
|
19
|
+
{ key: "ctaHref", kind: "url", label: FIELD.buttonLink },
|
|
20
|
+
alignField,
|
|
21
|
+
schemeField(),
|
|
22
|
+
styleField(sectionStyle("normal", "content")),
|
|
23
|
+
],
|
|
24
|
+
presets: [
|
|
25
|
+
{
|
|
26
|
+
key: "how-to-order",
|
|
27
|
+
label: l("كيف تطلب", "Comment commander", "How to order"),
|
|
28
|
+
props: {
|
|
29
|
+
title: { ar: "كيف تطلب", fr: "Comment commander", en: "How to order" },
|
|
30
|
+
body: paragraphs(
|
|
31
|
+
"اختر منتجك، املأ استمارة الطلب، وادفع نقدًا عند استلام طلبك.",
|
|
32
|
+
"Choisissez votre produit, remplissez le formulaire de commande et payez en espèces à la réception.",
|
|
33
|
+
"Pick your product, fill in the order form, and pay in cash when your order arrives.",
|
|
34
|
+
),
|
|
35
|
+
scheme: MUTED_SCHEME,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What several sections share: where they may be placed, common fields, and
|
|
3
|
+
* the reads a page's sections make of its route — a product page's product,
|
|
4
|
+
* a landing page and the product it sells — once per render, whichever
|
|
5
|
+
* section asks first.
|
|
6
|
+
*/
|
|
7
|
+
import { defineCapabilities, type FieldDefinition, type LoadContext } from "@abcart/theme";
|
|
8
|
+
import type { LandingPage, Product } from "@abcart/storefront";
|
|
9
|
+
import { FIELD, OPTION, HELP } from "../labels";
|
|
10
|
+
|
|
11
|
+
/** Every page a store composes; a section names the ones it serves. */
|
|
12
|
+
export const PAGE_SURFACES = ["home", "product", "collection", "category", "catalog", "page", "thank-you", "search", "track-order", "checkout", "contact"] as const;
|
|
13
|
+
/** A section a merchant may add to any page. */
|
|
14
|
+
export const ANYWHERE = defineCapabilities({ surfaces: PAGE_SURFACES });
|
|
15
|
+
/** A content section a landing page may hold too: it helps a shopper decide and leads nowhere else. */
|
|
16
|
+
export const WITH_LANDING = defineCapabilities({ surfaces: [...PAGE_SURFACES, "landing"] });
|
|
17
|
+
|
|
18
|
+
export const l = (ar: string, fr: string, en: string) => ({ ar, fr, en });
|
|
19
|
+
|
|
20
|
+
export const buttonFields = (labelKey?: string) =>
|
|
21
|
+
[
|
|
22
|
+
labelKey ? { key: "ctaLabel", kind: "text", label: FIELD.buttonLabel, contentKey: labelKey } : { key: "ctaLabel", kind: "text", label: FIELD.buttonLabel },
|
|
23
|
+
{ key: "ctaHref", kind: "url", label: FIELD.buttonLink, default: "/products" },
|
|
24
|
+
] as const satisfies readonly FieldDefinition[];
|
|
25
|
+
|
|
26
|
+
export const heightField = {
|
|
27
|
+
key: "height",
|
|
28
|
+
kind: "select",
|
|
29
|
+
label: FIELD.height,
|
|
30
|
+
options: ["medium", "tall"],
|
|
31
|
+
optionLabels: { medium: OPTION.medium, tall: OPTION.tall },
|
|
32
|
+
default: "tall",
|
|
33
|
+
display: "segmented",
|
|
34
|
+
} as const satisfies FieldDefinition;
|
|
35
|
+
|
|
36
|
+
export const columnsField = { key: "columns", kind: "number", label: FIELD.columns, description: HELP.columns, min: 2, max: 5, step: 1, default: 4, display: "slider" } as const satisfies FieldDefinition;
|
|
37
|
+
|
|
38
|
+
type Route = Pick<LoadContext, "storefront" | "context" | "reads">;
|
|
39
|
+
|
|
40
|
+
/** The read key of a landing page by its slug. The landing route and the preview fill it before rendering. */
|
|
41
|
+
export const landingRead = (slug: string) => `landing:${slug}`;
|
|
42
|
+
|
|
43
|
+
/** The landing page a landing route names; null on any other page. */
|
|
44
|
+
export async function routeLanding({ storefront, context, reads }: Route): Promise<LandingPage | null> {
|
|
45
|
+
const slug = context.params?.slug ?? "";
|
|
46
|
+
return context.params?.surface === "landing" && slug ? reads.get(landingRead(slug), () => storefront.pages.landing(slug)) : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The product a page is about: the product page's, or the one its landing page sells. */
|
|
50
|
+
export async function routeProduct(route: Route): Promise<Product | null> {
|
|
51
|
+
const handle = route.context.params?.handle ?? "";
|
|
52
|
+
if (handle) return route.reads.get(`product:${handle}`, () => route.storefront.products.get(handle));
|
|
53
|
+
return (await routeLanding(route))?.product ?? null;
|
|
54
|
+
}
|