Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/UserAssignSku.php
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands; | ||||
use Illuminate\Console\Command; | use App\Console\Command; | ||||
class UserAssignSku extends Command | class UserAssignSku extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $signature = 'user:assign-sku {user} {sku} {--qty=}'; | protected $signature = 'user:assign-sku {user} {sku} {--qty=}'; | ||||
/** | /** | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = 'Assign a SKU to the user'; | protected $description = 'Assign a SKU to the user'; | ||||
/** | /** | ||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$user = \App\User::where('email', $this->argument('user'))->first(); | $user = $this->getUser($this->argument('user')); | ||||
if (!$user) { | if (!$user) { | ||||
$this->error("Unable to find the user {$this->argument('user')}."); | $this->error("Unable to find the user {$this->argument('user')}."); | ||||
return 1; | return 1; | ||||
} | } | ||||
$sku = \App\Sku::find($this->argument('sku')); | $sku = $this->getObject(\App\Sku::class, $this->argument('sku'), 'title'); | ||||
if (!$sku) { | |||||
$sku = \App\Sku::where('title', $this->argument('sku'))->first(); | |||||
} | |||||
if (!$sku) { | if (!$sku) { | ||||
$this->error("Unable to find the SKU {$this->argument('sku')}."); | $this->error("Unable to find the SKU {$this->argument('sku')}."); | ||||
return 1; | return 1; | ||||
} | } | ||||
$quantity = (int) $this->option('qty'); | $quantity = (int) $this->option('qty'); | ||||
Show All 11 Lines |