Guest To Customer
The guest to customer abstraction layer enables you to create a transform adapter that processes the \Magento\Customer\Model\Data\Customer
object,
attempting to transform or create a store customer using the provided data.
How it works
This abstraction layer automatically adds a checkbox beneath the email address input in the Guest Details component. By default, this checkbox is unchecked, requiring the guest to explicitly agree to use their data for account creation by checking it.
Additionally, system configuration options are included in the Hyvä Checkout system configuration section:
- Hyvä Themes > Checkout > Components > Guest Details > Enable Guest to Customer
- Hyvä Themes > Checkout > Developer > Place Order > Guest to Customer Adapter
The adapter is utilized during the sales_model_service_quote_submit_before
observer event, where the transform
method is invoked.
This method can return true
or false
or throw an exception, which will be logged automatically. This process does not
interfere with the order process, ensuring that everything is captured correctly.
Compatible modules
- None
Please reach out to us via Slack to inform us when you develop a compatibility module. This will allow us to add it to our list for others to use.
Installation
Requirements
- PHP: 7.4 (or higher)
Usage
Build yourself a custom module which has a sequence
entry for Hyva_CheckoutGuestToCustomer
.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"
>
<module name="Vendor_Module">
<sequence>
<module name="Hyva_CheckoutGuestToCustomer"/>
</sequence>
</module>
</config>
Create a custom Guest To Customer Adapter which extends from \Hyva\CheckoutAutoComplete\Model\AddressAutoCompleteServiceAdapter\AbstractServiceAdapter
.
<?php
declare(strict_types=1);
namespace Vendor\Module\Model\HyvaCheckout\GuestToCustomer;
use Hyva\CheckoutGuestToCustomer\Model\AbstractGuestToCustomerAdapter;
use Magento\Customer\Model\Data\Customer as CustomerData;
class ExampleGuestToCustomerAdapter extends AbstractGuestToCustomerAdapter
{
public function transform(CustomerData $customer): bool
{
// All logic required to transform the guest into a customer account.
// It is recommended to leverage everything provided by the module
// you are integrating with for compatibility.
return true;
}
public function getServiceName(): string
{
// A descriptive service name used in the system configuration
// to allow administrators or developers to select the appropriate adapter.
return 'Your Adapter Name';
}
}
Inject it as one of the available adapters via etc/di.xml
.
<type name="Hyva\CheckoutGuestToCustomer\Model\GuestToCustomerManagement">
<arguments>
<argument name="adapters" xsi:type="array">
<item name="your_adapter_name" xsi:type="object">
Vendor\Module\Model\HyvaCheckout\GuestToCustomer\ExampleGuestToCustomerAdapter
</item>
</argument>
</arguments>
</type>