From ca3dfe804cdbe942829c2c804878f3a8fce91cc4 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Mon, 2 Sep 2019 13:52:28 +0530 Subject: [PATCH] Fixed issue #1380 --- .../Commands/Console/ActivateCatalogRule.php | 72 ------------------- .../Discount/src/Helpers/Cart/Discount.php | 21 ++++++ .../src/Providers/DiscountServiceProvider.php | 6 -- 3 files changed, 21 insertions(+), 78 deletions(-) delete mode 100644 packages/Webkul/Discount/src/Commands/Console/ActivateCatalogRule.php diff --git a/packages/Webkul/Discount/src/Commands/Console/ActivateCatalogRule.php b/packages/Webkul/Discount/src/Commands/Console/ActivateCatalogRule.php deleted file mode 100644 index 38d216eda..000000000 --- a/packages/Webkul/Discount/src/Commands/Console/ActivateCatalogRule.php +++ /dev/null @@ -1,72 +0,0 @@ -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')); - } - } - } -} \ No newline at end of file diff --git a/packages/Webkul/Discount/src/Helpers/Cart/Discount.php b/packages/Webkul/Discount/src/Helpers/Cart/Discount.php index afb761cc9..33c7031a9 100644 --- a/packages/Webkul/Discount/src/Helpers/Cart/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Cart/Discount.php @@ -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 * diff --git a/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php b/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php index 43e43f425..9c4e5fd5c 100644 --- a/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php +++ b/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php @@ -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); } /**