Hello ! I create a plugin for add custom javascript in product page but the javascript code added by Factory::getDocument()->addScriptDeclaration(/*Script set in a field*/); is add ~250 times in same page because the onHikashopBeforeDsiplay view is trigger many times, and i don't know how to solve this problem can u help me pls ?
My php code:
public function onHikashopBeforeDisplayView (&$view)
{
$plugin = JPluginHelper::getPlugin('hikashop', 'CustomJs');
$plg_params = new JRegistry();
$plg_params->loadString($plugin->params);
$user = Factory::getUser();
$dom = Factory::getDocument();
if($view->getName() === 'product' && $view->getLayout() === 'show_quantity')
{
if(intval($plg_params->get('allow')) === 1)
{
$dom->addScriptDeclaration($plg_params->get('javascript'));
}
}
}
In attachment, u can see what i have in the <script> tag inside the <head>