Prestashop Back-Office dynamic hooks (events) not working - php

Hi I'm developing a custom module for my company on Prestashop and I need some help. I've recently developed the same plugin on Magento but here I'm having some troubles with events (also called dynamic hooks).
I'm trying to use the dynamic hooks on the backend to manage product stocks. I'm not able to catch prestashop backend events on my module despite I've registered the hooks in my install() method:
function install() {
if (parent::install() == false
|| !$this->registerHook('home')
|| !$this->registerHook('productFooter')
|| !$this->registerHook('orderConfirmation')
|| !$this->registerHook('shoppingCart')
|| !$this->registerHook('actionProductDelete')
|| !$this->registerHook('actionProductUpdate')) {
return false;
}
//default configuration values
...
and placed specific methods for each one.
public function hookActionProductDelete($params) { ... }
I'm logging all the process on both sides. On my module with firePHP and FileLoggerCore and on Prestashop's core classes where events are dispatched with the prestashop's FileLoggerCore.
The events like (actionProductDelete) found on Product class are dispatched but I can not capture them.
Another point that I've noticed is that hook names change between prestashop versions. In this last version 1.5 there are a lot more hooks than in previous ones. It's possible to use same hooks in versions from 1.3 to 1.5?
Sorry for my english and many thanks in advance.

check if your module is hooked in "admin > modules > positions" on actionProductDelete hook
you can use old hook name for PS 1.3-1.5 compatibility, look at ps_hook_alias DB table. For hook that doesn't exist before 1.5, I think you need override for 1.4 & code modifications for 1.3

Related

OpenCart 3 not showing my module

I'm fairly new to OpenCart but I know PHP and MVC platforms. I want to make an importer for OpenCart to import some products from a CSV and the photos for them.
However, I've been struggling for the last 2 hours trying to see my module in the admin. I created an admin/controller/module/custom_importer.php:
<?php
class ControllerModuleCustomImporter extends Controller {
}
and a language file admin/language/en-gb/module/custom_importer.php:
$_['heading_title'] = 'Custom Importer';
However, in my admin I can't seem to find the module at all. It's the simplest, emptiest module. What am I doing wrong?
Opencart: Version 3.0.2.0
The path you are using is wrong. Put your file in admin/controller/extension/module/custom_importer.php. Note the class name changes in a corresponding way.
<?php
class ControllerExtensionModuleCustomImporter extends Controller {
}
The language file goes in admin/language/en-gb/extension/module/custom_importer.php.
<?php
$_['heading_title'] = 'Custom Importer';
Now go to Extensions->Extensions and choose Modules. You will see Custom Importer.

Prestashop : is there any hook to update the shipping price?

PRESTASHOP : I'm working on a prestashoo module and I need to make the shipping list dynamic
Is there any hook to update the shipping price ?
Yes, and the right hook is extraCarrier.
It adds a new carrier to the shop and is fully configurable.
See this link for an example of usage:
https://github.com/uab-balticode/dpd-shipping-module-prestashop-lt/blob/53679ab5935965d95950fb3dc99a18c0c995697d/balticode_dpd_courier/balticode_dpd_courier.php
Or even better you can copy from official carriers modules, like the TNT Express one:
https://github.com/PrestaShop/tntcarrier/blob/675d9e8866f675968cc46eaec73d4202278d90a1/tntcarrier.php
From the source of this modules you must look for $this->registerHook('extraCarrier') in install function to regiser your hook (remember to reinstall your module after the hook insertion in your code)
and for the function definition of public function hookextraCarrier($params) where all the magic happens
Also note how the class of the module must extend CarrierModule:
class TntCarrier extends CarrierModule
You can also read the official prestashop documentation about the argument:
http://doc.prestashop.com/display/PS16/Creating+a+carrier+module

Joomla - any chance to override com_content/models/category.php?

I'm trying to get a template to work with a sorting menu in Joomla 3.
I'm using the category layout and a infinity load script which is working fine.
After that I made a new menu out of the categorie_list module which adds parameters like this (?category=your_category) to the a tag.
Now in order to get this system to work, I need to change the category where the blog view gets its articles from.
I already found the position at
components/com_content/models/category.php
at line 222
function getItems()
{
$limit = $this->getState('list.limit');
if ($this->_articles === null && $category = $this->getCategory())
{
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', '$category->id'); // <- here!!!
$model->setState('filter.published', $this->getState('filter.published'));
$model->setState('filter.access', $this->getState('filter.access'));
$model->setState('filter.language', $this->getState('filter.language'));
$model->setState('list.ordering', $this->_buildContentOrderBy());
$model->setState('list.start', $this->getState('list.start'));
$model->setState('list.limit', $limit);
$model->setState('list.direction', $this->getState('list.direction'));
$model->setState('list.filter', $this->getState('list.filter'));
// filter.subcategories indicates whether to include articles from subcategories in the list or blog
$model->setState('filter.subcategories', $this->getState('filter.subcategories'));
$model->setState('filter.max_category_levels', $this->setState('filter.max_category_levels'));
$model->setState('list.links', $this->getState('list.links'));
if ($limit >= 0)
{
$this->_articles = $model->getItems();
if ($this->_articles === false)
{
$this->setError($model->getError());
}
}
else
{
$this->_articles = array();
}
$this->_pagination = $model->getPagination();
}
return $this->_articles;
}
Since I don't know, how to override a model within a template even having Googled it, I found nothing more than import it via a plugin.
And that is not what I need and want at all.
Maybe you guys have a handy trick for me.
1st suggestion
How to override the component mvc from the Joomla! core
http://docs.joomla.org/How_to_override_the_component_mvc_from_the_Joomla!_core
NOTICE: This method only works if you install and enable the 3rd party MVC plugin - or provide your own equivalent plugin. It is fine for advanced developers - just be aware that this is not part of Joomla! Core code.
2nd suggestion
Copy the entire core component, hack the copy and package the copy as a new component under a new name (e.g com_mycustomcontent). By doing this you will not have problems with upgrades unless there is a security issue with the original component. That means that you will be stuck if you don't know how to apply the updates of the original component to your component.

How can i create my own hook in drupal6?

How does drupal create its own hook. Similarly i want a customized hook for myself. How am I to proceed ?
May be you are looking for module_invoke_all
Some useful links to start with:
Creating hooks for your Drupal modules
How hooks are invoked with module_invoke_all()
If you have a hook that passes a parameter by reference, and you can not use drupal_alter (for example a presave hook that passes in more than one argument) you can use module_implements.
This way a module could implement it as modulename_foo_presave instead of modulename_presave_alter. It is good for when you you want to let modules alter something at multiple points in its life cycle.
For an example in drupal core checkout the code for the node_validate (drupal 7).
foreach (module_implements('node_validate') as $module) {
$function = $module . '_node_validate';
$function($node, $form, $form_state);
}
from http://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_validate/7
The same approach works in Drupal 6 if you want to create hook that can be implemented in this way.

Drupal completion hooks (og)

Drupal 7.12/organic groups 7.x-1.3
Does anyone know how I can do a quick cURL hit against a site with a few POST vars like group ID, group name, etc. when a user creates a group successfully?
I have no idea how the hooks system works in this case.
An organic group is defined as an Entity in Drupal 7, and as such you can implement hook_entity_insert in a custom module to react to a successful group creation:
function MYMODULE_entity_insert($entity, $type) {
if ($type == 'group') {
$group_id = $entity->gid;
// Install the Devel module and run the following code to get a full
// breakdown of what's available in the $entity object
dpm($entity);
// Perform your cURL here
}
}
Hope that helps

Categories