Guest User

hook.php orig

a guest
Sep 28th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.00 KB | None | 0 0
  1. <?php
  2. /*
  3. * 2007-2013 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to [email protected] so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. *  @author PrestaShop SA <[email protected]>
  22. *  @copyright  2007-2013 PrestaShop SA
  23. *  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  24. *  International Registered Trademark & Property of PrestaShop SA
  25. */
  26.  
  27. class HookCore extends ObjectModel
  28. {
  29.     /**
  30.      * @var string Hook name identifier
  31.      */
  32.     public $name;
  33.  
  34.     /**
  35.      * @var string Hook title (displayed in BO)
  36.      */
  37.     public $title;
  38.  
  39.     /**
  40.      * @var string Hook description
  41.      */
  42.     public $description;
  43.  
  44.     /**
  45.      * @var bool
  46.      */
  47.     public $position = false;
  48.  
  49.     /**
  50.      * @var bool Is this hook usable with live edit ?
  51.      */
  52.     public $live_edit = false;
  53.  
  54.     /**
  55.      * @var array List of executed hooks on this page
  56.      */
  57.     public static $executed_hooks = array();
  58.  
  59.     /**
  60.      * @see ObjectModel::$definition
  61.      */
  62.     public static $definition = array(
  63.         'table' => 'hook',
  64.         'primary' => 'id_hook',
  65.         'fields' => array(
  66.             'name' =>           array('type' => self::TYPE_STRING, 'validate' => 'isHookName', 'required' => true, 'size' => 64),
  67.             'title' =>          array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
  68.             'description' =>    array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml'),
  69.             'position' =>       array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
  70.             'live_edit' =>  array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
  71.         ),
  72.     );
  73.  
  74.     /**
  75.      * @deprecated 1.5.0
  76.      */
  77.     protected static $_hook_modules_cache = null;
  78.  
  79.     /**
  80.      * @deprecated 1.5.0
  81.      */
  82.     protected static $_hook_modules_cache_exec = null;
  83.  
  84.     public function add($autodate = true, $null_values = false)
  85.     {
  86.         Cache::clean('hook_idsbyname');
  87.         return parent::add($autodate, $null_values);
  88.     }
  89.  
  90.     /**
  91.      * Return Hooks List
  92.      *
  93.      * @param bool $position
  94.      * @return array Hooks List
  95.      */
  96.     public static function getHooks($position = false)
  97.     {
  98.         return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
  99.             SELECT * FROM `'._DB_PREFIX_.'hook` h
  100.             '.($position ? 'WHERE h.`position` = 1' : '').'
  101.             ORDER BY `name`'
  102.         );
  103.     }
  104.  
  105.     /**
  106.      * Return hook ID from name
  107.      *
  108.      * @param string $hook_name Hook name
  109.      * @return int Hook ID
  110.      */
  111.     public static function getIdByName($hook_name)
  112.     {
  113.         $hook_name = strtolower($hook_name);
  114.         if (!Validate::isHookName($hook_name))
  115.             return false;
  116.  
  117.         $cache_id = 'hook_idsbyname';
  118.         if (!Cache::isStored($cache_id))
  119.         {
  120.             // Get all hook ID by name and alias
  121.             $hook_ids = array();
  122.             $result = Db::getInstance()->ExecuteS('
  123.             SELECT `id_hook`, `name`
  124.             FROM `'._DB_PREFIX_.'hook`
  125.             UNION
  126.             SELECT `id_hook`, ha.`alias` as name
  127.             FROM `'._DB_PREFIX_.'hook_alias` ha
  128.             INNER JOIN `'._DB_PREFIX_.'hook` h ON ha.name = h.name');
  129.             foreach ($result as $row)
  130.                 $hook_ids[strtolower($row['name'])] = $row['id_hook'];         
  131.             Cache::store($cache_id, $hook_ids);
  132.         }
  133.         else
  134.             $hook_ids = Cache::retrieve($cache_id);
  135.  
  136.         return (isset($hook_ids[$hook_name]) ? $hook_ids[$hook_name] : false);
  137.     }
  138.  
  139.     /**
  140.      * Return hook ID from name
  141.      */
  142.     public static function getNameById($hook_id)
  143.     {
  144.         $cache_id = 'hook_namebyid_'.$hook_id;
  145.         if (!Cache::isStored($cache_id))
  146.             Cache::store($cache_id, Db::getInstance()->getValue('
  147.                 SELECT `name`
  148.                 FROM `'._DB_PREFIX_.'hook`
  149.                 WHERE `id_hook` = '.(int)$hook_id)
  150.             );
  151.         return Cache::retrieve($cache_id);
  152.     }
  153.    
  154.     /**
  155.      * Return hook live edit bool from ID
  156.      */
  157.     public static function getLiveEditById($hook_id)
  158.     {
  159.         $cache_id = 'hook_live_editbyid_'.$hook_id;
  160.         if (!Cache::isStored($cache_id))
  161.             Cache::store($cache_id, Db::getInstance()->getValue('
  162.                 SELECT `live_edit`
  163.                 FROM `'._DB_PREFIX_.'hook`
  164.                 WHERE `id_hook` = '.(int)$hook_id)
  165.             );
  166.         return Cache::retrieve($cache_id);
  167.     }  
  168.  
  169.     /**
  170.      * Get list of hook alias
  171.      *
  172.      * @since 1.5.0
  173.      * @return array
  174.      */
  175.     public static function getHookAliasList()
  176.     {
  177.         $cache_id = 'hook_alias';
  178.         if (!Cache::isStored($cache_id))
  179.         {
  180.             $hook_alias_list = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'hook_alias`');
  181.             $hook_alias = array();
  182.             if ($hook_alias_list)
  183.                 foreach ($hook_alias_list as $ha)
  184.                     $hook_alias[strtolower($ha['alias'])] = $ha['name'];
  185.             Cache::store($cache_id, $hook_alias);
  186.         }
  187.         return Cache::retrieve($cache_id);
  188.     }
  189.  
  190.     /**
  191.      * Return retrocompatible hook name
  192.      *
  193.      * @since 1.5.0
  194.      * @param string $hook_name Hook name
  195.      * @return int Hook ID
  196.      */
  197.     public static function getRetroHookName($hook_name)
  198.     {
  199.         $alias_list = Hook::getHookAliasList();
  200.         if (isset($alias_list[strtolower($hook_name)]))
  201.             return $alias_list[strtolower($hook_name)];
  202.  
  203.         $retro_hook_name = array_search($hook_name, $alias_list);
  204.         if ($retro_hook_name === false)
  205.             return '';
  206.         return $retro_hook_name;
  207.     }
  208.  
  209.     /**
  210.      * Get list of all registered hooks with modules
  211.      *
  212.      * @since 1.5.0
  213.      * @return array
  214.      */
  215.     public static function getHookModuleList()
  216.     {
  217.         $cache_id = 'hook_module_list';
  218.         if (!Cache::isStored($cache_id))
  219.         {
  220.             $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
  221.             SELECT h.id_hook, h.name as h_name, title, description, h.position, live_edit, hm.position as hm_position, m.id_module, m.name, active
  222.             FROM `'._DB_PREFIX_.'hook` h
  223.             INNER JOIN `'._DB_PREFIX_.'hook_module` hm ON (h.id_hook = hm.id_hook AND hm.id_shop = '.(int)Context::getContext()->shop->id.')
  224.             INNER JOIN `'._DB_PREFIX_.'module` as m ON (m.id_module = hm.id_module)
  225.             ORDER BY hm.position');
  226.             $list = array();
  227.             foreach ($results as $result)
  228.             {
  229.                 if (!isset($list[$result['id_hook']]))
  230.                     $list[$result['id_hook']] = array();
  231.  
  232.                 $list[$result['id_hook']][$result['id_module']] = array(
  233.                     'id_hook' => $result['id_hook'],
  234.                     'title' => $result['title'],
  235.                     'description' => $result['description'],
  236.                     'hm.position' => $result['position'],
  237.                     'live_edit' => $result['live_edit'],
  238.                     'm.position' => $result['hm_position'],
  239.                     'id_module' => $result['id_module'],
  240.                     'name' => $result['name'],
  241.                     'active' => $result['active'],
  242.                 );
  243.             }
  244.             Cache::store($cache_id, $list);
  245.  
  246.             // @todo remove this in 1.6, we keep it in 1.5 for retrocompatibility
  247.             Hook::$_hook_modules_cache = $list;
  248.         }
  249.  
  250.         return Cache::retrieve($cache_id);
  251.     }
  252.  
  253.     /**
  254.      * Return Hooks List
  255.      *
  256.      * @since 1.5.0
  257.      * @param int $id_hook
  258.      * @param int $id_module
  259.      * @return array Modules List
  260.      */
  261.     public static function getModulesFromHook($id_hook, $id_module = null)
  262.     {
  263.         $hm_list = Hook::getHookModuleList();
  264.         $module_list = (isset($hm_list[$id_hook])) ? $hm_list[$id_hook] : array();
  265.  
  266.         if ($id_module)
  267.             return (isset($module_list[$id_module])) ? array($module_list[$id_module]) : array();
  268.         return $module_list;
  269.     }
  270.  
  271.     /**
  272.      * Get list of modules we can execute per hook
  273.      *
  274.      * @since 1.5.0
  275.      * @param string $hook_name Get list of modules for this hook if given
  276.      * @return array
  277.      */
  278.     public static function getHookModuleExecList($hook_name = null)
  279.     {
  280.         $context = Context::getContext();
  281.         $cache_id = 'hook_module_exec_list'.((isset($context->customer)) ? '_'.$context->customer->id : '');
  282.         if (!Cache::isStored($cache_id) || $hook_name == 'displayPayment')
  283.         {
  284.             $frontend = true;
  285.             $groups = array();
  286.             if (isset($context->employee))
  287.             {
  288.                 $shop_list = array((int)$context->shop->id);
  289.                 $frontend = false;
  290.             }
  291.             else
  292.             {
  293.                 // Get shops and groups list
  294.                 $shop_list = Shop::getContextListShopID();
  295.                 if (isset($context->customer) && $context->customer->isLogged())
  296.                     $groups = $context->customer->getGroups();
  297.                 elseif (isset($context->customer) && $context->customer->isLogged(true))
  298.                     $groups = array((int)Configuration::get('PS_GUEST_GROUP'));
  299.                 else
  300.                     $groups = array((int)Configuration::get('PS_UNIDENTIFIED_GROUP'));
  301.             }
  302.            
  303.             // SQL Request
  304.             $sql = new DbQuery();
  305.             $sql->select('h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit`');
  306.             $sql->from('module', 'm');
  307.             $sql->innerJoin('hook_module', 'hm', 'hm.`id_module` = m.`id_module`');
  308.             $sql->innerJoin('hook', 'h', 'hm.`id_hook` = h.`id_hook`');
  309.             $sql->where('(SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN ('.implode(', ', $shop_list).')) = '.count($shop_list));
  310.             if ($hook_name != 'displayPayment')
  311.                 $sql->where('h.name != "displayPayment"');
  312.             // For payment modules, we check that they are available in the contextual country
  313.             elseif ($frontend)
  314.             {
  315.                 $sql->where(Module::getPaypalIgnore());
  316.                 if (Validate::isLoadedObject($context->country))
  317.                     $sql->where('(h.name = "displayPayment" AND (SELECT id_country FROM '._DB_PREFIX_.'module_country mc WHERE mc.id_module = m.id_module AND id_country = '.(int)$context->country->id.' AND id_shop = '.(int)$context->shop->id.' LIMIT 1) = '.(int)$context->country->id.')');
  318.                 if (Validate::isLoadedObject($context->currency))
  319.                     $sql->where('(h.name = "displayPayment" AND (SELECT id_currency FROM '._DB_PREFIX_.'module_currency mcr WHERE mcr.id_module = m.id_module AND id_currency IN ('.(int)$context->currency->id.', -2) LIMIT 1) IN ('.(int)$context->currency->id.', -2))');
  320.             }
  321.             if (Validate::isLoadedObject($context->shop))
  322.                 $sql->where('hm.id_shop = '.(int)$context->shop->id);
  323.  
  324.             if ($frontend)
  325.             {
  326.                 $sql->leftJoin('module_group', 'mg', 'mg.`id_module` = m.`id_module`');
  327.                 $sql->where('mg.`id_group` IN ('.implode(', ', $groups).')');
  328.                 $sql->groupBy('hm.id_hook, hm.id_module');
  329.             }
  330.  
  331.             $sql->orderBy('hm.`position`');
  332.  
  333.             $list = array();
  334.             if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
  335.                 foreach ($result as $row)
  336.                 {
  337.                     $row['hook'] = strtolower($row['hook']);
  338.                     if (!isset($list[$row['hook']]))
  339.                         $list[$row['hook']] = array();
  340.  
  341.                     $list[$row['hook']][] = array(
  342.                         'id_hook' => $row['id_hook'],
  343.                         'module' => $row['module'],
  344.                         'id_module' => $row['id_module'],
  345.                         'live_edit' => $row['live_edit'],
  346.                     );
  347.                 }
  348.             if ($hook_name != 'displayPayment')
  349.             {
  350.                 Cache::store($cache_id, $list);
  351.                 // @todo remove this in 1.6, we keep it in 1.5 for retrocompatibility
  352.                 self::$_hook_modules_cache_exec = $list;
  353.             }
  354.         }
  355.         else
  356.             $list = Cache::retrieve($cache_id);
  357.  
  358.         // If hook_name is given, just get list of modules for this hook
  359.         if ($hook_name)
  360.         {
  361.             $retro_hook_name = Hook::getRetroHookName($hook_name);
  362.             $hook_name = strtolower($hook_name);
  363.  
  364.             $return = array();
  365.             $inserted_modules = array();
  366.             if (isset($list[$hook_name]))
  367.                 $return = $list[$hook_name];
  368.             foreach ($return as $module)
  369.                 $inserted_modules[] = $module['id_module'];
  370.             if (isset($list[$retro_hook_name]))
  371.                 foreach ($list[$retro_hook_name] as $retro_module_call)
  372.                     if (!in_array($retro_module_call['id_module'], $inserted_modules))
  373.                         $return[] = $retro_module_call;
  374.  
  375.             return (count($return) > 0 ? $return : false);
  376.         }
  377.         else
  378.             return $list;
  379.     }
  380.  
  381.     /**
  382.      * Execute modules for specified hook
  383.      *
  384.      * @param string $hook_name Hook Name
  385.      * @param array $hook_args Parameters for the functions
  386.      * @param int $id_module Execute hook for this module only
  387.      * @return string modules output
  388.      */
  389.     public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true)
  390.     {
  391.         // Check arguments validity
  392.         if (($id_module && !is_numeric($id_module)) || !Validate::isHookName($hook_name))
  393.             throw new PrestaShopException('Invalid id_module or hook_name');
  394.  
  395.         // If no modules associated to hook_name or recompatible hook name, we stop the function
  396.        
  397.         if (!$module_list = Hook::getHookModuleExecList($hook_name))
  398.             return '';
  399.  
  400.         // Check if hook exists
  401.         if (!$id_hook = Hook::getIdByName($hook_name))
  402.             return false;
  403.  
  404.         // Store list of executed hooks on this page
  405.         Hook::$executed_hooks[$id_hook] = $hook_name;
  406.  
  407.         $live_edit = false;
  408.         $context = Context::getContext();
  409.         if (!isset($hook_args['cookie']) || !$hook_args['cookie'])
  410.             $hook_args['cookie'] = $context->cookie;
  411.         if (!isset($hook_args['cart']) || !$hook_args['cart'])
  412.             $hook_args['cart'] = $context->cart;
  413.  
  414.         $retro_hook_name = Hook::getRetroHookName($hook_name);
  415.  
  416.         // Look on modules list
  417.         $altern = 0;
  418.         $output = '';
  419.                        
  420.         foreach ($module_list as $array)
  421.         {
  422.             // Check errors
  423.             if ($id_module && $id_module != $array['id_module'])
  424.                 continue;
  425.             if (!($moduleInstance = Module::getInstanceByName($array['module'])))
  426.                 continue;
  427.  
  428.             // Check permissions
  429.             if ($check_exceptions)
  430.             {
  431.                 $exceptions = $moduleInstance->getExceptions($array['id_hook']);
  432.                 $controller = Dispatcher::getInstance()->getController();
  433.  
  434.                 if (in_array($controller, $exceptions))
  435.                     continue;
  436.                
  437.                 //retro compat of controller names
  438.                 $matching_name = array(
  439.                     'authentication' => 'auth',
  440.                     'compare' => 'products-comparison',
  441.                 );
  442.                 if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions))
  443.                     continue;
  444.                 if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee))
  445.                     continue;
  446.             }
  447.  
  448.             // Check which / if method is callable
  449.             $hook_callable = is_callable(array($moduleInstance, 'hook'.$hook_name));
  450.             $hook_retro_callable = is_callable(array($moduleInstance, 'hook'.$retro_hook_name));
  451.             if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name))
  452.             {
  453.                 $hook_args['altern'] = ++$altern;
  454.  
  455.                 // Call hook method
  456.                 if ($hook_callable)
  457.                     $display = $moduleInstance->{'hook'.$hook_name}($hook_args);
  458.                 else if ($hook_retro_callable)
  459.                     $display = $moduleInstance->{'hook'.$retro_hook_name}($hook_args);
  460.                 // Live edit
  461.                 if (!$array_return && $array['live_edit'] && Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getValue('liveToken') == Tools::getAdminToken('AdminModulesPositions'.(int)Tab::getIdFromClassName('AdminModulesPositions').(int)Tools::getValue('id_employee')))
  462.                 {
  463.                     $live_edit = true;
  464.                     $output .= self::wrapLiveEdit($display, $moduleInstance, $array['id_hook']);
  465.                 }
  466.                 else if ($array_return)
  467.                     $output[] = $display;
  468.                 else
  469.                     $output .= $display;
  470.             }
  471.         }
  472.         if ($array_return)
  473.             return $output;
  474.         else
  475.             return ($live_edit ? '<script type="text/javascript">hooks_list.push(\''.$hook_name.'\');</script>
  476.                 <div id="'.$hook_name.'" class="dndHook" style="min-height:50px">' : '').$output.($live_edit ? '</div>' : '');// Return html string
  477.     }
  478.  
  479.     public static function wrapLiveEdit($display, $moduleInstance, $id_hook)
  480.     {
  481.         return '<script type="text/javascript"> modules_list.push(\''.Tools::safeOutput($moduleInstance->name).'\');</script>
  482.                 <div id="hook_'.(int)$id_hook.'_module_'.(int)$moduleInstance->id.'_moduleName_'.str_replace('_', '-', Tools::safeOutput($moduleInstance->name)).'"
  483.                 class="dndModule" style="border: 1px dotted red;'.(!strlen($display) ? 'height:50px;' : '').'">
  484.                     <span style="font-family: Georgia;font-size:13px;font-style:italic;">
  485.                         <img style="padding-right:5px;" src="'._MODULE_DIR_.Tools::safeOutput($moduleInstance->name).'/logo.gif">'
  486.                 .Tools::safeOutput($moduleInstance->displayName).'<span style="float:right">
  487.                 <a href="#" id="'.(int)$id_hook.'_'.(int)$moduleInstance->id.'" class="moveModule">
  488.                     <img src="'._PS_ADMIN_IMG_.'arrow_out.png"></a>
  489.                 <a href="#" id="'.(int)$id_hook.'_'.(int)$moduleInstance->id.'" class="unregisterHook">
  490.                     <img src="'._PS_ADMIN_IMG_.'delete.gif"></a></span>
  491.                 </span>'.$display.'</div>';
  492.     }
  493.  
  494.  
  495.     /**
  496.      * @deprecated 1.5.0
  497.      */
  498.     public static function updateOrderStatus($newOrderStatusId, $id_order)
  499.     {
  500.         Tools::displayAsDeprecated();
  501.         $order = new Order((int)($id_order));
  502.         $newOS = new OrderState((int)($newOrderStatusId), $order->id_lang);
  503.  
  504.         $return = ((int)($newOS->id) == Configuration::get('PS_OS_PAYMENT')) ? Hook::exec('paymentConfirm', array('id_order' => (int)($order->id))) : true;
  505.         $return = Hook::exec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id))) && $return;
  506.         return $return;
  507.     }
  508.  
  509.     /**
  510.      * @deprecated 1.5.0
  511.      */
  512.     public static function postUpdateOrderStatus($newOrderStatusId, $id_order)
  513.     {
  514.         Tools::displayAsDeprecated();
  515.         $order = new Order((int)($id_order));
  516.         $newOS = new OrderState((int)($newOrderStatusId), $order->id_lang);
  517.         $return = Hook::exec('postUpdateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id)));
  518.         return $return;
  519.     }
  520.  
  521.     /**
  522.      * @deprecated 1.5.0
  523.      */
  524.     public static function orderConfirmation($id_order)
  525.     {
  526.         Tools::displayAsDeprecated();
  527.         if (Validate::isUnsignedId($id_order))
  528.         {
  529.             $params = array();
  530.             $order = new Order((int)$id_order);
  531.             $currency = new Currency((int)$order->id_currency);
  532.  
  533.             if (Validate::isLoadedObject($order))
  534.             {
  535.                 $cart = new Cart((int)$order->id_cart);
  536.                 $params['total_to_pay'] = $cart->getOrderTotal();
  537.                 $params['currency'] = $currency->sign;
  538.                 $params['objOrder'] = $order;
  539.                 $params['currencyObj'] = $currency;
  540.  
  541.                 return Hook::exec('orderConfirmation', $params);
  542.             }
  543.         }
  544.         return false;
  545.     }
  546.  
  547.     /**
  548.      * @deprecated 1.5.0
  549.      */
  550.     public static function paymentReturn($id_order, $id_module)
  551.     {
  552.         Tools::displayAsDeprecated();
  553.         if (Validate::isUnsignedId($id_order) && Validate::isUnsignedId($id_module))
  554.         {
  555.             $params = array();
  556.             $order = new Order((int)($id_order));
  557.             $currency = new Currency((int)($order->id_currency));
  558.  
  559.             if (Validate::isLoadedObject($order))
  560.             {
  561.                 $cart = new Cart((int)$order->id_cart);
  562.                 $params['total_to_pay'] = $cart->getOrderTotal();
  563.                 $params['currency'] = $currency->sign;
  564.                 $params['objOrder'] = $order;
  565.                 $params['currencyObj'] = $currency;
  566.  
  567.                 return Hook::exec('paymentReturn', $params, (int)($id_module));
  568.             }
  569.         }
  570.         return false;
  571.     }
  572.  
  573.     /**
  574.      * @deprecated 1.5.0
  575.      */
  576.     public static function PDFInvoice($pdf, $id_order)
  577.     {
  578.         Tools::displayAsDeprecated();
  579.         if (!is_object($pdf) || !Validate::isUnsignedId($id_order))
  580.             return false;
  581.         return Hook::exec('PDFInvoice', array('pdf' => $pdf, 'id_order' => $id_order));
  582.     }
  583.  
  584.     /**
  585.      * @deprecated 1.5.0
  586.      */
  587.     public static function backBeforePayment($module)
  588.     {
  589.         Tools::displayAsDeprecated();
  590.         $params['module'] = strval($module);
  591.         if (!$params['module'])
  592.             return false;
  593.         return Hook::exec('backBeforePayment', $params);
  594.     }
  595.  
  596.     /**
  597.      * @deprecated 1.5.0
  598.      */
  599.     public static function updateCarrier($id_carrier, $carrier)
  600.     {
  601.         Tools::displayAsDeprecated();
  602.         if (!Validate::isUnsignedId($id_carrier) || !is_object($carrier))
  603.             return false;
  604.         return Hook::exec('updateCarrier', array('id_carrier' => $id_carrier, 'carrier' => $carrier));
  605.     }
  606.  
  607.     /**
  608.      * Preload hook modules cache
  609.      *
  610.      * @deprecated 1.5.0 use Hook::getHookModuleList() instead
  611.      * @return boolean preload_needed
  612.      */
  613.     public static function preloadHookModulesCache()
  614.     {
  615.         Tools::displayAsDeprecated();
  616.  
  617.         if (!is_null(self::$_hook_modules_cache))
  618.             return false;
  619.  
  620.         self::$_hook_modules_cache = Hook::getHookModuleList();
  621.         return true;
  622.     }
  623.  
  624.     /**
  625.      * Return hook ID from name
  626.      *
  627.      * @param string $hookName Hook name
  628.      * @return integer Hook ID
  629.      *
  630.      * @deprecated since 1.5.0 use Hook::getIdByName() instead
  631.      */
  632.     public static function get($hookName)
  633.     {
  634.         Tools::displayAsDeprecated();
  635.         if (!Validate::isHookName($hookName))
  636.             die(Tools::displayError());
  637.  
  638.         $result = Db::getInstance()->getRow('
  639.         SELECT `id_hook`, `name`
  640.         FROM `'._DB_PREFIX_.'hook`
  641.         WHERE `name` = \''.pSQL($hookName).'\'');
  642.  
  643.         return ($result ? $result['id_hook'] : false);
  644.     }
  645.  
  646.     /**
  647.      * Called when quantity of a product is updated.
  648.      *
  649.      * @param Product
  650.      * @param Order
  651.      */
  652.     public static function newOrder($cart, $order, $customer, $currency, $orderStatus)
  653.     {
  654.         Tools::displayAsDeprecated();
  655.         return Hook::exec('newOrder', array(
  656.             'cart' => $cart,
  657.             'order' => $order,
  658.             'customer' => $customer,
  659.             'currency' => $currency,
  660.             'orderStatus' => $orderStatus));
  661.     }
  662.  
  663.     /**
  664.      * @deprecated 1.5.0
  665.      */
  666.     public static function updateQuantity($product, $order = null)
  667.     {
  668.         Tools::displayAsDeprecated();
  669.         return Hook::exec('updateQuantity', array('product' => $product, 'order' => $order));
  670.     }
  671.  
  672.     /**
  673.      * @deprecated 1.5.0
  674.      */
  675.     public static function productFooter($product, $category)
  676.     {
  677.         Tools::displayAsDeprecated();
  678.         return Hook::exec('productFooter', array('product' => $product, 'category' => $category));
  679.     }
  680.  
  681.     /**
  682.      * @deprecated 1.5.0
  683.      */
  684.     public static function productOutOfStock($product)
  685.     {
  686.         Tools::displayAsDeprecated();
  687.         return Hook::exec('productOutOfStock', array('product' => $product));
  688.     }
  689.  
  690.     /**
  691.      * @deprecated 1.5.0
  692.      */
  693.     public static function addProduct($product)
  694.     {
  695.         Tools::displayAsDeprecated();
  696.         return Hook::exec('addProduct', array('product' => $product));
  697.     }
  698.  
  699.     /**
  700.      * @deprecated 1.5.0
  701.      */
  702.     public static function updateProduct($product)
  703.     {
  704.         Tools::displayAsDeprecated();
  705.         return Hook::exec('updateProduct', array('product' => $product));
  706.     }
  707.  
  708.     /**
  709.      * @deprecated 1.5.0
  710.      */
  711.     public static function deleteProduct($product)
  712.     {
  713.         Tools::displayAsDeprecated();
  714.         return Hook::exec('deleteProduct', array('product' => $product));
  715.     }
  716.  
  717.     /**
  718.      * @deprecated 1.5.0
  719.      */
  720.     public static function updateProductAttribute($id_product_attribute)
  721.     {
  722.         Tools::displayAsDeprecated();
  723.         return Hook::exec('updateProductAttribute', array('id_product_attribute' => $id_product_attribute));
  724.     }
  725. }
Advertisement
Add Comment
Please, Sign In to add comment