From 871ce5c2c3a573f629e0dbc619fea64b49bd849e Mon Sep 17 00:00:00 2001 From: Annika Wolff Date: Wed, 10 Jun 2020 16:08:13 +0200 Subject: [PATCH 001/113] starting --- .../Resources/views/datagrid/table.blade.php | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php index 4dbff797b..68857840e 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -563,48 +563,48 @@ //make the filter array from url after being redirected arrayFromUrl: function() { - var obj = {}; - processedUrl = this.url.search.slice(1, this.url.length); - splitted = []; - moreSplitted = []; + + let obj = {}; + const processedUrl = this.url.search.slice(1, this.url.length); + let splitted = []; + let moreSplitted = []; splitted = processedUrl.split('&'); - for(i = 0; i < splitted.length; i++) { + for(let i = 0; i < splitted.length; i++) { moreSplitted.push(splitted[i].split('=')); } - for(i = 0; i < moreSplitted.length; i++) { - col = moreSplitted[i][0].replace(']', '').split('[')[0]; - cond = moreSplitted[i][0].replace(']', '').split('[')[1] - val = moreSplitted[i][1]; + for(let i = 0; i < moreSplitted.length; i++) { + const key = decodeURI(moreSplitted[i][0]); + const value = decodeURI(moreSplitted[i][1]); + + obj.column = key.replace(']', '').split('[')[0]; + obj.cond = key.replace(']', '').split('[')[1] + obj.val = value; label = 'cannotfindthislabel'; - obj.column = col; - obj.cond = cond; - obj.val = val; - - if(col == "sort") { + if(obj.column === "sort") { label = ''; for(colIndex in this.columns) { - if(this.columns[colIndex].index == obj.cond) { + if(this.columns[colIndex].index === obj.cond) { obj.label = this.columns[colIndex].label; } } - } else if (col == "search") { + } else if (obj.column === "search") { obj.label = 'Search'; } else { obj.label = ''; - for(colIndex in this.columns) { - if (this.columns[colIndex].index == obj.column) { + for(let colIndex in this.columns) { + if (this.columns[colIndex].index === obj.column) { obj.label = this.columns[colIndex].label; - if (this.columns[colIndex].type == 'boolean') { - if (obj.val == 1) { + if (this.columns[colIndex].type === 'boolean') { + if (obj.val === 1) { obj.val = '{{ __('ui::app.datagrid.true') }}'; } else { obj.val = '{{ __('ui::app.datagrid.false') }}'; @@ -614,7 +614,7 @@ } } - if (col != undefined && cond != undefined && val != undefined) + // if (col != undefined && cond != undefined && val != undefined) this.filters.push(obj); obj = {}; @@ -685,7 +685,7 @@ _method : element.getAttribute('data-method') }).then(function(response) { this.result = response; - + if (response.data.redirect) { window.location.href = response.data.redirect; } else { From abad17aabaa8e50a2267c9dabe068f160f5bacf6 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 10 Jun 2020 23:17:41 +0900 Subject: [PATCH 002/113] update product_flat table with values when changing attribue->use_in_flat --- packages/Webkul/Product/src/Listeners/ProductFlat.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/Product/src/Listeners/ProductFlat.php b/packages/Webkul/Product/src/Listeners/ProductFlat.php index 85da1ddaf..404707501 100644 --- a/packages/Webkul/Product/src/Listeners/ProductFlat.php +++ b/packages/Webkul/Product/src/Listeners/ProductFlat.php @@ -136,6 +136,10 @@ class ProductFlat $table->dropColumn($attribute->code . '_label'); } }); + + $query = "update product_flat f join product_attribute_values v on f.id = v.product_id and v.attribute_id = $attribute->id set f.$attribute->code = ". $attribute->type ."_value"; + \DB::update($query); + } } @@ -313,4 +317,4 @@ class ProductFlat } } } -} \ No newline at end of file +} From 42e3a94b988243ee916e0432994d525bbde355ce Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 11 Jun 2020 13:12:55 +0900 Subject: [PATCH 003/113] move query to repository method; use eloquent instead of raw query --- .../Webkul/Product/src/Listeners/ProductFlat.php | 3 +-- .../src/Repositories/ProductFlatRepository.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Product/src/Listeners/ProductFlat.php b/packages/Webkul/Product/src/Listeners/ProductFlat.php index 404707501..340255db0 100644 --- a/packages/Webkul/Product/src/Listeners/ProductFlat.php +++ b/packages/Webkul/Product/src/Listeners/ProductFlat.php @@ -137,8 +137,7 @@ class ProductFlat } }); - $query = "update product_flat f join product_attribute_values v on f.id = v.product_id and v.attribute_id = $attribute->id set f.$attribute->code = ". $attribute->type ."_value"; - \DB::update($query); + $this->productFlatRepository->updateAttributeColumn( $attribute ); } } diff --git a/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php b/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php index ecac18df9..d49a7efea 100644 --- a/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php @@ -86,4 +86,19 @@ class ProductFlatRepository extends Repository return $filterAttributes; } + + + /** + * update product_flat custom column + * + * @param \Webkul\Attribute\Models\Attribute $attribute + */ + public function updateAttributeColumn( \Webkul\Attribute\Models\Attribute $attribute ) { + return $this->model + ->leftJoin('product_attribute_values as v', function($join) use ($attribute) { + $join->on('product_flat.id', '=', 'v.product_id') + ->on('v.attribute_id', '=', \DB::raw($attribute->id)); + })->update(['product_flat.'.$attribute->code => \DB::raw($attribute->type .'_value')]); + } + } \ No newline at end of file From 2afb015a6aa34786be19b59ed2ae48a6e9961983 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 11 Jun 2020 17:55:02 +0900 Subject: [PATCH 004/113] fixed mass update attribute column for all attr types --- packages/Webkul/Product/src/Listeners/ProductFlat.php | 2 +- .../Product/src/Repositories/ProductFlatRepository.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/Webkul/Product/src/Listeners/ProductFlat.php b/packages/Webkul/Product/src/Listeners/ProductFlat.php index 340255db0..090763211 100644 --- a/packages/Webkul/Product/src/Listeners/ProductFlat.php +++ b/packages/Webkul/Product/src/Listeners/ProductFlat.php @@ -137,7 +137,7 @@ class ProductFlat } }); - $this->productFlatRepository->updateAttributeColumn( $attribute ); + $this->productFlatRepository->updateAttributeColumn( $attribute , $this ); } } diff --git a/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php b/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php index d49a7efea..2f33f4a82 100644 --- a/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php @@ -92,13 +92,16 @@ class ProductFlatRepository extends Repository * update product_flat custom column * * @param \Webkul\Attribute\Models\Attribute $attribute + * @param \Webkul\Product\Listeners\ProductFlat $listener */ - public function updateAttributeColumn( \Webkul\Attribute\Models\Attribute $attribute ) { + public function updateAttributeColumn( + \Webkul\Attribute\Models\Attribute $attribute , + \Webkul\Product\Listeners\ProductFlat $listener ) { return $this->model ->leftJoin('product_attribute_values as v', function($join) use ($attribute) { $join->on('product_flat.id', '=', 'v.product_id') ->on('v.attribute_id', '=', \DB::raw($attribute->id)); - })->update(['product_flat.'.$attribute->code => \DB::raw($attribute->type .'_value')]); + })->update(['product_flat.'.$attribute->code => \DB::raw($listener->attributeTypeFields[$attribute->type] .'_value')]); } } \ No newline at end of file From 2302a5a8d6fd1d8103a2922bd0a778ccbc38d028 Mon Sep 17 00:00:00 2001 From: Annika Wolff Date: Thu, 11 Jun 2020 13:00:06 +0200 Subject: [PATCH 005/113] keep search terms after page reload --- packages/Webkul/Ui/src/DataGrid/DataGrid.php | 41 +++-- .../Resources/views/datagrid/table.blade.php | 161 ++++++++++-------- 2 files changed, 113 insertions(+), 89 deletions(-) diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index 0de51f738..bd03bb4d2 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -8,14 +8,14 @@ abstract class DataGrid { /** * set index columns, ex: id. - * + * * @var int */ protected $index = null; /** * Default sort order of datagrid - * + * * @var string */ protected $sortOrder = 'asc'; @@ -23,21 +23,21 @@ abstract class DataGrid /** * Situation handling property when working with custom columns in datagrid, helps abstaining * aliases on custom column. - * + * * @var bool */ protected $enableFilterMap = false; /** * This is array where aliases and custom column's name are passed - * + * * @var array */ protected $filterMap = []; /** * array to hold all the columns which will be displayed on frontend. - * + * * @var array */ protected $columns = []; @@ -51,14 +51,14 @@ abstract class DataGrid /** * Hold query builder instance of the query prepared by executing datagrid * class method setQueryBuilder - * + * * @var array */ protected $queryBuilder = []; /** * Final result of the datagrid program that is collection object. - * + * * @var array */ protected $collection = []; @@ -66,7 +66,7 @@ abstract class DataGrid /** * Set of handly click tools which you could be using for various operations. * ex: dyanmic and static redirects, deleting, etc. - * + * * @var array */ protected $actions = []; @@ -74,21 +74,21 @@ abstract class DataGrid /** * Works on selection of values index column as comma separated list as response * to your endpoint set as route. - * + * * @var array */ protected $massActions = []; /** * Parsed value of the url parameters - * + * * @var array */ protected $parse; /** * To show mass action or not. - * + * * @var bool */ protected $enableMassAction = false; @@ -100,14 +100,14 @@ abstract class DataGrid /** * paginate the collection or not - * + * * @var bool */ protected $paginate = true; /** * If paginated then value of pagination. - * + * * @var int */ protected $itemsPerPage = 10; @@ -165,7 +165,7 @@ abstract class DataGrid ]; abstract public function prepareQueryBuilder(); - + abstract public function addColumns(); /** @@ -178,7 +178,7 @@ abstract class DataGrid /** * Parse the URL and get it ready to be used. - * + * * @return void */ private function parseUrl() @@ -400,12 +400,12 @@ abstract class DataGrid } } else { foreach ($this->completeColumnDetails as $column) { - if($column['index'] == $columnName && !$column['filterable']) { + if($column['index'] === $columnName && !$column['filterable']) { return $collection; } } - if (array_keys($info)[0] == "like" || array_keys($info)[0] == "nlike") { + if (array_keys($info)[0] === "like" || array_keys($info)[0] === "nlike") { foreach ($info as $condition => $filter_value) { if ($this->enableFilterMap && isset($this->filterMap[$columnName])) { $collection->where( @@ -429,7 +429,12 @@ abstract class DataGrid } } else { foreach ($info as $condition => $filter_value) { - if ($columnType == 'datetime') { + + if ($condition === 'undefined') { + $condition = '='; + } + + if ($columnType === 'datetime') { if ($this->enableFilterMap && isset($this->filterMap[$columnName])) { $collection->whereDate( $this->filterMap[$columnName], diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php index 68857840e..e0e1ffa3a 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -225,7 +225,7 @@ if (this.filters.length) { for (let i = 0; i < this.filters.length; i++) { - if (this.filters[i].column == 'perPage') { + if (this.filters[i].column === 'perPage') { this.perPage = this.filters[i].val; } } @@ -237,17 +237,17 @@ this.columnOrAlias = columnOrAlias; for(column in this.columns) { - if (this.columns[column].index == this.columnOrAlias) { + if (this.columns[column].index === this.columnOrAlias) { this.type = this.columns[column].type; - if (this.type == 'string') { + if (this.type === 'string') { this.stringConditionSelect = true; this.datetimeConditionSelect = false; this.booleanConditionSelect = false; this.numberConditionSelect = false; this.nullify(); - } else if (this.type == 'datetime') { + } else if (this.type === 'datetime') { this.datetimeConditionSelect = true; this.stringConditionSelect = false; this.booleanConditionSelect = false; @@ -261,14 +261,14 @@ this.numberConditionSelect = false; this.nullify(); - } else if (this.type == 'number') { + } else if (this.type === 'number') { this.numberConditionSelect = true; this.booleanConditionSelect = false; this.datetimeConditionSelect = false; this.stringConditionSelect = false; this.nullify(); - } else if (this.type == 'price') { + } else if (this.type === 'price') { this.numberConditionSelect = true; this.booleanConditionSelect = false; this.datetimeConditionSelect = false; @@ -290,18 +290,20 @@ getResponse: function() { label = ''; - for(colIndex in this.columns) { + for(let colIndex in this.columns) { if(this.columns[colIndex].index == this.columnOrAlias) { label = this.columns[colIndex].label; + break; } } - if (this.type == 'string') { + if (this.type === 'string') { this.formURL(this.columnOrAlias, this.stringCondition, encodeURIComponent(this.stringValue), label) } else if (this.type == 'number') { indexConditions = true; - if (this.filterIndex == this.columnOrAlias && (this.numberValue == 0 || this.numberValue < 0)) { + if (this.filterIndex === this.columnOrAlias + && (this.numberValue === 0 || this.numberValue < 0)) { indexConditions = false; alert('{{__('ui::app.datagrid.zero-index')}}'); @@ -309,22 +311,23 @@ if(indexConditions) this.formURL(this.columnOrAlias, this.numberCondition, this.numberValue, label); - } else if (this.type == 'boolean') { + } else if (this.type === 'boolean') { this.formURL(this.columnOrAlias, this.booleanCondition, this.booleanValue, label); - } else if (this.type == 'datetime') { + } else if (this.type === 'datetime') { this.formURL(this.columnOrAlias, this.datetimeCondition, this.datetimeValue, label); - } else if (this.type == 'price') { + } else if (this.type === 'price') { this.formURL(this.columnOrAlias, this.numberCondition, this.numberValue, label); } }, sortCollection: function(alias) { - label = ''; + let label = ''; - for(colIndex in this.columns) { - if(this.columns[colIndex].index == alias) { + for(let colIndex in this.columns) { + if(this.columns[colIndex].index === alias) { matched = 0; label = this.columns[colIndex].label; + break; } } @@ -332,9 +335,7 @@ }, searchCollection: function(searchValue) { - label = 'Search'; - - this.formURL("search", 'all', searchValue, label); + this.formURL("search", 'all', searchValue, 'Search'); }, // function triggered to check whether the query exists or not and then call the make filters from the url @@ -345,7 +346,7 @@ this.arrayFromUrl(); } - for(id in this.massActions) { + for(let id in this.massActions) { targetObj = { 'type': this.massActions[id].type, 'action': this.massActions[id].action @@ -355,24 +356,24 @@ targetObj = {}; - if (this.massActions[id].type == 'update') { + if (this.massActions[id].type === 'update') { this.massActionValues = this.massActions[id].options; } } }, findCurrentSort: function() { - for(i in this.filters) { - if (this.filters[i].column == 'sort') { + for(let i in this.filters) { + if (this.filters[i].column === 'sort') { this.currentSort = this.filters[i].val; } } }, changeMassActionTarget: function() { - if (this.massActionType == 'delete') { - for(i in this.massActionTargets) { - if (this.massActionTargets[i].type == 'delete') { + if (this.massActionType === 'delete') { + for(let i in this.massActionTargets) { + if (this.massActionTargets[i].type === 'delete') { this.massActionTarget = this.massActionTargets[i].action; break; @@ -380,9 +381,9 @@ } } - if (this.massActionType == 'update') { - for(i in this.massActionTargets) { - if (this.massActionTargets[i].type == 'update') { + if (this.massActionType === 'update') { + for(let i in this.massActionTargets) { + if (this.massActionTargets[i].type === 'update') { this.massActionTarget = this.massActionTargets[i].action; break; @@ -397,7 +398,9 @@ formURL: function(column, condition, response, label) { var obj = {}; - if (column == "" || condition == "" || response == "" || column == null || condition == null || response == null) { + if (column === "" || condition === "" || response === "" + || column === null || condition === null || response === null) + { alert('{{ __('ui::app.datagrid.filter-fields-missing') }}'); return false; @@ -469,7 +472,7 @@ } } - if (sort_exists == 0) { + if (sort_exists === 0) { if (this.currentSort == null) this.currentSort = this.sortAsc; @@ -486,7 +489,7 @@ } } - if (column == "search") { + if (column === "search") { search_found = 0; for(j = 0; j < this.filters.length; j++) { @@ -538,7 +541,7 @@ makeURL: function() { newParams = ''; - for(i = 0; i < this.filters.length; i++) { + for (let i = 0; i < this.filters.length; i++) { if (this.filters[i].column == 'status') { if (this.filters[i].val.includes("True")) { this.filters[i].val = 1; @@ -547,11 +550,17 @@ } } - if (i == 0) { - newParams = '?' + this.filters[i].column + '[' + this.filters[i].cond + ']' + '=' + this.filters[i].val; - } else { - newParams = newParams + '&' + this.filters[i].column + '[' + this.filters[i].cond + ']' + '=' + this.filters[i].val; + let condition = ''; + if (this.filters[i].cond !== undefined) { + condition = '[' + this.filters[i].cond + ']'; } + + if (i == 0) { + newParams = '?' + this.filters[i].column + condition + '=' + this.filters[i].val; + } else { + newParams = newParams + '&' + this.filters[i].column + condition + '=' + this.filters[i].val; + } + console.log('newParams', newParams); } var uri = window.location.href.toString(); @@ -583,47 +592,56 @@ obj.cond = key.replace(']', '').split('[')[1] obj.val = value; - label = 'cannotfindthislabel'; - - if(obj.column === "sort") { - label = ''; - - for(colIndex in this.columns) { - if(this.columns[colIndex].index === obj.cond) { - - obj.label = this.columns[colIndex].label; + switch (obj.column) { + case "search": + obj.label = "Search"; + break; + case "channel": + obj.label = "Channel"; + console.log(obj.column, obj.label, obj.cond, obj.val); + break; + case "customer_group": + obj.label = "Customer Group"; + break; + case "sort": + for (let colIndex in this.columns) { + if (this.columns[colIndex].index === obj.cond) { + obj.label = this.columns[colIndex].label; + break; + } } - } - } else if (obj.column === "search") { - obj.label = 'Search'; - } else { - obj.label = ''; + break; + default: + for (let colIndex in this.columns) { + if (this.columns[colIndex].index === obj.column) { + obj.label = this.columns[colIndex].label; - for(let colIndex in this.columns) { - if (this.columns[colIndex].index === obj.column) { - obj.label = this.columns[colIndex].label; - - if (this.columns[colIndex].type === 'boolean') { - if (obj.val === 1) { - obj.val = '{{ __('ui::app.datagrid.true') }}'; - } else { - obj.val = '{{ __('ui::app.datagrid.false') }}'; + if (this.columns[colIndex].type === 'boolean') { + if (obj.val === 1) { + obj.val = '{{ __('ui::app.datagrid.true') }}'; + } else { + obj.val = '{{ __('ui::app.datagrid.false') }}'; + } } } } - } + break; } - // if (col != undefined && cond != undefined && val != undefined) + if (obj.column !== undefined && obj.val !== undefined) { this.filters.push(obj); + } obj = {}; } }, removeFilter: function(filter) { - for(i in this.filters) { - if (this.filters[i].col == filter.col && this.filters[i].cond == filter.cond && this.filters[i].val == filter.val) { + for (let i in this.filters) { + if (this.filters[i].col === filter.col + && this.filters[i].cond === filter.cond + && this.filters[i].val === filter.val) + { this.filters.splice(i, 1); this.makeURL(); @@ -635,7 +653,7 @@ select: function() { this.allSelected = false; - if (this.dataIds.length == 0) { + if (this.dataIds.length === 0) { this.massActionsToggle = false; this.massActionType = null; } else { @@ -651,12 +669,13 @@ if (this.allSelected) { if (this.gridCurrentData.hasOwnProperty("data")) { - for (currentData in this.gridCurrentData.data) { + for (let currentData in this.gridCurrentData.data) { - i = 0; - for(currentId in this.gridCurrentData.data[currentData]) { - if (i==0) + let i = 0; + for (let currentId in this.gridCurrentData.data[currentData]) { + if (i==0) { this.dataIds.push(this.gridCurrentData.data[currentData][this.filterIndex]); + } i++; } @@ -664,9 +683,9 @@ } else { for (currentData in this.gridCurrentData) { - i = 0; - for(currentId in this.gridCurrentData[currentData]) { - if (i==0) + let i = 0; + for (let currentId in this.gridCurrentData[currentData]) { + if (i === 0) this.dataIds.push(this.gridCurrentData[currentData][currentId]); i++; From 3ba83ace265d796b2f8d6200748a165e11fc04e7 Mon Sep 17 00:00:00 2001 From: Annika Wolff Date: Thu, 11 Jun 2020 14:23:34 +0200 Subject: [PATCH 006/113] prevent flickering, use blisss theme --- .../Factories/BookingProductEventTicketFactory.php | 6 ++---- tests/_support/FunctionalTester.php | 9 +++++++++ tests/functional/Checkout/Cart/CartCest.php | 13 +++++++------ tests/functional/Customer/CustomerCest.php | 10 ++++++++-- tests/functional/Shop/GuestCheckoutCest.php | 14 +++++++------- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/packages/Webkul/BookingProduct/src/Database/Factories/BookingProductEventTicketFactory.php b/packages/Webkul/BookingProduct/src/Database/Factories/BookingProductEventTicketFactory.php index 09f79b311..608dd477d 100644 --- a/packages/Webkul/BookingProduct/src/Database/Factories/BookingProductEventTicketFactory.php +++ b/packages/Webkul/BookingProduct/src/Database/Factories/BookingProductEventTicketFactory.php @@ -2,16 +2,14 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ -use Carbon\Carbon; use Faker\Generator as Faker; use Webkul\BookingProduct\Models\BookingProduct; use Webkul\BookingProduct\Models\BookingProductEventTicket; -use Webkul\Product\Models\Product; -$factory->define(BookingProductEventTicket::class, function (Faker $faker, array $attributes) { +$factory->define(BookingProductEventTicket::class, static function (Faker $faker, array $attributes) { return [ 'price' => $faker->randomFloat(4, 3, 900), - 'qty' => $faker->randomNumber(2), + 'qty' => $faker->numberBetween(100, 1000), 'booking_product_id' => static function () { return factory(BookingProduct::class)->create(['type' => 'event'])->id; } diff --git a/tests/_support/FunctionalTester.php b/tests/_support/FunctionalTester.php index f4788d481..6d1e1f8b0 100644 --- a/tests/_support/FunctionalTester.php +++ b/tests/_support/FunctionalTester.php @@ -126,4 +126,13 @@ class FunctionalTester extends \Codeception\Actor } } } + + public function useDefaultTheme(): void + { + $channel = core()->getCurrentChannel(); + + if ($channel->theme !== 'default') { + $channel->update(['theme' => 'default']); + } + } } diff --git a/tests/functional/Checkout/Cart/CartCest.php b/tests/functional/Checkout/Cart/CartCest.php index db20d49f0..0a4e5890b 100644 --- a/tests/functional/Checkout/Cart/CartCest.php +++ b/tests/functional/Checkout/Cart/CartCest.php @@ -4,7 +4,6 @@ namespace Tests\Functional\Checkout\Cart; use FunctionalTester; use Webkul\Core\Helpers\Laravel5Helper; -use Cart; class CartCest { @@ -12,7 +11,7 @@ class CartCest public $productWithQuantityBox; public $productWithoutQuantityBox; - public function _before(FunctionalTester $I) + public function _before(FunctionalTester $I): void { $productConfig = [ 'productAttributes' => [], @@ -27,9 +26,11 @@ class CartCest $this->productWithoutQuantityBox = $I->haveProduct(Laravel5Helper::DOWNLOADABLE_PRODUCT, $productConfig); } - public function checkCartWithQuantityBox(FunctionalTester $I) + public function checkCartWithQuantityBox(FunctionalTester $I): void { - Cart::addProduct($this->productWithQuantityBox->id, [ + $I->useDefaultTheme(); + + cart()->addProduct($this->productWithQuantityBox->id, [ '_token' => session('_token'), 'product_id' => $this->productWithQuantityBox->id, 'quantity' => 1, @@ -39,9 +40,9 @@ class CartCest $I->seeElement('#update_cart_button'); } - public function checkCartWithoutQuantityBox(FunctionalTester $I) + public function checkCartWithoutQuantityBox(FunctionalTester $I): void { - Cart::addProduct($this->productWithoutQuantityBox->id, [ + cart()->addProduct($this->productWithoutQuantityBox->id, [ '_token' => session('_token'), 'product_id' => $this->productWithoutQuantityBox->id, 'links' => $this->productWithoutQuantityBox->downloadable_links->pluck('id')->all(), diff --git a/tests/functional/Customer/CustomerCest.php b/tests/functional/Customer/CustomerCest.php index 49978ee64..3d5fecfac 100644 --- a/tests/functional/Customer/CustomerCest.php +++ b/tests/functional/Customer/CustomerCest.php @@ -2,6 +2,7 @@ namespace Tests\Functional\Customer; +use Faker\Factory; use Webkul\Customer\Models\Customer; use Webkul\Customer\Models\CustomerAddress; use FunctionalTester; @@ -10,6 +11,11 @@ class CustomerCest { public $fields = []; + public function _before(FunctionalTester $I): void + { + $I->useDefaultTheme(); + } + public function updateCustomerProfile(FunctionalTester $I): void { $customer = $I->loginAsCustomer(); @@ -32,8 +38,8 @@ class CustomerCest public function updateCustomerAddress(FunctionalTester $I): void { - $I->wantTo('Instantiate a european faker factory to have the vat provider available'); - $faker = \Faker\Factory::create('at_AT'); + // Instantiate a european faker factory to have the vat provider available + $faker = Factory::create('at_AT'); $formCssSelector = '#customer-address-form'; diff --git a/tests/functional/Shop/GuestCheckoutCest.php b/tests/functional/Shop/GuestCheckoutCest.php index 5a69f08f7..f9865527a 100644 --- a/tests/functional/Shop/GuestCheckoutCest.php +++ b/tests/functional/Shop/GuestCheckoutCest.php @@ -10,16 +10,16 @@ use Webkul\Core\Helpers\Laravel5Helper; class GuestCheckoutCest { - private $faker, - $productNoGuestCheckout, $productGuestCheckout; + private $productNoGuestCheckout, $productGuestCheckout; function _before(FunctionalTester $I) { + $I->useDefaultTheme(); - $this->faker = Factory::create(); + $faker = Factory::create(); $pConfigDefault = [ - 'productInventory' => ['qty' => $this->faker->numberBetween(1, 1000)], + 'productInventory' => ['qty' => $faker->numberBetween(1, 1000)], 'attributeValues' => [ 'status' => true, 'new' => 1, @@ -27,7 +27,7 @@ class GuestCheckoutCest ], ]; $pConfigGuestCheckout = [ - 'productInventory' => ['qty' => $this->faker->numberBetween(1, 1000)], + 'productInventory' => ['qty' => $faker->numberBetween(1, 1000)], 'attributeValues' => [ 'status' => true, 'new' => 1, @@ -72,8 +72,8 @@ class GuestCheckoutCest $I->click(__('shop::app.checkout.cart.proceed-to-checkout'), '//a[@href="' . route('shop.checkout.onepage.index') . '"]'); $I->seeCurrentRouteIs($example['expectedRoute']); - $cart = Cart::getCart(); - $I->assertTrue(Cart::removeItem($cart->items[0]->id)); + $cart = cart()->getCart(); + $I->assertTrue(cart()->removeItem($cart->items[0]->id)); } protected function guestCheckoutProvider(): array From 9bf7810a5f026d81db42131516ed9656b0a4ab13 Mon Sep 17 00:00:00 2001 From: Annika Wolff Date: Thu, 11 Jun 2020 14:56:05 +0200 Subject: [PATCH 007/113] add encoding of search terms --- .../Resources/views/datagrid/table.blade.php | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php index e0e1ffa3a..a1d511120 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -405,18 +405,19 @@ return false; } else { - if (this.filters.length > 0) { - if (column != "sort" && column != "search") { - filterRepeated = 0; - for(j = 0; j < this.filters.length; j++) { - if (this.filters[j].column == column) { - if (this.filters[j].cond == condition && this.filters[j].val == response) { - filterRepeated = 1; + if (this.filters.length > 0) { + if (column !== "sort" && column !== "search") { + let filterRepeated = false; + + for(let j = 0; j < this.filters.length; j++) { + if (this.filters[j].column === column) { + if (this.filters[j].cond === condition && this.filters[j].val === response) { + filterRepeated = true; return false; - } else if(this.filters[j].cond == condition && this.filters[j].val != response) { - filterRepeated = 1; + } else if(this.filters[j].cond === condition && this.filters[j].val !== response) { + filterRepeated = true; this.filters[j].val = response; @@ -425,7 +426,7 @@ } } - if (filterRepeated == 0) { + if (filterRepeated === false) { obj.column = column; obj.cond = condition; obj.val = response; @@ -438,15 +439,15 @@ } } - if (column == "sort") { - sort_exists = 0; + if (column === "sort") { + let sort_exists = false; - for (j = 0; j < this.filters.length; j++) { - if (this.filters[j].column == "sort") { - if (this.filters[j].column == column && this.filters[j].cond == condition) { + for (let j = 0; j < this.filters.length; j++) { + if (this.filters[j].column === "sort") { + if (this.filters[j].column === column && this.filters[j].cond === condition) { this.findCurrentSort(); - if (this.currentSort == "asc") { + if (this.currentSort === "asc") { this.filters[j].column = column; this.filters[j].cond = condition; this.filters[j].val = this.sortDesc; @@ -468,12 +469,12 @@ this.makeURL(); } - sort_exists = 1; + sort_exists = true; } } - if (sort_exists === 0) { - if (this.currentSort == null) + if (sort_exists === false) { + if (this.currentSort === null) this.currentSort = this.sortAsc; obj.column = column; @@ -490,29 +491,29 @@ } if (column === "search") { - search_found = 0; + let search_found = false; - for(j = 0; j < this.filters.length; j++) { - if (this.filters[j].column == "search") { + for(let j = 0; j < this.filters.length; j++) { + if (this.filters[j].column === "search") { this.filters[j].column = column; this.filters[j].cond = condition; - this.filters[j].val = response; + this.filters[j].val = encodeURIComponent(response); this.filters[j].label = label; this.makeURL(); } } - for (j = 0;j < this.filters.length;j++) { - if (this.filters[j].column == "search") { - search_found = 1; + for (let j = 0;j < this.filters.length;j++) { + if (this.filters[j].column === "search") { + search_found = true; } } - if (search_found == 0) { + if (search_found === false) { obj.column = column; obj.cond = condition; - obj.val = response; + obj.val = encodeURIComponent(response); obj.label = label; this.filters.push(obj); @@ -525,7 +526,7 @@ } else { obj.column = column; obj.cond = condition; - obj.val = response; + obj.val = encodeURIComponent(response); obj.label = label; this.filters.push(obj); From 15d9155a9dcd5f890bd516a9a3a8d8b53e4ed578 Mon Sep 17 00:00:00 2001 From: Annika Wolff Date: Tue, 16 Jun 2020 15:33:03 +0200 Subject: [PATCH 008/113] refactoring --- packages/Webkul/Ui/src/DataGrid/DataGrid.php | 89 +++++++++++-------- .../Resources/views/datagrid/table.blade.php | 31 +++---- 2 files changed, 68 insertions(+), 52 deletions(-) diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index bd03bb4d2..6fa7cd8c0 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -209,33 +209,37 @@ abstract class DataGrid /** * Add the index as alias of the column and use the column to make things happen * - * @param string $alias - * @param string $column + * @param string $alias + * @param string $column + * * @return void */ - public function addFilter($alias, $column) { + public function addFilter($alias, $column) + { $this->filterMap[$alias] = $column; $this->enableFilterMap = true; } /** - * @param string $column + * @param string $column + * * @return void */ public function addColumn($column) { - $this->fireEvent('add.column.before.'.$column['index']); + $this->fireEvent('add.column.before.' . $column['index']); array_push($this->columns, $column); $this->setCompleteColumnDetails($column); - $this->fireEvent('add.column.after.'.$column['index']); + $this->fireEvent('add.column.after.' . $column['index']); } /** - * @param string $column + * @param string $column + * * @return void */ public function setCompleteColumnDetails($column) @@ -244,7 +248,8 @@ abstract class DataGrid } /** - * @param \Illuminate\Database\Query\Builder $queryBuilder + * @param \Illuminate\Database\Query\Builder $queryBuilder + * * @return void */ public function setQueryBuilder($queryBuilder) @@ -253,7 +258,8 @@ abstract class DataGrid } /** - * @param array $action + * @param array $action + * * @return void */ public function addAction($action) @@ -266,7 +272,7 @@ abstract class DataGrid $eventName = null; } - $this->fireEvent('action.before.'.$eventName); + $this->fireEvent('action.before.' . $eventName); array_push($this->actions, $action); @@ -276,7 +282,8 @@ abstract class DataGrid } /** - * @param array $massAction + * @param array $massAction + * * @return void */ public function addMassAction($massAction) @@ -306,21 +313,24 @@ abstract class DataGrid $parsedUrl = $this->parseUrl(); foreach ($parsedUrl as $key => $value) { - if ( $key == 'locale') { - if ( ! is_array($value)) { + if ($key == 'locale') { + if (! is_array($value)) { unset($parsedUrl[$key]); } - } elseif ( ! is_array($value)) { + } elseif (! is_array($value)) { unset($parsedUrl[$key]); } } if (count($parsedUrl)) { - $filteredOrSortedCollection = $this->sortOrFilterCollection($this->collection = $this->queryBuilder, $parsedUrl); + $filteredOrSortedCollection = $this->sortOrFilterCollection($this->collection = $this->queryBuilder, + $parsedUrl); if ($this->paginate) { - if ($this->itemsPerPage > 0) - return $filteredOrSortedCollection->orderBy($this->index, $this->sortOrder)->paginate($this->itemsPerPage)->appends(request()->except('page')); + if ($this->itemsPerPage > 0) { + return $filteredOrSortedCollection->orderBy($this->index, + $this->sortOrder)->paginate($this->itemsPerPage)->appends(request()->except('page')); + } } else { return $filteredOrSortedCollection->orderBy($this->index, $this->sortOrder)->get(); } @@ -328,7 +338,8 @@ abstract class DataGrid if ($this->paginate) { if ($this->itemsPerPage > 0) { - $this->collection = $this->queryBuilder->orderBy($this->index, $this->sortOrder)->paginate($this->itemsPerPage)->appends(request()->except('page')); + $this->collection = $this->queryBuilder->orderBy($this->index, + $this->sortOrder)->paginate($this->itemsPerPage)->appends(request()->except('page')); } } else { $this->collection = $this->queryBuilder->orderBy($this->index, $this->sortOrder)->get(); @@ -340,26 +351,28 @@ abstract class DataGrid /** * To find the alias of the column and by taking the column name. * - * @param array $columnAlias + * @param array $columnAlias + * * @return array */ public function findColumnType($columnAlias) { - foreach($this->completeColumnDetails as $column) { - if($column['index'] == $columnAlias) { + foreach ($this->completeColumnDetails as $column) { + if ($column['index'] == $columnAlias) { return [$column['type'], $column['index']]; } } } /** - * @param \Illuminate\Support\Collection $collection - * @param array $parseInfo + * @param \Illuminate\Support\Collection $collection + * @param array $parseInfo + * * @return \Illuminate\Support\Collection */ public function sortOrFilterCollection($collection, $parseInfo) { - foreach ($parseInfo as $key => $info) { + foreach ($parseInfo as $key => $info) { $columnType = $this->findColumnType($key)[0] ?? null; $columnName = $this->findColumnType($key)[1] ?? null; @@ -384,15 +397,16 @@ abstract class DataGrid } if ($count_keys == 1) { - $collection->where(function($collection) use($info) { + $collection->where(function ($collection) use ($info) { foreach ($this->completeColumnDetails as $column) { if ($column['searchable'] == true) { - if($this->enableFilterMap && isset($this->filterMap[$column['index']])) { - $collection->orWhere($this->filterMap[$column['index']], 'like', '%'.$info['all'].'%'); - } elseif($this->enableFilterMap && !isset($this->filterMap[$column['index']])) { - $collection->orWhere($column['index'], 'like', '%'.$info['all'].'%'); - }else { - $collection->orWhere($column['index'], 'like', '%'.$info['all'].'%'); + if ($this->enableFilterMap && isset($this->filterMap[$column['index']])) { + $collection->orWhere($this->filterMap[$column['index']], 'like', + '%' . $info['all'] . '%'); + } elseif ($this->enableFilterMap && ! isset($this->filterMap[$column['index']])) { + $collection->orWhere($column['index'], 'like', '%' . $info['all'] . '%'); + } else { + $collection->orWhere($column['index'], 'like', '%' . $info['all'] . '%'); } } } @@ -400,7 +414,7 @@ abstract class DataGrid } } else { foreach ($this->completeColumnDetails as $column) { - if($column['index'] === $columnName && !$column['filterable']) { + if ($column['index'] === $columnName && ! $column['filterable']) { return $collection; } } @@ -411,19 +425,19 @@ abstract class DataGrid $collection->where( $this->filterMap[$columnName], $this->operators[$condition], - '%'.$filter_value.'%' + '%' . $filter_value . '%' ); } elseif ($this->enableFilterMap && ! isset($this->filterMap[$columnName])) { $collection->where( $columnName, $this->operators[$condition], - '%'.$filter_value.'%' + '%' . $filter_value . '%' ); } else { $collection->where( $columnName, $this->operators[$condition], - '%'.$filter_value.'%' + '%' . $filter_value . '%' ); } } @@ -461,7 +475,7 @@ abstract class DataGrid $this->operators[$condition], $filter_value ); - } elseif($this->enableFilterMap && !isset($this->filterMap[$columnName])) { + } elseif ($this->enableFilterMap && ! isset($this->filterMap[$columnName])) { $collection->where( $columnName, $this->operators[$condition], @@ -484,7 +498,8 @@ abstract class DataGrid } /** - * @param string $name + * @param string $name + * * @return void */ protected function fireEvent($name) diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php index a1d511120..a1eefb2f5 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -236,7 +236,7 @@ getColumnOrAlias: function(columnOrAlias) { this.columnOrAlias = columnOrAlias; - for(column in this.columns) { + for (column in this.columns) { if (this.columns[column].index === this.columnOrAlias) { this.type = this.columns[column].type; @@ -290,8 +290,8 @@ getResponse: function() { label = ''; - for(let colIndex in this.columns) { - if(this.columns[colIndex].index == this.columnOrAlias) { + for (let colIndex in this.columns) { + if (this.columns[colIndex].index == this.columnOrAlias) { label = this.columns[colIndex].label; break; } @@ -309,8 +309,9 @@ alert('{{__('ui::app.datagrid.zero-index')}}'); } - if(indexConditions) + if (indexConditions) { this.formURL(this.columnOrAlias, this.numberCondition, this.numberValue, label); + } } else if (this.type === 'boolean') { this.formURL(this.columnOrAlias, this.booleanCondition, this.booleanValue, label); } else if (this.type === 'datetime') { @@ -323,8 +324,8 @@ sortCollection: function(alias) { let label = ''; - for(let colIndex in this.columns) { - if(this.columns[colIndex].index === alias) { + for (let colIndex in this.columns) { + if (this.columns[colIndex].index === alias) { matched = 0; label = this.columns[colIndex].label; break; @@ -346,7 +347,7 @@ this.arrayFromUrl(); } - for(let id in this.massActions) { + for (let id in this.massActions) { targetObj = { 'type': this.massActions[id].type, 'action': this.massActions[id].action @@ -363,7 +364,7 @@ }, findCurrentSort: function() { - for(let i in this.filters) { + for (let i in this.filters) { if (this.filters[i].column === 'sort') { this.currentSort = this.filters[i].val; } @@ -372,7 +373,7 @@ changeMassActionTarget: function() { if (this.massActionType === 'delete') { - for(let i in this.massActionTargets) { + for (let i in this.massActionTargets) { if (this.massActionTargets[i].type === 'delete') { this.massActionTarget = this.massActionTargets[i].action; @@ -382,7 +383,7 @@ } if (this.massActionType === 'update') { - for(let i in this.massActionTargets) { + for (let i in this.massActionTargets) { if (this.massActionTargets[i].type === 'update') { this.massActionTarget = this.massActionTargets[i].action; @@ -410,13 +411,13 @@ if (column !== "sort" && column !== "search") { let filterRepeated = false; - for(let j = 0; j < this.filters.length; j++) { + for (let j = 0; j < this.filters.length; j++) { if (this.filters[j].column === column) { if (this.filters[j].cond === condition && this.filters[j].val === response) { filterRepeated = true; return false; - } else if(this.filters[j].cond === condition && this.filters[j].val !== response) { + } else if (this.filters[j].cond === condition && this.filters[j].val !== response) { filterRepeated = true; this.filters[j].val = response; @@ -493,7 +494,7 @@ if (column === "search") { let search_found = false; - for(let j = 0; j < this.filters.length; j++) { + for (let j = 0; j < this.filters.length; j++) { if (this.filters[j].column === "search") { this.filters[j].column = column; this.filters[j].cond = condition; @@ -581,11 +582,11 @@ splitted = processedUrl.split('&'); - for(let i = 0; i < splitted.length; i++) { + for (let i = 0; i < splitted.length; i++) { moreSplitted.push(splitted[i].split('=')); } - for(let i = 0; i < moreSplitted.length; i++) { + for (let i = 0; i < moreSplitted.length; i++) { const key = decodeURI(moreSplitted[i][0]); const value = decodeURI(moreSplitted[i][1]); From a833677ffab8d6ebcb4291801fec1b61622db043 Mon Sep 17 00:00:00 2001 From: Annika Wolff Date: Tue, 30 Jun 2020 12:16:18 +0200 Subject: [PATCH 009/113] refactor --- .../Resources/views/datagrid/table.blade.php | 182 ++++++++++-------- 1 file changed, 104 insertions(+), 78 deletions(-) diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php index 317c5336a..01376ad2e 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -12,10 +12,13 @@
- +
- +
@@ -27,12 +30,13 @@ {{ __('ui::app.datagrid.items-per-page') }} - + + + + + @@ -49,7 +53,8 @@
  • - @foreach($results['columns'] as $column) @if(isset($column['filterable']) && $column['filterable']) @@ -66,7 +71,8 @@
  • +
  • @@ -86,7 +94,8 @@
  • +
  • @@ -107,7 +118,8 @@
  • @@ -128,7 +140,8 @@