PR review fixes

This commit is contained in:
Mateusz Zalewski 2016-06-10 14:25:15 +02:00
parent b506c1651b
commit ed5bcb65d8
22 changed files with 227 additions and 81 deletions

View file

@ -15,7 +15,7 @@ Feature: Addressing an order
Given I have product "PHP T-Shirt" in the cart
And I am at the checkout addressing step
When I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "France" for "Jon Snow"
And I proceed to the shipping step
And I complete the addressing step
Then I should be on the checkout shipping step
@ui
@ -25,5 +25,5 @@ Feature: Addressing an order
When I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "France" for "Jon Snow"
And I choose the different billing address
And I specify the billing address as "Ankh Morpork", "Frost Alley", "90210", "France" for "Eddard Stark"
And I proceed to the shipping step
And I complete the addressing step
Then I should be on the checkout shipping step

View file

@ -14,7 +14,7 @@ Feature: Order addressing validation
Given I have product "PHP T-Shirt" in the cart
And I am at the checkout addressing step
When I do not specify any shipping address information
And I try to proceed to the shipping step
And I try to complete the addressing step
Then I should be notified that the "first name" and the "last name" in shipping details are required
And I should also be notified that the "city" and the "street" in shipping details are required
@ -25,6 +25,6 @@ Feature: Order addressing validation
When I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "France" for "Jon Snow"
And I choose the different billing address
And I do not specify any billing address information
And I try to proceed to the shipping step
And I try to complete the addressing step
Then I should be notified that the "first name" and the "last name" in billing details are required
And I should also be notified that the "city" and the "street" in billing details are required

View file

@ -16,7 +16,7 @@ Feature: Preventing not available shipping method selection
And I have product "Targaryen T-Shirt" in the cart
When I am at the checkout addressing step
And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "France" for "Jon Snow"
And I proceed to the shipping step
And I complete the addressing step
Then I should not be able to select "Dragon Post" shipping method
@ui
@ -28,7 +28,7 @@ Feature: Preventing not available shipping method selection
And I have product "Targaryen T-Shirt" in the cart
When I am at the checkout addressing step
And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "France" for "Jon Snow"
And I proceed to the shipping step
And I complete the addressing step
Then I should not be able to select "Raven Post" shipping method
@ui
@ -40,7 +40,7 @@ Feature: Preventing not available shipping method selection
And I have product "Targaryen T-Shirt" in the cart
When I am at the checkout addressing step
And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "France" for "Jon Snow"
And I proceed to the shipping step
And I complete the addressing step
Then I should not be able to select "Raven Post" shipping method
And I should not be able to select "Dragon Post" shipping method
And I should be alerted, that there is no shipping method available for me
And I should be informed that my order cannot be shipped to this address

View file

@ -2,7 +2,7 @@
Feature: Selecting order shipping method
In order to ship my order properly
As a Customer
I want to be able to choose shipping method
I want to be able to choose a shipping method
Background:
Given the store operates on a single channel in "France"
@ -16,4 +16,4 @@ Feature: Selecting order shipping method
Given I have product "Targaryen T-Shirt" in the cart
And I specified the shipping address as "Ankh Morpork", "Frost Alley", "90210", "France" for "Jon Snow"
When I select "Raven Post" shipping method
And I proceed with the payment step
And I complete the shipping step

View file

@ -11,6 +11,7 @@ Feature: Apply correct taxes based on customer data
And there is a zone "The Rest of the World" containing all other countries
And default currency is "EUR"
And default tax zone is "EU"
And the store ships everywhere for free
And the store has "EU VAT" tax rate of 23% for "Clothes" within "EU" zone
And the store has "EU VAT" tax rate of 10% for "Clothes" for the rest of the world
And the store has a product "PHP T-Shirt" priced at "100.00"

View file

