Jump to content

Paypal with OrderInsurance Module [Solved]


akashheimlich

Recommended Posts

If any of you are using express checkout with PayPal and wish to use the OrderInsurance module for shipping which allows you to add a percentage to all items in case of loss of parcels, you can do it by modifying just one file: /modules/paypal/express_checkout/process.php

The workaround I found is to add the order insurance as an additional item - not perhaps the neatest way but it works fine.

Replace the function initParameters with the following (around line 117):

    private function initParameters()
    {
        if (!$this->context->cart || !$this->context->cart->id) {
            return false;
        }

        $cart_currency = new Currency((int) $this->context->cart->id_currency);
        $currency_module = $this->getCurrency((int) $this->context->cart->id_currency);

        if ($cart_currency !== $currency_module) {
            $this->context->cart->id_currency = $currency_module->id;
            $this->context->cart->update();
        }

        $this->context->currency = $currency_module;
        $this->product_list = $this->context->cart->getProducts(true);
      
       // Added by Akash on 26/1/18 - add order Insurance as a separate item
       
        require(_PS_MODULE_DIR_.'orderinsurance'.DIRECTORY_SEPARATOR.'orderinsurance.php');
       
        $orderInsurance = new OrderInsurance();
            
        $sql = 'SELECT inc.*, o.id_currency, o.total_paid
        FROM `'._DB_PREFIX_.'orderinsurance_cart` AS inc
        LEFT JOIN `'._DB_PREFIX_.'orders` o ON (inc.id_cart = o.id_cart)
        WHERE inc.id_cart='.$this->context->cart->id;
     
        $row = Db::getInstance()->getRow($sql);
        
        if ($row)
        {
            if ($row['active']) {
                
                $insurance_amount=$row['amount'];
             
                $item=array();
                $item['quantity']=1;
                $item['active']=1;
                $item['price']=$insurance_amount;
                $item['price_wt']=$insurance_amount;
                $item['name']='Seguridad';
                $this->product_list[]=$item;
                
            }
        }
        
        // end additions by Akash
        return (bool) count($this->product_list);
    }

 

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...