Skip to content

Commit

Permalink
[Admin][Order] Add order notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arminek committed Jun 22, 2016
1 parent 0311ffc commit 6318c0e
Show file tree
Hide file tree
Showing 31 changed files with 347 additions and 50 deletions.
38 changes: 38 additions & 0 deletions app/migrations/Version20160622114217.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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('DROP INDEX fulltext_search_idx ON sylius_search_index');
$this->addSql('CREATE INDEX fulltext_search_idx ON sylius_search_index (item_id)');
$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');
$this->addSql('DROP INDEX fulltext_search_idx ON sylius_search_index');
$this->addSql('CREATE FULLTEXT INDEX fulltext_search_idx ON sylius_search_index (value)');
}
}
Original file line number Diff line number Diff line change
@@ -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 the store has customer service account 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
Original file line number Diff line number Diff line change
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 the store has customer service account 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);
}
}
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Transform/CustomerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct(CustomerRepositoryInterface $customerRepository, Fac

/**
* @Transform :customer
* @Transform /^made by "[^"]+"$/
*/
public function getOrCreateCustomerByEmail($email)
{
Expand Down
30 changes: 28 additions & 2 deletions src/Sylius/Behat/Context/Transform/OrderContext.php
Original file line number Diff line number Diff line change
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,21 @@ 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));

$order = $this->orderRepository->findByCustomer($customer);
$order = end($order);
Assert::isInstanceOf($order, OrderInterface::class, sprintf('Cannot find order for %s.', $customer->getFullName()));

return $order;
}

/**
* @Transform :orderNumber
* @Transform /^an order "([^"]+)"$/
Expand Down
23 changes: 22 additions & 1 deletion src/Sylius/Behat/Context/Ui/Admin/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,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
13 changes: 13 additions & 0 deletions src/Sylius/Behat/Page/Admin/Order/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sylius\Behat\Service\Accessor\TableAccessorInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Symfony\Component\Routing\RouterInterface;
use Webmozart\Assert\Assert;

/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
Expand Down Expand Up @@ -337,6 +338,17 @@ public function getRouteName()
return 'sylius_admin_order_show';
}

/**
* {@inheritdoc}
*/
public function hasNote($note)
{
$orderNotesElement = $this->getElement('order_notes');
Assert::notNull($orderNotesElement, 'Cannot find order notes');

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

/**
* {@inheritdoc}
*/
Expand All @@ -358,6 +370,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public function hasBillingAddress(AddressInterface $address)
return $this->isAddressValid($billingAddress, $address);
}

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

/**
* {@inheritdoc}
*/
Expand All @@ -99,6 +107,7 @@ protected function getDefinedElements()
'billing_address' => '#addresses div:contains("Billing address") address',
'shipping_address' => '#addresses div:contains("Shipping address") address',
'items_table' => '#items table',
'extra_notes' =>'#sylius_checkout_summary_note_notes',
]);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Behat/Page/Shop/Checkout/SummaryPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public function hasShippingAddress(AddressInterface $address);
* @return bool
*/
public function hasBillingAddress(AddressInterface $address);

/**
* @param string $notes
*/
public function addNotes($notes);
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% if order.notes is defined and 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 %}
Loading

0 comments on commit 6318c0e

Please sign in to comment.