EventServiceProvider.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Longyi\ShippingInsurance\Providers;
  3. use Illuminate\Support\Facades\Event;
  4. use Illuminate\Support\ServiceProvider;
  5. use Longyi\Pay\Applepay\Events\CollectingAmountBreakdown;
  6. class EventServiceProvider extends ServiceProvider
  7. {
  8. /**
  9. * Bootstrap services.
  10. */
  11. public function boot(): void
  12. {
  13. // 运费险计算:监听购物车总计收集事件
  14. Event::listen('checkout.cart.collect.totals.after', 'Longyi\ShippingInsurance\Listeners\ShippingInsuranceHandler@applyShippingInsurance');
  15. // 购物车页面:在 tax 之后、grand total 之前显示运费险
  16. Event::listen('bagisto.shop.checkout.cart.summary.tax.after', function ($viewRenderEventManager) {
  17. $viewRenderEventManager->addTemplate('shippinginsurance::components.shipping-insurance-cartsummary');
  18. });
  19. // 结账页面:在 tax 之后、grand total 之前显示运费险
  20. Event::listen('bagisto.shop.checkout.onepage.summary.tax.after', function ($viewRenderEventManager) {
  21. $viewRenderEventManager->addTemplate('shippinginsurance::components.shipping-insurance-cartsummary');
  22. });
  23. // 后台订单详情:在 discount 之后、grand total 之前显示运费险金额
  24. // 参考礼品卡的 OrderViewHandler 方式:从路由获取订单后 echo 渲染组件
  25. Event::listen('bagisto.admin.sales.order.view.discount.after', 'Longyi\ShippingInsurance\Listeners\OrderViewHandler@renderShippingInsurance');
  26. // 前台会员中心订单详情:在 discount 之后、grand total 之前显示运费险金额
  27. Event::listen('bagisto.shop.customers.account.orders.view.information.discount.after', 'Longyi\ShippingInsurance\Listeners\OrderViewHandler@renderShippingInsurance');
  28. // 将运费险金额映射进 Apple Pay breakdown
  29. Event::listen(CollectingAmountBreakdown::class, 'Longyi\ShippingInsurance\Listeners\ApplepayBreakdownHandler@collect');
  30. }
  31. }