-
Notifications
You must be signed in to change notification settings - Fork 0
4. Technical Design
NoorulBhoelai edited this page Apr 8, 2018
·
12 revisions
As a Merchant I want all placed GuestOrders automatically be linked to an existing Customer(/ShadowCustomer) based on the email address of the order.
- Add Before plugin for
\Magento\Quote\Model\QuoteManagement::submit
- Use
\Ho\GuestToShadowCustomer\Model\ConvertGuestOrderToShadowCustomer::execute
IF {entity}->getCustomerId(), THROW (OrderAlreadyAssignedToCustomerException OR OrderAlreadyAssignedToShadowCustomerException) Look for e-mail address in customerRepository, applysetCustomer(), setCustomerId()
.
- use magento customer fixture to create an existing customer
- use quote/customer/order fixture to link order to existing customer on e-mail address match
As a Merchant I want all placed GuestOrders that can’t be automatically linked to a Customer/ShadowCustomer (because it doesn’t exist) automatically create a ShadowCustomer.
- Add Before plugin for
\Magento\Quote\Model\QuoteManagement::submit
- Use
\Ho\GuestToShadowCustomer\Model\ConvertGuestOrderToShadowCustomer::execute
IF NOT {entity}->getCustomerId() Look for e-mail address in customerRepository, if NOT EXISTS, create customer account by using the \Magento\Sales\Api\OrderCustomerManagementInterface::create implementation details, apply setCustomer(), setCustomerId().
Use the following Magento Data Fixtures:
- Use Magento data fixture order.php, fetch e-mail address in customerRepository and apply $this->assertEquals('[email protected]', $customer->getEmail());
As a Merchant I want all historic GuestOrders to be linked to Customers / Create new ShadowCustomers based on the above criteria.
As a Developer I want to be able to convert a very large set of historic GuestOrders without impacting the performance of the running shop.
- Use a customer guestOrderRepository.
class Cron {
private $orderRepository;
private $converter;
public function __construct(
OrderRepository $orderRepository,
ConvertGuestOrderToShadowCustomer $converter
) {
$this->guestOrderRepository = $orderRepository;
$this->converter = $converter;
}
public function cronExecute($cron) {
foreach ($this->guestOrderRepository->getList($serachCriteria) as $order) {
$this->converter->execute($order->getId());
}
}
}
- Use magento order_list.php fixture
- Use Tdd wizard quote/order fixture Note: U need at least a guest order and an order with customer.
As a Visitor I shouldn’t know that a ShadowCustomer is being created: I shouldn’t receive email communication about it.
- Use the around plugin to prevent sendEmailNotification function to be executed in function: \Magento\Customer\Model\AccountManagement::createAccountWithPasswordHash
- Magento/Sales/_files/order.php
- ConvertGuestOrderToShadowCustomerInterface::execute functie uitvoeren op order.php fixture
- Zelfde e-mail adres gebruiken uit order.php fixture om een customer registratie uit te voeren met de volgende code:
$email = '[email protected]';
$email2 = '[email protected]';
$firstname = 'Tester';
$lastname = 'McTest';
$groupId = 1;
$password = '_aPassword1';
/** @var \Magento\Customer\Model\Customer $customerModel */
$customerModel = $this->objectManager->create(\Magento\Customer\Model\CustomerFactory::class)->create();
$customerModel->setEmail($email)
->setFirstname($firstname)
->setLastname($lastname)
->setGroupId($groupId)
->setPassword($password);
$customerModel->save();
/** @var \Magento\Customer\Model\Customer $customerModel */
$savedModel = $this->objectManager
->create(\Magento\Customer\Model\CustomerFactory::class)
->create()
->load($customerModel->getId());
$dataInModel = $savedModel->getData();
$newCustomerEntity = $this->customerFactory->create()
->setEmail($email2)
->setFirstname($firstname)
->setLastname($lastname)
->setGroupId($groupId);
$customerData = $this->accountManagement->createAccount($newCustomerEntity, $password);
As a Visitor I shouldn’t know that a GuestOrder is being converted to a ShadowCustomerOrder: Order email communication should be as if I have placed a GuestOrder.
As a Visitor I want to be able to register in Magento with the normal flow, create a password / welcome email, etc.
As a Merchant I want to have a clear distinction on the Customer grid / Customer view if a customer is a normal customer or a ShadowCustomer.
- Add column in grid by showing the customers where hash is NULL, use label as (Is Shadow? Only in Backend.).
As a Merchant I want to have a clear distinction on the Order grid / Order view if an Order is a GuestOrder or a RegisteredCustomerOrder.
Add column in grid/info in view by showing the customers where hash is NULL, use label as (Is Shadow? Only in Backend.).
As a Developer I want the conversion of a GuestOrder to a ShadowCustomer to be abstract: When attributes are added etc. I shouldn’t have to change the code of this module.
- This issue will be fixed in Story 1 and Story 2.
- Add custom attribute to customer fixture
- perform story 1 and story 2 tests.