Plugin Directory

Changeset 2936334


Ignore:
Timestamp:
07/10/2023 06:10:44 AM (3 years ago)
Author:
kinguin
Message:

Vesrion 1.0.6

Location:
kinguin/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kinguin/trunk/README.txt

    r2777307 r2936334  
    44Tags: digital downloads, EDD, video games, marketplace, eStore, games distributing, gaming
    55Requires at least: 5.0
    6 Tested up to: 6.0.1
    7 Stable tag: 1.0.5
     6Tested up to: 6.2.2
     7Stable tag: 1.0.6
    88Requires PHP: 7.0
    99License: GPLv2
     
    5353== Changelog ==
    5454
     55= 1.0.6 =
     56* Reducing the import step for manual import to avoid interruption.
     57* Correction in the mechanism for sending keys for orders in the status 'on-hold'.
     58
    5559= 1.0.5 =
    5660* Divide products to categories during import.
  • kinguin/trunk/kinguin.php

    r2777307 r2936334  
    44    Description: Import over 70,000 digital products to your online store, including video games, software, gift cards and in-game content.
    55    Product: Kinguin
    6     Version: 1.0.5
     6    Version: 1.0.6
    77    Author: iLabs.dev
    88    Author URI: https://ilabs.dev/
     
    3434
    3535/* THESE TWO VARIABLES CAN BE CHANGED AUTOMATICALLY */
    36 $plugin_version     = '1.0.5';
     36$plugin_version     = '1.0.6';
    3737
    3838$plugin_name        = 'Kinguin';
  • kinguin/trunk/src/Plugin/Admin/Import.php

    r2777307 r2936334  
    4848    public function set_plugin_info( WPDesk_Plugin_Info $plugin_info ) {
    4949        $this->plugin_info            = $plugin_info;
    50         $this->limit                  = 35;
     50        $this->limit                  = 1;
    5151        $this->low_memory_limit_error = false;
    5252        $this->set_limit();
     
    131131                // between 256 Mb and 512 Mb
    132132                if ( $memory_limit >= 268435456 && $memory_limit < 536870912 ) {
    133                     $this->limit = 25;
     133                    //$this->limit = 25;
     134                    $this->limit = 1;
    134135                }
    135136                // between 160 Mb and 256 Mb
    136137                if ( $memory_limit >= 167772160 && $memory_limit < 268435456 ) {
    137                     $this->limit = 20;
     138                    //$this->limit = 20;
     139                    $this->limit = 1;
    138140                }
    139141                // lower than 160 Mb
  • kinguin/trunk/src/Plugin/Common/KeysEmail.php

    r2777307 r2936334  
    6565        $body = $this->get_email_message();
    6666        $keys = $this->order->get_meta( '_kinguin_keys' );
     67       
     68        if( ! $keys ) {
     69            return '';
     70        }
    6771
    6872        $body .= '<br>';
  • kinguin/trunk/src/Plugin/Common/OrderWebHook.php

    r2777307 r2936334  
    170170     */
    171171    private function set_order_status( string $status, \WC_Order $order, string $updated ) : array {
    172         $order->set_status( $status );
     172
     173        $current_order_status = $order->get_status();
     174
    173175        $order_details = $order->get_meta( '_kinguin_order' );
    174176
     
    189191
    190192            if ( 'completed' === $status ) {
    191                 try {
    192                     $mail = new KeysEmail( $order );
    193                     $mail->send();
    194                     $order->add_order_note( sprintf( __( 'Games keys has been sent to %s', 'kinguin' ), $mail->get_customer_email() ) );
    195                 } catch ( \Exception $e ) {
    196                     error_log( print_r( $e->getMessage(), true ) );
    197                 }
     193                if( 'completed' === $current_order_status || 'processing' === $current_order_status ) {
     194                    $this->send_keys_and_change_order_status( $order );
     195                }
    198196            }
    199197
     
    207205    }
    208206
     207
     208    public function kinguin_send_keys_only_on_paid_order( $order_id ) {
     209
     210        if ( ! $order_id ) {
     211            return;
     212        }
     213
     214        global $product;
     215        $order = wc_get_order( $order_id );
     216
     217        if ( $order->get_status() === 'processing' || $order->get_status() === 'completed' ) {
     218
     219            $kinguin_virtual_order = null;
     220            if ( count( $order->get_items() ) > 0 ) {
     221                foreach( $order->get_items() as $item ) {
     222                    if ( 'line_item' == $item['type'] ) {
     223                        $product_id = $item->get_product_id();
     224                       
     225                        $_product = wc_get_product( $product_id );
     226                        if( $_product && ! is_wp_error( $_product ) ) {
     227                            if ( ! $_product->is_virtual() ) {
     228                                // once we find one non-virtual product, break out of the loop
     229                                $kinguin_virtual_order = false;
     230                                break;
     231                            } else {
     232                                $sku_label = explode('-', $_product->get_sku())[0];
     233                                if ($sku_label === 'kinguin') {
     234                                    $kinguin_virtual_order = true;
     235                                }
     236                            }
     237                        }
     238                    }
     239                }
     240            }
     241            // if all are virtual kinguin products, send keys and mark as completed
     242            if ( $kinguin_virtual_order ) {
     243
     244                $this->send_keys_and_change_order_status( $order );
     245            }
     246        }
     247
     248    }
     249
     250
     251    public function send_keys_and_change_order_status( $order ) {
     252
     253        if ( ! $order ) {
     254            return;
     255        }
     256
     257        $current_order_status = $order->get_status();
     258
     259        if( ! $order->get_meta( '_kinguin_keys_sent' ) ) {
     260            try {
     261                $mail = new KeysEmail($order);
     262                $mail->send();
     263                $order->add_order_note(sprintf(__('Games keys has been sent to %s', 'kinguin'), $mail->get_customer_email()));
     264
     265                update_post_meta( $order->get_id(), '_kinguin_keys_sent', 1 );
     266
     267                if ('completed' !== $current_order_status) {
     268                    $order->update_status('wc-completed');
     269                }
     270
     271            } catch (\Exception $e) {
     272                error_log(print_r($e->getMessage(), true));
     273            }
     274        }
     275
     276    }
     277
    209278}
  • kinguin/trunk/src/Plugin/Plugin.php

    r2777307 r2936334  
    9696        add_action( 'rest_api_init', array( new OrderWebHook(), 'register_route' ) );
    9797        add_action( 'rest_api_init', array( new ProductWebHook(), 'register_route' ) );
     98
     99        add_action( 'woocommerce_order_status_changed', array( new OrderWebHook(), 'kinguin_send_keys_only_on_paid_order' ) );
    98100    }
    99101
Note: See TracChangeset for help on using the changeset viewer.