Skip to content

Commit

Permalink
Merge pull request #5319 from Arminek/order-notes
Browse files Browse the repository at this point in the history
[Admin][Order] Add order notes
  • Loading branch information
Paweł Jędrzejewski committed Jun 24, 2016
2 parents 4292643 + b3d2e44 commit faaec3b
Show file tree
Hide file tree
Showing 31 changed files with 345 additions and 50 deletions.
34 changes: 34 additions & 0 deletions app/migrations/Version20160622114217.php
@@ -0,0 +1,34 @@
<?php

namespace Sylius\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20160622114217 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_order DROP additional_information, CHANGE notes notes VARCHAR(1000) DEFAULT NULL');
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_order ADD additional_information VARCHAR(1000) DEFAULT NULL COLLATE utf8_unicode_ci, CHANGE notes notes VARCHAR(255) DEFAULT NULL COLLATE utf8_unicode_ci');
}
}
@@ -0,0 +1,23 @@
@placing_orders
Feature: Adding a note to order
In order to provide some extra information to order
As a Customer
I want to be able to provide a note for customer service

Background:
Given the store operates on a single channel in "France"
And the store has a product "PHP T-Shirt" priced at "$19.99"
And the store ships everywhere for free
And the store allows paying offline
And there is an administrator identified by "sylius@example.com"
And there is a customer account "customer@example.com" identified by "sylius"
And I am logged in as "customer@example.com"

@ui
Scenario: Adding note on the checkout summary step
Given I have product "PHP T-Shirt" in the cart
And I specified the shipping address as "Ankh Morpork", "Frost Alley", "90210", "France" for "Jon Snow"
And I proceed order with "Free" shipping method and "Offline" payment
When I provide additional note like "Code to the front gateway is #44*"
And I confirm my order
Then the customer service should know about this additional note for this order made by "customer@example.com"
32 changes: 22 additions & 10 deletions src/Sylius/Behat/Context/Setup/UserContext.php
Expand Up @@ -132,6 +132,28 @@ public function accountWasDeleted($email)
$this->userRepository->remove($user);
}

/**
* @Given his account was deleted
*/
public function hisAccountWasDeleted()
{
$user = $this->sharedStorage->get('user');

$this->userRepository->remove($user);
}

/**
* @Given there is an administrator identified by :email
*/
public function theStoreHasCustomerServiceAccountIdentifiedBy($email)
{
$administrator = $this->userFactory->createDefaultAdmin();
$administrator->setEmail($email);

$this->sharedStorage->set('customer_service', $administrator);
$this->userRepository->add($administrator);
}

/**
* @param string $firstName
* @param string $lastName
Expand Down Expand Up @@ -160,14 +182,4 @@ private function createAddress(

return $address;
}

/**
* @Given his account was deleted
*/
public function hisAccountWasDeleted()
{
$user = $this->sharedStorage->get('user');

$this->userRepository->remove($user);
}
}
29 changes: 27 additions & 2 deletions src/Sylius/Behat/Context/Transform/OrderContext.php
Expand Up @@ -12,24 +12,35 @@
namespace Sylius\Behat\Context\Transform;

use Behat\Behat\Context\Context;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Component\User\Repository\CustomerRepositoryInterface;
use Webmozart\Assert\Assert;

