Skip to content

Commit

Permalink
Merge pull request #4928 from magento-engcom/2.3-develop-prs
Browse files Browse the repository at this point in the history
[Magento Community Engineering] Community Contributions - 2.3-develop
  • Loading branch information
VladimirZaets authored Oct 26, 2019
2 parents 5e07374 + 37b2ab5 commit 68d2137
Show file tree
Hide file tree
Showing 30 changed files with 748 additions and 161 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Store/Switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ public function getHintHtml()
'What is this?'
) . '"' . ' class="admin__field-tooltip-action action-help"><span>' . __(
'What is this?'
) . '</span></a></span>' . ' </div>';
) . '</span></a>' . ' </div>';
}
return $html;
}
Expand Down
15 changes: 15 additions & 0 deletions app/code/Magento/CardinalCommerce/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,41 @@
<label>Environment</label>
<source_model>Magento\CardinalCommerce\Model\Adminhtml\Source\Environment</source_model>
<config_path>three_d_secure/cardinal/environment</config_path>
<depends>
<field id="enabled_authorize">1</field>
</depends>
</field>
<field id="org_unit_id" translate="label" type="obscure" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Org Unit Id</label>
<config_path>three_d_secure/cardinal/org_unit_id</config_path>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<depends>
<field id="enabled_authorize">1</field>
</depends>
</field>
<field id="api_key" translate="label" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
<label>API Key</label>
<config_path>three_d_secure/cardinal/api_key</config_path>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<depends>
<field id="enabled_authorize">1</field>
</depends>
</field>
<field id="api_identifier" translate="label" type="obscure" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>API Identifier</label>
<config_path>three_d_secure/cardinal/api_identifier</config_path>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<depends>
<field id="enabled_authorize">1</field>
</depends>
</field>
<field id="debug" translate="label" type="select" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Debug</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>three_d_secure/cardinal/debug</config_path>
<depends>
<field id="enabled_authorize">1</field>
</depends>
</field>
</group>
</group>
Expand Down
63 changes: 43 additions & 20 deletions app/code/Magento/Catalog/Model/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
use Magento\Catalog\Api\Data\ProductCustomOptionValuesInterfaceFactory;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Option\Type\Date;
use Magento\Catalog\Model\Product\Option\Type\DefaultType;
use Magento\Catalog\Model\Product\Option\Type\File;
use Magento\Catalog\Model\Product\Option\Type\Select;
use Magento\Catalog\Model\Product\Option\Type\Text;
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection;
use Magento\Catalog\Pricing\Price\BasePrice;
use Magento\Framework\EntityManager\MetadataPool;
Expand Down Expand Up @@ -98,6 +103,16 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
*/
protected $validatorPool;

/**
* @var string[]
*/
private $optionGroups;

/**
* @var string[]
*/
private $optionTypesToGroups;

