mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Merge pull request #808 from stloyd/bugfix/checkout_zone_matching
[CoreBundle] Fix the problem when none shipping method match the current user shipping address
This commit is contained in:
commit
c05357c120
7 changed files with 52 additions and 9 deletions
|
|
@ -17,13 +17,21 @@ Feature: Checkout addressing
|
|||
| email | password | enabled |
|
||||
| john@example.com | foo | yes |
|
||||
| rick@example.com | bar | yes |
|
||||
And I am logged in user
|
||||
And the following zones are defined:
|
||||
| name | type | members |
|
||||
| UK + Germany | country | United Kingdom, Germany |
|
||||
| USA | country | USA |
|
||||
And there are following countries:
|
||||
| name |
|
||||
| USA |
|
||||
| United Kingdom |
|
||||
| Poland |
|
||||
| Germany |
|
||||
And the following shipping methods exist:
|
||||
| zone | name | calculator | configuration |
|
||||
| UK + Germany | DHL Express | Flat rate | Amount: 5000 |
|
||||
| USA | FedEx | Flat rate | Amount: 6500 |
|
||||
And I am logged in user
|
||||
|
||||
Scenario: Filling the shipping address
|
||||
Given I added product "PHP Top" to cart
|
||||
|
|
|
|||
|
|
@ -17,6 +17,12 @@ Feature: Checkout shipping
|
|||
| name | type | members |
|
||||
| UK + Germany | country | United Kingdom, Germany |
|
||||
| USA | country | USA |
|
||||
And there are following countries:
|
||||
| name |
|
||||
| USA |
|
||||
| United Kingdom |
|
||||
| Poland |
|
||||
| Germany |
|
||||
And the following shipping methods exist:
|
||||
| zone | name | calculator | configuration |
|
||||
| UK + Germany | DHL Express | Flat rate | Amount: 5000 |
|
||||
|
|
@ -80,3 +86,10 @@ Feature: Checkout shipping
|
|||
Then I should be on the checkout finalize step
|
||||
And "Shipping total: €65.00" should appear on the page
|
||||
And "Total: €70.99" should appear on the page
|
||||
|
||||
Scenario: Selecting shipping address that not match any shop shipping zones
|
||||
Given I go to the checkout start page
|
||||
And I fill in the shipping address to Poland
|
||||
When I press "Continue"
|
||||
Then I should be on the checkout addressing step
|
||||
And "We're sorry" should appear on the page
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@
|
|||
|
||||
namespace Sylius\Bundle\CoreBundle\Checkout\Step;
|
||||
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Sylius\Bundle\AddressingBundle\Matcher\ZoneMatcherInterface;
|
||||
use Sylius\Bundle\CartBundle\Model\CartInterface;
|
||||
use Sylius\Bundle\CartBundle\Provider\CartProviderInterface;
|
||||
use Sylius\Bundle\CoreBundle\Model\OrderInterface;
|
||||
use Sylius\Bundle\FlowBundle\Process\Step\ControllerStep;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Sylius\Bundle\CoreBundle\Checkout\Step;
|
||||
|
||||
use Sylius\Bundle\AddressingBundle\Model\ZoneInterface;
|
||||
use Sylius\Bundle\CoreBundle\Checkout\SyliusCheckoutEvents;
|
||||
use Sylius\Bundle\CoreBundle\Model\OrderInterface;
|
||||
use Sylius\Bundle\FlowBundle\Process\Context\ProcessContextInterface;
|
||||
|
|
@ -26,6 +27,11 @@ use Symfony\Component\Form\FormInterface;
|
|||
*/
|
||||
class ShippingStep extends CheckoutStep
|
||||
{
|
||||
/**
|
||||
* @var null|ZoneInterface
|
||||
*/
|
||||
private $zone;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -36,6 +42,10 @@ class ShippingStep extends CheckoutStep
|
|||
|
||||
$form = $this->createCheckoutShippingForm($order);
|
||||
|
||||
if (null === $this->zone) {
|
||||
return $this->proceed($context->getPreviousStep()->getName());
|
||||
}
|
||||
|
||||
return $this->renderStep($context, $order, $form);
|
||||
}
|
||||
|
||||
|
|
@ -70,16 +80,20 @@ class ShippingStep extends CheckoutStep
|
|||
return $this->render('SyliusWebBundle:Frontend/Checkout/Step:shipping.html.twig', array(
|
||||
'order' => $order,
|
||||
'form' => $form->createView(),
|
||||
'context' => $context
|
||||
'context' => $context,
|
||||
));
|
||||
}
|
||||
|
||||
protected function createCheckoutShippingForm(OrderInterface $order)
|
||||
{
|
||||
$zone = $this->getZoneMatcher()->match($order->getShippingAddress());
|
||||
$this->zone = $this->getZoneMatcher()->match($order->getShippingAddress());
|
||||
|
||||
if (null === $this->zone) {
|
||||
$this->get('session')->getFlashBag()->add('error', 'sylius.checkout.shipping.error');
|
||||
}
|
||||
|
||||
return $this->createForm('sylius_checkout_shipping', $order, array(
|
||||
'criteria' => array('zone' => $zone)
|
||||
'criteria' => array('zone' => $this->zone)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class LoadZonesData extends DataFixture
|
|||
'GB'
|
||||
);
|
||||
|
||||
$restOfWorldCountries = array_diff(Intl::getRegionBundle()->getCountryNames(), $euCountries + array('US'));
|
||||
$restOfWorldCountries = array_diff(array_keys(Intl::getRegionBundle()->getCountryNames()), $euCountries + array('US'));
|
||||
|
||||
$manager->persist($eu = $this->createZone('EU', ZoneInterface::TYPE_COUNTRY, $euCountries));
|
||||
$manager->persist($this->createZone('USA', ZoneInterface::TYPE_COUNTRY, array('US')));
|
||||
|
|
@ -69,10 +69,7 @@ class LoadZonesData extends DataFixture
|
|||
$zoneMember = $this->getZoneMemberRepository($type)->createNew();
|
||||
|
||||
if ($this->hasReference('Sylius.'.ucfirst($type).'.'.$id)) {
|
||||
call_user_func(array(
|
||||
$zoneMember, 'set'.ucfirst($type)),
|
||||
$this->getReference('Sylius.'.ucfirst($type).'.'.$id)
|
||||
);
|
||||
$zoneMember->{'set'.ucfirst($type)}($this->getReference('Sylius.'.ucfirst($type).'.'.$id));
|
||||
}
|
||||
|
||||
$zone->addMember($zoneMember);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace Sylius\Bundle\ShippingBundle\Resolver;
|
|||
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
use Sylius\Bundle\ShippingBundle\Checker\ShippingMethodEligibilityCheckerInterface;
|
||||
use Sylius\Bundle\ShippingBundle\Model\ShippingMethodInterface;
|
||||
use Sylius\Bundle\ShippingBundle\Model\ShippingSubjectInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -68,6 +69,8 @@ class MethodsResolver implements MethodsResolverInterface
|
|||
* Return all methods matching given criteria.
|
||||
*
|
||||
* @param array $criteria
|
||||
*
|
||||
* @return ShippingMethodInterface[]
|
||||
*/
|
||||
protected function getMethods(array $criteria = array())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -610,6 +610,10 @@
|
|||
<source>sylius.checkout.shipping.header</source>
|
||||
<target>Shipping method</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="51ca81d45a9dfd2501c06009489807ae" resname="sylius.checkout.shipping.error">
|
||||
<source>sylius.checkout.shipping.error</source>
|
||||
<target>We're sorry, but our shop is not able to provide product shipping to country which you have chosen.</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="4f7b06a12e37b50e59c5c84d1040d68e" resname="sylius.confirmation.message">
|
||||
<source>sylius.confirmation.message</source>
|
||||
<target>Do you want to delete this item?</target>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue