|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magefan ([email protected]). All rights reserved. |
| 4 | + * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magefan\GoogleTagManager\Block\Adminhtml\System\Config\Form; |
| 10 | + |
| 11 | +abstract class InfoPlan extends \Magefan\Community\Block\Adminhtml\System\Config\Form\Info |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @return string |
| 15 | + */ |
| 16 | + protected abstract function getMinPlan(): string; |
| 17 | + |
| 18 | + /** |
| 19 | + * @return string |
| 20 | + */ |
| 21 | + protected abstract function getSectionId(): string; |
| 22 | + |
| 23 | + /** |
| 24 | + * @return string |
| 25 | + */ |
| 26 | + protected abstract function getText(): string; |
| 27 | + |
| 28 | + |
| 29 | + /** |
| 30 | + * Return info block html |
| 31 | + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element |
| 32 | + * @return string |
| 33 | + */ |
| 34 | + public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) |
| 35 | + { |
| 36 | + if ($this->getModuleVersion->execute($this->getModuleName() . $this->getMinPlan())) { |
| 37 | + return ''; |
| 38 | + } |
| 39 | + |
| 40 | + $html = ''; |
| 41 | + $html .= '<div style="padding:10px;background-color:#f8f8f8;border:1px solid #ddd;margin-bottom:7px;">'; |
| 42 | + $html .= $this->getText() . ' <a style="color: #ef672f; text-decoration: underline;" href="https://magefan.com/magento-2-google-tag-manager/pricing?utm_source=gtm_config&utm_medium=link&utm_campaign=regular" target="_blank">Read more</a>.'; |
| 43 | + $html .= '</div>'; |
| 44 | + |
| 45 | + $html .= '<script> |
| 46 | + require(["jquery", "Magento_Ui/js/modal/alert", "domReady!"], function($, alert){ |
| 47 | + setInterval(function(){ |
| 48 | + var $plusSection = $("#' . $this->getSectionId() . '-state").parent(".section-config"); |
| 49 | + $plusSection.find(".use-default").css("visibility", "hidden"); |
| 50 | + $plusSection.find("input,select").each(function(){ |
| 51 | + $(this).attr("readonly", "readonly"); |
| 52 | + $(this).removeAttr("disabled"); |
| 53 | + if ($(this).data("gtmdisabled")) return; |
| 54 | + $(this).data("gtmdisabled", 1); |
| 55 | + $(this).click(function(){ |
| 56 | + alert({ |
| 57 | + title: "You cannot change this option.", |
| 58 | + content: "' . |
| 59 | + ( |
| 60 | + ($this->getMinPlan() == 'Extra') |
| 61 | + ? 'This option is available in <strong>Extra</strong> plan only.' |
| 62 | + : 'This option is available in <strong>Plus or Extra</strong> plans only.' |
| 63 | + ) |
| 64 | + . '", |
| 65 | + buttons: [{ |
| 66 | + text: "Upgrade Plan Now", |
| 67 | + class: "action primary accept", |
| 68 | + click: function () { |
| 69 | + window.open("https://magefan.com/magento-2-google-tag-manager/pricing?utm_source=gtm_config&utm_medium=link&utm_campaign=regular"); |
| 70 | + } |
| 71 | + }] |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | + }, 1000); |
| 76 | + }); |
| 77 | + </script>'; |
| 78 | + |
| 79 | + return $html; |
| 80 | + } |
| 81 | + |
| 82 | +} |
0 commit comments