Plugin Directory

Changeset 2768442


Ignore:
Timestamp:
08/09/2022 03:12:33 PM (4 years ago)
Author:
nappssolutions
Message:

New trunk version 1.0.7

Location:
napps/trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • napps/trunk/includes/class-woocommerce.php

    r2726253 r2768442  
    1111    exit; // Exit if accessed directly
    1212}
    13 
     13use WC_Shipping_Zone;
    1414use WC_Shipping_Zones;
    1515use WC_Webhook;
     
    2424
    2525        private $initiated = false;
     26        private $qtranslateModule;
    2627
    2728        /**
     
    3435        }
    3536       
     37
    3638        /**
    3739         * Init hooks
     
    4951
    5052            add_action( 'woocommerce_rest_insert_shop_order_object', array( $this, 'on_rest_new_order' ), 10, 2);
    51             add_action( 'rest_api_init', array( $this, 'on_rest_api_init' ));
     53            add_action( 'woocommerce_shipping_init', array($this, 'woocoomerceInitShipping' ));
     54            add_filter( 'woocommerce_shipping_methods', array($this, 'woocoomerceLoadShipping' ) );
     55
     56            // Check if we need to include qtranslate module
     57            if(in_array('qtranslate-xt/qtranslate.php', apply_filters('active_plugins', get_option('active_plugins')))){
     58                require_once 'modules/qtranslate.php';
     59                $this->qtranslateModule = new NappsQtranslate();
     60            }
    5261
    5362            if(is_admin())
     
    6675                add_action( 'woocommerce_init', array( $this, 'woocommerce_init' ), 10, 0 );
    6776                add_action( 'woocommerce_admin_order_data_after_order_details', array( $this, 'woocommerce_is_napps_admin_order_fields'), 10, 1 );
    68                
     77
    6978            }
    7079
    7180            if(is_admin() || napps_doing_cron()) {
    72                 add_action( 'woocommerce_deliver_webhook_async', array( $this, 'woocommerce_deliver_webhook_async' ), 10, 2 );
    7381                add_action( 'woocommerce_webhook_payload', array( $this, 'woocommerce_webhook_payload' ), 10, 4);
    7482            }
    7583        }
    7684
    77         /*
    78         *   Apply filters before rest api
    79         *   so we can get the correct field based on the default language
    80         */
    81         public function on_rest_api_init() {
    82             if($this->isQTranslateActive()) {
    83 
    84                 add_filter( 'woocommerce_rest_prepare_product_attribute', array( $this, 'woocommerce_rest_product_attribute' ), 10, 3);
    85 
    86                 $use_filters = array(
    87                     'woocommerce_attribute'                             => 30,
    88                     'woocommerce_attribute_label'                       => 30,
    89                     'woocommerce_cart_item_name'                        => 30,
    90                     'woocommerce_cart_item_thumbnail'                   => 30,
    91                     'woocommerce_cart_shipping_method_full_label'       => 30,
    92                     'woocommerce_cart_tax_totals'                       => 30,
    93                     'woocommerce_email_footer_text'                     => 30,
    94                     'woocommerce_format_content'                        => 30,
    95                     'woocommerce_gateway_description'                   => 30,
    96                     'woocommerce_gateway_title'                         => 30,
    97                     'woocommerce_gateway_icon'                          => 30,
    98                     'woocommerce_get_privacy_policy_text'               => 30,
    99                     'woocommerce_order_details_after_order_table_items' => 30,
    100                     'woocommerce_order_item_display_meta_value'         => 30,
    101                     'woocommerce_order_item_name'                       => 30,
    102                     'woocommerce_order_get_tax_totals'                  => 30,
    103                     'woocommerce_order_shipping_to_display'             => 30,
    104                     'woocommerce_order_subtotal_to_display'             => 30,
    105                     'woocommerce_page_title'                            => 30,
    106                     'woocommerce_product_get_name'                      => 30,
    107                     'woocommerce_product_title'                         => 30,
    108                     'woocommerce_rate_label'                            => 30,
    109                     'woocommerce_product_get_description'               => 30,
    110                     'woocommerce_short_description'                     => 30,
    111                     'woocommerce_variation_option_name'                 => 30,
    112                     'wp_mail_from_name'                                 => 30,
    113                     'woocommerce_attribute_taxonomies'                  => 30
    114                 );
    115            
    116                 foreach ( $use_filters as $name => $priority ) {
    117                     add_filter( $name, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage', $priority );
    118                 }
    119 
    120             }
    121         }
    12285        /*
    12386        *   Integration with third party plugins
     
    137100
    138101        /*
    139          *  Override attribute (option) name on rest woocommerce api /products/attributes/{id}
    140          *
    141          * @param WP_REST_Response  $response  The response object.
    142          * @param object            $item      The original attribute object.
    143          * @param WP_REST_Request   $request   Request used to generate the response.
    144         */
    145         public function woocommerce_rest_product_attribute($response, $item, $request) {
    146             $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
    147             if($context == 'view'){
    148                 $data = $response->get_data();
    149                 $data['name'] = qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage( $data['name'] );
    150                 $response->set_data($data);
    151             }
    152             return $response;
    153         }
    154 
    155 
     102        *   Show if order is from napps mobile app
     103        */
    156104        public function woocommerce_is_napps_admin_order_fields($order) {
    157105            ?>
     
    174122        }
    175123
     124        /*
     125        *   Woocommerce init event
     126        */
    176127        public function woocommerce_init() {
    177128
     
    184135
    185136            $zones = WC_Shipping_Zones::get_zones();
     137
     138            $restOfTheWorld = new WC_Shipping_Zone(0);
     139            $restOfTheWorldZone = $restOfTheWorld->get_data();
     140            $restOfTheWorldZone['zone_id'] = $restOfTheWorld->get_id();
     141            $restOfTheWorldZone['formatted_zone_location'] = $restOfTheWorld->get_formatted_location();
     142            $restOfTheWorldZone['shipping_methods']        = $restOfTheWorld->get_shipping_methods( false, 'admin' );
     143
     144            array_push($zones, $restOfTheWorldZone);
    186145            //woocommerce_flat_rate_9_settings
    187146            foreach($zones as $zone) {
     
    196155        }
    197156
     157        /*
     158        *   New woocommerce shipping method
     159        */
     160        public function woocoomerceLoadShipping($methods) {
     161            $methods['flat_rate_cart'] = 'WC_Shipping_Flat_Rate_Cart';
     162            return $methods;
     163        }
     164
     165        /*
     166        *   Event woocommerce when shipping is available
     167        */
     168        public function woocoomerceInitShipping() {
     169            require_once 'modules/shipping-rate-cart.php';
     170        }
     171
    198172        public function on_tax_rate_postalcode_updated($value, $expiration, $transient) {
    199173
     
    219193                do_action( 'woocommerce_shipping_zone_method_saved', $zoneChanged );
    220194            }
    221         }
    222 
    223         private function isQTranslateActive() {
    224             return function_exists("qtranxf_wc_init_language") && function_exists("qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage");
    225         }
    226 
    227         public function woocommerce_deliver_webhook_async($webhook_id, $arg) {
    228 
    229             // We do not support multi language in our system
    230             // Ask for translated names
    231             $this->on_rest_api_init();
    232195        }
    233196
     
    276239                    case "woocommerce_attribute_deleted":
    277240                        return $resource_id;
     241                }
     242            } else if($resource == "product") {
     243
     244                // If is not a parent product
     245                if($payload["parent_id"] != 0) {
     246                    $webhook = (new WC_Webhook($this_id));
     247                    $payload["parent_product"] = $webhook->build_payload($payload["parent_id"]);
     248                    $payload["shipping_class_from_parent"] = empty(wp_get_post_terms( $payload["id"], 'product_shipping_class' )) ? true : false;
     249                    $payload["tax_class_from_parent"] = get_post_meta( $payload["id"], '_tax_class', true ) == "parent" ? true : false;
    278250                }
    279251            }
  • napps/trunk/index.php

    r2672465 r2768442  
    1 <?php // Silence is golden
     1<?php // Silence is golden 
  • napps/trunk/napps.php

    r2726253 r2768442  
    33 * Plugin Name: NAPPS
    44 * Description: Plugin to complement the napps E-commerce solution. More on https://napps.pt
    5  * Version:     1.0.6
     5 * Version:     1.0.7
    66 * Author:      NAPPS
    77 * Author URI:  https://napps.pt
     
    3535define( 'NAPPS_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
    3636define( 'NAPPS_PLUGIN_FILE',  __FILE__ );
    37 define( 'NAPPS_VERSION', '1.0.6' );
     37define( 'NAPPS_VERSION', '1.0.7' );
    3838define( 'NAPPS_REST_PREFIX', 'napps/v1' );
    3939
  • napps/trunk/readme.txt

    r2726253 r2768442  
    55Requires at least: 4.7
    66Tested up to: 5.8
    7 Stable tag: 1.0.6
     7Stable tag: 1.0.7
    88Requires PHP: 5.6
    99License: GPLv2
     
    7777== Changelog ==
    7878
     79= 1.0.7 =
     80
     81* Tweak - Improve qtranslate integration
     82
    7983= 1.0.6 =
    8084
Note: See TracChangeset for help on using the changeset viewer.