@ -11,6 +11,7 @@ Feature: Apply correct taxes for products with different tax rates for different
And there is a zone "The Rest of the World" containing all other countries
And default currency is "EUR"
And default tax zone is "EU"
And the store ships everywhere for free
And the store has "EU VAT" tax rate of 23% for "Clothes" within "EU" zone
And the store has "No tax" tax rate of 0% for "Clothes" for the rest of the world
And the store has "Low VAT" tax rate of 5% for "Mugs" for the rest of the world

View file

@ -11,6 +11,7 @@ Feature: Apply correct taxes on visitor cart
And there is a zone "The Rest of the World" containing all other countries
And default currency is "EUR"
And default tax zone is "EU"
And the store ships everywhere for free
And the store has "EU VAT" tax rate of 23% for "Clothes" within "EU" zone
And the store has "EU VAT" tax rate of 10% for "Clothes" for the rest of the world
And the store has a product "PHP T-Shirt" priced at "100.00"

View file

@ -171,7 +171,7 @@ final class CheckoutContext implements Context
{
$this->addressingPage->open();
$this->addressingPage->specifyShippingAddress($address);
$this->iProceedWithTheShippingStep();
$this->iCompleteTheAddressingStep();
}
/**
@ -182,46 +182,6 @@ final class CheckoutContext implements Context
$this->addressingPage->chooseDifferentBillingAddress();
}
public function iSpecifyTheBillingSLastNameAs($lastName = null)
{
$this->addressingPage->specifyBillingAddressLastName($lastName);
}
/**
* @When I specify the billing's street as :streetName
* @When I do not specify the billing's street
*/
public function iSpecifyTheBillingSStreetAs($streetName = null)
{
$this->addressingPage->specifyBillingAddressStreet($streetName);
}
/**
* @Given I choose :countryName as billing's country
*/
public function iChooseAsBillingSCountry($countryName)
{
$this->addressingPage->chooseBillingAddressCountry($countryName);
}
/**
* @When I specify the billing's city as :cityName
* @When I do not specify the billing's city
*/
public function iSpecifyTheBillingSCityAs($cityName = null)
{
$this->addressingPage->specifyBillingAddressCity($cityName);
}
/**
* @When I specify the billing's postcode as :postcode
* @When I do not specify the billing's postcode
*/
public function iSpecifyTheBillingSPostcodeAs($postcode = null)
{
$this->addressingPage->specifyBillingAddressPostcode($postcode);
}
/**
* @When I select :shippingMethod shipping method
*/
@ -242,18 +202,18 @@ final class CheckoutContext implements Context
}
/**
* @When I proceed to the shipping step
* @When I try to proceed to the shipping step
* @When I complete the addressing step
* @When I try to complete the addressing step
*/
public function iProceedWithTheShippingStep()
public function iCompleteTheAddressingStep()
{
$this->addressingPage->nextStep();
}
/**
* @When I proceed with the payment step
* @When I complete the shipping step
*/
public function iProceedWithThePaymentStep()
public function iCompleteTheShippingStep()
{
$this->shippingPage->nextStep();
}
@ -426,9 +386,9 @@ final class CheckoutContext implements Context
}
/**
* @Given I should be alerted, that there is no shipping method available for me
* @Then I should be informed that my order cannot be shipped to this address
*/
public function iShouldBeAlertedThatThereIsNoShippingMethodAvailableForMe()
public function iShouldBeInformedThatMyOrderCannotBeShippedToThisAddress()
{
Assert::true(
$this->shippingPage->hasNoShippingMethodsMessage(),

View file

@ -19,6 +19,7 @@ default:
- sylius.behat.context.setup.currency
- sylius.behat.context.setup.geographical
- sylius.behat.context.setup.product
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.taxation
- sylius.behat.context.setup.user
- sylius.behat.context.setup.zone

View file

@ -326,10 +326,6 @@
<argument type="service" id="sylius.order_processing.shipment_processor" />
</service>
<service id="sylius.resolver.default_shipping_method" class="%sylius.resolver.default_shipping_method.class%">
<argument type="service" id="sylius.repository.shipping_method" />
</service>
<service id="sylius.order.purger" class="%sylius.order.purger.class%">
<argument type="service" id="sylius.manager.order" />
<argument type="service" id="sylius.repository.order" />

View file

@ -23,6 +23,9 @@
<property name="billingAddress">
<constraint name="Valid" />
</property>
<property name="shipments">
<constraint name="Valid" />
</property>
</class>
<class name="Sylius\Component\Core\Model\ProductVariant">

View file

@ -24,6 +24,8 @@
<parameter key="sylius.composite_shipping_methods_resolver.class">Sylius\Component\Shipping\Resolver\CompositeMethodsResolver</parameter>
<parameter key="sylius.shipping_methods_resolver.class">Sylius\Component\Shipping\Resolver\MethodsResolver</parameter>
<parameter key="sylius.resolver.default_shipping_method.class">Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolver</parameter>
<parameter key="sylius.registry.shipping_calculator.class">Sylius\Component\Registry\ServiceRegistry</parameter>
<parameter key="sylius.shipping_calculator.class">Sylius\Component\Shipping\Calculator\DelegatingCalculator</parameter>
@ -92,6 +94,10 @@
<tag name="form.type" alias="sylius_shipping_method_choice" />
</service>
<service id="sylius.resolver.default_shipping_method" class="%sylius.resolver.default_shipping_method.class%">
<argument type="service" id="sylius.repository.shipping_method" />
</service>
<service id="sylius.form.type.shipping_calculator_choice" class="%sylius.form.type.shipping_calculator_choice.class%">
<argument>%sylius.shipping_calculators%</argument>
<tag name="form.type" alias="sylius_shipping_calculator_choice" />

View file

@ -92,6 +92,12 @@
<option name="groups">sylius</option>
</constraint>
</property>
<property name="method">
<constraint name="NotBlank">
<option name="message">sylius.shipment.shipping_method.not_blank</option>
<option name="groups">sylius</option>
</constraint>
</property>
</class>
</constraint-mapping>

View file

@ -13,8 +13,8 @@ namespace Sylius\Component\Core\OrderProcessing;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\Resolver\DefaultShippingMethodResolverInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolverInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
@ -70,8 +70,8 @@ class OrderShipmentProcessor implements OrderShipmentProcessorInterface
/** @var ShipmentInterface $shipment */
$shipment = $this->shipmentFactory->createNew();
$shipment->setMethod($this->defaultShippingMethodResolver->getDefaultShippingMethod());
$order->addShipment($shipment);
$shipment->setMethod($this->defaultShippingMethodResolver->getDefaultShippingMethod($shipment));
return $shipment;
}

View file

@ -11,7 +11,11 @@
namespace Sylius\Component\Core\Resolver;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Shipping\Model\ShipmentInterface;
use Sylius\Component\Shipping\Repository\ShippingMethodRepositoryInterface;
use Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolverInterface;
use Webmozart\Assert\Assert;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
@ -34,13 +38,28 @@ class DefaultShippingMethodResolver implements DefaultShippingMethodResolverInte
/**
* {@inheritdoc}
*/
public function getDefaultShippingMethod()
public function getDefaultShippingMethod(ShipmentInterface $shippingSubject)
{
$shippingMethods = $this->shippingMethodRepository->findAll();
Assert::isInstanceOf($shippingSubject, \Sylius\Component\Core\Model\ShipmentInterface::class);
$shippingMethods = $this->shippingMethodRepository->findBy(['enabled' => true]);
if (empty($shippingMethods)) {
return null;
}
return $shippingMethods[0];
/** @var ChannelInterface $channel */
$channel = $shippingSubject->getOrder()->getChannel();
foreach ($shippingMethods as $key => $shippingMethod) {
if (!$channel->hasShippingMethod($shippingMethod)) {
unset($shippingMethods[$key]);
}
}
if (empty($shippingMethods)) {
return null;
}
return current($shippingMethods);
}
}

View file

@ -17,9 +17,9 @@ use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemUnitInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\OrderProcessing\OrderShipmentProcessorInterface;
use Sylius\Component\Core\Resolver\DefaultShippingMethodResolverInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Shipping\Model\ShippingMethodInterface;
use Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolverInterface;
/**
* @mixin \Sylius\Component\Core\OrderProcessing\OrderShipmentProcessor
@ -54,7 +54,7 @@ class OrderShipmentProcessorSpec extends ObjectBehavior
ShipmentInterface $shipment,
ShippingMethodInterface $defaultShippingMethod
) {
$defaultShippingMethodResolver->getDefaultShippingMethod()->willReturn($defaultShippingMethod);
$defaultShippingMethodResolver->getDefaultShippingMethod($shipment)->willReturn($defaultShippingMethod);
$shipmentFactory->createNew()->willReturn($shipment);

View file

@ -12,9 +12,12 @@
namespace spec\Sylius\Component\Core\Resolver;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Core\Resolver\DefaultShippingMethodResolverInterface;
use Sylius\Component\Shipping\Repository\ShippingMethodRepositoryInterface;
use Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolverInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
@ -36,21 +39,60 @@ class DefaultShippingMethodResolverSpec extends ObjectBehavior
$this->shouldImplement(DefaultShippingMethodResolverInterface::class);
}
function it_returns_first_shipping_method_as_default(
function it_returns_first_enabled_shipping_method_from_shipment_order_channel_as_default(
ChannelInterface $channel,
OrderInterface $order,
ShipmentInterface $shipment,
ShippingMethodInterface $firstShippingMethod,
ShippingMethodInterface $secondShippingMethod,
ShippingMethodInterface $thirdShippingMethod,
ShippingMethodRepositoryInterface $shippingMethodRepository
) {
$shippingMethodRepository->findAll()->willReturn([$firstShippingMethod, $secondShippingMethod]);
$shippingMethodRepository
->findBy(['enabled' => true])
->willReturn([$firstShippingMethod, $secondShippingMethod, $thirdShippingMethod])
;
$this->getDefaultShippingMethod()->shouldReturn($firstShippingMethod);
$shipment->getOrder()->willReturn($order);
$order->getChannel()->willReturn($channel);
$channel->hasShippingMethod($firstShippingMethod)->willReturn(false);
$channel->hasShippingMethod($secondShippingMethod)->willReturn(true);
$channel->hasShippingMethod($thirdShippingMethod)->willReturn(true);
$this->getDefaultShippingMethod($shipment)->shouldReturn($secondShippingMethod);
}
function it_returns_null_if_there_is_not_shipping_methods(
function it_returns_null_if_there_is_no_enabled_shipping_methods(
ShippingMethodRepositoryInterface $shippingMethodRepository,
ShipmentInterface $shipment
) {
$shippingMethodRepository->findBy(['enabled' => true])->willReturn([]);
$this->getDefaultShippingMethod($shipment)->shouldReturn(null);
}
function it_returns_null_if_there_is_no_enabled_shipping_methods_for_channel(
ChannelInterface $channel,
OrderInterface $order,
ShipmentInterface $shipment,
ShippingMethodInterface $firstShippingMethod,
ShippingMethodInterface $secondShippingMethod,
ShippingMethodInterface $thirdShippingMethod,
ShippingMethodRepositoryInterface $shippingMethodRepository
) {
$shippingMethodRepository->findAll()->willReturn([]);
$shippingMethodRepository
->findBy(['enabled' => true])
->willReturn([$firstShippingMethod, $secondShippingMethod, $thirdShippingMethod])
;
$this->getDefaultShippingMethod()->shouldReturn(null);
$shipment->getOrder()->willReturn($order);
$order->getChannel()->willReturn($channel);
$channel->hasShippingMethod($firstShippingMethod)->willReturn(false);
$channel->hasShippingMethod($secondShippingMethod)->willReturn(false);
$channel->hasShippingMethod($thirdShippingMethod)->willReturn(false);
$this->getDefaultShippingMethod($shipment)->shouldReturn(null);
}
}

View file

@ -96,7 +96,7 @@ class Shipment implements ShipmentInterface
/**
* {@inheritdoc}
*/
public function setMethod(ShippingMethodInterface $method)
public function setMethod(ShippingMethodInterface $method = null)
{
$this->method = $method;
}

