Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1f8239

Browse files
committed
Add functional test and fixes
1 parent dea9f00 commit b1f8239

21 files changed

Lines changed: 320 additions & 93 deletions

File tree

features/cart/shopping_cart/allowing_access_only_for_correctly_logged_in_users.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Feature: Allowing access only for correctly logged in users
7070
Given the customer logged in
7171
And the customer has product "Stark T-Shirt" in the cart
7272
When the customer specify the billing address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
73-
And the customer complete the addressing step
73+
And the customer completes the addressing step
7474
Then the customer should have checkout address step completed
7575

7676
@api

features/checkout/addressing_order/changing_address_during_checkout.feature

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Sylius/Behat/Context/Api/AddressContext.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function iSpecifyTheEmailAs(?string $email): void
191191

192192
/**
193193
* @When /^I specify the billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
194-
* @When /^the (?:customer|visitor) (?:specifies|changes) the billing (address to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
194+
* @When /^the (?:customer|visitor) specify the billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
195195
* @When /^I specify the billing (address for "([^"]+)" from "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/
196196
* @Given /^the (?:visitor|customer) has specified (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
197197
*/
@@ -504,15 +504,15 @@ public function iProceedThroughCheckoutProcess(): void
504504
}
505505

506506
/**
507-
* @Then /^(address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) should be filled as (billing) address$/
507+
* @Then /^(address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+") should be filled as (billing) address$/
508508
*/
509509
public function addressShouldBeFilledAsBillingAddress(AddressInterface $address, string $addressType): void
510510
{
511511
$this->addressShouldBeFilledAs($address, $addressType);
512512
}
513513

