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 c4661ac commit ea324af
Show file tree
Hide file tree
Showing 27 changed files with 303 additions and 46 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,22 @@
@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 I am a logged in customer

@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
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);
}
}
22 changes: 21 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,14 @@ public function itShouldHaveState($state)
{
$this->indexPage->isSingleResourceOnPage(['state' => $state]);
}

/**
* @Then /^(the customer service) should know about (this additional note)$/
*/
public function theCustomerServiceShouldKnowAboutThisAdditionalNotes(UserInterface $user, $note)
{
$this->securityService->performActionAs($user, function () use ($note) {
$this->showPage->hasNote($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 @@ -337,6 +337,18 @@ public function getRouteName()
return 'sylius_admin_order_show';
}

/**
* {@inheritdoc}
*/
public function hasNote($note)
{
if ($this->hasElement('order_notes')) {
return false;
}

return $this->getElement('order_notes')->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);
}
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 @@ -48,6 +48,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 @@ -56,6 +64,7 @@ protected function getDefinedElements()
return array_merge(parent::getDefinedElements(), [
'billing_address' => '#addresses div:contains("Billing address") address',
'shipping_address' => '#addresses div:contains("Shipping address") address',
'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 @@ -32,4 +32,9 @@ public function hasShippingAddress(AddressInterface $address);
* @return bool
*/
public function hasBillingAddress(AddressInterface $address);

/**
* @param string $notes
*/
public function addNotes($notes);
}
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 @@ -14,6 +14,7 @@ default:
- 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.product
Expand All @@ -22,6 +23,5 @@ default:
- 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 %}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function it_builds_form_with_items_collection(FormBuilder $builder)
;

$builder
->add('additionalInformation')
->add('notes')
->willReturn($builder)
;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\CoreBundle\Form\Type\Checkout;

use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\FormBuilderInterface;

/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class SummaryNoteType extends AbstractResourceType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('notes', 'textarea', [
'label' => 'sylius.form.notes',
'required' => false,
]);
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'sylius_checkout_summary_note';
}
}
5 changes: 5 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Resources/config/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<parameter key="sylius.checkout_form.shipping.class">Sylius\Bundle\CoreBundle\Form\Type\Checkout\ShippingStepType</parameter>
<parameter key="sylius.checkout_form.shop_addressing.class">Sylius\Bundle\CoreBundle\Form\Type\Checkout\AddressingType</parameter>
<parameter key="sylius.checkout_form.shop_shipping.class">Sylius\Bundle\CoreBundle\Form\Type\Checkout\ShippingType</parameter>
<parameter key="sylius.checkout_form.summary_note.class">Sylius\Bundle\CoreBundle\Form\Type\Checkout\SummaryNoteType</parameter>

<parameter key="sylius.form.type.image.class">Sylius\Bundle\CoreBundle\Form\Type\ImageType</parameter>
<parameter key="sylius.form.type.list.class">Sylius\Bundle\CoreBundle\Form\Type\ListType</parameter>
Expand Down Expand Up @@ -93,6 +94,10 @@
</argument>
<tag name="form.type" alias="sylius_checkout_payment_step" />
</service>
<service id="sylius_checkout_form.summary_note" class="%sylius.checkout_form.summary_note.class%">
<argument>%sylius.model.cart.class%</argument>
<tag name="form.type" alias="sylius_checkout_summary_note" />
</service>

<service id="sylius.form.type.cart" class="%sylius.form.type.cart.class%">
<argument>%sylius.model.cart.class%</argument>
Expand Down
Loading

0 comments on commit ea324af

Please sign in to comment.