Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Changed shipping/billing address into defaultAddress on customer's model #6531

Merged
merged 2 commits into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions app/migrations/Version20161020113011.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

final class Version20161020113011 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql('ALTER TABLE sylius_customer DROP FOREIGN KEY FK_7E82D5E64D4CFF2B');
$this->addSql('ALTER TABLE sylius_customer DROP FOREIGN KEY FK_7E82D5E679D0C0E4');
$this->addSql('DROP INDEX UNIQ_7E82D5E679D0C0E4 ON sylius_customer');
$this->addSql('DROP INDEX UNIQ_7E82D5E64D4CFF2B ON sylius_customer');
$this->addSql('ALTER TABLE sylius_customer ADD default_address_id INT DEFAULT NULL, DROP shipping_address_id, DROP billing_address_id');
$this->addSql('ALTER TABLE sylius_customer ADD CONSTRAINT FK_7E82D5E6BD94FB16 FOREIGN KEY (default_address_id) REFERENCES sylius_address (id) ON DELETE SET NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_7E82D5E6BD94FB16 ON sylius_customer (default_address_id)');
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$this->addSql('ALTER TABLE sylius_customer DROP FOREIGN KEY FK_7E82D5E6BD94FB16');
$this->addSql('DROP INDEX UNIQ_7E82D5E6BD94FB16 ON sylius_customer');
$this->addSql('ALTER TABLE sylius_customer ADD billing_address_id INT DEFAULT NULL, CHANGE default_address_id shipping_address_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE sylius_customer ADD CONSTRAINT FK_7E82D5E64D4CFF2B FOREIGN KEY (shipping_address_id) REFERENCES sylius_address (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE sylius_customer ADD CONSTRAINT FK_7E82D5E679D0C0E4 FOREIGN KEY (billing_address_id) REFERENCES sylius_address (id) ON DELETE SET NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_7E82D5E679D0C0E4 ON sylius_customer (billing_address_id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_7E82D5E64D4CFF2B ON sylius_customer (shipping_address_id)');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ Feature: Seeing customer's details

@ui
Scenario: Seeing customer's addresses
Given his shipping address is "Hobbiton", "Bag End", "1", "New Zealand" for "Frodo Baggins"
And his billing address is "Rivendell", "The Last Homely House", "7", "New Zealand" for "Bilbo Baggins"
Given his default address is "Hobbiton", "Bag End", "1", "New Zealand" for "Frodo Baggins"
When I view details of the customer "f.baggins@shire.me"
Then his shipping address should be "Frodo Baggins, Bag End, Hobbiton, NEW ZEALAND 1"
And his billing address should be "Bilbo Baggins, The Last Homely House, Rivendell, NEW ZEALAND 7"
Then his default address should be "Frodo Baggins, Bag End, Hobbiton, NEW ZEALAND 1"

@ui
Scenario: Seeing information about no existing account for a given customer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Feature: Seeing a province on customer's details
Scenario: Seeing customer's addresses
Given I am logged in as an administrator
And the store has customer "f.baggins@shire.me" with name "Frodo Baggins" since "2011-01-10 21:00"
And his shipping address is "Frodo Baggins", "Bag End", "12-1321", "Hobbiton", "United Kingdom", "East of England"
And his billing address is "Bilbo Baggins", "The Last Homely House", "7", "Rivendell", "United Kingdom", "West of England"
And his default address is "Frodo Baggins", "Bag End", "12-1321", "Hobbiton", "United Kingdom", "East of England"
When I view details of the customer "f.baggins@shire.me"
Then the province in the shipping address should be "East of England"
Then the province in the billing address should be "West of England"
Then the province in the default address should be "East of England"
19 changes: 4 additions & 15 deletions src/Sylius/Behat/Context/Setup/CustomerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,12 @@ public function thereIsAdministratorIdentifiedByEmailAndPassword($name, $email,
}

/**
* @Given /^(his) shipping (address is "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)" for "(?:[^"]+)")$/
* @Given /^(his) shipping (address is "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/
* @Given /^(his) default (address is "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)" for "(?:[^"]+)")$/
* @Given /^(his) default (address is "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/
*/
public function heHasShippingAddress(CustomerInterface $customer, AddressInterface $address)
public function heHasDefaultAddress(CustomerInterface $customer, AddressInterface $address)
{
$customer->setShippingAddress($address);

$this->customerManager->flush();
}

