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 view actions #11527

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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 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\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();
}
}
@@ -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 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\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
);
}
}
}
@@ -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 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\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
);
}
}
}
@@ -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 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\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;
}
}
@@ -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 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\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);
}
@@ -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 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\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);
}