Skip to content

Commit

Permalink
[Core] Fix customer order addresses saver
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Dec 19, 2017
1 parent d645651 commit f495ec2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Sylius/Component/Core/Customer/CustomerOrderAddressesSaver.php
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Component\Core\Customer;

use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;

Expand Down Expand Up @@ -42,10 +43,18 @@ public function saveAddresses(OrderInterface $order): void
return;
}

$shippingAddress = $order->getShippingAddress();
$billingAddress = $order->getBillingAddress();
$this->addAddress($customer, $order->getBillingAddress());
$this->addAddress($customer, $order->getShippingAddress());
}

$this->addressAdder->add($customer, clone $billingAddress);
$this->addressAdder->add($customer, clone $shippingAddress);
/**
* @param CustomerInterface $customer
* @param AddressInterface|null $address
*/
private function addAddress(CustomerInterface $customer, ?AddressInterface $address): void
{
if (null !== $address) {
$this->addressAdder->add($customer, clone $address);
}
}
}
Expand Up @@ -67,4 +67,22 @@ function it_does_not_save_addresses_for_guest_order(

$this->saveAddresses($order);
}

function it_does_not_save_empty_addresses(
CustomerAddressAdderInterface $addressAdder,
OrderInterface $order,
CustomerInterface $customer,
ShopUserInterface $user
): void {
$order->getCustomer()->willReturn($customer);
$customer->getUser()->willReturn($user);

$order->getShippingAddress()->willReturn(null);
$order->getBillingAddress()->willReturn(null);

$addressAdder->add($customer, Argument::any())->shouldNotBeCalled();
$addressAdder->add($customer, Argument::any())->shouldNotBeCalled();

$this->saveAddresses($order);
}
}

0 comments on commit f495ec2

Please sign in to comment.