/**
* @Given /^(his) billing (address is "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)" for "(?:[^"]+)")$/
* @Given /^(his) billing (address is "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/
*/
public function heHasBillingAddress(CustomerInterface $customer, AddressInterface $address)
{
$customer->setBillingAddress($address);
$customer->setDefaultAddress($address);

$this->customerManager->flush();
}
Expand Down
39 changes: 8 additions & 31 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingCustomersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,26 +474,14 @@ public function hisEmailShouldBe($email)
}

/**
* @Then his shipping address should be :shippingAddress
* @Then his default address should be :defaultAddress
*/
public function hisShippingAddressShouldBe($shippingAddress)
public function hisShippingAddressShouldBe($defaultAddress)
{
Assert::same(
str_replace(',', '', $shippingAddress),
$this->showPage->getShippingAddress(),
'Customer shipping address should be "%s", but it is not.'
);
}

/**
* @Then his billing address should be :billingAddress
*/
public function hisBillingAddressShouldBe($billingAddress)
{
Assert::same(
str_replace(',', '', $billingAddress),
$this->showPage->getBillingAddress(),
'Customer billing address should be "%s", but it is not.'
str_replace(',', '', $defaultAddress),
$this->showPage->getDefaultAddress(),
'Customer\'s default address should be "%s", but it is not.'
);
}

Expand Down Expand Up @@ -539,23 +527,12 @@ public function thisCustomerShouldBeSubscribedToTheNewsletter()
}

/**
* @Then the province in the shipping address should be :provinceName
*/
public function theProvinceInTheShippingAddressShouldBe($provinceName)
{
Assert::true(
$this->showPage->hasShippingProvinceName($provinceName),
sprintf('Cannot find shipping address with province %s', $provinceName)
);
}

/**
* @Then the province in the billing address should be :provinceName
* @Then the province in the default address should be :provinceName
*/
public function theProvinceInTheShippingBillingShouldBe($provinceName)
public function theProvinceInTheDefaultAddressShouldBe($provinceName)
{
Assert::true(
$this->showPage->hasBillingProvinceName($provinceName),
$this->showPage->hasDefaultAddressProvinceName($provinceName),
sprintf('Cannot find shipping address with province %s', $provinceName)
);
}
Expand Down
31 changes: 6 additions & 25 deletions src/Sylius/Behat/Page/Admin/Customer/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,9 @@ public function getRegistrationDate()
/**
* {@inheritdoc}
*/
public function getShippingAddress()
public function getDefaultAddress()
{
return $this->getElement('shipping_address')->getText();
}

/**
* {@inheritdoc}
*/
public function getBillingAddress()
{
return $this->getElement('billing_address')->getText();
return $this->getElement('default_address')->getText();
}

/**
Expand All @@ -102,21 +94,11 @@ public function isSubscribedToNewsletter()
/**
* {@inheritdoc}
*/
public function hasShippingProvinceName($provinceName)
{
$shippingAddressText = $this->getElement('shipping_address')->getText();

return false !== stripos($shippingAddressText, $provinceName);
}

/**
* {@inheritdoc}
*/
public function hasBillingProvinceName($provinceName)
public function hasDefaultAddressProvinceName($provinceName)
{
$billingAddressText = $this->getElement('billing_address')->getText();
$defaultAddressProvince = $this->getElement('default_address')->getText();

return false !== stripos($billingAddressText, $provinceName);
return false !== stripos($defaultAddressProvince, $provinceName);
}

/**
Expand All @@ -133,13 +115,12 @@ public function getRouteName()
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'billing_address' => '#billingAddress address',
'customer_email' => '#info .content.extra > a',
'customer_name' => '#info .content > a',
'default_address' => '#defaultAddress address',
'delete_account_button' => '#actions',
'no_account' => '#no-account',
'registration_date' => '#info .content .date',
'shipping_address' => '#shippingAddress address',
'subscribed_to_newsletter' => '#subscribed-to-newsletter',
]);
}
Expand Down
15 changes: 2 additions & 13 deletions src/Sylius/Behat/Page/Admin/Customer/ShowPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ public function getRegistrationDate();
/**
* @return string
*/
public function getShippingAddress();

/**
* @return string
*/
public function getBillingAddress();
public function getDefaultAddress();

/**
* @return bool
Expand All @@ -74,12 +69,6 @@ public function isSubscribedToNewsletter();
*
* @return bool
*/
public function hasShippingProvinceName($provinceName);
public function hasDefaultAddressProvinceName($provinceName);

