Exemplo n.º 1
0
 /**
  * Insert order in Certissim table, with the state concerned by the payment method and the configuration
  *
  * @param array $params
  * @return boolean
  */
 public function hookNewOrder($params)
 {
     //checks if the order already exists
     $sql_secure = "SELECT *\n\t\t\tFROM `" . _DB_PREFIX_ . self::CERTISSIM_ORDER_TABLE_NAME . "`\n\t\t\tWHERE `id_order`=" . $params['order']->id;
     $select = Db::getInstance()->execute($sql_secure);
     $count = Db::getInstance()->numRows();
     //if order exists, end of process
     if (!$select || $count > 0) {
         CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, "Erreur de verif existence order. Select = " . (string) $select . " et erreur = " . Db::getInstance()->getMsgError() . " ou commande déjà insérée (count =" . $count . ")");
         return false;
     }
     //lists all payment methods
     if (_PS_VERSION_ < '1.5') {
         $payments = $this->getInstalledPaymentModules();
     } else {
         $payments = PaymentModule::getPaymentModules();
     }
     //looks for the payment module used
     $found = false;
     $payment_name = $params['order']->module;
     while (!$found && ($payment = array_pop($payments))) {
         $found = $payment_name == $payment['name'];
     }
     //if module found
     if ($found) {
         //if PS 1.4 or lower
         if (_PS_VERSION_ < '1.5') {
             /** gets the id of the module * */
             $module = Module::getInstanceByName($payment['name']);
             $id_module = $module->id;
         } else {
             $id_module = $payment['id_module'];
         }
         CertissimLogger::insertLog(__METHOD__ . " : " . __LINE__, "Module détecté : {$payment_name}, 'CERTISSIM_" . $id_module . "_PAYMENT_TYPE' = " . Configuration::get('CERTISSIM_' . $id_module . '_PAYMENT_TYPE') . ", 'CERTISSIM_" . $id_module . "_PAYMENT_ENABLED' = " . Configuration::get('CERTISSIM_' . $id_module . '_PAYMENT_ENABLED'));
         //defines the state label according to the status of the payment module (activated for Certissim or not)
         $state_label = Configuration::get('CERTISSIM_' . $id_module . '_PAYMENT_ENABLED') == '1' ? 'ready to send' : 'not concerned';
         CertissimLogger::insertLog(__METHOD__ . " : " . __LINE__, "State sélectionné : {$state_label}");
     } else {
         //if module not found, end of process with log
         CertissimLogger::insertLog(__METHOD__ . " : " . __LINE__, "Erreur module paiement : module {$payment_name} non référencé dans liste (" . implode(', ', $payments) . "). Insertion commande annulée.");
         return false;
     }
     //gets the certissim_state
     $state_sql = "SELECT `id_certissim_state` FROM `" . _DB_PREFIX_ . self::CERTISSIM_STATE_TABLE_NAME . "` WHERE `label`='{$state_label}'";
     $state_id = Db::getInstance()->getValue($state_sql);
     //inserts the order into the certissim table with the state previously set
     self::insertCertissimOrder(array('id_order' => (int) $params['order']->id, 'id_certissim_state' => $state_id, 'customer_ip_address' => Tools::getRemoteAddr(), 'date' => date('Y-m-d H:i:s')));
     return true;
 }