| 12345678910111213141516171819202122232425262728 |
- <?php
-
- namespace App\Commerce\Shipping;
-
- use App\Models\Store;
-
- /**
- * One fee for Peninsular Malaysia, another for Sabah, Sarawak and Labuan,
- * and free shipping above an amount the merchant chooses.
- */
- final class FlatRateShipping implements ShippingProvider
- {
- /**
- * States across the sea from the peninsula, where couriers charge more.
- *
- * @var list<string>
- */
- public const array EAST_MALAYSIA = ['Sabah', 'Sarawak', 'Labuan'];
-
- public function quote(Store $store, int $subtotal, string $state): int
- {
- if ($store->free_shipping_over !== null && $subtotal >= $store->free_shipping_over) {
- return 0;
- }
-
- return in_array($state, self::EAST_MALAYSIA, true) ? $store->shipping_east : $store->shipping_west;
- }
- }
|