Fixed issue #1380
This commit is contained in:
parent
5ad8e46a86
commit
ca3dfe804c
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Commands\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
|
||||
|
||||
class ActivateCatalogRule extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'bagisto:activate {param}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* To hold attribute repository instance
|
||||
*/
|
||||
protected $attribute;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Attribute $attribute)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->attribute = $attribute;
|
||||
|
||||
$this->description = trans('admin::app.promotion.activate-catalog');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$param = $this->argument('param');
|
||||
|
||||
if (isset($param) && $param == 'catalog-rule') {
|
||||
$attribute = $this->attribute->findWhere([
|
||||
'code' => 'special_price'
|
||||
]);
|
||||
|
||||
if ($attribute->count()) {
|
||||
$attribute = $attribute->first();
|
||||
|
||||
if ($attribute->value_per_channel == 1) {
|
||||
$this->info(trans('admin::app.promotion.catalog-rule-already-activated'));
|
||||
} else {
|
||||
$attribute->update(['value_per_channel' => 1]);
|
||||
|
||||
$this->info(trans('admin::app.promotion.catalog-rule-activated'));
|
||||
}
|
||||
} else {
|
||||
$this->info(trans('admin::app.promotion.cannot-activate-catalog-rule'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,6 +143,27 @@ abstract class Discount
|
|||
return collect();
|
||||
}
|
||||
|
||||
/**
|
||||
* To find the oldes rule
|
||||
*
|
||||
* @param Collection $rules
|
||||
*
|
||||
* @return CartRule $oldestRule
|
||||
*/
|
||||
public function findOldestRule($rules)
|
||||
{
|
||||
$leastID = 999999999999;
|
||||
|
||||
foreach ($rules as $index => $rule) {
|
||||
if ($rule->id < $leastID) {
|
||||
$leastID = $rule->id;
|
||||
$oldestRule = $rule;
|
||||
}
|
||||
}
|
||||
|
||||
return $oldestRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* To sort the rules by the least priority
|
||||
*
|
||||
|
|
|
|||
|
|
@ -7,10 +7,6 @@ use Illuminate\Routing\Router;
|
|||
|
||||
class DiscountServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected $commands = [
|
||||
'Webkul\Discount\Commands\Console\ActivateCatalogRule'
|
||||
];
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
|
|
@ -29,8 +25,6 @@ class DiscountServiceProvider extends ServiceProvider
|
|||
public function register()
|
||||
{
|
||||
$this->registerConfig();
|
||||
|
||||
$this->commands($this->commands);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue