Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/SkusController.php
<?php | <?php | ||||
namespace App\Http\Controllers\API\V4; | namespace App\Http\Controllers\API\V4; | ||||
use App\Http\Controllers\ResourceController; | use App\Http\Controllers\ResourceController; | ||||
use App\Sku; | use App\Sku; | ||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use Illuminate\Support\Str; | |||||
class SkusController extends ResourceController | class SkusController extends ResourceController | ||||
{ | { | ||||
/** | /** | ||||
* Get a list of SKUs available to the domain. | * Get a list of SKUs available to the domain. | ||||
* | * | ||||
* @param int $id Domain identifier | * @param int $id Domain identifier | ||||
* | * | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | public function userSkus($id) | ||||
if (!$this->guard()->user()->canRead($user)) { | if (!$this->guard()->user()->canRead($user)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
return $this->objectSkus($user); | return $this->objectSkus($user); | ||||
} | } | ||||
/** | /** | ||||
* Return SKUs available to the specified user/domain. | * Return SKUs available to the specified object. | ||||
* | * | ||||
* @param object $object User or Domain object | * @param object $object User/Domain/etc object | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
protected static function objectSkus($object) | public static function objectSkus($object) | ||||
{ | { | ||||
$type = $object instanceof \App\Domain ? 'domain' : 'user'; | $type = Str::kebab(\class_basename($object::class)); | ||||
$response = []; | $response = []; | ||||
// Note: Order by title for consistent ordering in tests | // Note: Order by title for consistent ordering in tests | ||||
$skus = Sku::withObjectTenantContext($object)->orderBy('title')->get(); | $skus = Sku::withObjectTenantContext($object)->orderBy('title')->get(); | ||||
foreach ($skus as $sku) { | foreach ($skus as $sku) { | ||||
if (!class_exists($sku->handler_class)) { | if (!class_exists($sku->handler_class)) { | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |