-
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.
Added config fields, added frontend model, not in working state (#1)
Added configuration fields
- Loading branch information
Showing
3 changed files
with
124 additions
and
10 deletions.
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Elgentos\HyvaCheckoutABTest\Block\Adminhtml\Form\Field; | ||
|
||
use Hyva\CheckoutCore\Block\Adminhtml\Element\FieldArray\TypeRenderer; | ||
use Magento\Backend\Block\Template\Context; | ||
use \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray; | ||
use Magento\Framework\View\Helper\SecureHtmlRenderer; | ||
|
||
class Checkouts extends AbstractFieldArray | ||
{ | ||
private \Magento\Framework\View\Element\BlockFactory $blockFactory; | ||
private \Hyva\CheckoutCore\Model\Config\Source\Checkout $checkoutSource; | ||
|
||
public function __construct( | ||
Context $context, | ||
\Magento\Framework\View\Element\BlockFactory $blockFactory, | ||
\Hyva\CheckoutCore\Model\Config\Source\Checkout $checkoutSource, | ||
array $data = [], | ||
?SecureHtmlRenderer $secureRenderer = null | ||
) { | ||
parent::__construct($context, $data, $secureRenderer); | ||
$this->blockFactory = $blockFactory; | ||
$this->checkoutSource = $checkoutSource; | ||
} | ||
|
||
protected function _prepareToRender() | ||
{ | ||
$checkoutOptions = array_combine( | ||
array_column($this->checkoutSource->toOptionArray(), 'value'), | ||
array_column($this->checkoutSource->toOptionArray(), 'label') | ||
); | ||
$this->addColumn('checkout', [ | ||
'label' => __('Checkout'), | ||
'class' => 'required-entry', | ||
'renderer' => $this->blockFactory->createBlock(TypeRenderer::class) | ||
->setElementType('select') | ||
->setElementOptions($checkoutOptions), | ||
'style' => 'width: 150px' | ||
]); | ||
$this->addColumn('percentage', ['label' => __('Percentage Shown During Test'), 'class' => 'required-entry']); | ||
$this->_addAfter = false; | ||
$this->_addButtonLabel = __('Add Checkout'); | ||
} | ||
} |
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
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 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Elgentos B.V.. All rights reserved. | ||
* https://www.elgentos.nl/ | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> | ||
<system> | ||
<section id="hyva_themes_checkout"> | ||
<group id="ab_test" translate="label" type="text" sortOrder="15" showInDefault="1" showInWebsite="0" showInStore="0"> | ||
<label>A/B Test</label> | ||
<field id="enabled" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0"> | ||
<label>Enabled</label> | ||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> | ||
</field> | ||
<field id="checkouts" translate="label" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0"> | ||
<label>Checkouts</label> | ||
<frontend_model>Elgentos\HyvaCheckoutABTest\Block\Adminhtml\Form\Field\Checkouts</frontend_model> | ||
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model> | ||
</field> | ||
</group> | ||
</section> | ||
</system> | ||
</config> |