Skip to content

Commit

Permalink
added secure rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan Berezhniy committed Jul 17, 2024
1 parent 810eb8f commit 6cedd9f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Block/Adminhtml/Rule/DuplicateButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getButtonData()
$data = [
'label' => __('Duplicate (Plus)'),
'class' => 'duplicate',
'on_click' => 'versionsManager._currentPlan == "Basic" ? versionsManager.showAlert("Plus or Extra") : window.location=\'' . $this->getDuplicateUrl() . '\'',
'on_click' => '(typeof versionsManager !== "undefined" && versionsManager._currentPlan == "Basic") ? versionsManager.showAlert("Plus or Extra") : window.location=\'' . $this->getDuplicateUrl() . '\'',
'sort_order' => 40,
];
}
Expand Down
83 changes: 47 additions & 36 deletions view/adminhtml/templates/form/versionsManager.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/

/** @var \Magento\Framework\Escaper $escaper */
/** @var \Magento\Framework\Escaper $escaper
* $mfSecureRenderer \Magefan\Community\Api\SecureHtmlRendererInterface
*/
?>
<?php $script = ''; ?>

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
Expand All @@ -20,34 +23,39 @@ if ($getModuleVersion->execute('Magefan_AutoRelatedProductExtra')) {
}
?>

<script type="text/javascript">
<?php
$script .= "
var versionsManager = {
_currentPlan: '<?= /*@noEscape*/ $currentPlan ?>',
_currentPlan: '" . $currentPlan . "',
_selector: {
'Extra': [
'[name="template"]',
],
<?php if ($currentPlan != 'Plus') { ?>
'[name=\"template\"]',
],";

if ($currentPlan != 'Plus') {
$script .= "
'Plus': [
'[data-index="same_as_conditions_apply_to"]',
'[name="from_one_category_only"]',
'[name="only_with_lower_price"]',
'[name="only_with_higher_price"]',
'[name="who_bought_this_also_bought"]',
'[name="who_viewed_this_also_viewed"]',
'[name="customer_group_ids"]',
'[name="start_date"]',
'[name="finish_date"]',
'[data-index="preview_button"]',
'[data-index="hide_preview_button"]',
'[name="block_position"]',
'[name="sort_by"]',
'[name="apply_same_as_condition"]',
'[name="autorp_rule_formrule_same_as_conditions_fieldset_"]',
'[data-index="add_product_to"]',
'[name="template"]'
]
<?php } ?>
'[data-index=\"same_as_conditions_apply_to\"]',
'[name=\"from_one_category_only\"]',
'[name=\"only_with_lower_price\"]',
'[name=\"only_with_higher_price\"]',
'[name=\"who_bought_this_also_bought\"]',
'[name=\"who_viewed_this_also_viewed\"]',
'[name=\"customer_group_ids\"]',
'[name=\"start_date\"]',
'[name=\"finish_date\"]',
'[data-index=\"preview_button\"]',
'[data-index=\"hide_preview_button\"]',
'[name=\"block_position\"]',
'[name=\"sort_by\"]',
'[name=\"apply_same_as_condition\"]',
'[name=\"autorp_rule_formrule_same_as_conditions_fieldset_\"]',
'[data-index=\"add_product_to\"]',
'[name=\"template\"]'
]";
}

$script .= "
},
initListener: function () {
Expand All @@ -62,11 +70,11 @@ if ($getModuleVersion->execute('Magefan_AutoRelatedProductExtra')) {
if (
element.tagName == 'SELECT'
&& Array.from(element.options).some(option => option.text.includes("Plus") || option.text.includes("Extra"))
&& Array.from(element.options).some(option => option.text.includes('Plus') || option.text.includes('Extra'))
) {
element.addEventListener('change', function() {
var selectedOptionText = this.options[this.selectedIndex].text;
if (selectedOptionText.includes("("+ plan +")")) {
if (selectedOptionText.includes('('+ plan +')')) {
versionsManager.showAlert(plan);
this.selectedIndex = 0;
this.dispatchEvent(new Event('change', { bubbles: true }));
Expand Down Expand Up @@ -102,18 +110,18 @@ if ($getModuleVersion->execute('Magefan_AutoRelatedProductExtra')) {
},
showAlert: function (extensionPlan) {
require(["jquery", "Magento_Ui/js/modal/alert"], function($, alert) {
if (extensionPlan === "Plus") {
extensionPlan = "Plus or Extra";
require(['jquery', 'Magento_Ui/js/modal/alert'], function($, alert) {
if (extensionPlan === 'Plus') {
extensionPlan = 'Plus or Extra';
}
alert({
title: "<?= $escaper->escapeHtml(__('You cannot use this option.')) ?>",
content: "<?= $escaper->escapeHtml(__('This feature is available in')) ?>" + " <strong>" + extensionPlan + "</strong> <?= __('plan only.') ?>",
title: '" . $escaper->escapeHtml(__('You cannot use this option.')) . "',
content: '" . $escaper->escapeHtml(__('This feature is available in')) . "' + ' <strong>' + extensionPlan + '</strong> " . __('plan only.') . "',
buttons: [{
text: "<?= $escaper->escapeHtml(__('Upgrade Plan Now')) ?>",
class: "action primary accept",
text: '" . $escaper->escapeHtml(__('Upgrade Plan Now')) . "',
class: 'action primary accept',
click: function () {
window.open("https://magefan.com");
window.open('https://magefan.com');
}
}]
});
Expand All @@ -123,4 +131,7 @@ if ($getModuleVersion->execute('Magefan_AutoRelatedProductExtra')) {
versionsManager.initListener();
</script>
";
?>

<?= /* @noEscape */ $mfSecureRenderer->renderTag('script', [], $script, false) ?>

0 comments on commit 6cedd9f

Please sign in to comment.