Can not add data attributes in script tag in PrestaShop 1.6
Asked Answered
S

1

15

I am developing a custom payment module in PrestaShop 1.6. My front controller path is: mymodule/controllers/front/payment.php

payment.php contains:

 $this->context->smarty->assign(array( 
'dataCompleteURL' =>  Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__.'index.php?fc=module&module=mymodule&controller=callback&cart='.$cartID));
$this->setTemplate('payment.tpl');

My template file path is: mymodule/views/templates/front/payment.tpl

payment.tpl contains:

<script src="http://easternbank.test.gateway.com/checkout.js" data-complete="{$dataCompleteURL}" type="text/javascript"> </script>

The problem is that in my localhost it is working fine. I get the data-complete URL in the script tag. But when I install the module in my test server I do not get the data-complete URL.

Any help or suggestion will be appreciated.

Thanks in advance.

UPDATE

I have found that the problem is "https" in the "src" of the script tag. I can not understand why data-complete vanishes if the src URL begins with https. Without https it is okay.

When I view the source in the browser for the following code with https in src, I get:

<script src="http://easternbank.test.gateway.com/checkout.js" data-complete="{$dataCompleteURL}" type="text/javascript"> </script>

The data-complete attribute vanishes. But when I view the source of the script with src without "https" I get the data-complete attribute.

I could not find the reason.

OR I can add javascript in the payment.php controller using :

$this->context->controller->addJS(($this->_path).'js/checkout.js');

But I do not know how to pass data attributes in the addJS function.

Slapdash answered 18/11, 2016 at 10:26 Comment(2)
In payment.tpl put somewhere {$dataCompleteURL|var_dump} and check result.Felic
I am getting the value of $dataCompleteURL. please see the UPDATESlapdash
S
5

Finally I have found the solution. It seems very strange to me. Because I did only the following change in BO in prestashop:

  • go to back office
  • go Advanced Parameters -> Performance
  • go to CCC
  • disable the option: Move JavaScript to the end

That's it. My problem is solved.

BTW, I have learned something from this problem: I should have tried every possible configuration options in prestashop back office.

I didn't think that this option can be responsible for this type of problem. But it is. So trying every possible ways should be the key formula to solve a problem though it seems that this is not related to the concerned problem context.

Slapdash answered 4/1, 2017 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.