Skip to content

4. Technical Design

NoorulBhoelai edited this page Apr 8, 2018 · 12 revisions

User Story 1:

As a Merchant I want all placed GuestOrders automatically be linked to an existing Customer(/ShadowCustomer) based on the email address of the order.

Proposed Solution:

  • 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, apply setCustomer(), setCustomerId().

Proposed Solution for Integration Test:

  • 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

User Story 2:

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.

Proposed Solution:

  • 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().

Proposed Solution for Integration Test:

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());

User Story 3:

As a Merchant I want all historic GuestOrders to be linked to Customers / Create new ShadowCustomers based on the above criteria.

User Story 9:

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.

Proposed Solution:

  • 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());
        }
    }
}

Proposed Solution for Integration Test:

  • 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.

User Story 4:

As a Visitor I shouldn’t know that a ShadowCustomer is being created: I shouldn’t receive email communication about it.

Proposed Solution:

  • Use the around plugin to prevent sendEmailNotification function to be executed in function: \Magento\Customer\Model\AccountManagement::createAccountWithPasswordHash

Proposed Solution for Integration Test:

  • 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);

User Story 5:

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.

Proposed Solution:

Proposed Solution for Integration Test:


User Story 6:

As a Visitor I want to be able to register in Magento with the normal flow, create a password / welcome email, etc.

Proposed Solution:

Proposed Solution for Integration Test:


User Story 7:

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.

Proposed Solution:

  • Add column in grid by showing the customers where hash is NULL, use label as (Is Shadow? Only in Backend.).

Proposed Solution for Integration Test:


User Story 8:

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.

Proposed Solution

Add column in grid/info in view by showing the customers where hash is NULL, use label as (Is Shadow? Only in Backend.).

Proposed Solution for Integration Test:

User Story 10:

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.

Proposed Solution:

  • This issue will be fixed in Story 1 and Story 2.

Proposed Solution for Integration Test:

  • Add custom attribute to customer fixture
  • perform story 1 and story 2 tests.
Clone this wiki locally