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

Migrate customer Add/Edit actions #11723

Merged
merged 51 commits into from Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f976fd4
implement add customer command
sarjon Nov 27, 2018
312c9bd
add CustomerType for forms
sarjon Nov 27, 2018
b0c3a13
implement edit customer command
sarjon Nov 27, 2018
fc2cdca
add getting customer for editing
sarjon Nov 28, 2018
b2a8b7b
implement form rendering with default data
sarjon Nov 28, 2018
18f8cf9
implement b2b part of customer form
sarjon Nov 28, 2018
09d9ead
add b2b customer suppor type
sarjon Nov 29, 2018
ba95270
make password field requirement configurable for customer
sarjon Nov 29, 2018
100d9ef
render customer form with correct ui
sarjon Nov 29, 2018
aabdb11
make customer birthday field single widget
sarjon Nov 29, 2018
e4508db
add VOs for customer email, firstname, lastname and password
sarjon Nov 30, 2018
6016504
add b2b customer fields to edit customer command
sarjon Nov 30, 2018
b917fd5
implement edit customer command dispatching when customer edit form i…
sarjon Nov 30, 2018
0d2231d
implement b2b fields editing using command
sarjon Dec 10, 2018
0fc7390
add b2b customer data to form provider
sarjon Dec 10, 2018
e2fd737
update AddCustomerCommand handler
sarjon Dec 10, 2018
9ad9ea7
add assertion for customer email when editing
sarjon Dec 10, 2018
d62f2fa
add error handling in customer controller
sarjon Dec 10, 2018
bc73e93
allow creating customer when shop is selected
sarjon Dec 10, 2018
7ec713f
update edit customer command building
sarjon Dec 10, 2018
b2a2e52
use vo's instead of plain values when creating customer
sarjon Dec 10, 2018
be43570
mark required fields with asterisks
sarjon Dec 10, 2018
35123ce
add password hashing on customer add/edit
sarjon Dec 10, 2018
e5498f1
add some unit tests
sarjon Dec 11, 2018
0fb0f4a
add more unit tests
sarjon Dec 11, 2018
f32ee39
add more unit tests
sarjon Dec 11, 2018
3594c8c
do not diplsy password input when editing guest customer
sarjon Dec 11, 2018
623a527
add group selection in request when handling form submit
sarjon Dec 11, 2018
35e2dc8
improve exception translation to user friendly errors
sarjon Dec 11, 2018
24b23ae
compare current customer email with new one when editing customer
sarjon Dec 11, 2018
064c72d
fix birthday saving on add/edit for customer
sarjon Dec 11, 2018
ec2970c
display minimum required password length
sarjon Dec 11, 2018
d6bb3c0
enable ChoiceTable for add/edit forms
sarjon Dec 11, 2018
2fe20cb
improve validation of customers birthday
sarjon Dec 12, 2018
5d75e51
keep allowed first and last names chars in variable
sarjon Dec 12, 2018
a953713
cs fixer
sarjon Dec 12, 2018
4c7e878
handle duplicate email exception
sarjon Dec 13, 2018
9e66678
handle group access selection exception
sarjon Dec 13, 2018
3d41118
add ape code validation
sarjon Dec 13, 2018
b0a6146
remove margin from material choice table
sarjon Dec 13, 2018
97206d3
cs fixer
sarjon Dec 13, 2018
187cd69
minor fixes
sarjon Dec 13, 2018
97e4a1f
cs fixer
sarjon Dec 13, 2018
2f750e6
fix password editing for customer
sarjon Dec 17, 2018
a7811df
redirect user to customers list after successful edit
sarjon Dec 17, 2018
3935bc5
use legacy layout for birthday input
sarjon Dec 19, 2018
eb19ba1
upate form rending with macro helper
sarjon Dec 19, 2018
49081be
add new error messages
sarjon Dec 19, 2018
0afca84
add additional constraints for customer form
sarjon Dec 20, 2018
b9f9342
redirect to list after customer creation
sarjon Dec 20, 2018
edae291
Fix CustomerFormDataProviderTest
matks Jan 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions admin-dev/themes/new-theme/js/pages/customer/index.js
Expand Up @@ -55,4 +55,7 @@ $(() => {
customerGrid.addExtension(new SubmitBulkExtension());
customerGrid.addExtension(new SubmitGridExtension());
customerGrid.addExtension(new LinkRowActionExtension());

// needed for "Group access" input in Add/Edit customer forms
new ChoiceTable();
});
152 changes: 152 additions & 0 deletions src/Adapter/Customer/CommandHandler/AddCustomerHandler.php
@@ -0,0 +1,152 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