/**
* @var MetadataPool
*/
Expand All @@ -121,6 +136,8 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param ProductCustomOptionValuesInterfaceFactory|null $customOptionValuesFactory
* @param array $optionGroups
* @param array $optionTypesToGroups
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -135,14 +152,34 @@ public function __construct(
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = [],
ProductCustomOptionValuesInterfaceFactory $customOptionValuesFactory = null
ProductCustomOptionValuesInterfaceFactory $customOptionValuesFactory = null,
array $optionGroups = [],
array $optionTypesToGroups = []
) {
$this->productOptionValue = $productOptionValue;
$this->optionTypeFactory = $optionFactory;
$this->validatorPool = $validatorPool;
$this->string = $string;
$this->validatorPool = $validatorPool;
$this->customOptionValuesFactory = $customOptionValuesFactory ?:
\Magento\Framework\App\ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
$this->optionGroups = $optionGroups ?: [
self::OPTION_GROUP_DATE => Date::class,
self::OPTION_GROUP_FILE => File::class,
self::OPTION_GROUP_SELECT => Select::class,
self::OPTION_GROUP_TEXT => Text::class,
];
$this->optionTypesToGroups = $optionTypesToGroups ?: [
self::OPTION_TYPE_FIELD => self::OPTION_GROUP_TEXT,
self::OPTION_TYPE_AREA => self::OPTION_GROUP_TEXT,
self::OPTION_TYPE_FILE => self::OPTION_GROUP_FILE,
self::OPTION_TYPE_DROP_DOWN => self::OPTION_GROUP_SELECT,
self::OPTION_TYPE_RADIO => self::OPTION_GROUP_SELECT,
self::OPTION_TYPE_CHECKBOX => self::OPTION_GROUP_SELECT,
self::OPTION_TYPE_MULTIPLE => self::OPTION_GROUP_SELECT,
self::OPTION_TYPE_DATE => self::OPTION_GROUP_DATE,
self::OPTION_TYPE_DATE_TIME => self::OPTION_GROUP_DATE,
self::OPTION_TYPE_TIME => self::OPTION_GROUP_DATE,
];

parent::__construct(
$context,
Expand Down Expand Up @@ -314,36 +351,22 @@ public function getGroupByType($type = null)
if ($type === null) {
$type = $this->getType();
}
$optionGroupsToTypes = [
self::OPTION_TYPE_FIELD => self::OPTION_GROUP_TEXT,
self::OPTION_TYPE_AREA => self::OPTION_GROUP_TEXT,
self::OPTION_TYPE_FILE => self::OPTION_GROUP_FILE,
self::OPTION_TYPE_DROP_DOWN => self::OPTION_GROUP_SELECT,
self::OPTION_TYPE_RADIO => self::OPTION_GROUP_SELECT,
self::OPTION_TYPE_CHECKBOX => self::OPTION_GROUP_SELECT,
self::OPTION_TYPE_MULTIPLE => self::OPTION_GROUP_SELECT,
self::OPTION_TYPE_DATE => self::OPTION_GROUP_DATE,
self::OPTION_TYPE_DATE_TIME => self::OPTION_GROUP_DATE,
self::OPTION_TYPE_TIME => self::OPTION_GROUP_DATE,
];

return $optionGroupsToTypes[$type] ?? '';
return $this->optionTypesToGroups[$type] ?? '';
}

/**
* Group model factory
*
* @param string $type Option type
* @return \Magento\Catalog\Model\Product\Option\Type\DefaultType
* @return DefaultType
* @throws LocalizedException
*/
public function groupFactory($type)
{
$group = $this->getGroupByType($type);
if (!empty($group)) {
return $this->optionTypeFactory->create(
'Magento\Catalog\Model\Product\Option\Type\\' . $this->string->upperCaseWords($group)
);
if (!empty($group) && isset($this->optionGroups[$group])) {
return $this->optionTypeFactory->create($this->optionGroups[$group]);
}
throw new LocalizedException(__('The option type to get group instance is incorrect.'));
}
Expand Down
22 changes: 22 additions & 0 deletions app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,28 @@
</argument>
</arguments>
</type>
<type name="Magento\Catalog\Model\Product\Option">
<arguments>
<argument name="optionGroups" xsi:type="array">
<item name="date" xsi:type="string">Magento\Catalog\Model\Product\Option\Type\Date</item>
<item name="file" xsi:type="string">Magento\Catalog\Model\Product\Option\Type\File</item>
<item name="select" xsi:type="string">Magento\Catalog\Model\Product\Option\Type\Select</item>
<item name="text" xsi:type="string">Magento\Catalog\Model\Product\Option\Type\Text</item>
</argument>
<argument name="optionTypesToGroups" xsi:type="array">
<item name="field" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_TEXT</item>
<item name="area" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_TEXT</item>
<item name="file" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_FILE</item>
<item name="drop_down" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT</item>
<item name="radio" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT</item>
<item name="checkbox" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT</item>
<item name="multiple" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT</item>
<item name="date" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE</item>
<item name="date_time" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE</item>
<item name="time" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE</item>
</argument>
</arguments>
</type>
<type name="Magento\Catalog\Model\Product\Option\Validator\Pool">
<arguments>
<argument name="validators" xsi:type="array">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ protected function getAgreementsConfig()
: nl2br($this->escaper->escapeHtml($agreement->getContent())),
'checkboxText' => $this->escaper->escapeHtml($agreement->getCheckboxText()),
'mode' => $agreement->getMode(),
'agreementId' => $agreement->getAgreementId()
'agreementId' => $agreement->getAgreementId(),
'contentHeight' => $agreement->getContentHeight()
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function testGetConfigIfContentIsHtml()
$escapedCheckboxText = 'escaped_checkbox_text';
$mode = \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_AUTO;
$agreementId = 100;
$contentHeight = '100px';
$expectedResult = [
'checkoutAgreements' => [
'isEnabled' => 1,
Expand All @@ -86,6 +87,7 @@ public function testGetConfigIfContentIsHtml()
'checkboxText' => $escapedCheckboxText,
'mode' => $mode,
'agreementId' => $agreementId,
'contentHeight' => $contentHeight
],
],
],
Expand Down Expand Up @@ -116,6 +118,7 @@ public function testGetConfigIfContentIsHtml()
$agreement->expects($this->once())->method('getCheckboxText')->willReturn($checkboxText);
$agreement->expects($this->once())->method('getMode')->willReturn($mode);
$agreement->expects($this->once())->method('getAgreementId')->willReturn($agreementId);
$agreement->expects($this->once())->method('getContentHeight')->willReturn($contentHeight);

$this->assertEquals($expectedResult, $this->model->getConfig());
}
Expand All @@ -133,6 +136,7 @@ public function testGetConfigIfContentIsNotHtml()
$escapedCheckboxText = 'escaped_checkbox_text';
$mode = \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_AUTO;
$agreementId = 100;
$contentHeight = '100px';
$expectedResult = [
'checkoutAgreements' => [
'isEnabled' => 1,
Expand All @@ -142,6 +146,7 @@ public function testGetConfigIfContentIsNotHtml()
'checkboxText' => $escapedCheckboxText,
'mode' => $mode,
'agreementId' => $agreementId,
'contentHeight' => $contentHeight
],
],
],
Expand Down Expand Up @@ -172,6 +177,7 @@ public function testGetConfigIfContentIsNotHtml()
$agreement->expects($this->once())->method('getCheckboxText')->willReturn($checkboxText);
$agreement->expects($this->once())->method('getMode')->willReturn($mode);
$agreement->expects($this->once())->method('getAgreementId')->willReturn($agreementId);
$agreement->expects($this->once())->method('getContentHeight')->willReturn($contentHeight);

$this->assertEquals($expectedResult, $this->model->getConfig());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ define([
agreements: agreementsConfig.agreements,
modalTitle: ko.observable(null),
modalContent: ko.observable(null),
contentHeight: ko.observable(null),
modalWindow: null,

/**
Expand All @@ -42,6 +43,7 @@ define([
showContent: function (element) {
this.modalTitle(element.checkboxText);
this.modalContent(element.content);
this.contentHeight(element.contentHeight ? element.contentHeight : 'auto');
agreementsModal.showModal();
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<!-- /ko -->
<!-- /ko -->
<div id="checkout-agreements-modal" data-bind="afterRender: initModal" style="display: none">
<div class="checkout-agreements-item-content" data-bind="html: modalContent"></div>
<div class="checkout-agreements-item-content" data-bind="html: modalContent, style: {height: contentHeight, overflow:'auto' }"></div>
</div>
</div>
</div>
Loading

0 comments on commit 68d2137

Please sign in to comment.