From 62abcb13f98cbf06d7eb3912b2d43fada61f9308 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Tue, 27 Mar 2018 10:08:07 +0200 Subject: [PATCH 01/10] Filtering orders without time scenaio --- .../filtering_orders_by_date.feature | 15 +++++++++++++-- .../Context/Ui/Admin/ManagingOrdersContext.php | 4 ++-- src/Sylius/Behat/Page/Admin/Order/IndexPage.php | 16 ++++++++-------- .../Page/Admin/Order/IndexPageInterface.php | 8 ++++---- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/features/order/managing_orders/filtering_orders_by_date.feature b/features/order/managing_orders/filtering_orders_by_date.feature index 863ece0acfd..b8fed274868 100644 --- a/features/order/managing_orders/filtering_orders_by_date.feature +++ b/features/order/managing_orders/filtering_orders_by_date.feature @@ -7,9 +7,9 @@ Feature: Filtering orders Background: Given the store operates on a single channel in "United States" And the store has customer "Mike Ross" with email "ross@teammike.com" - And this customer has placed an order "#00000001" at "2016-12-05 08:00:00" + And this customer has placed an order "#00000001" at "2016-12-04 08:00:00" And this customer has also placed an order "#00000002" at "2016-12-05 09:00:00" - And this customer has also placed an order "#00000003" at "2016-12-05 10:00:00" + And this customer has also placed an order "#00000003" at "2016-12-06 10:00:00" And I am logged in as an administrator @ui @@ -42,3 +42,14 @@ Feature: Filtering orders And I should see an order with "#00000002" number But I should not see an order with "#00000001" number And I should not see an order with "#00000003" number + + @ui + Scenario: Filtering orders by date from without time + When I browse orders + And I specify filter date from as "2016-12-05" + And I specify filter date to as "2016-12-06" + And I filter + Then I should see 2 orders in the list + And I should see an order with "#00000002" number + And I should see an order with "#00000003" number + But I should not see an order with "#00000001" number diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingOrdersContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingOrdersContext.php index ebac4f87656..16d1fe45549 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingOrdersContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingOrdersContext.php @@ -164,7 +164,7 @@ public function iSwitchSortingBy($fieldName) */ public function iSpecifyFilterDateFromAs($dateTime) { - $this->indexPage->specifyFilterDateFrom(new \DateTime($dateTime)); + $this->indexPage->specifyFilterDateFrom($dateTime); } /** @@ -172,7 +172,7 @@ public function iSpecifyFilterDateFromAs($dateTime) */ public function iSpecifyFilterDateToAs($dateTime) { - $this->indexPage->specifyFilterDateTo(new \DateTime($dateTime)); + $this->indexPage->specifyFilterDateTo($dateTime); } /** diff --git a/src/Sylius/Behat/Page/Admin/Order/IndexPage.php b/src/Sylius/Behat/Page/Admin/Order/IndexPage.php index 12a2a432196..4922ade9624 100644 --- a/src/Sylius/Behat/Page/Admin/Order/IndexPage.php +++ b/src/Sylius/Behat/Page/Admin/Order/IndexPage.php @@ -20,23 +20,23 @@ class IndexPage extends BaseIndexPage implements IndexPageInterface /** * {@inheritdoc} */ - public function specifyFilterDateFrom(\DateTimeInterface $dateTime) + public function specifyFilterDateFrom(string $dateTime) { - $timestamp = $dateTime->getTimestamp(); + $dateAndTime = explode(' ', $dateTime); - $this->getDocument()->fillField('criteria_date_from_date', date('Y-m-d', $timestamp)); - $this->getDocument()->fillField('criteria_date_from_time', date('H:i', $timestamp)); + $this->getDocument()->fillField('criteria_date_from_date', $dateAndTime[0]); + $this->getDocument()->fillField('criteria_date_from_time', $dateAndTime[1] ?? ''); } /** * {@inheritdoc} */ - public function specifyFilterDateTo(\DateTimeInterface $dateTime) + public function specifyFilterDateTo(string $dateTime) { - $timestamp = $dateTime->getTimestamp(); + $dateAndTime = explode(' ', $dateTime); - $this->getDocument()->fillField('criteria_date_to_date', date('Y-m-d', $timestamp)); - $this->getDocument()->fillField('criteria_date_to_time', date('H:i', $timestamp)); + $this->getDocument()->fillField('criteria_date_to_date', $dateAndTime[0]); + $this->getDocument()->fillField('criteria_date_to_time', $dateAndTime[1] ?? ''); } /** diff --git a/src/Sylius/Behat/Page/Admin/Order/IndexPageInterface.php b/src/Sylius/Behat/Page/Admin/Order/IndexPageInterface.php index 790e88ff7f1..079f71290d9 100644 --- a/src/Sylius/Behat/Page/Admin/Order/IndexPageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Order/IndexPageInterface.php @@ -18,14 +18,14 @@ interface IndexPageInterface extends BaseIndexPageInterface { /** - * @param \DateTimeInterface $dateTime + * @param string $dateTime */ - public function specifyFilterDateFrom(\DateTimeInterface $dateTime); + public function specifyFilterDateFrom(string $dateTime); /** - * @param \DateTimeInterface $dateTime + * @param string $dateTime */ - public function specifyFilterDateTo(\DateTimeInterface $dateTime); + public function specifyFilterDateTo(string $dateTime); /** * @param string $channelName From 5384e4d973c81ac6d22d1369a0fab35bb765bb4c Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Tue, 27 Mar 2018 11:28:00 +0200 Subject: [PATCH 02/10] Provide default times for datetime filter --- .../DateTimeFilterTransformer.php | 49 +++++++++++++++++++ .../Form/Type/Filter/DateFilterType.php | 4 ++ .../Component/Grid/Filter/DateFilter.php | 9 ++-- .../Grid/spec/Filter/DateFilterSpec.php | 8 +-- 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 src/Sylius/Bundle/GridBundle/Form/DataTransformer/DateTimeFilterTransformer.php diff --git a/src/Sylius/Bundle/GridBundle/Form/DataTransformer/DateTimeFilterTransformer.php b/src/Sylius/Bundle/GridBundle/Form/DataTransformer/DateTimeFilterTransformer.php new file mode 100644 index 00000000000..9ff560d8607 --- /dev/null +++ b/src/Sylius/Bundle/GridBundle/Form/DataTransformer/DateTimeFilterTransformer.php @@ -0,0 +1,49 @@ + ['hour' => '00', 'minute' => '00'], + 'to' => ['hour' => '23', 'minute' => '59'], + ]; + + /** @var string */ + private $type; + + public function __construct(string $type) + { + Assert::oneOf($type, array_keys(static::$defaultTime)); + + $this->type = $type; + } + + /** + * {@inheritdoc} + */ + public function transform($value): array + { + return $value; + } + + /** + * {@inheritdoc} + */ + public function reverseTransform($value): array + { + if (!$value['date']['year']) { + return $value; + } + + $value['time']['hour'] = $value['time']['hour'] === '' ? static::$defaultTime[$this->type]['hour'] : $value['time']['hour']; + $value['time']['minute'] = $value['time']['minute'] === '' ? static::$defaultTime[$this->type]['minute'] : $value['time']['minute']; + + return $value; + } +} diff --git a/src/Sylius/Bundle/GridBundle/Form/Type/Filter/DateFilterType.php b/src/Sylius/Bundle/GridBundle/Form/Type/Filter/DateFilterType.php index 18aed68ddf6..98d1955f707 100644 --- a/src/Sylius/Bundle/GridBundle/Form/Type/Filter/DateFilterType.php +++ b/src/Sylius/Bundle/GridBundle/Form/Type/Filter/DateFilterType.php @@ -13,6 +13,7 @@ namespace Sylius\Bundle\GridBundle\Form\Type\Filter; +use Sylius\Bundle\GridBundle\Form\DataTransformer\DateTimeFilterTransformer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\FormBuilderInterface; @@ -39,6 +40,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'required' => false, ]) ; + + $builder->get('from')->addViewTransformer(new DateTimeFilterTransformer('from')); + $builder->get('to')->addViewTransformer(new DateTimeFilterTransformer('to')); } /** diff --git a/src/Sylius/Component/Grid/Filter/DateFilter.php b/src/Sylius/Component/Grid/Filter/DateFilter.php index ee5073bf83e..fe0b8e3eda1 100644 --- a/src/Sylius/Component/Grid/Filter/DateFilter.php +++ b/src/Sylius/Component/Grid/Filter/DateFilter.php @@ -31,7 +31,7 @@ public function apply(DataSourceInterface $dataSource, string $name, $data, arra $field = (string) $this->getOption($options, 'field', $name); - $from = isset($data['from']) ? $this->getDateTime($data['from']) : null; + $from = isset($data['from']) ? $this->getDateTime($data['from'], '00:00') : null; if (null !== $from) { $inclusive = (bool) $this->getOption($options, 'inclusive_from', self::DEFAULT_INCLUSIVE_FROM); if (true === $inclusive) { @@ -41,7 +41,7 @@ public function apply(DataSourceInterface $dataSource, string $name, $data, arra } } - $to = isset($data['to']) ? $this->getDateTime($data['to']) : null; + $to = isset($data['to']) ? $this->getDateTime($data['to'], '23:59') : null; if (null !== $to) { $inclusive = (bool) $this->getOption($options, 'inclusive_to', self::DEFAULT_INCLUSIVE_TO); if (true === $inclusive) { @@ -66,17 +66,18 @@ private function getOption(array $options, string $name, $default) /** * @param string[] $data + * @param string $defaultTime * * @return string|null */ - private function getDateTime(array $data): ?string + private function getDateTime(array $data, string $defaultTime): ?string { if (empty($data['date'])) { return null; } if (empty($data['time'])) { - return $data['date']; + $data['time'] = $defaultTime; } return $data['date'] . ' ' . $data['time']; diff --git a/src/Sylius/Component/Grid/spec/Filter/DateFilterSpec.php b/src/Sylius/Component/Grid/spec/Filter/DateFilterSpec.php index 85f7129ac42..7883acf5979 100644 --- a/src/Sylius/Component/Grid/spec/Filter/DateFilterSpec.php +++ b/src/Sylius/Component/Grid/spec/Filter/DateFilterSpec.php @@ -77,14 +77,14 @@ function it_filters_date_from_not_inclusive( ); } - function it_filters_date_from_without_time( + function it_filters_date_from_with_default_time( DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder ): void { $dataSource->getExpressionBuilder()->willReturn($expressionBuilder); $expressionBuilder - ->greaterThanOrEqual('checkoutCompletedAt', '2016-12-05') + ->greaterThanOrEqual('checkoutCompletedAt', '2016-12-05 00:00') ->shouldBeCalled() ; @@ -157,14 +157,14 @@ function it_filters_date_to_inclusive( ); } - function it_filters_date_to_without_time( + function it_filters_date_to_with_default_time( DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder ): void { $dataSource->getExpressionBuilder()->willReturn($expressionBuilder); $expressionBuilder - ->lessThan('checkoutCompletedAt', '2016-12-06') + ->lessThan('checkoutCompletedAt', '2016-12-06 23:59') ->shouldBeCalled() ; From 361157dd39e571fa8b3370475f00e1d5e43bbcb2 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Fri, 6 Apr 2018 10:24:39 +0200 Subject: [PATCH 03/10] Test edge case for orders filtering --- .../filtering_orders_by_date.feature | 28 ++++++++++++++----- .../Resources/config/grids/order.yml | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/features/order/managing_orders/filtering_orders_by_date.feature b/features/order/managing_orders/filtering_orders_by_date.feature index b8fed274868..0d8324b199a 100644 --- a/features/order/managing_orders/filtering_orders_by_date.feature +++ b/features/order/managing_orders/filtering_orders_by_date.feature @@ -7,15 +7,15 @@ Feature: Filtering orders Background: Given the store operates on a single channel in "United States" And the store has customer "Mike Ross" with email "ross@teammike.com" - And this customer has placed an order "#00000001" at "2016-12-04 08:00:00" - And this customer has also placed an order "#00000002" at "2016-12-05 09:00:00" - And this customer has also placed an order "#00000003" at "2016-12-06 10:00:00" + And this customer has placed an order "#00000001" at "2016-12-04 08:00" + And this customer has also placed an order "#00000002" at "2016-12-05 09:00" + And this customer has also placed an order "#00000003" at "2016-12-06 10:00" And I am logged in as an administrator @ui Scenario: Filtering orders by date from When I browse orders - And I specify filter date from as "2016-12-05 08:30:00" + And I specify filter date from as "2016-12-05 08:30" And I filter Then I should see 2 orders in the list And I should see an order with "#00000002" number @@ -25,7 +25,7 @@ Feature: Filtering orders @ui Scenario: Filtering orders by date to When I browse orders - And I specify filter date to as "2016-12-05 09:30:00" + And I specify filter date to as "2016-12-05 09:30" And I filter Then I should see 2 orders in the list And I should see an order with "#00000001" number @@ -35,8 +35,8 @@ Feature: Filtering orders @ui Scenario: Filtering orders by date from to When I browse orders - And I specify filter date from as "2016-12-05 08:30:00" - And I specify filter date to as "2016-12-05 09:30:00" + And I specify filter date from as "2016-12-05 08:30" + And I specify filter date to as "2016-12-05 09:30" And I filter Then I should see a single order in the list And I should see an order with "#00000002" number @@ -53,3 +53,17 @@ Feature: Filtering orders And I should see an order with "#00000002" number And I should see an order with "#00000003" number But I should not see an order with "#00000001" number + + @ui + Scenario: Filtering orders placed at midnight or just before midnight + Given this customer has placed an order "#00000004" at "2016-12-10 00:00" + And this customer has also placed an order "#00000005" at "2016-12-11 23:59" + And this customer has also placed an order "#00000006" at "2016-12-12 00:00" + When I browse orders + And I specify filter date from as "2016-12-10" + And I specify filter date to as "2016-12-11" + And I filter + Then I should see 2 orders in the list + And I should see an order with "#00000004" number + And I should see an order with "#00000005" number + But I should not see an order with "#00000006" number diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml index 57f860499b1..ca6b05f0b99 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml @@ -85,6 +85,7 @@ sylius_grid: label: sylius.ui.date options: field: checkoutCompletedAt + inclusive_to: true channel: type: entity label: sylius.ui.channel From 0b387cb1b38677c9bc69e85d175ee2faf710177d Mon Sep 17 00:00:00 2001 From: Cedric Ziel Date: Sun, 8 Apr 2018 20:24:46 +0200 Subject: [PATCH 04/10] Correct minor typo in docs --- docs/customization/form.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/customization/form.rst b/docs/customization/form.rst index 2c6f8a2a67a..0207391a6f4 100644 --- a/docs/customization/form.rst +++ b/docs/customization/form.rst @@ -28,7 +28,7 @@ Assuming that you would like to (for example): These will be the steps that you will have to take to achieve that: -**1.** If your are planning to add new fields remember that beforehand they need to be added on the model that the form type is based on. +**1.** If you are planning to add new fields remember that beforehand they need to be added on the model that the form type is based on. In case of our example if you need to have the ``contactHours`` on the model and the entity mapping for the ``Customer`` resource. To get to know how to prepare that go :doc:`there `. From 9dc97997814b6c3760f58d20daee5f2d6e116ec3 Mon Sep 17 00:00:00 2001 From: Cedric Ziel Date: Sun, 8 Apr 2018 12:57:32 +0200 Subject: [PATCH 05/10] Minor doc fix --- docs/book/introduction/introduction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/book/introduction/introduction.rst b/docs/book/introduction/introduction.rst index d942d1770ae..fc588cfca15 100644 --- a/docs/book/introduction/introduction.rst +++ b/docs/book/introduction/introduction.rst @@ -9,7 +9,7 @@ Sylius is a game-changing e-commerce solution for PHP, based on the Symfony fram Philosophy ---------- -Sylius is completely open source (MIT license) and free, maintained by diverse and creative community of developers and companies. +Sylius is completely open source (MIT license) and free, maintained by a diverse and creative community of developers and companies. What are our core values and what makes us different from other solutions? From ffb9dc69e04a1cf6a2f7b2f5e4f359d67d6e75e8 Mon Sep 17 00:00:00 2001 From: Cedric Ziel Date: Sun, 8 Apr 2018 18:11:42 +0200 Subject: [PATCH 06/10] Minor documentation changes for product reviews --- docs/book/products/product_reviews.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/book/products/product_reviews.rst b/docs/book/products/product_reviews.rst index 458d6bef86d..46fbc4266de 100644 --- a/docs/book/products/product_reviews.rst +++ b/docs/book/products/product_reviews.rst @@ -4,7 +4,7 @@ Product Reviews =============== -Product Reviews are a marketing tool that let your customers to give opinions about the products they buy in your shop. +Product Reviews are a marketing tool that let your customers give opinions about the products they buy in your shop. They have a ``rating`` and ``comment``. Rating @@ -36,7 +36,7 @@ How is the average rating calculated? The average rating is updated by the `AverageRatingUpdater `_ service. -It has inside the `AverageRatingCalculator `_, +It wraps the `AverageRatingCalculator `_, and uses it inside the ``updateFromReview`` method. How to add a ProductReview programmatically? From 655afe112c944b53e37f8eab2c3b4b9f05b1a8a9 Mon Sep 17 00:00:00 2001 From: Bartosz Pietrzak Date: Tue, 10 Apr 2018 17:40:32 +0200 Subject: [PATCH 07/10] willdurand/hateoas 2.12 version update (#9302) * willdurand/hateoas 2.12 version update * WIP * Expected response scheme fixes after hateoas package update * Unnecessary file removal * Revert "Unnecessary file removal" --- composer.json | 6 ++-- .../Expected/taxon/index_response.json | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 73547a459a5..f6805b22e6f 100644 --- a/composer.json +++ b/composer.json @@ -63,7 +63,7 @@ "twig/twig": "^2.0", "webmozart/assert": "^1.1", "white-october/pagerfanta-bundle": "^1.0.8", - "willdurand/hateoas": "^2.10", + "willdurand/hateoas": "^2.12", "willdurand/hateoas-bundle": "^1.2", "winzou/state-machine-bundle": "^0.3", "zendframework/zend-hydrator": "^2.2", @@ -137,14 +137,12 @@ "sylius/ui-bundle": "self.version", "sylius/user": "self.version", "sylius/user-bundle": "self.version", - "symfony/polyfill-php71": "*", "symfony/polyfill-php70": "*", "symfony/polyfill-php56": "*" }, "conflict": { - "symfony/symfony": "3.4.7 || 4.0.7", - "willdurand/hateoas": "^2.11" + "symfony/symfony": "3.4.7 || 4.0.7" }, "suggest": { "ext-iconv": "For better performance than using Symfony Polyfill Component", diff --git a/tests/Responses/Expected/taxon/index_response.json b/tests/Responses/Expected/taxon/index_response.json index 74cfd432ebb..1d13bbfc47b 100644 --- a/tests/Responses/Expected/taxon/index_response.json +++ b/tests/Responses/Expected/taxon/index_response.json @@ -39,7 +39,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -51,7 +51,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -79,7 +79,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -91,7 +91,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -119,7 +119,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -131,7 +131,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -159,7 +159,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -171,7 +171,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -199,7 +199,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -210,8 +210,10 @@ "parent": { "id": @integer@, "code": "t-shirts", + "root": @array@, + "parent": @array@, "position": 3, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -239,7 +241,7 @@ "id": @integer@, "code": "category", "position": 0, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { @@ -250,8 +252,10 @@ "parent": { "id": @integer@, "code": "t-shirts", + "root": @array@, + "parent": @array@, "position": 3, - "translations": [], + "translations": @array@, "images": [], "_links": { "self": { From 71aec39cb4eb824913f537dac29f00dba595ea40 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 11 Apr 2018 10:16:55 +0200 Subject: [PATCH 08/10] formatting content in a email message --- .../ShopBundle/Resources/views/Email/contactRequest.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/ShopBundle/Resources/views/Email/contactRequest.html.twig b/src/Sylius/Bundle/ShopBundle/Resources/views/Email/contactRequest.html.twig index 24e275e49c4..b7b2b497560 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/views/Email/contactRequest.html.twig +++ b/src/Sylius/Bundle/ShopBundle/Resources/views/Email/contactRequest.html.twig @@ -8,6 +8,6 @@
Content:
- "{{ data.message }}" + "{{ data.message|nl2br }}" {% endautoescape %} {% endblock %} From bb359005ada73beec6e799a7c29bcde4ca9b0d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Holeczy?= Date: Fri, 16 Mar 2018 00:22:57 +0100 Subject: [PATCH 09/10] Use nullable return type In doctrine config the field flag is defined as nullable, so we should use nullable type in getter. --- docs/customization/model.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/customization/model.rst b/docs/customization/model.rst index be81f0f7f88..c42fc7f6685 100644 --- a/docs/customization/model.rst +++ b/docs/customization/model.rst @@ -59,9 +59,9 @@ Assuming that you would want to add another field on the model - for instance a private $flag; /** - * @return bool + * @return bool|null */ - public function getFlag(): bool + public function getFlag(): ?bool { return $this->flag; } From 3b493d4799c29379dbc8decf52381490f4f7f68f Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Fri, 6 Apr 2018 19:28:50 +0200 Subject: [PATCH 10/10] Fix JS error when autocomplete field is empty --- .../UiBundle/Resources/private/js/sylius-auto-complete.js | 6 +++--- .../Resources/private/js/sylius-product-auto-complete.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Sylius/Bundle/UiBundle/Resources/private/js/sylius-auto-complete.js b/src/Sylius/Bundle/UiBundle/Resources/private/js/sylius-auto-complete.js index 50c51b2487c..085a9993eb7 100644 --- a/src/Sylius/Bundle/UiBundle/Resources/private/js/sylius-auto-complete.js +++ b/src/Sylius/Bundle/UiBundle/Resources/private/js/sylius-auto-complete.js @@ -52,7 +52,7 @@ } }); - if (0 < autocompleteValue.split(',').length) { + if (0 < autocompleteValue.split(',').filter(String).length) { var menuElement = element.find('div.menu'); menuElement.api({ @@ -60,7 +60,7 @@ method: 'GET', url: loadForEditUrl, beforeSend: function (settings) { - settings.data[choiceValue] = autocompleteValue.split(','); + settings.data[choiceValue] = autocompleteValue.split(',').filter(String); return settings; }, @@ -75,7 +75,7 @@ } window.setTimeout(function () { - element.dropdown('set selected', element.find('input.autocomplete').val().split(',')); + element.dropdown('set selected', element.find('input.autocomplete').val().split(',').filter(String)); }, 5000); }); } diff --git a/src/Sylius/Bundle/UiBundle/Resources/private/js/sylius-product-auto-complete.js b/src/Sylius/Bundle/UiBundle/Resources/private/js/sylius-product-auto-complete.js index 8d38cd19468..e9b2a70e2fe 100644 --- a/src/Sylius/Bundle/UiBundle/Resources/private/js/sylius-product-auto-complete.js +++ b/src/Sylius/Bundle/UiBundle/Resources/private/js/sylius-product-auto-complete.js @@ -13,7 +13,7 @@ $.fn.extend({ productAutoComplete: function () { $(this).each(function() { - $(this).dropdown('set selected', $(this).find('input[name*="[associations]"]').val().split(',')); + $(this).dropdown('set selected', $(this).find('input[name*="[associations]"]').val().split(',').filter(String)); }); $(this).dropdown({ @@ -49,7 +49,7 @@ }, onAdd: function(addedValue, addedText, $addedChoice) { var inputAssociation = $addedChoice.parents('.product-select').find('input[name*="[associations]"]'); - var associatedProductCodes = 0 < inputAssociation.val().length ? inputAssociation.val().split(',') : []; + var associatedProductCodes = 0 < inputAssociation.val().length ? inputAssociation.val().split(',').filter(String) : []; associatedProductCodes.push(addedValue); $.unique(associatedProductCodes.sort()); @@ -58,7 +58,7 @@ }, onRemove: function(removedValue, removedText, $removedChoice) { var inputAssociation = $removedChoice.parents('.product-select').find('input[name*="[associations]"]'); - var associatedProductCodes = 0 < inputAssociation.val().length ? inputAssociation.val().split(',') : []; + var associatedProductCodes = 0 < inputAssociation.val().length ? inputAssociation.val().split(',').filter(String) : []; associatedProductCodes.splice($.inArray(removedValue, associatedProductCodes), 1);