View file

@ -48,7 +48,7 @@ interface ShipmentInterface extends ResourceInterface, ShippingSubjectInterface,
/**
* @param ShippingMethodInterface $method
*/
public function setMethod(ShippingMethodInterface $method);
public function setMethod(ShippingMethodInterface $method = null);
/**
* @return Collection|ShipmentUnitInterface[]

View file

@ -0,0 +1,47 @@
<?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\Component\Shipping\Resolver;
use Sylius\Component\Shipping\Model\ShipmentInterface;
use Sylius\Component\Shipping\Repository\ShippingMethodRepositoryInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
*/
class DefaultShippingMethodResolver implements DefaultShippingMethodResolverInterface
{
/**
* @var ShippingMethodRepositoryInterface
*/
private $shippingMethodRepository;
/**
* @param ShippingMethodRepositoryInterface $shippingMethodRepository
*/
public function __construct(ShippingMethodRepositoryInterface $shippingMethodRepository)
{
$this->shippingMethodRepository = $shippingMethodRepository;
}
/**
* {@inheritdoc}
*/
public function getDefaultShippingMethod(ShipmentInterface $shipment)
{
$shippingMethods = $this->shippingMethodRepository->findBy(['enabled' => true]);
if (empty($shippingMethods)) {
return null;
}
return $shippingMethods[0];
}
}