/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
*/
final class OrderContext implements Context
{
/**
* @var CustomerRepositoryInterface
*/
private $customerRepository;

/**
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
* @param CustomerRepositoryInterface $customerRepository
* @param OrderRepositoryInterface $orderRepository
*/
public function __construct(OrderRepositoryInterface $orderRepository)
{
public function __construct(
CustomerRepositoryInterface $customerRepository,
OrderRepositoryInterface $orderRepository
) {
$this->customerRepository = $customerRepository;
$this->orderRepository = $orderRepository;
}

Expand All @@ -46,6 +57,20 @@ public function getOrderByNumber($orderNumber)
return $order;
}

/**
* @Transform /^this order made by "([^"]+)"$/
*/
public function getOrderByCustomer($email)
{
$customer = $this->customerRepository->findOneBy(['email' => $email]);
Assert::notNull($customer, sprintf('Cannot find customer with email %s.', $email));

$orders = $this->orderRepository->findByCustomer($customer);
Assert::notEmpty($orders);

return end($orders);
}

/**
* @Transform :orderNumber
* @Transform /^an order "([^"]+)"$/
Expand Down
23 changes: 22 additions & 1 deletion src/Sylius/Behat/Context/Ui/Admin/ManagingOrdersContext.php
Expand Up @@ -16,8 +16,10 @@
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Behat\Page\Admin\Order\ShowPageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Behat\Service\SecurityServiceInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -47,22 +49,30 @@ final class ManagingOrdersContext implements Context
*/
private $notificationChecker;

/**
* @var SecurityServiceInterface
*/
private $securityService;

/**
* @param SharedStorageInterface $sharedStorage
* @param IndexPageInterface $indexPage
* @param ShowPageInterface $showPage
* @param NotificationCheckerInterface $notificationChecker
* @param SecurityServiceInterface $securityService
*/
public function __construct(
SharedStorageInterface $sharedStorage,
IndexPageInterface $indexPage,
ShowPageInterface $showPage,
NotificationCheckerInterface $notificationChecker
NotificationCheckerInterface $notificationChecker,
SecurityServiceInterface $securityService
) {
$this->sharedStorage = $sharedStorage;
$this->indexPage = $indexPage;
$this->showPage = $showPage;
$this->notificationChecker = $notificationChecker;
$this->securityService = $securityService;
}

/**
Expand Down Expand Up @@ -539,4 +549,15 @@ public function itShouldHaveState($state)
{
$this->indexPage->isSingleResourceOnPage(['state' => $state]);
}

/**
* @Then /^(the customer service) should know about (this additional note) for (this order made by "[^"]+")$/
*/
public function theCustomerServiceShouldKnowAboutThisAdditionalNotes(UserInterface $user, $note, OrderInterface $order)
{
$this->securityService->performActionAs($user, function () use ($note, $order) {
$this->showPage->open(['id' => $order->getId()]);
Assert::true($this->showPage->hasNote($note), sprintf('I should see %s note, but I do not see', $note));
});
}
}
9 changes: 9 additions & 0 deletions src/Sylius/Behat/Context/Ui/CheckoutContext.php
Expand Up @@ -363,6 +363,15 @@ public function iChangeShippingMethod($shippingMethodName)
$this->checkoutShippingStep->continueCheckout();
}

/**
* @When /^I provide additional note like "([^"]+)"$/
*/
public function iProvideAdditionalNotesLike($notes)
{
$this->sharedStorage->set('additional_note', $notes);
$this->summaryPage->addNotes($notes);
}

/**
* @Given /^I proceed logging as "([^"]*)" with "([^"]*)" password$/
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Sylius/Behat/Page/Admin/Order/ShowPage.php
Expand Up @@ -329,6 +329,16 @@ public function deleteOrder()
$this->getDocument()->pressButton('Delete');
}

/**
* {@inheritdoc}
*/
public function hasNote($note)
{
$orderNotesElement = $this->getElement('order_notes');

return $orderNotesElement->getText() === $note;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -358,6 +368,7 @@ protected function getDefinedElements()
'taxes' => '#taxes',
'total' => '#total',
'order_state' => 'div.sub.header > span.ui.label',
'order_notes' => '#sylius-order-notes',
]);
}

Expand Down
7 changes: 7 additions & 0 deletions src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php
Expand Up @@ -210,4 +210,11 @@ public function getOrderState();
public function cancelOrder();

public function deleteOrder();

/**
* @param string $note
*
* @return bool
*/
public function hasNote($note);
}
7 changes: 6 additions & 1 deletion src/Sylius/Behat/Page/Shop/Checkout/FinalizeStep.php
Expand Up @@ -11,6 +11,7 @@

