| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace Longyi\ShippingInsurance\Services;
- use Webkul\Checkout\Facades\Cart;
- class ShippingInsuranceService
- {
- /**
- * 启用运费险
- */
- public function activate(): void
- {
- $cart = Cart::getCart();
- if (! $cart) {
- throw new \Exception('Cart not found.');
- }
- $cart->update([
- 'use_shipping_insurance' => true,
- ]);
- Cart::collectTotals();
- }
- /**
- * 移除运费险
- */
- public function remove(): void
- {
- $cart = Cart::getCart();
- if (! $cart) {
- throw new \Exception('Cart not found.');
- }
- $cart->update([
- 'use_shipping_insurance' => false,
- ]);
- Cart::collectTotals();
- }
- }
|