View file

@ -9,9 +9,11 @@
* file that was distributed with this source code.
*/
namespace Sylius\Component\Core\Resolver;
namespace Sylius\Component\Shipping\Resolver;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Shipping\Model\ShipmentInterface;
use Sylius\Component\Shipping\Model\ShippingSubjectInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
@ -19,7 +21,9 @@ use Sylius\Component\Core\Model\ShippingMethodInterface;
interface DefaultShippingMethodResolverInterface
{
/**
* @param ShipmentInterface $shipment
*
* @return ShippingMethodInterface|null
*/
public function getDefaultShippingMethod();
public function getDefaultShippingMethod(ShipmentInterface $shipment);
}

View file

@ -0,0 +1,59 @@
<?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 spec\Sylius\Component\Shipping\Resolver;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Shipping\Model\ShipmentInterface;
use Sylius\Component\Shipping\Repository\ShippingMethodRepositoryInterface;
use Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolverInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
*/
class DefaultShippingMethodResolverSpec extends ObjectBehavior
{
function let(ShippingMethodRepositoryInterface $shippingMethodRepository)
{
$this->beConstructedWith($shippingMethodRepository);
}
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolver');
}
function it_implements_default_shipping_method_resolver_interface()
{
$this->shouldImplement(DefaultShippingMethodResolverInterface::class);
}
function it_returns_first_enabled_shipping_method_as_default(
ShippingMethodInterface $firstShippingMethod,
ShippingMethodInterface $secondShippingMethod,
ShippingMethodRepositoryInterface $shippingMethodRepository,
ShipmentInterface $shipment
) {
$shippingMethodRepository->findBy(['enabled' => true])->willReturn([$firstShippingMethod, $secondShippingMethod]);
$this->getDefaultShippingMethod($shipment)->shouldReturn($firstShippingMethod);
}
function it_returns_null_if_there_is_no_enabled_shipping_methods(
ShippingMethodRepositoryInterface $shippingMethodRepository,
ShipmentInterface $shipment
) {
$shippingMethodRepository->findBy(['enabled' => true])->willReturn([]);
$this->getDefaultShippingMethod($shipment)->shouldReturn(null);
}
}