SAP Spartacus 中的 checkout(结帐) 设计

简介: SAP Spartacus 中的 checkout(结帐) 设计

https://sap.github.io/spartacus-docs/extending-checkoutimage.png在 checkout 流程里,我们通常从一个链接跳转到另一个链接,因此 Spartacus 采取在 Storefront 配置里,将每个 checkout page 注册成 semantic page.

默认的 checkout 配置:image.pngimage.pngimage.png虽然默认的 checkout 只有4个步骤,但是配置里包含了5个semantic 页面,具有一个通用的路由,路径为 route.

image.png4个步骤对应的页面:image.png使用自己实现的 CheckoutGuard 跳转到正确的 checkout step 上去。image.png如果要实现单步 checkout 步骤,从 Component configuration 中移除 CheckoutGuard.image.pngimage.png

id:checkout step 的唯一标识

name:used in the CheckoutProgress component to indicate which checkout steps have been completed.

用于 CheckoutProgress 中,标识当前已经完成了哪一个 checkout 步骤。


image.png

  • routeName:specifies the semantic page for each step - 每个 checkout 步骤的 semantic 页面名称
  • type:用于 checkout guards

steps 数组里的步骤决定了 checkout 次序。image.png

  • checkout 步骤使用 Component guard,而不是 page guard.
  • 在 CMS Component mapping 里定义 guard.

image.pngSpartacus 提供了下列的 Component guard:

(1) ShippingAddressSetGuard

(2) DeliveryModeSetGuard

(3) PaymentDetailsSetGuard

(4) CheckoutGuardimage.png因此,当试图访问 Review Order 页面时,Spartacus 首先遍历这个页面所有的 Component guards,只有这些 guard 全部返回 true 之后,才能打开 Review order 页面。

image.pngComponent guard 最先返回哪个 redirect url,用户就被重定向到哪个 url 去。所以 Component guard 的顺序很重要。

如何定义重定向 urlimage.pngimage.pngCMS Catalog Content and Default Template

点击购物车按钮后,跳转到 checkout route:image.png当从 cart 跳转到 checkout 时,有一个 cancel 操作,cancel 的是 checkout default step:image.png最终跳转到 shipping address url:image.pnghttp://localhost:4200/electronics-spa/en/USD/checkoutimage.png如下图所示:image.png包含 16个 content slot:image.pngimage.png

调换 checkout 步骤的顺序

一个例子:image.png@NgModule({

 imports: [

   B2cStorefrontModule.withConfig({

     ...restOfConfig,

     checkout: {

       // You must specify all of the steps (this configuration is not merged with the default one)

       steps: [

         {

           id: 'shippingAddress',

           name: 'checkoutProgress.shippingAddress',

           routeName: 'checkoutShippingAddress',

           type: [CheckoutStepType.SHIPPING_ADDRESS],

         },

         // Change the payment details step to be before the delivery mode

         {

           id: 'paymentDetails',

           name: 'checkoutProgress.paymentDetails',

           routeName: 'checkoutPaymentDetails',

           type: [CheckoutStepType.PAYMENT_DETAILS],

         },

         {

           id: 'deliveryMode',

           name: 'checkoutProgress.deliveryMode',

           routeName: 'checkoutDeliveryMode',

           type: [CheckoutStepType.DELIVERY_MODE],

         },

         {

           id: 'reviewOrder',

           name: 'checkoutProgress.reviewOrder',

           routeName: 'checkoutReviewOrder',

           type: [CheckoutStepType.REVIEW_ORDER],

         },

       ],

     },

     cmsComponents: {

       CheckoutPaymentDetails: {

         component: PaymentMethodsComponent,

         // The default CheckoutPaymentDetails uses the DeliveryModeSetGuard, but in this case, the delivery mode details will not be set yet.

         // Instead, override the component guards with a new set that does not include the DeliveryModeSetGuard

         guards: [AuthGuard, CartNotEmptyGuard, ShippingAddressSetGuard],

       },

       CheckoutDeliveryMode: {

         component: DeliveryModeComponent,

         // In the CheckoutDeliveryMode, we need to also check if the payment details are set, so we add the PaymentDetailsSetGuard

         guards: [

           AuthGuard,

           CartNotEmptyGuard,

           ShippingAddressSetGuard,

           PaymentDetailsSetGuard,

         ],

       },

     },

   }),

 ],

 bootstrap: [StorefrontComponent],

})

export class AppModule {}CheckoutPaymentDetails Component,只有在进入 payment step 时才加载:image.pngCheckoutPaymentDetailsimage.pngimage.png在 CMS Component mapping 里指定 Component guard:image.png

相关文章
|
7月前
|
缓存 负载均衡 前端开发
SAP Spartacus 和 Sticky session 相关的话题
SAP Spartacus 和 Sticky session 相关的话题
39 0
|
7月前
|
存储
SAP Emarsys 和 SAP Spartacus 的集成
SAP Emarsys 和 SAP Spartacus 的集成
51 0
|
4月前
|
JSON 开发者 数据格式
关于 SAP Spartacus LandingPage2Template 区域的 layout 设计实现
关于 SAP Spartacus LandingPage2Template 区域的 layout 设计实现
26 0
|
4月前
|
搜索推荐 开发者 UED
关于 SAP Spartacus 层的 UI 设计
关于 SAP Spartacus 层的 UI 设计
42 0
|
4月前
|
开发者 UED
SAP Spartacus BREAKPOINT 枚举类型在 Spartacus layout 实现中的作用
SAP Spartacus BREAKPOINT 枚举类型在 Spartacus layout 实现中的作用
25 0
|
7月前
|
前端开发 搜索推荐 JavaScript
什么是 SAP Spartacus 的 CMS Page Connector
什么是 SAP Spartacus 的 CMS Page Connector
47 0
|
7月前
|
JavaScript 容器
关于 SAP Spartacus generic-link component 的模板代码
关于 SAP Spartacus generic-link component 的模板代码
42 2
|
7月前
|
前端开发 JavaScript API
SAP Commerce Accelerator Storefront 到 Spartacus 的 page by page migration 策略
SAP Commerce Accelerator Storefront 到 Spartacus 的 page by page migration 策略
32 0
|
7月前
|
JSON 前端开发 API
SAP Spartacus UI 中的 CmsTicketInterceptor
SAP Spartacus UI 中的 CmsTicketInterceptor
39 0
|
7月前
|
前端开发 UED 开发者
SAP Spartacus 开源项目中 $skipComponentStyles 的作用介绍
SAP Spartacus 开源项目中 $skipComponentStyles 的作用介绍
49 0