Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions Block/Adminhtml/System/Config/Form/InfoPlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/

declare(strict_types=1);

namespace Magefan\Translation\Block\Adminhtml\System\Config\Form;

use Magefan\Community\Api\SecureHtmlRendererInterface;

abstract class InfoPlan extends \Magefan\Community\Block\Adminhtml\System\Config\Form\Info
{
/**
* @return string
*/
abstract protected function getMinPlan(): string;

/**
* @return string
*/
abstract protected function getSectionsJson(): string;

/**
* @return string
*/
abstract protected function getText(): string;


/**
* Return info block html
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
if ($this->getModuleVersion->execute($this->getModuleName() . $this->getMinPlan())) {
return '';
}

$html = '';

if ($text = $this->getText()) {
$textHtml = '<div style="padding:10px;background-color:#f8f8f8;border:1px solid #ddd;margin-bottom:7px;">';
$textHtml .= $text . ' <a style="color: #ef672f; text-decoration: underline;" href="https://magefan.com/magento-2-translation-extension/pricing?utm_source=translation_config&utm_medium=link&utm_campaign=regular" target="_blank">Read more</a>.';
$textHtml .= '</div>';
}

$optionAvailableInText = ($this->getMinPlan() == 'Extra')
? 'This option is available in <strong>Extra</strong> plan only.'
: 'This option is available in <strong>Plus or Extra</strong> plans only.';

$script = '
require(["jquery", "Magento_Ui/js/modal/alert", "domReady!"], function($, alert){
setInterval(function(){
var sections = ' . $this->getSectionsJson() . ';

sections.forEach(function(sectionId) {
var $section = $("#" + sectionId + "-state").parent(".section-config");
if (!$section.length) {
$section = $("#" + sectionId).parents("tr:first");
} else {
var $fieldset = $section.find("fieldset:first");
if (!$fieldset.data("mfftext")) {
$fieldset.data("mfftext", 1);
$fieldset.prepend(\'' . $textHtml . '\');
}
}

$section.find(".use-default").css("visibility", "hidden");
$section.find("input,select").each(function(){
$(this).attr("readonly", "readonly");
$(this).removeAttr("disabled");
if ($(this).data("mffdisabled")) return;
$(this).data("mffdisabled", 1);
$(this).click(function(){
$(this).val($(this).data("mfOldValue")).trigger("change");
alert({
title: "You cannot use this option.",
content: "' . $optionAvailableInText . '",
buttons: [{
text: "Upgrade Plan Now",
class: "action primary accept",
click: function () {
window.open("https://magefan.com/magento-2-translation-extension/pricing?utm_source=translation_config&utm_medium=link&utm_campaign=regular");
}
}]
});
}).on("focus", function() {
$(this).data("mfOldValue", $(this).val());
});
});
});
}, 1000);
});
';

$html .= $this->mfSecureRenderer->renderTag('script', [], $script, false);

return $html;
}
}
29 changes: 29 additions & 0 deletions Block/Adminhtml/System/Config/Form/InfoTranslationExtra.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php


namespace Magefan\Translation\Block\Adminhtml\System\Config\Form;

class InfoTranslationExtra extends InfoPlan
{

protected function getMinPlan(): string
{
return 'Extra';
}

protected function getSectionsJson(): string
{
$sections = json_encode([
'mftranslation_mftranslationapis_locale_source',
'mftranslation_mftranslationapis_mfgoogleapi',
'mftranslation_mftranslationapis_mfchatgptapi',
'mftranslation_mftranslationapis_mfdeeplapi',
]);
return $sections;
}

protected function getText(): string
{
return (string)__("This option is available in <strong>%1</strong> plan only.", $this->getMinPlan());
}
}
27 changes: 27 additions & 0 deletions Block/Adminhtml/System/Config/Form/InfoTranslationPlus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php


namespace Magefan\Translation\Block\Adminhtml\System\Config\Form;

class InfoTranslationPlus extends InfoPlan
{

protected function getMinPlan(): string
{
return 'Plus';
}

protected function getSectionsJson(): string
{
$sections = json_encode([
'mftranslation_general_flush_cache_on_translation',
'mftranslation_general_ignore_gws_permissions'
]);
return $sections;
}

protected function getText(): string
{
return (string)__("This option is available in <strong>%1</strong> plan only.", $this->getMinPlan());
}
}
86 changes: 86 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<field id="version" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Magefan\Translation\Block\Adminhtml\System\Config\Form\Info</frontend_model>
</field>
<field id="infoPlus" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Magefan\Translation\Block\Adminhtml\System\Config\Form\InfoTranslationPlus</frontend_model>
</field>
<field id="infoExtra" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Magefan\Translation\Block\Adminhtml\System\Config\Form\InfoTranslationExtra</frontend_model>
</field>
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Extension Enable</label>
Expand All @@ -30,6 +36,86 @@
<label>Product Key</label>
<frontend_model>Magefan\Community\Block\Adminhtml\System\Config\Form\ProductKeyField</frontend_model>
</field>
<field id="flush_cache_on_translation" translate="label comment" type="select" sortOrder="21" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Flush Cache On Translation Change</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="ignore_gws_permissions" translate="label comment" type="select" sortOrder="22" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Ignore GWS Permissions On Translation Grid</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="mftranslationapis" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Translation APIs (Extra)</label>
<field id="locale_source" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<depends>
<field id="enabled">1</field>
</depends>
<label>Default Locale (Translate From)</label>
<source_model>Magefan\TranslationExtra\Model\Config\Source\LocaleSource</source_model>
</field>
<group id="mfgoogleapi" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Google Translation API</label>
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="google_api_key" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<depends>
<field id="enabled">1</field>
</depends>
<label>API Key</label>
</field>
<field id="google_priority" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Priority</label>
<comment>Enter a whole number. A higher value means a higher priority. This field can be left empty.</comment>
<depends>
<field id="enabled">1</field>
</depends>
</field>
</group>
<group id="mfchatgptapi" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>ChatGPT Translation API</label>
<field id="enabled" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="chatgpt_api_key" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<depends>
<field id="enabled">1</field>
</depends>
<label>Chat-GPT API Key</label>
</field>
<field id="chat_gpt_priority" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Priority</label>
<comment>Enter a whole number. A higher value means a higher priority. This field can be left empty.</comment>
<depends>
<field id="enabled">1</field>
</depends>
</field>
</group>
<group id="mfdeeplapi" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>DeepL Translation API</label>
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="deepl_api_key" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<depends>
<field id="enabled">1</field>
</depends>
<label>API Key</label>
</field>
<field id="deepl_priority" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Priority</label>
<comment>Enter a whole number. A higher value means a higher priority. This field can be left empty.</comment>
<depends>
<field id="enabled">1</field>
</depends>
</field>
</group>
</group>
</section>
</system>
Expand Down
19 changes: 19 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@
<enabled>0</enabled>
<mfmodule>Translation</mfmodule>
</general>
<mftranslationapis>
<locale_source/>
<mfgoogleapi>
<enabled/>
<google_api_key></google_api_key>
<google_priority></google_priority>
</mfgoogleapi>
<mfchatgptapi>
<enabled/>
<chatgpt_api_key></chatgpt_api_key>
<chat_gpt_priority></chat_gpt_priority>
</mfchatgptapi>
<mfdeeplapi>
<enabled/>
<deepl_api_key></deepl_api_key>
<deepl_priority></deepl_priority>
</mfdeeplapi>
</mftranslationapis>
</mftranslation>
</default>
</config>