Changeset 2768442
- Timestamp:
- 08/09/2022 03:12:33 PM (4 years ago)
- Location:
- napps/trunk
- Files:
-
- 3 added
- 4 edited
-
includes/class-woocommerce.php (modified) (11 diffs)
-
includes/modules (added)
-
includes/modules/qtranslate.php (added)
-
includes/modules/shipping-rate-cart.php (added)
-
index.php (modified) (1 diff)
-
napps.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
napps/trunk/includes/class-woocommerce.php
r2726253 r2768442 11 11 exit; // Exit if accessed directly 12 12 } 13 13 use WC_Shipping_Zone; 14 14 use WC_Shipping_Zones; 15 15 use WC_Webhook; … … 24 24 25 25 private $initiated = false; 26 private $qtranslateModule; 26 27 27 28 /** … … 34 35 } 35 36 37 36 38 /** 37 39 * Init hooks … … 49 51 50 52 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 } 52 61 53 62 if(is_admin()) … … 66 75 add_action( 'woocommerce_init', array( $this, 'woocommerce_init' ), 10, 0 ); 67 76 add_action( 'woocommerce_admin_order_data_after_order_details', array( $this, 'woocommerce_is_napps_admin_order_fields'), 10, 1 ); 68 77 69 78 } 70 79 71 80 if(is_admin() || napps_doing_cron()) { 72 add_action( 'woocommerce_deliver_webhook_async', array( $this, 'woocommerce_deliver_webhook_async' ), 10, 2 );73 81 add_action( 'woocommerce_webhook_payload', array( $this, 'woocommerce_webhook_payload' ), 10, 4); 74 82 } 75 83 } 76 84 77 /*78 * Apply filters before rest api79 * so we can get the correct field based on the default language80 */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' => 30114 );115 116 foreach ( $use_filters as $name => $priority ) {117 add_filter( $name, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage', $priority );118 }119 120 }121 }122 85 /* 123 86 * Integration with third party plugins … … 137 100 138 101 /* 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 */ 156 104 public function woocommerce_is_napps_admin_order_fields($order) { 157 105 ?> … … 174 122 } 175 123 124 /* 125 * Woocommerce init event 126 */ 176 127 public function woocommerce_init() { 177 128 … … 184 135 185 136 $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); 186 145 //woocommerce_flat_rate_9_settings 187 146 foreach($zones as $zone) { … … 196 155 } 197 156 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 198 172 public function on_tax_rate_postalcode_updated($value, $expiration, $transient) { 199 173 … … 219 193 do_action( 'woocommerce_shipping_zone_method_saved', $zoneChanged ); 220 194 } 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 system230 // Ask for translated names231 $this->on_rest_api_init();232 195 } 233 196 … … 276 239 case "woocommerce_attribute_deleted": 277 240 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; 278 250 } 279 251 } -
napps/trunk/index.php
r2672465 r2768442 1 <?php // Silence is golden 1 <?php // Silence is golden -
napps/trunk/napps.php
r2726253 r2768442 3 3 * Plugin Name: NAPPS 4 4 * Description: Plugin to complement the napps E-commerce solution. More on https://napps.pt 5 * Version: 1.0. 65 * Version: 1.0.7 6 6 * Author: NAPPS 7 7 * Author URI: https://napps.pt … … 35 35 define( 'NAPPS_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); 36 36 define( 'NAPPS_PLUGIN_FILE', __FILE__ ); 37 define( 'NAPPS_VERSION', '1.0. 6' );37 define( 'NAPPS_VERSION', '1.0.7' ); 38 38 define( 'NAPPS_REST_PREFIX', 'napps/v1' ); 39 39 -
napps/trunk/readme.txt
r2726253 r2768442 5 5 Requires at least: 4.7 6 6 Tested up to: 5.8 7 Stable tag: 1.0. 67 Stable tag: 1.0.7 8 8 Requires PHP: 5.6 9 9 License: GPLv2 … … 77 77 == Changelog == 78 78 79 = 1.0.7 = 80 81 * Tweak - Improve qtranslate integration 82 79 83 = 1.0.6 = 80 84
Note: See TracChangeset
for help on using the changeset viewer.