Search code examples
hookprestashop-1.6

How could I get a list of hooks in checkout process of prestashop?


I want to create a custom module, which log some activity of prestashop. For instance, when ever an order get complete, I log the user id, time, amount and device.

For this matter I think I have to use the hook which be called after placing an order; however, I couldn't find a source that listed all the hooks related to checkout process or order creation. Could any one help me to find the hook responsible for this job, or provide me by some resource of prestashop 1.6 hooks


Solution

  • I found it and maybe it could be useful for others: first of all I added two hook to my install and two constatnts:

    const HOOK_NEW_ORDER = 1;
    const HOOK_ACTION_ORDER_STATUS_POST_UPDATE = 2;
    

    actionValidateOrder & actionOrderStatusPostUpdate

    if (!parent::install() ||
                !$this->registerHook('actionValidateOrder') ||
                !$this->registerHook('actionOrderStatusPostUpdate') ||
                !Configuration::updateValue('AR_ADMIN_CLUB', 'customer club') ||
                !$this->installModuleTab() ||
                !$this->installDB() ||
                !$this->registerHook("displayBackOfficeHeader") ||
                !$this->insertInitData() ||
                !$this->createFolders()
            )
    

    then I added two method to handle these hooks:

    public function hookActionValidateOrder($params)
        {
            if (Module::isEnabled($this->name)) {
                $this->hookOrderProcess(self::HOOK_NEW_ORDER, $params);
            }
        }
    

    and

    public function hookActionOrderStatusPostUpdate($params)
        {
            if (Module::isEnabled($this->name) && (!isset($GLOBALS['hookNewOrder']) || $GLOBALS['hookNewOrder'] != 1)) {
                $this->hookOrderProcess(self::HOOK_ACTION_ORDER_STATUS_POST_UPDATE, $params);
            }
        }
    

    finally I added the method to do the actions I needed, based on every order status changes:

    private function hookOrderProcess($hook, $params)
        {
            if ($hook == self::HOOK_NEW_ORDER) {
                $id_shop   = $params['order']->id_shop;
                $shop_name = $shop_info->name;
                $GLOBALS['hookNewOrder'] = 1;
            } elseif ($hook == self::HOOK_ACTION_ORDER_STATUS_POST_UPDATE) {
                $order_id = $params['id_order'];
                $order_info        = new Order($params['id_order']);
                $id_shop           = $order_info->id_shop;
                $shop_info         = new Shop($id_shop);
                $order_status = $order_info->getCurrentState();
    
                $customer_id = $order_info->getCustomer()->id;
                $group_id = $order_info->getCustomer()->id_default_group;
                if($order_status == 5){
    
                    $this->actoin_first($order_id, $group_id, $customer_id);
    
                } elseif($order_status == 6){
                    $this->actoin_second($order_id, $group_id, $customer_id,'all');
    
                }elseif($order_status == 7){
                    $this->actoin_third($order_id, $group_id, $customer_id);
                }
            }
        }