Skip to content

Commit

Permalink
Merge pull request PrestaShop#11527 from sarjon/migrate/customer-view…
Browse files Browse the repository at this point in the history
…-actions

Migrate customer view actions
  • Loading branch information
PierreRambaud authored Dec 11, 2018
2 parents 6ef4baf + 3914055 commit a6c8cc2
Show file tree
Hide file tree
Showing 15 changed files with 612 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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 [email protected] 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 <[email protected]>
* @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\Domain\Customer\Command\SavePrivateNoteForCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\CommandHandler\SavePrivateNoteForCustomerHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerNotFoundException;

/**
* Handles command that saves private note for customer
*
* @internal
*/
final class SavePrivateNoteForCustomerHandler implements SavePrivateNoteForCustomerHandlerInterface
{
/**
* @param SavePrivateNoteForCustomerCommand $command
*/
public function handle(SavePrivateNoteForCustomerCommand $command)
{
$customerId = $command->getCustomerId();
$customer = new Customer($customerId->getValue());

if ($customer->id !== $customerId->getValue()) {
throw new CustomerNotFoundException(
$customerId,
sprintf('Customer with id "%s" was not found.', $customerId->getValue())
);
}

$customer->note = $command->getPrivateNote();
$customer->update();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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 [email protected] 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 <[email protected]>
* @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\Domain\Customer\Command\TransformGuestToCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\CommandHandler\TransformGuestToCustomerHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerTransformationException;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId;

/**
* Handles guest to customer transformation command
*
* @internal
*/
final class TransformGuestToCustomerHandler implements TransformGuestToCustomerHandlerInterface
{
/**
* @var int
*/
private $contextLangId;

/**
* @param int $contextLangId
*/
public function __construct($contextLangId)
{
$this->contextLangId = $contextLangId;
}

/**
* @param TransformGuestToCustomerCommand $command
*/
public function handle(TransformGuestToCustomerCommand $command)
{
$customerId = $command->getCustomerId();
$customer = new Customer($customerId->getValue());

$this->assertCustomerExists($customerId, $customer);
$this->assertCustomerIsGuest($customer);

if (!$customer->transformToCustomer($this->contextLangId)) {
throw new CustomerTransformationException(
sprintf('Failed to transform guest into customer'),
CustomerTransformationException::TRANSFORMATION_FAILED
);
}
}

/**
* @param CustomerId $customerId
* @param Customer $customer
*
* @throws CustomerNotFoundException
*/
private function assertCustomerExists(CustomerId $customerId, Customer $customer)
{
if ($customer->id !== $customerId->getValue()) {
throw new CustomerNotFoundException(
$customerId,
sprintf('Customer with id "%s" was not found', $customerId->getValue())
);
}
}

/**
* @param Customer $customer
*
* @throws CustomerTransformationException
*/
private function assertCustomerIsGuest(Customer $customer)
{
if (Customer::customerExists($customer->email)) {
throw new CustomerTransformationException(
sprintf('Customer with id "%s" already exists as non-guest', $customer->id),
CustomerTransformationException::CUSTOMER_IS_NOT_GUEST
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?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 [email protected] 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 <[email protected]>
* @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\Core\Domain\Customer\Command;

use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId;

/**
* Saves private note for customer that can only be seen in Back Office
*/
class SavePrivateNoteForCustomerCommand
{
/**
* @var CustomerId
*/
private $customerId;

/**
* @var string
*/
private $privateNote;

/**
* @param CustomerId $customerId
* @param string $privateNote
*/
public function __construct(CustomerId $customerId, $privateNote)
{
$this->assertPrivateNoteIsString($privateNote);

$this->customerId = $customerId;
$this->privateNote = $privateNote;
}

/**
* @return CustomerId
*/
public function getCustomerId()
{
return $this->customerId;
}

/**
* @return string
*/
public function getPrivateNote()
{
return $this->privateNote;
}

/**
* @param string $privateNote
*
* @throws CustomerConstraintException
*/
private function assertPrivateNoteIsString($privateNote)
{
if (!is_string($privateNote)) {
throw new CustomerConstraintException(
'Invalid private note provided. Private note must be a string.',
CustomerConstraintException::INVALID_PRIVATE_NOTE
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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 [email protected] 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 <[email protected]>
* @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\Core\Domain\Customer\Command;

use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId;

/**
* Transforms guest (customer without password) into registered customer account
*/
class TransformGuestToCustomerCommand
{
/**
* @var CustomerId
*/
private $customerId;

/**
* @param CustomerId $customerId
*/
public function __construct(CustomerId $customerId)
{
$this->customerId = $customerId;
}

/**
* @return CustomerId
*/
public function getCustomerId()
{
return $this->customerId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 [email protected] 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 <[email protected]>
* @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\Core\Domain\Customer\CommandHandler;

use PrestaShop\PrestaShop\Core\Domain\Customer\Command\SavePrivateNoteForCustomerCommand;

/**
* Defines interface for service that handles command which saves private note for customer
*/
interface SavePrivateNoteForCustomerHandlerInterface
{
/**
* @param SavePrivateNoteForCustomerCommand $command
*/
public function handle(SavePrivateNoteForCustomerCommand $command);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 [email protected] 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 <[email protected]>
* @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\Core\Domain\Customer\CommandHandler;

use PrestaShop\PrestaShop\Core\Domain\Customer\Command\TransformGuestToCustomerCommand;

/**
* Defines contract for service that handles command which transforms guest into customer
*/
interface TransformGuestToCustomerHandlerInterface
{
/**
* @param TransformGuestToCustomerCommand $command
*/
public function handle(TransformGuestToCustomerCommand $command);
}
Loading

0 comments on commit a6c8cc2

Please sign in to comment.