forked from PrestaShop/PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PrestaShop#11527 from sarjon/migrate/customer-view…
…-actions Migrate customer view actions
- Loading branch information
Showing
15 changed files
with
612 additions
and
8 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/Adapter/Customer/CommandHandler/SavePrivateNoteForCustomerHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/Adapter/Customer/CommandHandler/TransformGuestToCustomerHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/Core/Domain/Customer/Command/SavePrivateNoteForCustomerCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/Core/Domain/Customer/Command/TransformGuestToCustomerCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Core/Domain/Customer/CommandHandler/SavePrivateNoteForCustomerHandlerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Core/Domain/Customer/CommandHandler/TransformGuestToCustomerHandlerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.