Skip to content

Commit

Permalink
Merge pull request #546 from FatchipRobert/MAG2-315-Bugfixes
Browse files Browse the repository at this point in the history
MAG2-315 - FIxed javascript problems
  • Loading branch information
janteuber authored Jul 15, 2024
2 parents 29bd580 + a8f07c5 commit ad16717
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 5 deletions.
89 changes: 89 additions & 0 deletions Helper/Script.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

/**
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
*
* PHP version 5
*
* @category Payone
* @package Payone_Magento2_Plugin
* @author FATCHIP GmbH <[email protected]>
* @copyright 2003 - 2024 Payone GmbH
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
* @link http://www.payone.de
*/

namespace Payone\Core\Helper;

use Magento\Framework\App\ObjectManager;

class Script extends \Payone\Core\Helper\Base
{
/**
* @var \Magento\Framework\App\ProductMetadata
*/
protected $productMetadata;

/**
* Constructor
*
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Payone\Core\Helper\Shop $shopHelper
* @param \Magento\Framework\App\State $state
* @param \Magento\Framework\App\ProductMetadata $productMetadata
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Payone\Core\Helper\Shop $shopHelper,
\Magento\Framework\App\State $state,
\Magento\Framework\App\ProductMetadata $productMetadata
) {
parent::__construct($context, $storeManager, $shopHelper, $state);
$this->productMetadata = $productMetadata;
}

/**
* Magento 2.4.7 doesnt allow inline javascript - this method is used to handle this
*
* @param string $script
* @return string
*/
public function insertScript($script)
{
$sReturn = "<script>".$script."</script>";
if (version_compare($this->productMetadata->getVersion(), '2.4.7', '>=')) {
$secureRenderer = ObjectManager::getInstance()->create(\Magento\Framework\View\Helper\SecureHtmlRenderer::class);
$sReturn = $secureRenderer->renderTag('script', [], $script, false);
}
return $sReturn;
}

/**
* Magento 2.4.7 doesnt allow inline javascript - this method is used to handle this
*
* @return string
*/
public function insertEvent($sEventName, $sScript)
{
$sReturn = $sEventName."='".$sScript."'";
if (false && version_compare($this->productMetadata->getVersion(), '2.4.7', '>=')) {
$secureRenderer = ObjectManager::getInstance()->create(\Magento\Framework\View\Helper\SecureHtmlRenderer::class);
$sReturn = $secureRenderer->renderEventListener($sEventName, $sScript);
}
return $sReturn;

}
}
1 change: 1 addition & 0 deletions view/frontend/web/js/action/installmentplan.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ define([
function (response) {
if (response.success == true) {
$('#' + baseView.getCode() + '_installmentplan').html(response.installment_plan_html);
baseView.addEvents("hiddenSwitchInstallmentPlan", "|||", 3);
$('#' + baseView.getCode() + '_installmentplan').show();
$('#' + baseView.getCode() + '_check').hide();
$('#' + baseView.getCode() + '_submit').show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,23 @@ define(
}
return parentReturn;
},
displayInstallmentInfo(installmentplan) {
addEvents: function (selectorClass, delimiter, valueCount) {
var elementsColl = document.getElementsByClassName(selectorClass);
for (var iVar = 0; iVar < elementsColl.length; iVar++) {
console.log(elementsColl[iVar].previousElementSibling);
elementsColl[iVar].previousElementSibling.addEventListener("click", function (e) {
console.log(this.nextElementSibling);
let splitVar = this.nextElementSibling.value.split(delimiter);
if (splitVar.length === valueCount) {
switchBNPLInstallmentPlan(splitVar[0], splitVar[1], splitVar[2], this);
}
e.preventDefault();
});
}
},
displayInstallmentInfo: function (installmentplan) {
$('#' + this.getCode() + '_installmentplan').html(installmentplan.installment_plan_html);
this.addEvents("hiddenSwitchInstallmentPlanBnpl", "|||", 3);
$('#' + this.getCode() + '_installmentplan').show();
$('#' + this.getCode() + '_check').hide();
$('#' + this.getCode() + '_submit').show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ define(
}
}
},
addEvents: function (selectorClass, delimiter, valueCount) {
var elementsColl = document.getElementsByClassName(selectorClass);
for (var iVar = 0; iVar < elementsColl.length; iVar++) {
elementsColl[iVar].previousElementSibling.addEventListener("click", function (e) {
let splitVar = this.nextElementSibling.value.split(delimiter);
if (splitVar.length === valueCount) {
switchInstallmentPlan(splitVar[0], splitVar[1], splitVar[2]);
}
e.preventDefault();
});
}
},
switchInstallmentPlan: function (sKey, sCode, iInstallments) {
$('.payolution_installmentplans').hide();
$('.payolution_installment_overview').hide();
Expand Down
4 changes: 2 additions & 2 deletions view/webapi_rest/templates/bnpl/installment_plan.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ $aInstallmentData = $aInstallmentResponse['runtimes'];
</label><br>
<div>
<?php foreach ($aInstallmentData as $sKey => $aInstallment): ?>
<div class="payoneBNPLselector" onclick="switchBNPLInstallmentPlan('<?php echo $sKey; ?>', '<?php echo $this->getCode(); ?>', '<?php echo $aInstallment['installment_option_id']; ?>', this);">
<div class="payoneBNPLselector">
<input type="radio" name="bnplCondition" id="bnplCondition_<?php echo $sKey; ?>">
<a href="#" class="bnplCondition" onclick="return false;">
<?php echo $this->getSelectLinkText($aInstallment) ?>
</a>
</div>
</div><input class="hiddenSwitchInstallmentPlanBnpl" type="hidden" value="<?php echo $sKey; ?>|||<?php echo $this->getCode(); ?>|||<?php echo $aInstallment['installment_option_id']; ?>">
<?php endforeach; ?>

<?php foreach ($aInstallmentData as $sKey => $aInstallment): ?>
Expand Down
4 changes: 2 additions & 2 deletions view/webapi_rest/templates/payolution/installment_plan.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ $aInstallmentData = array_reverse($this->getInstallmentData());
</label><br>
<div style="float:left;">
<?php foreach ($aInstallmentData as $sKey => $aInstallment): ?>
<a href="#" onclick="switchInstallmentPlan('<?php echo $sKey; ?>', '<?php echo $this->getCode(); ?>', '<?php echo $aInstallment['duration']; ?>');return false;">
<a href="#">
<?php echo $this->getSelectLinkText($aInstallment) ?>
</a><br>
</a><input class="hiddenSwitchInstallmentPlan" type="hidden" value="<?php echo $sKey; ?>|||<?php echo $this->getCode(); ?>|||<?php echo $aInstallment['duration']; ?>"><br>
<?php endforeach; ?>

<?php foreach ($aInstallmentData as $sKey => $aInstallment): ?>
Expand Down

0 comments on commit ad16717

Please sign in to comment.