From 9f9e0b6a68310b16dec78a734d5db37394c1a515 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Mon, 15 Jul 2019 16:02:39 +0530 Subject: [PATCH] Created a command to activate the usage of catalog rule --- .../Admin/src/Resources/lang/en/app.php | 3 + .../promotions/cart-rule/create.blade.php | 20 ++++-- .../Database/Seeders/AttributeTableSeeder.php | 2 +- .../src/Repositories/AttributeRepository.php | 26 +++++-- .../Commands/Console/ActivateCatalogRule.php | 72 +++++++++++++++++++ .../src/Providers/DiscountServiceProvider.php | 6 ++ .../Webkul/Ui/src/Resources/lang/en/form.php | 3 +- 7 files changed, 117 insertions(+), 15 deletions(-) create mode 100644 packages/Webkul/Discount/src/Commands/Console/ActivateCatalogRule.php diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index 4f7a817fd..78de14d6d 100755 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -819,6 +819,9 @@ return [ 'select-products' => 'How to choose products ?', 'select-category' => 'Select by Categories', 'select-attribute' => 'Select by Attributes', + 'cannot-activate-catalog-rule' => 'Cannot activate catalog rule', + 'catalog-rule-already-activated' => 'Catalog rule is already activated', + 'catalog-rule-activated' => 'Catalog rule is activated', 'general-info' => [ 'sku-like' => 'SKU Like', 'on-shipping' => 'If applied on shipping', diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php index 7f3b2675e..c58fe5f78 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php @@ -363,7 +363,7 @@
- +
@@ -416,9 +416,6 @@ data () { return { - dummy_options: [ - 1, 2, 3, 4, 5 - ], name: null, description: null, conditions_list: [], @@ -483,7 +480,8 @@ attr_object: { attribute: null, condition: null, - value: [] + value: [], + options: [] }, attribute_input: @json($cart_rule[3]), attribute_options: [], @@ -500,6 +498,10 @@ return attribute_options.name + ' [ ' + attribute_options.type + ' ]'; }, + attributeListLabel (index) { + console.log(this.attribute_list[index], index); + }, + addCondition () { if (this.criteria == 'product_subselection' || this.criteria == 'cart') { this.condition_on = this.criteria; @@ -526,7 +528,8 @@ this.attr_object = { attribute: null, condition: null, - value: [] + value: [], + options: [] }; }, @@ -558,8 +561,11 @@ for(i in this.attribute_input) { if (i == selectedIndex) { + if (this.attribute_input[i].has_options == true) { + this.attribute_input[i].options = this.attribute_input[i].options; + } + this.attribute_list[index].type = this.attribute_input[i].type; - console.log(this.attribute_list[index].type); } } }, diff --git a/packages/Webkul/Attribute/src/Database/Seeders/AttributeTableSeeder.php b/packages/Webkul/Attribute/src/Database/Seeders/AttributeTableSeeder.php index 7d24e2e9e..68bacea58 100755 --- a/packages/Webkul/Attribute/src/Database/Seeders/AttributeTableSeeder.php +++ b/packages/Webkul/Attribute/src/Database/Seeders/AttributeTableSeeder.php @@ -28,7 +28,7 @@ class AttributeTableSeeder extends Seeder ['id' => '10','code' => 'description','admin_name' => 'Description','type' => 'textarea','validation' => NULL,'position' => '10','is_required' => '1','is_unique' => '0','value_per_locale' => '1','value_per_channel' => '1','is_filterable' => '0','is_configurable' => '0','is_user_defined' => '0','is_visible_on_front' => '0','created_at' => $now,'updated_at' => $now], ['id' => '11','code' => 'price','admin_name' => 'Price','type' => 'price','validation' => 'decimal','position' => '11','is_required' => '1','is_unique' => '0','value_per_locale' => '0','value_per_channel' => '0','is_filterable' => '1','is_configurable' => '0','is_user_defined' => '0','is_visible_on_front' => '0','created_at' => $now,'updated_at' => $now], ['id' => '12','code' => 'cost','admin_name' => 'Cost','type' => 'price','validation' => 'decimal','position' => '12','is_required' => '0','is_unique' => '0','value_per_locale' => '0','value_per_channel' => '1','is_filterable' => '0','is_configurable' => '0','is_user_defined' => '1','is_visible_on_front' => '0','created_at' => $now,'updated_at' => $now], - ['id' => '13','code' => 'special_price','admin_name' => 'Special Price','type' => 'price','validation' => 'decimal','position' => '13','is_required' => '0','is_unique' => '0','value_per_locale' => '0','value_per_channel' => '0','is_filterable' => '0','is_configurable' => '0','is_user_defined' => '0','is_visible_on_front' => '0','created_at' => $now,'updated_at' => $now], + ['id' => '13','code' => 'special_price','admin_name' => 'Special Price','type' => 'price','validation' => 'decimal','position' => '13','is_required' => '0','is_unique' => '0','value_per_locale' => '0','value_per_channel' => '1','is_filterable' => '0','is_configurable' => '0','is_user_defined' => '0','is_visible_on_front' => '0','created_at' => $now,'updated_at' => $now], ['id' => '14','code' => 'special_price_from','admin_name' => 'Special Price From','type' => 'date','validation' => NULL,'position' => '14','is_required' => '0','is_unique' => '0','value_per_locale' => '0','value_per_channel' => '1','is_filterable' => '0','is_configurable' => '0','is_user_defined' => '0','is_visible_on_front' => '0','created_at' => $now,'updated_at' => $now], ['id' => '15','code' => 'special_price_to','admin_name' => 'Special Price To','type' => 'date','validation' => NULL,'position' => '15','is_required' => '0','is_unique' => '0','value_per_locale' => '0','value_per_channel' => '1','is_filterable' => '0','is_configurable' => '0','is_user_defined' => '0','is_visible_on_front' => '0','created_at' => $now,'updated_at' => $now], ['id' => '16','code' => 'meta_title','admin_name' => 'Meta Title','type' => 'textarea','validation' => NULL,'position' => '16','is_required' => '0','is_unique' => '0','value_per_locale' => '1','value_per_channel' => '1','is_filterable' => '0','is_configurable' => '0','is_user_defined' => '0','is_visible_on_front' => '0','created_at' => $now,'updated_at' => $now], diff --git a/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php b/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php index fa4fc8ee3..4c7c921a9 100755 --- a/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php +++ b/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php @@ -221,12 +221,26 @@ class AttributeRepository extends Repository foreach($attributes as $key => $attribute) { if ($attribute->code != 'tax_category_id' && ($attribute->type == 'select' || $attribute->type == 'multiselect' || $attribute->code == 'sku')) { - array_push($trimmed, [ - 'id' => $attribute->id, - 'name' => $attribute->name, - 'type' => $attribute->type, - 'code' => $attribute->code, - ]); + if ($attribute->options()->exists()) { + array_push($trimmed, [ + 'id' => $attribute->id, + 'name' => $attribute->name, + 'type' => $attribute->type, + 'code' => $attribute->code, + 'has_options' => true, + 'options' => $attribute->options + ]); + } else { + array_push($trimmed, [ + 'id' => $attribute->id, + 'name' => $attribute->name, + 'type' => $attribute->type, + 'code' => $attribute->code, + 'has_options' => false, + 'options' => null + ]); + } + } } diff --git a/packages/Webkul/Discount/src/Commands/Console/ActivateCatalogRule.php b/packages/Webkul/Discount/src/Commands/Console/ActivateCatalogRule.php new file mode 100644 index 000000000..38d216eda --- /dev/null +++ b/packages/Webkul/Discount/src/Commands/Console/ActivateCatalogRule.php @@ -0,0 +1,72 @@ +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/Providers/DiscountServiceProvider.php b/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php index e799353d0..4989397e4 100644 --- a/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php +++ b/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php @@ -7,6 +7,10 @@ use Illuminate\Routing\Router; class DiscountServiceProvider extends ServiceProvider { + protected $commands = [ + 'Webkul\Discount\Commands\Console\ActivateCatalogRule' + ]; + /** * Bootstrap services. * @@ -25,6 +29,8 @@ class DiscountServiceProvider extends ServiceProvider public function register() { $this->registerConfig(); + + $this->commands($this->commands); } /** diff --git a/packages/Webkul/Ui/src/Resources/lang/en/form.php b/packages/Webkul/Ui/src/Resources/lang/en/form.php index bc30e3f6d..a84013cc0 100644 --- a/packages/Webkul/Ui/src/Resources/lang/en/form.php +++ b/packages/Webkul/Ui/src/Resources/lang/en/form.php @@ -1,5 +1,6 @@ 'Enter :attribute' + 'enter-attribute' => 'Enter :attribute', + 'select-attribute' => 'Select :attribute' ]; \ No newline at end of file