how to call only blocktopmenu module in prestashop - prestashop

can anyone tell me how to call only blocktopmenu module in prestashop...if i use displayTop hook it calls various other modules along with it..but i only want to call blocktopmenu..is it possible to create an object of Blocktopmenu class and access the hookDisplayTop() of that class..so that i can avoid other modules...i tried but its not working
when i try to implement this
Call Module in tpl file in prestashop
it shows "This module cannot be transplanted to this hook."

When you call Hook::exec() you can specify a module ID in the 3rd parameter.
It would be something like that:
Hook::exec('displayTop', null, Module::getModuleIdByName('blocktopmenu'));
Regards,

Never touch the FrontController.
You have to create a new hook, then attach your module to this hook.
After that, you can call Hook::exec('your_hook').

Related

Prestashop 1.7 Context::getContext() not working in AdminController

I have created custom admin controller in my custom module but i am not able to use Context::getContext() in my admin controller.
When i try to use that i am getting below error.
Attempted to call an undefined method named "getContext" of class "PrestaShop\PrestaShop\Adapter\Shop\Context".
Did you mean to call e.g. "getContextListShopID", "getContextListShopIDUsingCustomerSharingSettings", "getContextShopGroup" or "getContextShopID"?
I have already added this line at the top of my file use PrestaShop\PrestaShop\Adapter\Shop\Context;
but still facing same issue.
If anyone have any idea why Context::getContext() doesn't work I would like to hear it.
Thanks

Need help on a minimal module for prestashop 1.7.x

I would like to write a module for prestashop 1.7.x for the first time !
It would be nice if someone could give me a hint how to start up.
I would like to use a php function with smarty call like {$page.page_name|test}
Hi #Hardy Thiergart and welcome to SO!
You can easily write your first PrestaShop module by following the tutorial here:
https://devdocs.prestashop.com/1.7/modules/creation/
Main steps:
Create a folder with your module's name
Create a PHP file with the same name
Make sure your PHP file contains at least the __construct(), install(), uninstall() and getContent() methods (the last one is required only if you allow users to 'Configure' this module)
You can then add additional methods for Hooks, including calls to your template files
Once ready, create a zip file of this folder, with your module's name
I hope this helps.
Here is a link to generate an empty Prestashop module with hooks, etc ... : https://validator.prestashop.com/auth/login
Regards

Create New Hook To Call module blocksearch Inside Another Module

I need to put blocksearch module into a leomegamenu module, my problem is how to do that(that is which files to modify. Can somebody give me pointers to which files to go.
thanks in advance
If you look at blocksearch.php. It is linked to hook hookDisplaySearch.
In your leomegamenu template files you can add this code:
{hook h='displaySearch' mod='blocksearch'}

SilverStripe 3: Can a module extend mysite/code/Page.php?

Good afternoon,
I don't know if what I want to do is possible, so here goes.
I have a module that extends Page_Controller, but I want certain functions to be accessible via the site root.
Eg: getMyDataObjectList();
Currently, they only work if I go through the normal MVC routing structure.
I've found that when I place the function 'getMyDataObjectList' within '/mysite/code/Page.php' it works.The problem is, I don't want to place the code in there. I want it bundled with my Custom Module, but to work the same as though it was in 'mysite/code/Page.php'
[Example Scenario]
site root: http://[somesite].com
By default, the 'Page.ss' template loads.
I would like the theme developer to be able to call my module functions (API) within any template/Layout page, and have the result returned from the site root
Currently, this only works if I move the "API" functions to '/mysite/code/Page.php'
If the code is in my module, then data is only returned when you go to:
http://[somesite].com/[module_controller]
Can this be achieved? If so, how?
Thanks for your assistance.
[Update - Code Solution]
///>MyExtension.php
class MyExtension extends Extension{
public function getMyDataObjectList(){
return 'object list goes here!';
}
}//class
///>[Module] => _config.php
Object::add_extension('Page_Controller', 'MyExtension');
And as always, I do a (/dev/build?flush=1) just in case.
Thanks to: 'simon_w'
Yes, this is relatively straightforward. Simply, create an Extension subclass with your methods in them and then add that to Page_Controller. An Extension subclass is almost exactly the same as a DataExtension, they're just for classes other than DataObjects.

How to get a module instance in PRISM

I have a PRISM desktop app which loads modules from a directory with the help of the DirectoryModuleCatalog.
Everything is fine, except that I cannot find a way to get the instance of a loaded module.
IModuleManager and IModuleCatalog don't have a method like getInstance(ModuleInfo) or similar.
See
moduleManager.LoadModule(moduleInfo.ModuleName);
This line loads the module properly(moduleManager is of type IModuleManager), but what do I have to do next to get the actual instance of this module?
The modules are loaded on demand of the user, so I cannot register all modules at startup within the bootstrapper.
If by Module instance you mean the class that implement IModule, then you must explicitly register the instance into the container to be able to get it.
Although the aforementioned will work, you should not take that approach at all. The idea is that the module classes are specific to a particular module and should only be used for module initialization purposes.
I would place each module's Start method in a separate component (IStartable), register each component in the container with a different Id and resolve/import an IEnumerable to get all instances that have the start method.
Hope this helps