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
Related
I am trying to modify a Wordpress plugins' method without changing the plugin core code itself. I need to set some status flag in a different part of the website.
The method is defined in the plugin class like so:
add_action('plugins_action_name', [$this, 'local_method_name']);
The plugin method does not offer any actions or filters to hook into.
If this wasn't Wordpress but plain PHP I would write my own class, which extends the plugins' original class but has it's own method by the same name - but in Wordpress this gets me nowhere since I just move the problem from one plugin file to the next.
Is there a way to remove the plugins action altogether? And then redefine my own version of it?
Since the add_action has been called with $this - how would I remove it in some functions.php file?
Thanks
UPDATE
Indeed I want to learn how to handle different scenarios. Not expecting a one size fits all solution, but I do need to know how to avoid core changes, as each core-change complicates my deploy/update process exponentially.
Sure I will add some more details. My example plugin is WooCommerce Germanized Pro which comes with a WC_GZDP_Download_Handler::download() method which I needed to modify, in order to set some sort of "Warehouse downloaded the invoice" flag for each order. Which is later used to highlight new orders, filter orders that have been handed over to fulfilment etc.
There seems to be a Invoice Helper class which does in fact have a singleton pattern.
my modification in the download class is trivial:
public static function download( $pdf, $force = false ) {
... /* original code above, now my modifications */
if ($check_some_codition) {
$invoice = $pdf->get_invoice();
update_post_meta($invoice->get_id(), 'some-flag', 'some-value');
}
/* then resume original function (return the file to the browser) */
self::out( $filename, $file, $force );
}
I've installed a plugin that enables a custom shipping method into my store (calculates shipping method with my postal service).
It works with any product, except those with recurring profile enabled.
I found this link http://www.magentocommerce.com/knowledge-base/entry/working-with-recurring-profiles/Magento-Knowledge-Base-Working-with-Recurring-Profiles saying:
... For products with recurring profiles, the customer can only choose
between the fixed-price shipping methods (flat, table or free) when
checking out. ...
Why there is this rule? How can I make my custom shipping method work with recurring profile products?
I've tried these plugins and both doesn't work.
https://github.com/pedro-teixeira/correios
https://github.com/willstorm/correios
Which files should I look at to edit to solve this?
To solve this you need to basically change your shipping method class in order to add this:
class Namespace_Shipping_Model_Carrier_Customrate
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
protected $_code = 'my_customrate';
protected $_isFixed = true; // << THIS ONE
...
}
I want to modify the Downloadable Information / Links of a product programmability.
I am able to create a downloadable product.
But I can't find how to edit the links.
I think the fonction setDownloadableData / getDownloadableData could help me.
But, i can't find them in the Magento source (1.7.0.2).
with
grep -r "setDownloadableData" magento/*
I can only see the call to the function. Not the implementation. ...
/magento/app/code/core/Mage/Downloadable/Model/Link/Api.php
$product->setDownloadableData($downloadable);
/magento/app/code/core/Mage/Downloadable/Model/Observer.php
$product->setDownloadableData($downloadable);
You cannot find the methods because they don't exist.
Most of the classes in Magento extend Varian_Object class that overloads the 'magic method' __call. This is called when a method in the class does not exist.
To get a better view on this take a look at Varien_Object::__call(), this article and what php.net has to say about overloading
The answer is Varien Data Collections
http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections
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
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.