[*] PROJECT : New Module API (part 1)
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9790 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1050,8 +1050,8 @@ class AdminControllerCore extends Controller
|
||||
'pic_dir' => _THEME_PROD_PIC_DIR_
|
||||
));
|
||||
$this->context->smarty->assign(array(
|
||||
'HOOK_HEADER' => Module::hookExec('backOfficeHeader'),
|
||||
'HOOK_TOP' => Module::hookExec('backOfficeTop'),
|
||||
'HOOK_HEADER' => Hook::exec('backOfficeHeader'),
|
||||
'HOOK_TOP' => Hook::exec('backOfficeTop'),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -1132,7 +1132,7 @@ class AdminControllerCore extends Controller
|
||||
));
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'HOOK_FOOTER' => Module::hookExec('backOfficeFooter'),
|
||||
'HOOK_FOOTER' => Hook::exec('backOfficeFooter'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
$return = parent::delete();
|
||||
if ($return)
|
||||
Module::hookExec('afterDeleteAttribute', array('id_attribute' => $this->id));
|
||||
Hook::exec('afterDeleteAttribute', array('id_attribute' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class AttributeCore extends ObjectModel
|
||||
{
|
||||
$return = parent::update($null_values);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
Hook::exec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
$return = parent::add($autodate, $null_values);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
Hook::exec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,14 +76,14 @@ class AttributeGroupCore extends ObjectModel
|
||||
$this->position = AttributeGroup::getHigherPosition() + 1;
|
||||
|
||||
$return = parent::add($autodate, true);
|
||||
Module::hookExec('afterSaveAttributeGroup', array('id_attribute_group' => $this->id));
|
||||
Hook::exec('afterSaveAttributeGroup', array('id_attribute_group' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function update($nullValues = false)
|
||||
{
|
||||
$return = parent::update($nullValues);
|
||||
Module::hookExec('afterSaveAttributeGroup', array('id_attribute_group' => $this->id));
|
||||
Hook::exec('afterSaveAttributeGroup', array('id_attribute_group' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ class AttributeGroupCore extends ObjectModel
|
||||
return false;
|
||||
$return = parent::delete();
|
||||
if ($return)
|
||||
Module::hookExec('afterDeleteAttributeGroup', array('id_attribute_group' => $this->id));
|
||||
Hook::exec('afterDeleteAttributeGroup', array('id_attribute_group' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -167,7 +167,7 @@ class CartCore extends ObjectModel
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
{
|
||||
$return = parent::add($autodate);
|
||||
Module::hookExec('cart');
|
||||
Hook::exec('cart');
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ class CartCore extends ObjectModel
|
||||
unset(self::$_totalWeight[$this->id]);
|
||||
$this->_products = NULL;
|
||||
$return = parent::update();
|
||||
Module::hookExec('cart');
|
||||
Hook::exec('cart');
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ class CategoryCore extends ObjectModel
|
||||
if (!isset($this->doNotRegenerateNTree) || !$this->doNotRegenerateNTree)
|
||||
self::regenerateEntireNtree();
|
||||
$this->updateGroup($this->groupBox);
|
||||
Module::hookExec('categoryAddition', array('category' => $this));
|
||||
Hook::exec('categoryAddition', array('category' => $this));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ class CategoryCore extends ObjectModel
|
||||
self::regenerateEntireNtree();
|
||||
$this->recalculateLevelDepth($this->id_category);
|
||||
}
|
||||
Module::hookExec('categoryUpdate', array('category' => $this));
|
||||
Hook::exec('categoryUpdate', array('category' => $this));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ class CategoryCore extends ObjectModel
|
||||
public function toggleStatus()
|
||||
{
|
||||
$result = parent::toggleStatus();
|
||||
Module::hookExec('categoryUpdate');
|
||||
Hook::exec('categoryUpdate');
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ class CategoryCore extends ObjectModel
|
||||
if (!isset($this->doNotRegenerateNTree) || !$this->doNotRegenerateNTree)
|
||||
self::regenerateEntireNtree();
|
||||
|
||||
Module::hookExec('categoryDeletion', array('category' => $this));
|
||||
Hook::exec('categoryDeletion', array('category' => $this));
|
||||
|
||||
/* Delete Categories in GroupReduction */
|
||||
foreach ($to_delete as $category)
|
||||
@@ -1055,7 +1055,7 @@ class CategoryCore extends ObjectModel
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_parent` = '.(int)$moved_category['id_parent'].'
|
||||
AND `id_category`='.(int)$moved_category['id_category']));
|
||||
Module::hookExec('categoryUpdate');
|
||||
Hook::exec('categoryUpdate');
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -113,7 +113,7 @@ class FeatureCore extends ObjectModel
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
{
|
||||
$return = parent::add($autodate, true);
|
||||
Module::hookExec('afterSaveFeature', array('id_feature' => $this->id));
|
||||
Hook::exec('afterSaveFeature', array('id_feature' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ class FeatureCore extends ObjectModel
|
||||
|
||||
$return = parent::delete();
|
||||
if($return)
|
||||
Module::hookExec('afterDeleteFeature', array('id_feature' => $this->id));
|
||||
Hook::exec('afterDeleteFeature', array('id_feature' => $this->id));
|
||||
|
||||
/* Reinitializing position */
|
||||
$this->cleanPositions();
|
||||
@@ -155,7 +155,7 @@ class FeatureCore extends ObjectModel
|
||||
Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'UPDATE', '`'.
|
||||
pSQL($this->identifier).'` = '.(int)$this->id.' AND `id_lang` = '.(int)$field['id_lang']);
|
||||
}
|
||||
Module::hookExec('afterSaveFeature', array('id_feature' => $this->id));
|
||||
Hook::exec('afterSaveFeature', array('id_feature' => $this->id));
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ class FeatureValueCore extends ObjectModel
|
||||
{
|
||||
$return = parent::add($autodate, $nullValues);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
|
||||
Hook::exec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ class FeatureValueCore extends ObjectModel
|
||||
$return = parent::delete();
|
||||
|
||||
if ($return)
|
||||
Module::hookExec('afterDeleteFeatureValue', array('id_feature_value' => $this->id));
|
||||
Hook::exec('afterDeleteFeatureValue', array('id_feature_value' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ class FeatureValueCore extends ObjectModel
|
||||
{
|
||||
$return = parent::update($nullValues);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
|
||||
Hook::exec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class qqUploadedFileXhr
|
||||
return array('error' => Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']));
|
||||
}
|
||||
unlink($tmpName);
|
||||
Module::hookExec('watermark', array('id_image' => $id_image, 'id_product' => $id_product));
|
||||
Hook::exec('watermark', array('id_image' => $id_image, 'id_product' => $id_product));
|
||||
$lang = Context::getContext()->employee->id_lang;
|
||||
|
||||
foreach (Language::getLanguages(false) as $l)
|
||||
|
||||
@@ -543,9 +543,9 @@ class FrontControllerCore extends Controller
|
||||
'content_only' => (int)Tools::getValue('content_only')
|
||||
));
|
||||
$this->context->smarty->assign(array(
|
||||
'HOOK_HEADER' => Module::hookExec('header'),
|
||||
'HOOK_TOP' => Module::hookExec('top'),
|
||||
'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn')
|
||||
'HOOK_HEADER' => Hook::exec('header'),
|
||||
'HOOK_TOP' => Hook::exec('top'),
|
||||
'HOOK_LEFT_COLUMN' => Hook::exec('leftColumn')
|
||||
));
|
||||
|
||||
if ((Configuration::get('PS_CSS_THEME_CACHE') OR Configuration::get('PS_JS_THEME_CACHE')) AND is_writable(_PS_THEME_DIR_.'cache'))
|
||||
@@ -564,8 +564,8 @@ class FrontControllerCore extends Controller
|
||||
public function initFooter()
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => $this->context->cart)),
|
||||
'HOOK_FOOTER' => Module::hookExec('footer'),
|
||||
'HOOK_RIGHT_COLUMN' => Hook::exec('rightColumn', array('cart' => $this->context->cart)),
|
||||
'HOOK_FOOTER' => Hook::exec('footer'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
+175
-22
@@ -29,6 +29,7 @@ class HookCore extends ObjectModel
|
||||
{
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
public $title;
|
||||
|
||||
protected $fieldsRequired = array('name');
|
||||
protected $fieldsSize = array('name' => 32);
|
||||
@@ -37,12 +38,16 @@ class HookCore extends ObjectModel
|
||||
protected $table = 'hook';
|
||||
protected $identifier = 'id_hook';
|
||||
|
||||
protected static $_hookModulesCache;
|
||||
|
||||
static $preloadModulesFromHooks = null;
|
||||
static $preloadHookAlias = null;
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
$fields['name'] = pSQL($this->name);
|
||||
$fields['title'] = pSQL($this->title);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -95,6 +100,15 @@ class HookCore extends ObjectModel
|
||||
'.($position ? 'WHERE h.`position` = 1' : ''));
|
||||
}
|
||||
|
||||
static public function preloadHookAlias()
|
||||
{
|
||||
if (!is_null(self::$preloadHookAlias))
|
||||
return ;
|
||||
$hookAliasList = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'hook_alias`');
|
||||
foreach ($hookAliasList as $ha)
|
||||
self::$preloadHookAlias[$ha['alias']] = $ha['name'];
|
||||
}
|
||||
|
||||
static public function preloadModulesFromHooks()
|
||||
{
|
||||
if (!is_null(self::$preloadModulesFromHooks))
|
||||
@@ -138,23 +152,144 @@ class HookCore extends ObjectModel
|
||||
return $list;
|
||||
}
|
||||
|
||||
static public function newOrder($cart, $order, $customer, $currency, $orderStatus)
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Execute modules for specified hook
|
||||
*
|
||||
* @param string $hook_name Hook Name
|
||||
* @param array $hookArgs Parameters for the functions
|
||||
* @return string modules output
|
||||
*/
|
||||
public static function exec($hook_name, $hookArgs = array(), $id_module = NULL)
|
||||
{
|
||||
return Module::hookExec('newOrder', array(
|
||||
'cart' => $cart,
|
||||
'order' => $order,
|
||||
'customer' => $customer,
|
||||
'currency' => $currency,
|
||||
'orderStatus' => $orderStatus));
|
||||
$context = Context::getContext();
|
||||
if ((!empty($id_module) && !Validate::isUnsignedId($id_module)) || !Validate::isHookName($hook_name))
|
||||
die(Tools::displayError());
|
||||
|
||||
self::preloadHookAlias();
|
||||
$hook_name_retro = strtolower($hook_name);
|
||||
if (isset(self::$preloadHookAlias[$hook_name]))
|
||||
$hook_name = self::$preloadHookAlias[$hook_name];
|
||||
|
||||
$live_edit = false;
|
||||
if (!isset($hookArgs['cookie']) || !$hookArgs['cookie'])
|
||||
$hookArgs['cookie'] = $context->cookie;
|
||||
if (!isset($hookArgs['cart']) || !$hookArgs['cart'])
|
||||
$hookArgs['cart'] = $context->cart;
|
||||
$hook_name = strtolower($hook_name);
|
||||
|
||||
if (!isset(self::$_hookModulesCache))
|
||||
{
|
||||
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
|
||||
$list = $context->shop->getListOfID();
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
$groups = $context->customer->getGroups();
|
||||
|
||||
$sql = 'SELECT h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit`
|
||||
FROM `'._DB_PREFIX_.'module` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm
|
||||
ON hm.`id_module` = m.`id_module`';
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'group_module_restriction` gmr
|
||||
ON gmr.`id_module` = m.`id_module`';
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h
|
||||
ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).'
|
||||
AND hm.id_shop IN('.implode(', ', $list).')';
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
$sql .= '
|
||||
AND (gmr.`authorized` = 1 AND gmr.`id_group` IN('.implode(', ', $groups).'))';
|
||||
$sql .= '
|
||||
GROUP BY hm.id_hook, hm.id_module
|
||||
ORDER BY hm.`position`';
|
||||
$result = $db->executeS($sql, false);
|
||||
self::$_hookModulesCache = array();
|
||||
|
||||
if ($result)
|
||||
while ($row = $db->nextRow())
|
||||
{
|
||||
$row['hook'] = strtolower($row['hook']);
|
||||
if (!isset(self::$_hookModulesCache[$row['hook']]))
|
||||
self::$_hookModulesCache[$row['hook']] = array();
|
||||
self::$_hookModulesCache[$row['hook']][] = array('id_hook' => $row['id_hook'], 'module' => $row['module'], 'id_module' => $row['id_module'], 'live_edit' => $row['live_edit']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset(self::$_hookModulesCache[$hook_name]) && !isset(self::$_hookModulesCache[$hook_name_retro]))
|
||||
return;
|
||||
|
||||
$hookModulesCache = array();
|
||||
if (isset(self::$_hookModulesCache[$hook_name]))
|
||||
$hookModulesCache = self::$_hookModulesCache[$hook_name];
|
||||
if (isset(self::$_hookModulesCache[$hook_name_retro]))
|
||||
$hookModulesCache = self::$_hookModulesCache[$hook_name_retro];
|
||||
|
||||
$altern = 0;
|
||||
$output = '';
|
||||
foreach ($hookModulesCache as $array)
|
||||
{
|
||||
if ($id_module && $id_module != $array['id_module'])
|
||||
continue;
|
||||
if (!($moduleInstance = Module::getInstanceByName($array['module'])))
|
||||
continue;
|
||||
|
||||
$exceptions = $moduleInstance->getExceptions($array['id_hook']);
|
||||
if (in_array(Dispatcher::getInstance()->getController(), $exceptions))
|
||||
continue;
|
||||
if (isset($context->employee) && !$moduleInstance->getPermission('view', $context->employee))
|
||||
continue;
|
||||
|
||||
$hook_callable = is_callable(array($moduleInstance, 'hook'.$hook_name));
|
||||
$hook_retro_callable = is_callable(array($moduleInstance, 'hook'.$hook_name_retro));
|
||||
if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name))
|
||||
{
|
||||
$hookArgs['altern'] = ++$altern;
|
||||
|
||||
if ($hook_callable)
|
||||
$display = call_user_func(array($moduleInstance, 'hook'.$hook_name), $hookArgs);
|
||||
else if ($hook_retro_callable)
|
||||
$display = call_user_func(array($moduleInstance, 'hook'.$hook_name_retro), $hookArgs);
|
||||
if ($array['live_edit'] && ((Tools::isSubmit('live_edit') && Tools::getValue('ad') && (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))))
|
||||
{
|
||||
$live_edit = true;
|
||||
$output .= '<script type="text/javascript"> modules_list.push(\''.$moduleInstance->name.'\');</script>
|
||||
<div id="hook_'.$array['id_hook'].'_module_'.$moduleInstance->id.'_moduleName_'.$moduleInstance->name.'"
|
||||
class="dndModule" style="border: 1px dotted red;'.(!strlen($display) ? 'height:50px;' : '').'">
|
||||
<span><img src="'.$moduleInstance->_path.'/logo.gif">'
|
||||
.$moduleInstance->displayName.'<span style="float:right">
|
||||
<a href="#" id="'.$array['id_hook'].'_'.$moduleInstance->id.'" class="moveModule">
|
||||
<img src="'._PS_ADMIN_IMG_.'arrow_out.png"></a>
|
||||
<a href="#" id="'.$array['id_hook'].'_'.$moduleInstance->id.'" class="unregisterHook">
|
||||
<img src="'._PS_ADMIN_IMG_.'delete.gif"></span></a>
|
||||
</span>'.$display.'</div>';
|
||||
}
|
||||
else
|
||||
$output .= $display;
|
||||
}
|
||||
}
|
||||
return ($live_edit ? '<script type="text/javascript">hooks_list.push(\''.$hook_name.'\'); </script><!--<div id="add_'.$hook_name.'" class="add_module_live_edit">
|
||||
<a class="exclusive" href="#">Add a module</a></div>--><div id="'.$hook_name.'" class="dndHook" style="min-height:50px">' : '').$output.($live_edit ? '</div>' : '');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static public function updateOrderStatus($newOrderStatusId, $id_order)
|
||||
{
|
||||
$order = new Order((int)($id_order));
|
||||
$newOS = new OrderState((int)($newOrderStatusId), $order->id_lang);
|
||||
|
||||
$return = ((int)($newOS->id) == Configuration::get('PS_OS_PAYMENT')) ? Module::hookExec('paymentConfirm', array('id_order' => (int)($order->id))) : true;
|
||||
$return = Module::hookExec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id))) AND $return;
|
||||
$return = ((int)($newOS->id) == Configuration::get('PS_OS_PAYMENT')) ? Hook::exec('paymentConfirm', array('id_order' => (int)($order->id))) : true;
|
||||
$return = Hook::exec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id))) AND $return;
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -162,7 +297,7 @@ class HookCore extends ObjectModel
|
||||
{
|
||||
$order = new Order((int)($id_order));
|
||||
$newOS = new OrderState((int)($newOrderStatusId), $order->id_lang);
|
||||
$return = Module::hookExec('postUpdateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id)));
|
||||
$return = Hook::exec('postUpdateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id)));
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -172,39 +307,57 @@ class HookCore extends ObjectModel
|
||||
* @param Product
|
||||
* @param Order
|
||||
*/
|
||||
static public function newOrder($cart, $order, $customer, $currency, $orderStatus)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec('newOrder', array(
|
||||
'cart' => $cart,
|
||||
'order' => $order,
|
||||
'customer' => $customer,
|
||||
'currency' => $currency,
|
||||
'orderStatus' => $orderStatus));
|
||||
}
|
||||
|
||||
static public function updateQuantity($product, $order = null)
|
||||
{
|
||||
return Module::hookExec('updateQuantity', array('product' => $product, 'order' => $order));
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec('updateQuantity', array('product' => $product, 'order' => $order));
|
||||
}
|
||||
|
||||
static public function productFooter($product, $category)
|
||||
{
|
||||
return Module::hookExec('productFooter', array('product' => $product, 'category' => $category));
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec('productFooter', array('product' => $product, 'category' => $category));
|
||||
}
|
||||
|
||||
static public function productOutOfStock($product)
|
||||
{
|
||||
return Module::hookExec('productOutOfStock', array('product' => $product));
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec('productOutOfStock', array('product' => $product));
|
||||
}
|
||||
|
||||
static public function addProduct($product)
|
||||
{
|
||||
return Module::hookExec('addProduct', array('product' => $product));
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec('addProduct', array('product' => $product));
|
||||
}
|
||||
|
||||
static public function updateProduct($product)
|
||||
{
|
||||
return Module::hookExec('updateProduct', array('product' => $product));
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec('updateProduct', array('product' => $product));
|
||||
}
|
||||
|
||||
static public function deleteProduct($product)
|
||||
{
|
||||
return Module::hookExec('deleteProduct', array('product' => $product));
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec('deleteProduct', array('product' => $product));
|
||||
}
|
||||
|
||||
static public function updateProductAttribute($id_product_attribute)
|
||||
{
|
||||
return Module::hookExec('updateProductAttribute', array('id_product_attribute' => $id_product_attribute));
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec('updateProductAttribute', array('id_product_attribute' => $id_product_attribute));
|
||||
}
|
||||
|
||||
static public function orderConfirmation($id_order)
|
||||
@@ -222,7 +375,7 @@ class HookCore extends ObjectModel
|
||||
$params['objOrder'] = $order;
|
||||
$params['currencyObj'] = $currency;
|
||||
|
||||
return Module::hookExec('orderConfirmation', $params);
|
||||
return Hook::exec('orderConfirmation', $params);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -243,7 +396,7 @@ class HookCore extends ObjectModel
|
||||
$params['objOrder'] = $order;
|
||||
$params['currencyObj'] = $currency;
|
||||
|
||||
return Module::hookExec('paymentReturn', $params, (int)($id_module));
|
||||
return Hook::exec('paymentReturn', $params, (int)($id_module));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -253,7 +406,7 @@ class HookCore extends ObjectModel
|
||||
{
|
||||
if (!is_object($pdf) OR !Validate::isUnsignedId($id_order))
|
||||
return false;
|
||||
return Module::hookExec('PDFInvoice', array('pdf' => $pdf, 'id_order' => $id_order));
|
||||
return Hook::exec('PDFInvoice', array('pdf' => $pdf, 'id_order' => $id_order));
|
||||
}
|
||||
|
||||
static public function backBeforePayment($module)
|
||||
@@ -261,14 +414,14 @@ class HookCore extends ObjectModel
|
||||
$params['module'] = strval($module);
|
||||
if (!$params['module'])
|
||||
return false;
|
||||
return Module::hookExec('backBeforePayment', $params);
|
||||
return Hook::exec('backBeforePayment', $params);
|
||||
}
|
||||
|
||||
static public function updateCarrier($id_carrier, $carrier)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_carrier) OR !is_object($carrier))
|
||||
return false;
|
||||
return Module::hookExec('updateCarrier', array('id_carrier' => $id_carrier, 'carrier' => $carrier));
|
||||
return Hook::exec('updateCarrier', array('id_carrier' => $id_carrier, 'carrier' => $carrier));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+35
-108
@@ -78,7 +78,6 @@ abstract class ModuleCore
|
||||
public $limited_countries = array();
|
||||
|
||||
protected static $modulesCache;
|
||||
protected static $_hookModulesCache;
|
||||
|
||||
protected static $_INSTANCE = array();
|
||||
|
||||
@@ -343,13 +342,26 @@ abstract class ModuleCore
|
||||
if (!isset($this->id) OR !is_numeric($this->id))
|
||||
return false;
|
||||
|
||||
// Retrocompatibility
|
||||
Hook::preloadHookAlias();
|
||||
if (isset(Hook::$preloadHookAlias[$hook_name]))
|
||||
$hook_name = Hook::$preloadHookAlias[$hook_name];
|
||||
|
||||
// Get hook id
|
||||
$sql = 'SELECT `id_hook`
|
||||
FROM `'._DB_PREFIX_.'hook`
|
||||
WHERE `name` = \''.pSQL($hook_name).'\'';
|
||||
$hookID = Db::getInstance()->getValue($sql);
|
||||
if (!$hookID)
|
||||
return false;
|
||||
{
|
||||
$newHook = new Hook();
|
||||
$newHook->name = pSQL($hook_name);
|
||||
$newHook->title = pSQL($hook_name);
|
||||
$newHook->add();
|
||||
$hookID = $newHook->id;
|
||||
if (!$hookID)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null($shopList))
|
||||
$shopList = Shop::getShops(true, null, true);
|
||||
@@ -402,6 +414,11 @@ abstract class ModuleCore
|
||||
// Get hook id if a name is given as argument
|
||||
if (!is_numeric($hook_id))
|
||||
{
|
||||
// Retrocompatibility
|
||||
Hook::preloadHookAlias();
|
||||
if (isset(Hook::$preloadHookAlias[$hook_id]))
|
||||
$hook_id = Hook::$preloadHookAlias[$hook_id];
|
||||
|
||||
$sql = 'SELECT `id_hook`
|
||||
FROM `'._DB_PREFIX_.'hook`
|
||||
WHERE `name` = \''.pSQL($hook_id).'\'';
|
||||
@@ -775,118 +792,24 @@ abstract class ModuleCore
|
||||
*/
|
||||
public static function hookExec($hook_name, $hookArgs = array(), $id_module = NULL)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
if ((!empty($id_module) && !Validate::isUnsignedId($id_module)) || !Validate::isHookName($hook_name))
|
||||
die(Tools::displayError());
|
||||
|
||||
$live_edit = false;
|
||||
if (!isset($hookArgs['cookie']) || !$hookArgs['cookie'])
|
||||
$hookArgs['cookie'] = $context->cookie;
|
||||
if (!isset($hookArgs['cart']) || !$hookArgs['cart'])
|
||||
$hookArgs['cart'] = $context->cart;
|
||||
$hook_name = strtolower($hook_name);
|
||||
|
||||
if (!isset(self::$_hookModulesCache))
|
||||
{
|
||||
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
|
||||
$list = $context->shop->getListOfID();
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
$groups = $context->customer->getGroups();
|
||||
|
||||
$sql = 'SELECT h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit`
|
||||
FROM `'._DB_PREFIX_.'module` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm
|
||||
ON hm.`id_module` = m.`id_module`';
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'group_module_restriction` gmr
|
||||
ON gmr.`id_module` = m.`id_module`';
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h
|
||||
ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).'
|
||||
AND hm.id_shop IN('.implode(', ', $list).')';
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
$sql .= '
|
||||
AND (gmr.`authorized` = 1 AND gmr.`id_group` IN('.implode(', ', $groups).'))';
|
||||
$sql .= '
|
||||
GROUP BY hm.id_hook, hm.id_module
|
||||
ORDER BY hm.`position`';
|
||||
$result = $db->executeS($sql, false);
|
||||
self::$_hookModulesCache = array();
|
||||
|
||||
if ($result)
|
||||
while ($row = $db->nextRow())
|
||||
{
|
||||
$row['hook'] = strtolower($row['hook']);
|
||||
if (!isset(self::$_hookModulesCache[$row['hook']]))
|
||||
self::$_hookModulesCache[$row['hook']] = array();
|
||||
self::$_hookModulesCache[$row['hook']][] = array('id_hook' => $row['id_hook'], 'module' => $row['module'], 'id_module' => $row['id_module'], 'live_edit' => $row['live_edit']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset(self::$_hookModulesCache[$hook_name]))
|
||||
return;
|
||||
|
||||
$altern = 0;
|
||||
$output = '';
|
||||
foreach (self::$_hookModulesCache[$hook_name] as $array)
|
||||
{
|
||||
if ($id_module && $id_module != $array['id_module'])
|
||||
continue;
|
||||
if (!($moduleInstance = Module::getInstanceByName($array['module'])))
|
||||
continue;
|
||||
|
||||
$exceptions = $moduleInstance->getExceptions($array['id_hook']);
|
||||
if (in_array(Dispatcher::getInstance()->getController(), $exceptions))
|
||||
continue;
|
||||
if (isset($context->employee) && !$moduleInstance->getPermission('view', $context->employee))
|
||||
continue;
|
||||
|
||||
if (is_callable(array($moduleInstance, 'hook'.$hook_name)))
|
||||
{
|
||||
$hookArgs['altern'] = ++$altern;
|
||||
|
||||
$display = call_user_func(array($moduleInstance, 'hook'.$hook_name), $hookArgs);
|
||||
if ($array['live_edit'] && ((Tools::isSubmit('live_edit') && Tools::getValue('ad') && (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))))
|
||||
{
|
||||
$live_edit = true;
|
||||
$output .= '<script type="text/javascript"> modules_list.push(\''.$moduleInstance->name.'\');</script>
|
||||
<div id="hook_'.$array['id_hook'].'_module_'.$moduleInstance->id.'_moduleName_'.$moduleInstance->name.'"
|
||||
class="dndModule" style="border: 1px dotted red;'.(!strlen($display) ? 'height:50px;' : '').'">
|
||||
<span><img src="'.$moduleInstance->_path.'/logo.gif">'
|
||||
.$moduleInstance->displayName.'<span style="float:right">
|
||||
<a href="#" id="'.$array['id_hook'].'_'.$moduleInstance->id.'" class="moveModule">
|
||||
<img src="'._PS_ADMIN_IMG_.'arrow_out.png"></a>
|
||||
<a href="#" id="'.$array['id_hook'].'_'.$moduleInstance->id.'" class="unregisterHook">
|
||||
<img src="'._PS_ADMIN_IMG_.'delete.gif"></span></a>
|
||||
</span>'.$display.'</div>';
|
||||
}
|
||||
else
|
||||
$output .= $display;
|
||||
}
|
||||
}
|
||||
return ($live_edit ? '<script type="text/javascript">hooks_list.push(\''.$hook_name.'\'); </script><!--<div id="add_'.$hook_name.'" class="add_module_live_edit">
|
||||
<a class="exclusive" href="#">Add a module</a></div>--><div id="'.$hook_name.'" class="dndHook" style="min-height:50px">' : '').$output.($live_edit ? '</div>' : '');
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec($hook_name, $hookArgs, $id_module);
|
||||
}
|
||||
|
||||
public static function hookExecPayment()
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$hookArgs = array('cookie' => $context->cookie, 'cart' => $context->cart);
|
||||
$output = '';
|
||||
|
||||
$result = self::getPaymentModules();
|
||||
|
||||
if ($result)
|
||||
foreach ($result AS $module)
|
||||
if (($moduleInstance = Module::getInstanceByName($module['name'])) AND is_callable(array($moduleInstance, 'hookpayment')))
|
||||
if (!$moduleInstance->currencies OR ($moduleInstance->currencies AND sizeof(Currency::checkPaymentCurrencies($moduleInstance->id))))
|
||||
$output .= call_user_func(array($moduleInstance, 'hookpayment'), $hookArgs);
|
||||
return $output;
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec('payment');
|
||||
}
|
||||
|
||||
|
||||
public static function preCall($moduleName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the list of the payment module associated to the current customer
|
||||
* @see PaymentModule::getInstalledPaymentModules() if you don't care about the context
|
||||
@@ -901,6 +824,10 @@ abstract class ModuleCore
|
||||
if (isset($context->customer))
|
||||
$groups = $context->customer->getGroups();
|
||||
|
||||
$hookPayment = 'Payment';
|
||||
if (Db::getInstance()->getValue('SELECT `id_hook` FROM `'._DB_PREFIX_.'hook` WHERE `name` = \'displayPayment\''))
|
||||
$hookPayment = 'displayPayment';
|
||||
|
||||
$list = Context::getContext()->shop->getListOfID();
|
||||
$sql = 'SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
|
||||
FROM `'._DB_PREFIX_.'module_country` mc
|
||||
@@ -913,7 +840,7 @@ abstract class ModuleCore
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'group_module_restriction` gmr ON gmr.`id_module` = m.`id_module`';
|
||||
$sql .= '
|
||||
WHERE h.`name` = \'payment\'
|
||||
WHERE h.`name` = \''.$hookPayment.'\'
|
||||
AND mc.id_country = '.(int)($billing->id_country).'
|
||||
AND mc.id_shop = '.(int)$context->shop->getID(true).'
|
||||
AND mg.id_shop = '.(int)$context->shop->getID(true).'
|
||||
|
||||
@@ -205,6 +205,9 @@ abstract class ObjectModelCore
|
||||
if (!Validate::isTableOrIdentifier($this->table))
|
||||
die(Tools::displayError('not table or identifier : ').$this->table);
|
||||
|
||||
/* Hook */
|
||||
Hook::exec('actionObject'.get_class($this).'AddBefore');
|
||||
|
||||
/* Automatically fill dates */
|
||||
if ($autodate AND key_exists('date_add', $this))
|
||||
$this->date_add = date('Y-m-d H:i:s');
|
||||
@@ -258,6 +261,10 @@ abstract class ObjectModelCore
|
||||
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'group_shop')
|
||||
$result &= $this->associateTo(Context::getContext()->shop->getGroupID(), 'group_shop');
|
||||
}
|
||||
|
||||
/* Hook */
|
||||
Hook::exec('actionObject'.get_class($this).'AddAfter');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -271,6 +278,9 @@ abstract class ObjectModelCore
|
||||
if (!Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table))
|
||||
die(Tools::displayError());
|
||||
|
||||
/* Hook */
|
||||
Hook::exec('actionObject'.get_class($this).'UpdateBefore');
|
||||
|
||||
$this->clearCache();
|
||||
/* Automatically fill dates */
|
||||
if (key_exists('date_upd', $this))
|
||||
@@ -326,6 +336,10 @@ abstract class ObjectModelCore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Hook */
|
||||
Hook::exec('actionObject'.get_class($this).'UpdateAfter');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -339,6 +353,9 @@ abstract class ObjectModelCore
|
||||
if (!Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table))
|
||||
die(Tools::displayError());
|
||||
|
||||
/* Hook */
|
||||
Hook::exec('actionObject'.get_class($this).'DeleteBefore');
|
||||
|
||||
$this->clearCache();
|
||||
|
||||
/* Database deletion */
|
||||
@@ -349,6 +366,10 @@ abstract class ObjectModelCore
|
||||
/* Database deletion for multilingual fields related to the object */
|
||||
if (method_exists($this, 'getTranslationsFieldsChild'))
|
||||
Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` WHERE `'.pSQL($this->identifier).'` = '.(int)($this->id));
|
||||
|
||||
/* Hook */
|
||||
Hook::exec('actionObject'.get_class($this).'DeleteAfter');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class PaymentCCCore extends ObjectModel
|
||||
{
|
||||
if (parent::add($autodate, $nullValues))
|
||||
{
|
||||
Module::hookExec('paymentCCAdded', array('paymentCC' => $this));
|
||||
Hook::exec('paymentCCAdded', array('paymentCC' => $this));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -293,11 +293,11 @@ abstract class PaymentModuleCore extends Module
|
||||
$message->update();
|
||||
}
|
||||
|
||||
// Hook new order
|
||||
// Hook validate order
|
||||
$orderStatus = new OrderState((int)$id_order_state, (int)$order->id_lang);
|
||||
if (Validate::isLoadedObject($orderStatus))
|
||||
{
|
||||
Hook::newOrder($cart, $order, $customer, $currency, $orderStatus);
|
||||
Hook::exec('newOrder', array('cart' => $cart, 'order' => $order, 'customer' => $customer, 'currency' => $currency, 'orderStatus' => $orderStatus));
|
||||
foreach ($cart->getProducts() AS $product)
|
||||
if ($orderStatus->logable)
|
||||
ProductSale::addProductSale((int)$product['id_product'], (int)$product['cart_quantity']);
|
||||
@@ -513,7 +513,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$modules = PaymentModuleCore::getInstalledPaymentModules();
|
||||
foreach ($modules as $module)
|
||||
$id_module_list[] = $module['id_module'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($id_module_list as $id_module)
|
||||
$values .= '('.(int)$id_module.','.(int)$id_currency.'),';
|
||||
@@ -547,5 +547,19 @@ abstract class PaymentModuleCore extends Module
|
||||
AND m.`active` = 1
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
public static function preCall($moduleName)
|
||||
{
|
||||
if (!parent::preCall($moduleName))
|
||||
return false;
|
||||
|
||||
if (($moduleInstance = Module::getInstanceByName($moduleName)))
|
||||
if (!$moduleInstance->currencies OR ($moduleInstance->currencies AND sizeof(Currency::checkPaymentCurrencies($moduleInstance->id))))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -391,14 +391,14 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if (!parent::add($autodate, $nullValues))
|
||||
return false;
|
||||
Module::hookExec('afterSaveProduct', array('id_product' => $this->id));
|
||||
Hook::exec('afterSaveProduct', array('id_product' => $this->id));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($nullValues = false)
|
||||
{
|
||||
$return = parent::update($nullValues);
|
||||
Module::hookExec('afterSaveProduct', array('id_product' => $this->id));
|
||||
Hook::exec('afterSaveProduct', array('id_product' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -590,7 +590,7 @@ class ProductCore extends ObjectModel
|
||||
if (!GroupReduction::deleteProductReduction($this->id))
|
||||
return false;
|
||||
|
||||
Hook::deleteProduct($this);
|
||||
Hook::exec('deleteProduct', array('product' => $this));
|
||||
if (!parent::delete() OR
|
||||
!$this->deleteCategories(true) OR
|
||||
!$this->deleteImages() OR
|
||||
@@ -1061,7 +1061,7 @@ class ProductCore extends ObjectModel
|
||||
if (!Db::getInstance()->AutoExecute(_DB_PREFIX_.'product_attribute', $data, 'UPDATE', '`id_product_attribute` = '.(int)($id_product_attribute)) OR !Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_attribute_image` WHERE `id_product_attribute` = '.(int)($id_product_attribute)))
|
||||
return false;
|
||||
if ($quantity)
|
||||
Hook::updateProductAttribute($id_product_attribute);
|
||||
Hook::exec('updateProductAttribute', array('id_product_attribute' => $id_product_attribute));
|
||||
Product::updateDefaultAttribute($this->id);
|
||||
if (empty($id_images))
|
||||
return true;
|
||||
@@ -1094,7 +1094,7 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function deleteProductAttributes()
|
||||
{
|
||||
Module::hookExec('deleteProductAttribute', array('id_product_attribute' => 0, 'id_product' => $this->id, 'deleteAllAttributes' => true));
|
||||
Hook::exec('deleteProductAttribute', array('id_product_attribute' => 0, 'id_product' => $this->id, 'deleteAllAttributes' => true));
|
||||
|
||||
$result = Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
|
||||
@@ -1239,7 +1239,7 @@ class ProductCore extends ObjectModel
|
||||
if (!$this->id || !$id_product_attribute OR !is_numeric($id_product_attribute))
|
||||
return false;
|
||||
|
||||
Module::hookExec('deleteProductAttribute', array('id_product_attribute' => $id_product_attribute, 'id_product' => $this->id, 'deleteAllAttributes' => false));
|
||||
Hook::exec('deleteProductAttribute', array('id_product_attribute' => $id_product_attribute, 'id_product' => $this->id, 'deleteAllAttributes' => false));
|
||||
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product_attribute` = '.$id_product_attribute.'
|
||||
@@ -3257,7 +3257,7 @@ class ProductCore extends ObjectModel
|
||||
if ($stockMvt->add())
|
||||
{
|
||||
$this->quantity = $this->getStock();
|
||||
Hook::updateQuantity($this, null);
|
||||
Hook::exec('updateQuantity', array('product' => $this, 'order' => null));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
+1
-1
@@ -1526,7 +1526,7 @@ FileETag INode MTime Size
|
||||
fwrite($write_fd, "\n\n".trim($specific_after));
|
||||
fclose($write_fd);
|
||||
|
||||
Module::hookExec('afterCreateHtaccess');
|
||||
Hook::exec('afterCreateHtaccess');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user