Skip to content

Commit

Permalink
Merge branch '1.0' into 1.1
Browse files Browse the repository at this point in the history
* 1.0:
  Fix JS error when autocomplete field is empty
  Use nullable return type
  formatting content in a email message
  willdurand/hateoas 2.12 version update (#9302)
  Minor documentation changes for product reviews
  Minor doc fix
  Correct minor typo in docs
  Test edge case for orders filtering
  Provide default times for datetime filter
  Filtering orders without time scenaio
  • Loading branch information
pamil committed Apr 12, 2018
2 parents 2ce672c + 6a0673d commit 0f9bfdb
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 58 deletions.
6 changes: 2 additions & 4 deletions composer.json
Expand Up @@ -64,7 +64,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",
Expand Down Expand Up @@ -138,14 +138,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",
Expand Down
2 changes: 1 addition & 1 deletion docs/book/introduction/introduction.rst
Expand Up @@ -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?

Expand Down
4 changes: 2 additions & 2 deletions docs/book/products/product_reviews.rst
Expand Up @@ -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
Expand Down Expand Up @@ -36,7 +36,7 @@ How is the average rating calculated?
The average rating is updated by
the `AverageRatingUpdater <https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/ReviewBundle/Updater/AverageRatingUpdater.php>`_ service.

It has inside the `AverageRatingCalculator <https://github.com/Sylius/Sylius/blob/master/src/Sylius/Component/Review/Calculator/AverageRatingCalculator.php>`_,
It wraps the `AverageRatingCalculator <https://github.com/Sylius/Sylius/blob/master/src/Sylius/Component/Review/Calculator/AverageRatingCalculator.php>`_,
and uses it inside the ``updateFromReview`` method.

How to add a ProductReview programmatically?
Expand Down
2 changes: 1 addition & 1 deletion docs/customization/form.rst
Expand Up @@ -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 </customization/model>`.
Expand Down
4 changes: 2 additions & 2 deletions docs/customization/model.rst
Expand Up @@ -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;
}
Expand Down
39 changes: 32 additions & 7 deletions features/order/managing_orders/filtering_orders_by_date.feature
Expand Up @@ -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-05 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 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
Expand All @@ -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
Expand All @@ -35,10 +35,35 @@ 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
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

@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
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingOrdersContext.php
Expand Up @@ -164,15 +164,15 @@ public function iSwitchSortingBy($fieldName)
*/
public function iSpecifyFilterDateFromAs($dateTime)
{
$this->indexPage->specifyFilterDateFrom(new \DateTime($dateTime));
$this->indexPage->specifyFilterDateFrom($dateTime);
}

/**
* @When I specify filter date to as :dateTime
*/
public function iSpecifyFilterDateToAs($dateTime)
{
$this->indexPage->specifyFilterDateTo(new \DateTime($dateTime));
$this->indexPage->specifyFilterDateTo($dateTime);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/Sylius/Behat/Page/Admin/Order/IndexPage.php
Expand Up @@ -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] ?? '');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Sylius/Behat/Page/Admin/Order/IndexPageInterface.php
Expand Up @@ -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
Expand Down
Expand Up @@ -85,6 +85,7 @@ sylius_grid:
label: sylius.ui.date
options:
field: checkoutCompletedAt
inclusive_to: true
channel:
type: entity
label: sylius.ui.channel
Expand Down
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Sylius\Bundle\GridBundle\Form\DataTransformer;

use Symfony\Component\Form\DataTransformerInterface;
use Webmozart\Assert\Assert;

final class DateTimeFilterTransformer implements DataTransformerInterface
{
private static $defaultTime = [
'from' => ['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;
}
}
Expand Up @@ -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;
Expand All @@ -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'));
}

/**
Expand Down
Expand Up @@ -8,6 +8,6 @@
<br/>
Content:
<br/>
"{{ data.message }}"
"{{ data.message|nl2br }}"
{% endautoescape %}
{% endblock %}
Expand Up @@ -52,15 +52,15 @@
}
});

if (0 < autocompleteValue.split(',').length) {
if (0 < autocompleteValue.split(',').filter(String).length) {
var menuElement = element.find('div.menu');

menuElement.api({
on: 'now',
method: 'GET',
url: loadForEditUrl,
beforeSend: function (settings) {
settings.data[choiceValue] = autocompleteValue.split(',');
settings.data[choiceValue] = autocompleteValue.split(',').filter(String);

return settings;
},
Expand All @@ -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);
});
}
Expand Down
Expand Up @@ -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({
Expand Down Expand Up @@ -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());
Expand All @@ -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);

Expand Down
9 changes: 5 additions & 4 deletions src/Sylius/Component/Grid/Filter/DateFilter.php
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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'];
Expand Down

0 comments on commit 0f9bfdb

Please sign in to comment.