AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FlatRateShipping.php 786B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Commerce\Shipping;
  3. use App\Models\Store;
  4. /**
  5. * One fee for Peninsular Malaysia, another for Sabah, Sarawak and Labuan,
  6. * and free shipping above an amount the merchant chooses.
  7. */
  8. final class FlatRateShipping implements ShippingProvider
  9. {
  10. /**
  11. * States across the sea from the peninsula, where couriers charge more.
  12. *
  13. * @var list<string>
  14. */
  15. public const array EAST_MALAYSIA = ['Sabah', 'Sarawak', 'Labuan'];
  16. public function quote(Store $store, int $subtotal, string $state): int
  17. {
  18. if ($store->free_shipping_over !== null && $subtotal >= $store->free_shipping_over) {
  19. return 0;
  20. }
  21. return in_array($state, self::EAST_MALAYSIA, true) ? $store->shipping_east : $store->shipping_west;
  22. }
  23. }