/**
* @param string $provinceName
*
* @return bool
*/
public function hasBillingProvinceName($provinceName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
</div>
</div>
<div class="ui two column stackable grid">
{% if customer.shippingAddress %}
<div class="column" id="shippingAddress">
<h4 class="ui dividing header">{{ 'sylius.ui.shipping_address'|trans }}</h4>
{% include '@SyliusAdmin/Common/_address.html.twig' with {'address': customer.shippingAddress} %}
</div>
{% endif %}
{% if customer.billingAddress %}
<div class="column" id="billingAddress">
<h4 class="ui dividing header">{{ 'sylius.ui.billing_address'|trans }}</h4>
{% include '@SyliusAdmin/Common/_address.html.twig' with {'address': customer.billingAddress} %}
{% if customer.defaultAddress %}
<div class="column" id="defaultAddress">
<h4 class="ui dividing header">{{ 'sylius.ui.default'|trans }}</h4>
{% include '@SyliusAdmin/Common/_address.html.twig' with {'address': customer.defaultAddress} %}
</div>
{% endif %}
</div>
</div>
</div>

Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@ public function setCustomerAddressing(GenericEvent $event)
return;
}

if (null === $customer->getShippingAddress()) {
$customer->setShippingAddress(clone $order->getShippingAddress());
}

if (null === $customer->getBillingAddress()) {
$customer->setBillingAddress(clone $order->getBillingAddress());
if (null === $customer->getDefaultAddress()) {
$customer->setDefaultAddress(clone $order->getShippingAddress());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@

-->

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Sylius\Component\Core\Model\Customer" table="sylius_customer">
<one-to-one field="billingAddress" target-entity="Sylius\Component\Addressing\Model\AddressInterface">
<join-column name="billing_address_id" on-delete="SET NULL" />
<cascade>
<cascade-persist />
</cascade>
</one-to-one>
<one-to-one field="shippingAddress" target-entity="Sylius\Component\Addressing\Model\AddressInterface">
<join-column name="shipping_address_id" on-delete="SET NULL" />
<one-to-one field="defaultAddress" target-entity="Sylius\Component\Addressing\Model\AddressInterface">
<join-column name="default_address_id" on-delete="SET NULL" />
<cascade>
<cascade-persist />
</cascade>
Expand All @@ -47,5 +37,4 @@
</cascade>
</one-to-many>
</mapped-superclass>

</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,32 @@ function it_does_nothing_when_context_doesnt_have_customer(GenericEvent $event,
$this->setCustomerAddressing($event);
}

function it_sets_customer_default_addressing_from_order(GenericEvent $event, OrderInterface $order, CustomerInterface $customer, AddressInterface $address)
function it_sets_customer_default_address_from_order(GenericEvent $event, OrderInterface $order, CustomerInterface $customer, AddressInterface $address)
{
$event->getSubject()->willReturn($order);

$order->getCustomer()->willReturn($customer);

$order->getShippingAddress()->willReturn($address);
$customer->getShippingAddress()->willReturn(null);
$customer->setShippingAddress($address)->shouldBeCalled();

$order->getBillingAddress()->willReturn($address);
$customer->getBillingAddress()->willReturn(null);
$customer->setBillingAddress($address)->shouldBeCalled();

$customer->getDefaultAddress()->willReturn(null);
$customer->setDefaultAddress($address)->shouldBeCalled();

$this->setCustomerAddressing($event);
}

function it_does_not_set_customer_addressing_when_customer_already_have_default_addresses(GenericEvent $event, OrderInterface $order, CustomerInterface $customer, AddressInterface $address)
function it_does_not_set_customer_default_address_when_they_already_have_one(GenericEvent $event, OrderInterface $order, CustomerInterface $customer, AddressInterface $address)
{
$event->getSubject()->willReturn($order);

$order->getCustomer()->willReturn($customer);

$order->getShippingAddress()->willReturn($address);
$customer->getShippingAddress()->willReturn($address);
$customer->setShippingAddress($address)->shouldNotBeCalled();

$order->getBillingAddress()->willReturn($address);
$customer->getBillingAddress()->willReturn($address);
$customer->setBillingAddress($address)->shouldNotBeCalled();

$customer->getDefaultAddress()->willReturn($address);
$customer->setDefaultAddress($address)->shouldNotBeCalled();

$this->setCustomerAddressing($event);
}
Expand Down
Loading