namespace Sylius\Behat\Page\Shop\Checkout;

use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Page\SymfonyPage;

/**
Expand All @@ -23,7 +24,11 @@ class FinalizeStep extends SymfonyPage implements FinalizeStepInterface
*/
public function confirmOrder()
{
$this->getDocument()->clickLink('Place order');
try {
$this->getDocument()->clickLink('Place order');
} catch (ElementNotFoundException $exception) {
$this->getDocument()->pressButton('Place order');
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/Sylius/Behat/Page/Shop/Checkout/SummaryPage.php
Expand Up @@ -149,6 +149,14 @@ public function hasOrderTotal($total)
return $this->getTotalFromString($this->getElement('order_total')->getText()) === $total;
}

/**
* {@inheritdoc}
*/
public function addNotes($notes)
{
$this->getElement('extra_notes')->setValue($notes);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -188,6 +196,7 @@ protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'billing_address' => '#addresses div:contains("Billing address") address',
'extra_notes' =>'#sylius_checkout_summary_notes',
'shipping_address' => '#addresses div:contains("Shipping address") address',
'items_table' => '#items table',
'shipping_method' => '#sylius-checkout-summary-shipping-method',
Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Behat/Page/Shop/Checkout/SummaryPageInterface.php
Expand Up @@ -73,6 +73,11 @@ public function hasProductDiscountedUnitPriceBy(ProductInterface $product, $amou
*/
public function hasOrderTotal($total);

/**
* @param string $notes
*/
public function addNotes($notes);

/**
* @param string $promotionTotal
*
Expand Down
Expand Up @@ -89,6 +89,7 @@
</service>

<service id="sylius.behat.context.transform.order" class="%sylius.behat.context.transform.order.class%" scope="scenario">
<argument type="service" id="sylius.repository.customer" container="symfony" />
<argument type="service" id="sylius.repository.order" container="symfony" />
<tag name="sylius.behat.context" />
</service>
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Behat/Resources/config/services/contexts/ui.xml
Expand Up @@ -99,6 +99,7 @@
<argument type="service" id="sylius.behat.page.admin.order.index" />
<argument type="service" id="sylius.behat.page.admin.order.show" />
<argument type="service" id="sylius.behat.notification_checker" />
<argument type="service" id="sylius.behat.security" />
<tag name="sylius.behat.context" />
</service>

Expand Down
Expand Up @@ -8,20 +8,22 @@ default:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.customer
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.product
- sylius.behat.context.setup.security
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.user

- sylius.behat.context.transform.addressing
- sylius.behat.context.transform.customer
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.order
- sylius.behat.context.transform.product
- sylius.behat.context.transform.shared_storage

- sylius.behat.context.ui.admin.managing_orders
- sylius.behat.context.ui.checkout
- sylius.behat.context.ui.shop.cart

filters:
tags: "@placing_orders && @ui"
@@ -0,0 +1,8 @@
{% if order.notes is not null %}
<h4 class="ui top attached styled header">
{{ 'sylius.ui.notes'|trans }}
</h4>
<div class="ui attached segment" id="sylius-order-notes">
{{ order.notes }}
</div>
{% endif %}
Expand Up @@ -30,6 +30,7 @@
{% include '@SyliusAdmin/Order/Show/_addresses.html.twig' %}
{% include '@SyliusAdmin/Order/Show/_payments.html.twig' %}
{% include '@SyliusAdmin/Order/Show/_shipments.html.twig' %}
{% include '@SyliusAdmin/Order/Show/_notes.html.twig' %}
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/CartBundle/Form/Type/CartType.php
Expand Up @@ -31,7 +31,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('items', 'collection', [
'type' => 'sylius_cart_item',
])
->add('additionalInformation')
->add('notes')
;
}

Expand Down

0 comments on commit faaec3b

Please sign in to comment.