<?php
class ModelExtensionModuleYurticikargo extends Model {

    use MngArasYurticiTrait;

    public function cancelOrder($order_info, $order_status_id)
    {

        if($order_status_id == 7){

            $order_id = $order_info['order_id'];

            $results = $this->db->query("SELECT * FROM ps_order_yurticikargo WHERE order_id = '". $order_id ."' ")->row;

            if($results){

                if($results['sender_type'] == 3){
                    $wsUserName  = $this->config->get('yurticikargo_gonderici_odemeli_tahsilatli_teslimat_kullanici_adi');
                    $wsPassword = $this->config->get('yurticikargo_gonderici_odemeli_tahsilatli_teslimat_sifre');
                }else{
                    $wsUserName  = $this->config->get('yurticikargo_gonderici_odemeli_kullanici_adi');
                    $wsPassword = $this->config->get('yurticikargo_gonderici_odemeli_sifre');
                }

                $wsLanguage = 'TR';
                $talep_no = $results['kargo_barcode'];


                $serviceurl = 'http://webservices.yurticikargo.com:8080/KOPSWebServices/ShippingOrderDispatcherServices?wsdl';
                $client 	= new SoapClient($serviceurl);
                $send		= array('wsUserName' => $wsUserName, 'wsPassword' => $wsPassword, 'userLanguage' => $wsLanguage, 'cargoKeys' => $talep_no);

                $response = $client->cancelShipment($send);

                $this->db->query("DELETE FROM ps_order_yurticikargo WHERE order_id = '". $order_id ."' ");


            }



        }

    }

}