namespace PrestaShop\PrestaShop\Adapter\Customer\CommandHandler;

use Customer;
use PrestaShop\PrestaShop\Core\Crypto\Hashing;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\AddCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\CommandHandler\AddCustomerHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerDefaultGroupAccessException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\DuplicateCustomerEmailException;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\Email;

/**
* Handles command that adds new customer
*
* @internal
*/
final class AddCustomerHandler implements AddCustomerHandlerInterface
{
/**
* @var Hashing
*/
private $hashing;

/**
* @var string Value of legacy _COOKIE_KEY_
*/
private $legacyCookieKey;

/**
* @param Hashing $hashing
* @param string $legacyCookieKey
*/
public function __construct(Hashing $hashing, $legacyCookieKey)
{
$this->hashing = $hashing;
$this->legacyCookieKey = $legacyCookieKey;
}

/**
* {@inheritdoc}
*/
public function handle(AddCustomerCommand $command)
{
$customer = new Customer();

$this->fillCustomerWithCommandData($customer, $command);

if (false === $customer->validateFields(false)) {
throw new CustomerException('Customer contains invalid field values');
}

$this->assertCustomerWithGivenEmailDoesNotExist($command->getEmail());
$this->assertCustomerCanAccessDefaultGroup($command);

$customer->add();

return new CustomerId((int) $customer->id);
}

/**
* @param Email $email
*/
private function assertCustomerWithGivenEmailDoesNotExist(Email $email)
{
$customer = new Customer();
$customer->getByEmail($email->getValue());

if ($customer->id) {
throw new DuplicateCustomerEmailException(
$email,
sprintf('Customer with email "%s" already exists', $email->getValue())
);
}
}

/**
* @param Customer $customer
* @param AddCustomerCommand $command
*/
private function fillCustomerWithCommandData(Customer $customer, AddCustomerCommand $command)
{
$apeCode = null !== $command->getApeCode() ?
$command->getApeCode()->getValue() :
null
;

$hashedPassword = $this->hashing->hash(
$command->getPassword()->getValue(),
$this->legacyCookieKey
);

$customer->firstname = $command->getFirstName()->getValue();
$customer->lastname = $command->getLastName()->getValue();
$customer->email = $command->getEmail()->getValue();
$customer->passwd = $hashedPassword;
$customer->id_default_group = $command->getDefaultGroupId();
$customer->groupBox = $command->getGroupIds();
$customer->id_gender = $command->getGenderId();
$customer->active = $command->isEnabled();
$customer->optin = $command->isPartnerOffersSubscribed();
$customer->birthday = $command->getBirthday()->getValue();
$customer->id_shop = $command->getShopId();

// fill b2b customer fields
$customer->company = $command->getCompanyName();
$customer->siret = $command->getSiretCode();
$customer->ape = $apeCode;
$customer->website = $command->getWebsite();
$customer->outstanding_allow_amount = $command->getAllowedOutstandingAmount();
$customer->max_payment_days = $command->getMaxPaymentDays();
$customer->id_risk = $command->getRiskId();
}

/**
* @param AddCustomerCommand $command
*/
private function assertCustomerCanAccessDefaultGroup(AddCustomerCommand $command)
{
if (!in_array($command->getDefaultGroupId(), $command->getGroupIds())) {
throw new CustomerDefaultGroupAccessException(
sprintf('Customer default group with id "%s" must be in access groups', $command->getDefaultGroupId())
);
}
}
}