Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2485184
AssignSkuCommand.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
AssignSkuCommand.php
View Options
<?php
namespace
App\Console\Commands\User
;
use
App\Console\Command
;
class
AssignSkuCommand
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'user:assign-sku {user} {sku} {--qty=}'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Assign a SKU to the user'
;
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$user
=
$this
->
getUser
(
$this
->
argument
(
'user'
));
if
(!
$user
)
{
$this
->
error
(
"User not found."
);
return
1
;
}
$sku
=
$this
->
getObject
(
\App\Sku
::
class
,
$this
->
argument
(
'sku'
),
'title'
);
if
(!
$sku
)
{
$this
->
error
(
"Unable to find the SKU {$this->argument('sku')}."
);
return
1
;
}
$quantity
=
(
int
)
$this
->
option
(
'qty'
);
// Check if the entitlement already exists
if
(
empty
(
$quantity
))
{
if
(
$user
->
entitlements
()->
where
(
'sku_id'
,
$sku
->
id
)->
first
())
{
$this
->
error
(
"The entitlement already exists. Maybe try with --qty=X?"
);
return
1
;
}
}
$user
->
assignSku
(
$sku
,
$quantity
?:
1
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 21, 5:24 AM (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
387400
Default Alt Text
AssignSkuCommand.php (1 KB)
Attached To
Mode
R2 kolab
Attached
Detach File
Event Timeline
Log In to Comment