Skip to content

Adding an event to add code in case a customer was newly registered #18

Description

@renttek

Currently to check if a customer was registered by the observer, I am using an around plugin to check for this.
Something like this:

public function aroundExecute(ConvertGuestToCustomer $subject, callable $proceed, Observer $observer): void
{
    /** @var Quote $quote */
    $quote = $observer->getEvent()->getQuote();

    // Should be null for guest orders
    $customerIdBeforeObserver = (int)$quote->getCustomerId();

    $proceed($observer);

    // Will be set of the observer ran successfully
    $customerIdAfterObserver = (int)$quote->getCustomerId();

    if ($customerIdBeforeObserver === $customerIdAfterObserver || !$this->isCreateAccountChecked()) {
        return;
    }

    // my custom code here
}

Would it make sense to add an event in the observer?
Like this:

    public function execute(Observer $observer): void
    {
        // ...

        if ($this->newAccountConfig->sendPasswordMailEnabled()) {
            $this->sendPasswordResetEmail($customer->getEmail());
        }

        $this->eventManager->dispatch(
            'vendic_checkout_customer_created,
            [
                'quote'    => $quote,
                'order'    => $order,
                'customer' => $customer
            ]
        );
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions