Prestashop template hook call - hook

I want to call a hook from template like this:
{hook h='displayCustom' mod='customcontent'}
I created a new hook and added method to module like this:
$this->registerHook('displayCustom');
public function hookDisplayCustom($params) {
return $this->display(__FILE__, 'customcontent.tpl');
}
I see that module triggered but there is no output. How can i fix it?
Prestashop 1.6, customcontent.tpl contents simple text 'TEST'.

If smbdy will get in trouble with this.
Possible solution is:
There is a trigger in admin panel that turns off all other modules except native.
The path is: Admin panel -> Configuration -> Performance -> Turn off all non-native modules. It has to be off.

Related

Identify Reference to Destroy & Re-Initialize Swiper in Elementor

Elementor Pro (the WordPress page builder) integrates beautifully with Swiper, tying their GUI to the JS parameters and database content.
However, for my project, I need to make some changes to the Swiper "CoverFlow" skin Init parameters (show more slides, change the 3D effect facing direction...).
My hope is to to use the Destroy method of the Swiper API which looks like:
mySwiper.destroy(deleteInstance, cleanStyles);
Then I can initialize the Swiper again, with my own custom parameters. The challenge is that the way Elementor calls Swiper in frontend.js is a complex anonymous function that doesn't really allow me to know what "mySwiper" would be... On line 567:
this.swipers.main = new Swiper(this.elements.$mainSwiper, this.getSwiperOptions());
I would be so grateful if someone could please help me understand what "this.swipers.main" would translate to after Init so that I can destroy the swiper and initialize it again with my own parameters.
Obviously I cannot edit frontend.js itself as it is a plugin file that needs to be updated.
Extra points for whomever teaches me how to fish and what the methodology is to solve these types of puzzles for other similar situations.
You can give an ID to the Elementor widget ex: slider1 and then with JS you can use:
var sliderInstance = document.querySelector('#slider1 .swiper-container').swiper;
After this you can call sliderInstance.destroy() wherever you want.
And if you want to initialize it again you can call:
var sliderInstance = new Swiper('#slider1 .swiper-container', {
//options
});

How to insert module into product page in prestashop

I am creating a new module in Prestashop 1.6 which displays some data on the products page in the info box. I have created a new hook in the install method of the module like this: $this->registerHook('combinationDescription') and created the hookDisplayCombinationDescription function for assigning some smarty variables and displaying them with a tpl file.
After installing my module the hook is registered into the database so its usable.
Manually I can insert code into the product.tpl file just like: {hook h="hookDisplayCombinationDescription"} and I think it's working, but I would like to make this step automatically when the module gets installed. How can I do that?
My guess would be that to edit the product.tpl file from the install method of the module but it's a bit dirty method for me. Is there some other nice way to do that?
If you made a custom hook you need to insert its execution somewhere manually: into .tpl or into overrided ProductController.php (if it is an action hook). Prestashop can't execute it automatically for it doesn't know where do you want to execute it.
But you can use the default Prestashop 1.6 hooks to make your part of the code hooked and ready after the module installation. For the product page are these:
displayLeftColumnProduct
displayRightColumnProduct
displayProductTab
displayProductTabContent
displayFooterProduct
displayProductButtons
displayProductPriceBlock
actionProductOutOfStock
You can use one of these hooks and position your content with css (or javascript - to any part of the page).
If you make any custom hook then you have to make it executable first.Prestashop can't execute custom hooks automatically.But for displaying some data on product page you can use predefined prestashop hooks.Some are following
displayProductButtons
displayProductTab
To use these hooks, first you have to register hooks in install function like
public function install()
{
if (!parent::install() || !$this->registerHook('displayProductButtons')){
}
}
and in the same file you have to make a function like
public function hookDisplayProductButtons($params)
{
}
Now in that function you can assign some smarty variables which you want to access or show in your tpl file like
public function hookDisplayProductButtons($params)
{
$this->smarty->assign(array(
'product_name' => 'abc'
));
}
Now in your tpl file you can access that
If you want to add new custom hook and execute them when your particular module is active or installed.
Please follow the following steps:
Add you new custom hook code any where you want to perform your action.
Then, you can insert entry for that new custom hook into database at the time of installing module.
Now, your hook will execute as per your need.
Delete the same entry of hook from database at the time of uninstalling module so that hook could not be executed after uninstalling module.
I am not sure for, Is any other solution available to fulfill your need in prestashop?

