Jump to content

43440 Klarna payment module - Exception on hookActionOrderHistoryAddAfter()


cristian71

Recommended Posts

Hi,

when I pay an order with Klarna module I obtain always an exception on line 424 on the hookActionOrderHistoryAddAfter() in klarnapaymentsofficial.php. I use Prestashop 1.7.8.2 on php 7.4. 

In debug I see that on the hook hookActionOrderHistoryAddAfter() is fired too early,  the following variables are nulls because the db table klarnapayments_orders are not updated yet: 

           $sql = "SELECT `id_order_klarna`, `capture_id`, `refund_id`  
                    FROM " . _DB_PREFIX_ . "klarnapayments_orders
                    WHERE id_order_presta = " . (int) $id_order;

            $klarnaOrder = Db::getInstance()->getRow($sql);

            $captureId = $klarnaOrder['capture_id'];  //<<<----- EXCEPTION BECAUSE $klarnaOrder IS FALSE
            $refundId = $klarnaOrder['refund_id'];
            $id_order_klarna = $klarnaOrder['id_order_klarna'];

The problem is that the klarna table is updated after module->ValidateOrder() is executed. But inside  module->ValidateOrder() the hookActionOrderHistoryAddAfter() is fired (in the addwithemail()).

How can I solve this problem?

Is it a configuration problem?

Thanks in advance

Cristian

Link to comment
Share on other sites

I downloaded the last version of klarna module.

To solve the exception I had to add the following code on the hookActionOrderHistoryAddAfter() function in klarnapaymentsofficial.php:

    public function hookActionOrderHistoryAddAfter($params)
    {
        $orderHistory = $params['order_history'];

        $new_id_order_state = (int) $orderHistory->id_order_state;
        $id_order = $orderHistory->id_order;
        
        if ($id_order < 1) {
            return;
        }

        if (Validate::isLoadedObject($orderHistory) && (int) $new_id_order_state !== (int) Configuration::get('KP_CAPTURE_ERROR')) {
            $sql = "SELECT `id_order_klarna`, `capture_id`, `refund_id`  
                    FROM " . _DB_PREFIX_ . "klarnapayments_orders
                    WHERE id_order_presta = " . (int) $id_order;

            $klarnaOrder = Db::getInstance()->getRow($sql);
            
            //-------------------
            // START FIX
          
            if (empty($klarnaOrder)){
                return;
            }
          
            // END FIX
            //-------------------

            $captureId = $klarnaOrder['capture_id'];
            $refundId = $klarnaOrder['refund_id'];
            $id_order_klarna = $klarnaOrder['id_order_klarna'];
          
           ......

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...