-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Elgentos\HyvaCheckoutABTest\Plugin; | ||
|
||
use Exception; | ||
use Hyva\CheckoutCore\Model\CheckoutInformation\Luma; | ||
use Hyva\CheckoutCore\Model\Config; | ||
use Magento\Checkout\Model\Session as CheckoutSession; | ||
use Magento\Framework\App\State; | ||
|
||
class PickRandomCheckout | ||
{ | ||
public function __construct(private CheckoutSession $checkoutSession, private State $appState) { | ||
|
||
} | ||
|
||
/** | ||
* @param Config $subject | ||
* @param string $result | ||
* | ||
* @return string | ||
* @throws Exception | ||
*/ | ||
public function afterGetActiveCheckoutNamespace( | ||
Config $subject, | ||
string $result | ||
): string { | ||
// Retrieve the active checkout from the session, if present | ||
$activeCheckoutNamespace = $this->checkoutSession->getData('active_checkout_namespace'); | ||
if ($activeCheckoutNamespace) { | ||
return $activeCheckoutNamespace; | ||
} | ||
|
||
// 50% of the time, use the Luma checkout. | ||
// Otherwise, default to the Hyva Checkout config | ||
// Only do the AB test in production | ||
if ( | ||
random_int(0, 1) && | ||
$this->appState->getMode() !== State::MODE_DEVELOPER | ||
) { | ||
$result = Luma::NAMESPACE; | ||
} | ||
|
||
// Save the randomly chosen checkout in the checkout session to make sure | ||
// this session always has the same checkout | ||
$this->checkoutSession->setData('active_checkout_namespace', $result); | ||
$this->checkoutSession->getQuote()->setData('active_checkout_namespace', $result)->save(); | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
# magento2-hyva-checkout-ab-test | ||
# elgentos/magento2-hyva-checkout-ab-test | ||
|
||
This extension allows you to set up an A/B test with different available Hyvä and the Luma fallback checkout. | ||
|
||
It will randomly do a 50% split between the configured Hyva Checkout and the Luma fallback checkout. | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require elgentos/magento2-hyva-checkout-ab-test | ||
bin/magento set:up | ||
``` | ||
|
||
## Configuration | ||
|
||
None, as of now. | ||
|
||
## Reports | ||
|
||
You can check the progress of the A/B test by running this query; | ||
|
||
```sql | ||
SET SQL_MODE=''; | ||
SELECT quote.active_checkout_namespace as checkout, COUNT(quote.entity_id) as quotes, COUNT(sales_order.quote_id) as orders, (COUNT(sales_order.quote_id) / COUNT(quote.entity_id)*100) as conversion_percentage | ||
FROM quote | ||
LEFT JOIN sales_order ON quote.entity_id = sales_order.quote_id AND sales_order.state IN ('completed', 'processing') | ||
WHERE quote.active_checkout_namespace IS NOT NULL | ||
GROUP BY quote.active_checkout_namespace; | ||
``` | ||
|
||
If you want to see the results in the Magento admin, you can install [degdigital/magento2-customreports](https://github.com/degdigital/magento2-customreports) and add the above query. Be sure to leave out the SQL_MODE part (Magento does this for you) and leave no trailing/leading white lines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "elgentos/magento2-hyva-checkout-ab-test", | ||
"version": "1.0.0", | ||
"description": "Set up an A/B test with different available Hyvä and Luma checkouts", | ||
"type": "magento2-module", | ||
"require": { | ||
"php": "^8.1", | ||
"magento/framework": "*", | ||
"hyva-themes/checkout-core": "*" | ||
}, | ||
"suggest": { | ||
"degdigital/magento2-customreports": "Useful to check A/B test results in the Magento admin" | ||
}, | ||
"license": [ | ||
"MIT" | ||
], | ||
"autoload": { | ||
"files": [ | ||
"registration.php" | ||
], | ||
"psr-4": { | ||
"Elgentos\\HyvaHyvaCheckoutABTest\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" ?> | ||
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd"> | ||
<table name="quote"> | ||
<column name="active_checkout_namespace" nullable="true" xsi:type="varchar" comment="Active Checkout Namespace" length="255"/> | ||
</table> | ||
</schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
|
||
<type name="Hyva\CheckoutCore\Model\Config"> | ||
<plugin name="PickRandomCheckout" | ||
type="Elgentos\HyvaCheckoutABTest\Plugin\PickRandomCheckout"/> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Hyva\CheckoutCore\Plugin\Magento\Checkout\Controller\Index\Index"> | ||
<plugin name="PickRandomCheckout" | ||
type="Elgentos\HyvaCheckoutABTest\Plugin\PickRandomCheckout"/> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Elgentos_HyvaCheckoutABTest"> | ||
<sequence> | ||
<module name="Hyva_CheckoutCore"/> | ||
</sequence> | ||
</module> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
|
||
ComponentRegistrar::register( | ||
ComponentRegistrar::MODULE, | ||
'Elgentos_HyvaCheckoutABTest', | ||
__DIR__ | ||
); |