@@ -42,7 +42,7 @@ public function install() {
4242 return false ;
4343 }
4444
45- if (!parent ::install () || !$ this ->registerHook ('invoice ' ) || !$ this ->registerHook ('paymentReturn ' ) || !$ this ->registerHook ('payment ' ) || !$ this ->registerHook ('paymentOptions ' )) {
45+ if (!parent ::install () || !$ this ->registerHook ('invoice ' ) || !$ this ->registerHook ('paymentReturn ' ) || !$ this ->registerHook ('payment ' ) || !$ this ->registerHook ('paymentOptions ' ) || $ this -> addOrderState ( $ this -> l ( ' Procesando CryptoCompra ' )) ) {
4646 return false ;
4747 }
4848
@@ -214,12 +214,13 @@ public function execPayment($cart) {
214214 $ min_value = (float ) $ result ->data [0 ]->bid * 0.001 ;
215215 $ total_order = (float )$ cart ->getOrderTotal (true , Cart::BOTH );
216216
217- if ($ total_order > $ min_value ) {
217+ if ($ total_order > $ min_value ) {
218218 try {
219219 //create order
220220 $ customer = new Customer ($ cart ->id_customer );
221- $ this ->validateOrder ($ cart ->id , Configuration::get ('PS_OS_PREPARATION ' ), $ total_order , $ this ->displayName , NULL , NULL , (int )$ currency ->id , false , $ customer ->secure_key );
222-
221+ $ order_state = $ this ->getOrderState ('Procesando CryptoCompra ' );
222+ $ this ->validateOrder ($ cart ->id , $ order_state ['id_order_state ' ], $ total_order , $ this ->displayName , NULL , NULL , (int )$ currency ->id , false , $ customer ->secure_key );
223+
223224 if (_PS_VERSION_ <= '1.5 ' ) {
224225 $ success_url = (Configuration::get ('PS_SSL_ENABLED ' ) ? 'https:// ' : 'http:// ' ) . htmlspecialchars ($ _SERVER ['HTTP_HOST ' ], ENT_COMPAT , 'UTF-8 ' ) . __PS_BASE_URI__ . 'order-confirmation.php?id_cart= ' . $ cart ->id . '&id_module= ' . $ this ->id . '&id_order= ' . $ this ->currentOrder ;
225226 } else {
@@ -236,7 +237,7 @@ public function execPayment($cart) {
236237 'success_url ' => $ success_url ,
237238 'refund_email ' => $ this ->context ->customer ->email ,
238239 'language ' => strtolower (Configuration::get ('PS_LOCALE_LANGUAGE ' ))
239- );
240+ );
240241
241242 $ payload = $ client ->createPayOrder ($ payment );
242243
@@ -256,7 +257,6 @@ public function execPayment($cart) {
256257 }
257258 }
258259
259-
260260 public function linkToCryptoMkt () {
261261 $ cryptomarket_option = new PrestaShop \PrestaShop \Core \Payment \PaymentOption ();
262262 $ paymentGateway = $ this ->fetch ('module:cryptomarket/views/templates/front/payment_execution.tpl ' );
@@ -265,5 +265,52 @@ public function linkToCryptoMkt() {
265265 ->setAction (Configuration::get ('PS_FO_PROTOCOL ' ) . __PS_BASE_URI__ . "modules/ {$ this ->name }/payment.php " );
266266 return $ cryptomarket_option ;
267267 }
268+
269+ public function addOrderState ($ name ){
270+ $ state_exist = false ;
271+ $ states = OrderState::getOrderStates ((int )$ this ->context ->language ->id );
272+
273+ // check if order state exist
274+ foreach ($ states as $ state ) {
275+ if (in_array ($ name , $ state )) {
276+ $ state_exist = true ;
277+ break ;
278+ }
279+ }
280+
281+ // If the state does not exist, we create it.
282+ if (!$ state_exist ) {
283+ // create new order state
284+ $ order_state = new OrderState ();
285+ $ order_state ->color = '#00ffff ' ;
286+ $ order_state ->send_email = true ;
287+ $ order_state ->module_name = $ this ->name ;
288+ $ order_state ->template = 'preparation ' ;
289+ $ order_state ->name = array ();
290+ $ languages = Language::getLanguages (false );
291+ foreach ($ languages as $ language )
292+ $ order_state ->name [ $ language ['id_lang ' ] ] = $ name ;
293+
294+ // Update object
295+ $ order_state ->add ();
296+ }
297+
298+ return true ;
299+ }
300+
301+ public function getOrderState ($ name ){
302+ $ state = false ;
303+ $ states = OrderState::getOrderStates ((int )$ this ->context ->language ->id );
304+
305+ // check if order state exist
306+ foreach ($ states as $ state ) {
307+ if (in_array ($ name , $ state )) {
308+ $ state = $ state ;
309+ break ;
310+ }
311+ }
312+
313+ return $ state ;
314+ }
268315}
269- ?>
316+ ?>
0 commit comments