Prestashop | Remove transplant restrictions

So, there's a problem - I need to transplant "Categories Block" module to "displayTopColumn" hook (yep, designer put categories list near (on?) slider). But, by default, there is no possibilities to do this. I don't like that awful Prestashop restrictions, so maybe there is solution for this problem - remove those restrictions?
Thanks.
Removing those restrictions would not resolve anything for a simple reason: if you could hook the module blockcategories to displayTopColumn, this module would not know what to display in this hook because there is no hookDisplayTopColumn() function in it.
However, you can modify the module, and add a function to manage this hook.
To do so, open the file blockcategories.php and add the following:
public function hookDisplayTopColumn($params)
{
// Your code
}
If you want to display here the same content as in the hookLeftColumn hook, you can simply do this:
public function hookDisplayTopColumn($params)
{
return $this->hookLeftColumn($params);
}
You can also create your own function and template by copying, pasting and modifying the code you can find in the function hookLeftColumn() or in the function hookFooter().

Autoloading a class in Symfony 2.1

I'm porting a Symfony 1.2 project to Symfony 2.x. I'm currently running the latest 2.1.0-dev release.
From my old project I have a class called Tools which has some simple functions for things like munging arrays into strings and generating slugs from strings. I'd like to use this class in my new project but I'm unclear how to use this class outside of a bundle.
I've looked at various answers here which recommend changing app/autoload.php but my autoload.php looks different to the ones in the answers, maybe something has changed here between 2.0 and 2.1.
I'd like to keep my class in my src or app directories as they're under source control. My vendors directory isn't as I'm using composer to take care of that.
Any advice would be appreciated here.
Another way is to use the /app/config/autoload.php:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add( 'YOURNAMESPACE', __DIR__.'/../vendor/YOURVENDOR/src' );
// intl
if (!function_exists('intl_get_error_code')) {
require_once _DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
Just replace YOURNAMESPACE and YOURVENDOR with your values. Works quite well for me, so far.
You're correct, I stumbled upon the changes in autoload from 2.0 to 2.1. The above code works fine with the latest version, to which I upgraded my project ;-)
For a simple case like this the quickest solution is creating a folder (for example Common) directly under src and put your class in it.
src
-- Common
-- Tools.php
Tools.php contains your class with proper namespace, for example
<?php
namespace Common;
class Tools
{
public static function slugify($string)
{
// ...
}
}
Before calling your function do not forget the use statement
use Common\Tools;
// ...
Tools::slugify('my test string');
If you put your code under src following the proper folder structure and namespace as above, it will work without touching app/autoload.php.

Declaring function in Blocks in Drupal 6

I am facing an issue in declaring a fucation in block which I have added . I am calling a function by including an file which ia placed in the theme. I have also tried it by placing out of the theme folder. The function is alredy being user in front page. But when I am using the same function in that block. The screen gets blank and nothing displays. some part of my block coding is written below. Please help me.
<?php
global $base_url;
include($_SERVER['DOCUMENT_ROOT']."/travellar/geoiploc.php"); // indluded file
$ip = "203.189.25.0"; // Australia IP test
$country_code = getCountryFromIP($ip, "code");
I've had no problems loading functions from modules into custom blocks, but I've never tried loading one from a theme before. It's not clear to me whether or not theme functions are loaded before the page content is loaded.
You might have to create a custom module or include file to hold the function. Check out the module_load_include() function for how to load a specific include file.
A custom module would be a good approach as it is loaded before the theme layer and can be accessed from almost anywhere in Drupal except other modules with a lower weight than the custom module. It is also likely to come in handy for hooks and other overrides.
However, if you must have it in the theme layer, another option is adding it to template.php of your theme which should make it available within page.tpl.php and such, but not blocks I don't believe.
/sites/all/modules/mymodule/mymodule.info
name = My Module
package = !
description = It is MY module, not yours!
core = 6.x
The package "!" will make this module appear at the top of the modules page
/sites/all/modules/mymodule/mymodule.module
<?php
// Load mymodule.morePHP.inc
module_load_include('inc', 'mymodule', 'mymodule.morePHP');
// A custom function
function mymodule_my_custom_function($args) {
/* do custom stuff here */
return 'output';
}
/sites/all/modules/mymodule/mymodule.morePHP.inc
<?php
// An included custom function
function mymodule_other_custom_stuff() {
}

Resources