514514
/**
515-
* @Then /^(address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) should be filled as (shipping) address$/
515+
* @Then /^(address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+") should be filled as (shipping) address$/
516516
*/
517517
public function addressShouldBeFilledAsShippingAddress(AddressInterface $address, string $addressType): void
518518
{

src/Sylius/Behat/Context/Transform/AddressContext.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public function createNewAddressWithNameAndProvince($name, $street, $postcode, $
119119
* @Transform /^of "([^"]+)" in the "([^"]+)", "([^"]+)" "([^"]+)", "([^"]+)"$/
120120
* @Transform /^addressed it to "([^"]+)", "([^"]+)", "([^"]+)" "([^"]+)" in the "([^"]+)"$/
121121
* @Transform /^address (?:|is |as )"([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/
122-
* @Transform /^"([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" address$/
123122
*/
124123
public function createNewAddressWithName($name, $street, $postcode, $city, $countryName)
125124
{

src/Sylius/Behat/Resources/config/services/contexts/api/email.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,5 @@
1818
<argument type="service" id="sylius.behat.email_checker" />
1919
<argument type="service" id="translator" />
2020
</service>
21-
22-
<service id="sylius.behat.context.api.address" class="Sylius\Behat\Context\Api\AddressContext">
23-
<argument type="service" id="sylius.repository.address" />
24-
</service>
2521
</services>
2622
</container>

src/Sylius/Behat/Resources/config/suites/api/checkout/checkout.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ default:
4747

4848
- sylius.behat.context.api.admin.managing_orders
4949

50-
- sylius.behat.context.api.address
5150
- sylius.behat.context.api.shop.cart
5251
- sylius.behat.context.api.shop.channel
5352
- sylius.behat.context.api.shop.address

src/Sylius/Bundle/ApiBundle/Command/Checkout/AddressOrder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace Sylius\Bundle\ApiBundle\Command\Checkout;
1515

1616
use Sylius\Bundle\ApiBundle\Command\OrderTokenValueAwareInterface;
17-
use Sylius\Component\Addressing\Model\AddressInterface;
17+
use Sylius\Component\Core\Model\AddressInterface;
1818

1919
/** @experimental */
2020
class AddressOrder implements OrderTokenValueAwareInterface

src/Sylius/Bundle/ApiBundle/CommandHandler/Checkout/AddressOrderHandler.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\Persistence\ObjectManager;
1717
use SM\Factory\FactoryInterface as StateMachineFactoryInterface;
1818
use Sylius\Bundle\ApiBundle\Command\Checkout\AddressOrder;
19+
use Sylius\Bundle\ApiBundle\Mapper\AddressMapperInterface;
1920
use Sylius\Component\Core\Model\AddressInterface;
2021
use Sylius\Component\Core\Model\CustomerInterface;
2122
use Sylius\Component\Core\Model\OrderInterface;
@@ -44,18 +45,23 @@ final class AddressOrderHandler implements MessageHandlerInterface
4445
/** @var StateMachineFactoryInterface */
4546
private $stateMachineFactory;
4647

48+
/** @var AddressMapperInterface */
49+
private $addressMapper;
50+
4751
public function __construct(
4852
OrderRepositoryInterface $orderRepository,
4953
CustomerRepositoryInterface $customerRepository,
5054
FactoryInterface $customerFactory,
5155
ObjectManager $manager,
52-
StateMachineFactoryInterface $stateMachineFactory
56+
StateMachineFactoryInterface $stateMachineFactory,
57+
AddressMapperInterface $addressMapper
5358
) {
5459
$this->orderRepository = $orderRepository;
5560
$this->customerRepository = $customerRepository;
5661
$this->customerFactory = $customerFactory;
5762
$this->manager = $manager;
5863
$this->stateMachineFactory = $stateMachineFactory;
64+
$this->addressMapper = $addressMapper;
5965
}
6066

6167
public function __invoke(AddressOrder $addressOrder): OrderInterface
@@ -83,16 +89,19 @@ public function __invoke(AddressOrder $addressOrder): OrderInterface
8389
$shippingAddress = $order->getShippingAddress();
8490

8591
if ($billingAddress !== null) {
86-
$this->manager->remove($billingAddress);
92+
$order->setBillingAddress($this->addressMapper->mapExisting($billingAddress, $addressOrder->billingAddress));
93+
} else {
94+
$order->setBillingAddress($addressOrder->billingAddress);
8795
}
8896

97+
$newShippingAddress = $addressOrder->shippingAddress ?? clone $addressOrder->billingAddress;
98+
8999
if ($shippingAddress !== null) {
90-
$this->manager->remove($shippingAddress);
100+
$order->setShippingAddress($this->addressMapper->mapExisting($shippingAddress, $newShippingAddress));
101+
} else {
102+
$order->setShippingAddress($newShippingAddress);
91103
}
92104

93-
$order->setBillingAddress($addressOrder->billingAddress);
94-
$order->setShippingAddress($addressOrder->shippingAddress ?? clone $addressOrder->billingAddress);
95-
96105
$stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS);
97106

98107
$this->manager->persist($order);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Bundle\ApiBundle\Mapper;
15+
16+
use Sylius\Component\Core\Model\AddressInterface;
17+
18+
final class AddressMapper implements AddressMapperInterface
19+
{
20+
public function mapExisting(AddressInterface $currentAddress, AddressInterface $targetAddress): AddressInterface
21+
{
22+
$currentAddress->setFirstName($targetAddress->getFirstName());
23+
$currentAddress->setLastName($targetAddress->getLastName());
24+
$currentAddress->setCompany($targetAddress->getCompany());
25+
$currentAddress->setStreet($targetAddress->getStreet());
26+
$currentAddress->setCountryCode($targetAddress->getCountryCode());
27+
$currentAddress->setCity($targetAddress->getCity());
28+
$currentAddress->setPostcode($targetAddress->getPostcode());
29+
$currentAddress->setPhoneNumber($targetAddress->getPhoneNumber());
30+
31+
if (null !== $targetAddress->getProvinceCode()) {
32+
$currentAddress->setProvinceCode($targetAddress->getProvinceCode());
33+
$currentAddress->setProvinceName($targetAddress->getProvinceName());
34+
}
35+
36+
return $currentAddress;
37+
}
38+
}

0 commit comments

Comments
 (0)