Advertisement
Guest User

hook.php diff

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