HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/ShippingCosts/ShippingCostsController.php
<?php

namespace App\ShippingCosts;

use App\Forms\Models\Request;
use Komma\KMS\Core\SectionController;

class ShippingCostsController extends SectionController
{
    protected string $slug = "shipping_costs";
    protected string $classModelName = ShippingCost::class;

    public function __construct()
    {
        $section = new ShippingCostSection($this->slug);
        parent::__construct($section);
        $this->modelService = app(ShippingCostsService::class);
    }

    public function getShippingCostsForCountry(Request $request)
    {
        if(!$request->ajax()) abort(400, 'Only AJAX requests please');
        $iso3 = $request->get('ISO_3');
        if(!$iso3) abort(400, 'Please specify ISO_3 field');
        /** @var ShippingCostsService $shippingCostService */
        $shippingCostService = app(ShippingCostsService::class);
        $shippingCost = $shippingCostService->models()->where('code', '=', $iso3)->first();
        if(!$shippingCost) $shippingCost = $shippingCostService->models()->where('is_default', '=', 1)->first();
        if(!$shippingCost) abort(500, 'No shipping costs for "'.$iso3.'" found. And no default shipping cost defined. Always make sure there is 1 shippingCost marked as default');
        return $shippingCost;
    }
}