@DrByte
Thanks for the Oserver code! I was able to properly load my 2 js scripts globaly from plugin template directory. Other methods won't work. Actually I was not able to load anything from template's css or jscript folders without it. It is like no autoloading works there.
From modules/pages script seems to be found but it is like ZC looks for files in main catalog, not plugin's one.
Here is the code I have now for the observer class.post_auto.php:
PHP Code:
<?php
/**
* Designed for v2.1.0+ (depends on InteractsWithPlugins trait and NOTIFY_HTML_HEAD_END notifier added in v2.1.0 )
*/
use Zencart\PageLoader\PageLoader;
use Zencart\Traits\InteractsWithPlugins;
use Zencart\Traits\NotifierManager;
use Zencart\Traits\ObserverManager;
class zcObserverPostAuto
{
use InteractsWithPlugins;
use NotifierManager;
use ObserverManager;
public function __construct()
{
$this->attach($this, ['NOTIFY_HTML_HEAD_END']);
/**
* Determine this zc_plugin's paths: $this->zcPluginCatalogPath is used to load more template assets
*/
$this->detectZcPluginDetails(__DIR__);
}
/**
* Catalog: Runs at the end of the active template's html_header.php (just before the </head> tag)
* We can load additional plugin assets here.
*/
public function notify_html_head_end(&$class, $eventID, string $current_page_base): void
{
// load a plugin-specific stylesheet, first from plugin dir, then from store's template:
//$this->linkCatalogStylesheet('my_plugin_stylesheet.css', $current_page_base);
$this->linkCatalogStylesheet('stylesheet_jquery.powertip.min.css', $current_page_base);
// load a JS file from the plugin's jscript directory:
$pageLoader = PageLoader::getInstance();
/* $filename = 'jscript_postcode.js';
if (file_exists($file = $pageLoader->getTemplatePluginDir($filename, 'jscript', $this->zcPluginDirName) . $filename)) {
echo '<script src="' . $file . '"></script>' . "\n";
}
*/ $filename = 'jscript_postcode.php';
if (file_exists($file = $pageLoader->getTemplatePluginDir($filename, 'jscript', $this->zcPluginDirName) . $filename)) {
//echo '<script src="' . $file . '"></script>' . "\n";
include($file);
}
}
}
I made its config.post_auto.php to load it automatically, but I am not sure at which point it should be loaded.
PHP Code:
<?php
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
$autoLoadConfig[139][] = [
'autoType'=>'class',
// the filename, relative to the `classes` folder:
'loadFile'=>'observers/class.post_auto.php',
'classPath'=>DIR_WS_CLASSES
];
$autoLoadConfig[139][] = [
'autoType'=>'classInstantiate',
// the name of the class as declared inside the observer class file
'className'=>'zcObserverPostAuto',
// the name of the global object into which the class is instantiated
'objectName'=>'zcObserverPostAuto'
];
With this observer I can load style sheet and script whatever in a js file or php file. The script I load then load its require second script and wait it is loaded to run. Now Javascript works fine and when filling a form the AJAX call is triggered. Unfortunately the AJA call is FAILLING! I got a HTTP 400 error and a log file with this in it:
Code:
Uncaught Error: Class "Zencart\Plugins\Catalog\PostAuto\base" not found
The line referred to in php file doing the call is the class declaration:
Code:
class zcAjaxPostcodeQuery extends base
Something that is necessary is not accessible from the plugin, and for now I have no clue how to fix that.
Bookmarks