| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: MakeCommerce for WooCommerce |
| 4 | 4 | Description: Adds MakeCommerce payment gateway and Itella/Omniva parcel machine shipping methods to Woocommerce checkout |
| 5 | - Version: 1.0.1 | |
| 5 | + Version: 1.1.7 | |
| 6 | 6 | Author: Maksekeskus AS |
| 7 | 7 | Author URI: https://MakeCommerce.net/ |
| 8 | 8 | Text Domain: wc_makecommerce_domain |
| 9 | 9 | */ |
| @@ -71,9 +71,9 @@ | ||
| 71 | 71 | const module_homepage_url = 'https://maksekeskus.ee/en/integration-modules/makecommerce-woocommerce-payment-plugin/'; |
| 72 | 72 | const testenv_homepage_url = 'http://maksekeskus.ee/en/for-developers/test-environment/'; |
| 73 | 73 | |
| 74 | 74 | public $id = 'makecommerce'; |
| 75 | - public $version = '1.1'; | |
| 75 | + public $version = '1.1.7'; | |
| 76 | 76 | |
| 77 | 77 | public $return_url; |
| 78 | 78 | public $return_url_cancel; |
| 79 | 79 | |
| @@ -110,8 +110,11 @@ | ||
| 110 | 110 | |
| 111 | 111 | $this->initBanklinks(); |
| 112 | 112 | |
| 113 | 113 | $this->title = $this->settings['ui_widget_title']; |
| 114 | + if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE])) { | |
| 115 | + $this->title = $this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE]; | |
| 116 | + } | |
| 114 | 117 | $this->method_title = 'MakeCommerce'; |
| 115 | 118 | $this->description = true; |
| 116 | 119 | |
| 117 | 120 | $this->_api = mk_get_api(); |
| @@ -189,36 +192,38 @@ | ||
| 189 | 192 | * Initialise Gateway Settings Form Fields |
| 190 | 193 | */ |
| 191 | 194 | function init_form_fields() { |
| 192 | 195 | |
| 193 | - $this->form_fields = array( | |
| 194 | - 'header' => array( | |
| 196 | + $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 197 | + | |
| 198 | + $this->form_fields = array(); | |
| 199 | + $this->form_fields['header'] = array( | |
| 195 | 200 | 'type' => 'mc_header', |
| 196 | - ), | |
| 197 | - 'active' => array( | |
| 201 | + ); | |
| 202 | + $this->form_fields['active'] = array( | |
| 198 | 203 | 'title' => __('Enable/Disable', 'wc_makecommerce_domain'), |
| 199 | 204 | 'type' => 'checkbox', |
| 200 | 205 | 'label' => __('Enable MakeCommerce payments', 'wc_makecommerce_domain'), |
| 201 | 206 | 'default' => 'no' |
| 202 | - ), | |
| 203 | - 'api_title' => array( | |
| 207 | + ); | |
| 208 | + $this->form_fields['api_title'] = array( | |
| 204 | 209 | 'title' => __('MakeCommerce API', 'wc_makecommerce_domain'), |
| 205 | 210 | 'description' => sprintf(__('Go to <a href="%s">API settings</a> to fill in the credentials', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api')), |
| 206 | 211 | 'type' => 'title', |
| 207 | - ), | |
| 208 | - 'ui_title' => array( | |
| 212 | + ); | |
| 213 | + $this->form_fields['ui_title'] = array( | |
| 209 | 214 | 'title' => '<br>'.__('User Interface', 'wc_makecommerce_domain'), |
| 210 | 215 | 'type' => 'title', |
| 211 | 216 | 'class' => 'ui-identifier', |
| 212 | - ), | |
| 213 | - 'ui_open_by_default' => array( | |
| 217 | + ); | |
| 218 | + $this->form_fields['ui_open_by_default'] = array( | |
| 214 | 219 | 'title' => __('Set as default selection', 'wc_makecommerce_domain'), |
| 215 | 220 | 'label' => __('MakeCommerce payments widget will be selected by default', 'wc_makecommerce_domain'), |
| 216 | 221 | 'type' => 'checkbox', |
| 217 | 222 | 'default' => 'yes', |
| 218 | 223 | 'class' => 'ui-identifier', |
| 219 | - ), | |
| 220 | - 'ui_mode' => array( | |
| 224 | + ); | |
| 225 | + $this->form_fields['ui_mode'] = array( | |
| 221 | 226 | 'title' => __('Display MC payment channels as', 'wc_makecommerce_domain'), |
| 222 | 227 | 'type' => 'mc_hidden', |
| 223 | 228 | 'default' => 'widget', |
| 224 | 229 | 'options' => array( |
| @@ -225,17 +230,32 @@ | ||
| 225 | 230 | 'inline' => __('List', 'wc_makecommerce_domain'), |
| 226 | 231 | 'widget' => __('Grouped to widget', 'wc_makecommerce_domain'), |
| 227 | 232 | ), |
| 228 | 233 | 'class' => 'ui-identifier', |
| 229 | - ), | |
| 230 | - 'ui_widget_title' => array( | |
| 231 | - 'title' => __('MC payments widget title', 'wc_makecommerce_domain'), | |
| 232 | - 'type' => 'text', | |
| 233 | - 'desc_tip' => __("Appropriate title may depend on the configuration you have made, i.e. 'pay with bank-link or credit card', 'pay with bank-links' or 'payment methods'", 'wc_makecommerce_domain'), | |
| 234 | - 'default' => __('Pay with bank-links or credit card', 'wc_makecommerce_domain'), | |
| 235 | - 'class' => 'ui-identifier', | |
| 236 | - ), | |
| 237 | - 'ui_inline_uselogo' => array( | |
| 234 | + ); | |
| 235 | + | |
| 236 | + | |
| 237 | + if (empty($languages)) { | |
| 238 | + $this->form_fields['ui_widget_title'] = array( | |
| 239 | + 'title' => __('Payments widget title', 'wc_makecommerce_domain'), | |
| 240 | + 'type' => 'text', | |
| 241 | + 'desc_tip' => __("Appropriate title may depend on the configuration you have made, i.e. 'pay with bank-link or credit card', 'pay with bank-links' or 'payment methods'", 'wc_makecommerce_domain'), | |
| 242 | + 'default' => __('Pay with bank-links or credit card', 'wc_makecommerce_domain'), | |
| 243 | + 'class' => 'ui-identifier', | |
| 244 | + ); | |
| 245 | + } else { | |
| 246 | + foreach ($languages as $language_code => $language) { | |
| 247 | + $language_name = !empty($language['translated_name']) ? $language['translated_name'] : $language_code; | |
| 248 | + $this->form_fields['ui_widget_title_'.$language_code] = array( | |
| 249 | + 'title' => __('Payments widget title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code), | |
| 250 | + 'type' => 'text', | |
| 251 | + 'desc_tip' => __("Appropriate title may depend on the configuration you have made, i.e. 'pay with bank-link or credit card', 'pay with bank-links' or 'payment methods'", 'wc_makecommerce_domain'), | |
| 252 | + 'default' => __('Pay with bank-links or credit card', 'wc_makecommerce_domain'), | |
| 253 | + 'class' => 'ui-identifier', | |
| 254 | + ); | |
| 255 | + } | |
| 256 | + } | |
| 257 | + $this->form_fields['ui_inline_uselogo'] = array( | |
| 238 | 258 | 'title' => __('MC payment channels display style', 'wc_makecommerce_domain'), |
| 239 | 259 | 'type' => 'select', |
| 240 | 260 | 'default' => 'logo', |
| 241 | 261 | 'options' => array( |
| @@ -243,10 +263,10 @@ | ||
| 243 | 263 | 'text_logo' => __('Text & logo', 'wc_makecommerce_domain'), |
| 244 | 264 | 'text' => __('Text', 'wc_makecommerce_domain'), |
| 245 | 265 | ), |
| 246 | 266 | 'class' => 'ui-identifier', |
| 247 | - ), | |
| 248 | - 'ui_widget_logosize' => array( | |
| 267 | + ); | |
| 268 | + $this->form_fields['ui_widget_logosize'] = array( | |
| 249 | 269 | 'title' => __('Size of payment channel logos', 'wc_makecommerce_domain'), |
| 250 | 270 | 'type' => 'select', |
| 251 | 271 | 'default' => 'medium', |
| 252 | 272 | 'options' => array( |
| @@ -254,16 +274,16 @@ | ||
| 254 | 274 | 'medium' => __('Medium', 'wc_makecommerce_domain'), |
| 255 | 275 | 'large' => __('Large', 'wc_makecommerce_domain') |
| 256 | 276 | ), |
| 257 | 277 | 'class' => 'ui-identifier', |
| 258 | - ), | |
| 259 | - 'ui_widget_groupcountries' => array( | |
| 278 | + ); | |
| 279 | + $this->form_fields['ui_widget_groupcountries'] = array( | |
| 260 | 280 | 'title' => __('Group bank-links by countries', 'wc_makecommerce_domain'), |
| 261 | 281 | 'type' => 'mc_hidden', |
| 262 | 282 | 'default' => 'no', |
| 263 | 283 | 'class' => 'ui-identifier', |
| 264 | - ), | |
| 265 | - 'ui_widget_countryselector' => array( | |
| 284 | + ); | |
| 285 | + $this->form_fields['ui_widget_countryselector'] = array( | |
| 266 | 286 | 'title' => __('Country selector style', 'wc_makecommerce_domain'), |
| 267 | 287 | 'type' => 'mc_hidden', |
| 268 | 288 | 'default' => 'flag', |
| 269 | 289 | 'options' => array( |
| @@ -270,56 +290,49 @@ | ||
| 270 | 290 | 'flag' => __('Flag', 'wc_makecommerce_domain'), |
| 271 | 291 | 'dropdown' => __('Dropdown', 'wc_makecommerce_domain'), |
| 272 | 292 | ), |
| 273 | 293 | 'class' => 'ui-identifier', |
| 274 | - ), | |
| 275 | - 'ui_widget_groupcc' => array( | |
| 294 | + ); | |
| 295 | + $this->form_fields['ui_widget_groupcc'] = array( | |
| 276 | 296 | 'title' => __('Group credit card into separate widget', 'wc_makecommerce_domain'), |
| 277 | 297 | 'type' => 'mc_hidden', |
| 278 | 298 | 'default' => 'no', |
| 279 | 299 | 'class' => 'ui-identifier', |
| 280 | - ), | |
| 281 | - 'ui_chorder' => array( | |
| 300 | + ); | |
| 301 | + $this->form_fields['ui_chorder'] = array( | |
| 282 | 302 | 'title' => __('Define custom order of payment channels', 'wc_makecommerce_domain'), |
| 283 | 303 | 'type' => 'text', |
| 284 | 304 | 'desc_tip' => __('If you want to change default order, put here comma separated list of channels. i,e, - seb,lhv,swedbank. see more on the module home page (link above)', 'wc_makecommerce_domain'), |
| 285 | 305 | 'class' => 'ui-identifier', |
| 286 | - ), | |
| 287 | - 'ui_javascript' => array( | |
| 306 | + ); | |
| 307 | + $this->form_fields['ui_javascript'] = array( | |
| 288 | 308 | 'type' => 'ui_javascript', |
| 289 | - ), | |
| 290 | - 'cc_title' => array( | |
| 309 | + ); | |
| 310 | + $this->form_fields['cc_title'] = array( | |
| 291 | 311 | 'title' => '<br>'.__('Credit Card Settings', 'wc_makecommerce_domain'), |
| 292 | 312 | 'type' => 'title', |
| 293 | - ), | |
| 294 | - 'cc_pass_cust_data' => array( | |
| 313 | + ); | |
| 314 | + $this->form_fields['cc_pass_cust_data'] = array( | |
| 295 | 315 | 'title' => __('Prefill Credit Card form with customer data', 'wc_makecommerce_domain'), |
| 296 | 316 | 'type' => 'checkbox', |
| 297 | 317 | 'default' => 'yes', |
| 298 | 318 | 'desc_tip' => __('It will pass user Name and e-mail address to the Credit Card dialog to make the form filling easier', 'wc_makecommerce_domain'), |
| 299 | - ), | |
| 300 | - 'cc_shop_name' => array( | |
| 301 | - 'title' => __('Shop name on credit card payment', 'wc_makecommerce_domain'), | |
| 302 | - 'type' => 'text', | |
| 303 | - 'desc_tip' => __('This will appear on buyer\'s credit card transaction', 'wc_makecommerce_domain'), | |
| 304 | - ), | |
| 305 | - 'cc_cart_reference_string' => array( | |
| 306 | - 'title' => __('Order reference on credit card payment', 'wc_makecommerce_domain'), | |
| 307 | - 'type' => 'text', | |
| 308 | - 'default' => 'Order %s', | |
| 309 | - 'desc_tip' => __('This will appear on buyer\'s credit card transaction where "%s" is the order number', 'wc_makecommerce_domain'), | |
| 310 | - ), | |
| 311 | - 'adv_title' => array( | |
| 312 | - 'title' => '<br>'.__('Advanced Settings', 'wc_makecommerce_domain'), | |
| 319 | + ); | |
| 320 | + $this->form_fields['adv_title'] = array( | |
| 321 | + 'title' => '<hr><br>'.__('Advanced Settings', 'wc_makecommerce_domain'), | |
| 313 | 322 | 'type' => 'title', |
| 314 | - ), | |
| 315 | - 'reload_links' => array( | |
| 323 | + ); | |
| 324 | + $this->form_fields['reload_links'] = array( | |
| 316 | 325 | 'type' => 'mc_banklinks_reload', |
| 317 | 326 | 'title' => __('Update payment methods', 'wc_makecommerce_domain'), |
| 318 | 327 | 'description' => __('Update', 'wc_makecommerce_domain'), |
| 319 | 328 | 'desc_tip' => __('This will update shop configuration from MakeCommerce servers.', 'wc_makecommerce_domain'), |
| 320 | - ), | |
| 321 | - ); | |
| 329 | + ); | |
| 330 | + $this->form_fields['cron_info'] = array( | |
| 331 | + 'type' => 'cron_link', | |
| 332 | + 'title' => __('Update url', 'wc_makecommerce_domain'), | |
| 333 | + 'desc_tip' => __('Update url for cron job.', 'wc_makecommerce_domain'), | |
| 334 | + ); | |
| 322 | 335 | } |
| 323 | 336 | |
| 324 | 337 | public function generate_mc_hidden_html( $key, $data ) { |
| 325 | 338 | $field_key = $this->get_field_key($key); |
| @@ -332,9 +345,43 @@ | ||
| 332 | 345 | </tr> |
| 333 | 346 | <?php |
| 334 | 347 | return ob_get_clean(); |
| 335 | 348 | } |
| 349 | + | |
| 350 | + public function generate_cron_link_html( $key, $data ) { | |
| 351 | + $field = $this->get_field_key( $key ); | |
| 352 | + $defaults = array( | |
| 353 | + 'title' => '', | |
| 354 | + 'disabled' => false, | |
| 355 | + 'class' => '', | |
| 356 | + 'css' => '', | |
| 357 | + 'placeholder' => '', | |
| 358 | + 'type' => 'text', | |
| 359 | + 'desc_tip' => false, | |
| 360 | + 'description' => '', | |
| 361 | + 'custom_attributes' => array() | |
| 362 | + ); | |
| 336 | 363 | |
| 364 | + $data = wp_parse_args( $data, $defaults ); | |
| 365 | + $shop_id_text = get_option('mc_banklinks_api_type', false) == 'live' ? 'mk-shop-id': 'mk-test-shop-id'; | |
| 366 | + ob_start(); | |
| 367 | + ?> | |
| 368 | + <tr valign="top"> | |
| 369 | + <th scope="row" class="titledesc"> | |
| 370 | + <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> | |
| 371 | + <?php echo $this->get_tooltip_html( $data ); ?> | |
| 372 | + </th> | |
| 373 | + <td class="forminp"> | |
| 374 | + <fieldset> | |
| 375 | + <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> | |
| 376 | + <p><?php echo get_site_url(null, '?mk-action=mk-update&'.$shop_id_text.'=') . get_option('mk_test_shop_id', false);?></p> | |
| 377 | + </fieldset> | |
| 378 | + </td> | |
| 379 | + </tr> | |
| 380 | + <?php | |
| 381 | + return ob_get_clean(); | |
| 382 | + } | |
| 383 | + | |
| 337 | 384 | public function generate_mc_banklinks_reload_html( $key, $data ) { |
| 338 | 385 | |
| 339 | 386 | $field = $this->get_field_key( $key ); |
| 340 | 387 | $defaults = array( |
| @@ -472,9 +519,9 @@ | ||
| 472 | 519 | } |
| 473 | 520 | |
| 474 | 521 | public function mc_banklinks_reload($force = false) { |
| 475 | 522 | if ($force || (defined('DOING_AJAX') && DOING_AJAX)) { |
| 476 | - | |
| 523 | + | |
| 477 | 524 | global $wpdb; |
| 478 | 525 | global $mkDbTable; |
| 479 | 526 | global $wp_version; |
| 480 | 527 | |
| @@ -486,14 +533,21 @@ | ||
| 486 | 533 | 'platform' => 'wordpress '.$wp_version, |
| 487 | 534 | 'module' => $this->id.' '.$this->version, |
| 488 | 535 | )), |
| 489 | 536 | ); |
| 537 | + | |
| 538 | + if (!$this->_api) { | |
| 539 | + return false; | |
| 540 | + } | |
| 490 | 541 | |
| 491 | 542 | try { |
| 492 | - $methods = $this->_api->getShopConfig($request_params)->paymentMethods; | |
| 543 | + $shopConfig = $this->_api->getShopConfig($request_params); | |
| 544 | + $methods = $shopConfig->payment_methods; | |
| 493 | 545 | } catch (Exception $e) { |
| 546 | + error_log(print_r($e, 1)); | |
| 494 | 547 | return false; |
| 495 | 548 | } |
| 549 | + | |
| 496 | 550 | if(isset($methods->banklinks)) { |
| 497 | 551 | foreach($methods->banklinks as $method) { |
| 498 | 552 | $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url)); |
| 499 | 553 | } |
| @@ -505,11 +559,17 @@ | ||
| 505 | 559 | $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name)); |
| 506 | 560 | } |
| 507 | 561 | $updated = true; |
| 508 | 562 | } |
| 563 | + | |
| 564 | + if(isset($shopConfig) && strlen($shopConfig->name)) { | |
| 565 | + update_option( 'mc_shop_name', $shopConfig->name ); | |
| 566 | + } | |
| 567 | + | |
| 509 | 568 | if ($updated) { |
| 510 | 569 | update_option( 'mc_banklinks_api_type', get_option('mk_api_type', false) ); |
| 511 | 570 | } |
| 571 | + | |
| 512 | 572 | if ($force) { |
| 513 | 573 | $this->initBankLinks(); |
| 514 | 574 | return $updated; |
| 515 | 575 | } |
| @@ -640,8 +700,9 @@ | ||
| 640 | 700 | <?php |
| 641 | 701 | } |
| 642 | 702 | ?> |
| 643 | 703 | </ul> |
| 704 | + <div class="mc-clear-both"></div> | |
| 644 | 705 | <script type="text/javascript"> |
| 645 | 706 | var makecommerceId = '<?php echo $this->id; ?>'; |
| 646 | 707 | var selectedCountry = jQuery('input[name=makecommerce_country_picker]:checked').val(); |
| 647 | 708 | |
| @@ -760,9 +821,9 @@ | ||
| 760 | 821 | |
| 761 | 822 | $posA = array_search($a->name, $order); |
| 762 | 823 | $posB = array_search($b->name, $order); |
| 763 | 824 | |
| 764 | - if($posA === $posB) return 0; | |
| 825 | + if($posA === $posB) return $a->id > $b->id ? 1 : -1; | |
| 765 | 826 | if($posA === FALSE) return 1; |
| 766 | 827 | if($posB === FALSE) return -1; |
| 767 | 828 | |
| 768 | 829 | return $posA > $posB ? 1 : -1; |
| @@ -905,9 +966,9 @@ | ||
| 905 | 966 | } |
| 906 | 967 | |
| 907 | 968 | protected function _getOrderConfirmationUrl($order) { |
| 908 | 969 | //$url = add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id')))); |
| 909 | - $url = site_url('?makecommerce_card_pay=1&order_id='.$order->id); | |
| 970 | + $url = site_url('?makecommerce_card_pay=1&order_id='.$order->id.'&lang='.(defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2)))); | |
| 910 | 971 | return $url; |
| 911 | 972 | } |
| 912 | 973 | |
| 913 | 974 | function receipt_page($orderId) { |
| @@ -927,14 +988,14 @@ | ||
| 927 | 988 | 'key' => $this->_api->getPublishableKey(), |
| 928 | 989 | 'transaction' => $transactionId, |
| 929 | 990 | 'selector' => '#submit_banklinkmakecommerce_payment_form', |
| 930 | 991 | 'amount' => round($order->order_total, 2), |
| 931 | - 'locale' => strtolower(substr(get_locale(), 0, 2)), | |
| 992 | + 'locale' => !empty($_GET['lang']) ? $_GET['lang'] : (defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))), | |
| 932 | 993 | 'open-on-load' => 'true', |
| 933 | 994 | 'client-name' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) ($order->billing_first_name . ' ' . $order->billing_last_name) : ''), |
| 934 | 995 | 'email' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) $order->billing_email : ''), |
| 935 | - 'name' => $this->settings['cc_shop_name'], | |
| 936 | - 'description' => (string)sprintf($this->settings['cc_cart_reference_string'], (string) $idReference), | |
| 996 | + 'name' => get_option('mc_shop_name', ''), | |
| 997 | + 'description' => __('Order', 'woocommerce') . ' ' . (string) $idReference, | |
| 937 | 998 | 'completed' => 'makecommerce_cc_complete', |
| 938 | 999 | 'currency' => 'EUR', |
| 939 | 1000 | ); |
| 940 | 1001 | ?> |
| @@ -1233,8 +1294,11 @@ | ||
| 1233 | 1294 | $this->init_settings(); |
| 1234 | 1295 | |
| 1235 | 1296 | $this->enable = $this->settings['active']; |
| 1236 | 1297 | $this->title = $this->settings['method_name']; |
| 1298 | + if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['method_name_'.ICL_LANGUAGE_CODE])) { | |
| 1299 | + $this->title = $this->settings['method_name_'.ICL_LANGUAGE_CODE]; | |
| 1300 | + } | |
| 1237 | 1301 | $this->availability = 'specific'; |
| 1238 | 1302 | $this->countries = $this->settings['countries']; |
| 1239 | 1303 | $this->prioritization = $this->settings['prioritization']; |
| 1240 | 1304 | $this->free_shipping_min_amount = $this->settings['free_shipping_min_amount']; |
| @@ -1242,19 +1306,62 @@ | ||
| 1242 | 1306 | $this->short_office_names = $this->settings['short_office_names']; |
| 1243 | 1307 | $this->order_country = 'unknown'; |
| 1244 | 1308 | add_action('woocommerce_update_options_shipping_' . $this->id, array(&$this, 'process_admin_options')); |
| 1245 | 1309 | add_filter('woocommerce_review_order_after_shipping' , array(&$this, 'add_parcelmachine_checkout_fields')); |
| 1310 | + //add_filter('woocommerce_update_order_review_fragments' , array(&$this, 'add_parcelmachine_checkout_fields')); | |
| 1246 | 1311 | add_action('woocommerce_checkout_process', array(&$this, 'check_parcelmachine_checkout_fields')); |
| 1312 | + add_action('woocommerce_after_checkout_validation', array(&$this, 'check_parcelmachine_checkout_fields')); | |
| 1247 | 1313 | add_action('woocommerce_checkout_update_order_meta', array(&$this, 'add_parcelmachine_order_meta')); |
| 1248 | - add_filter('woocommerce_order_shipping_to_display_shipped_via', array(&$his, 'add_admin_parcelmachine_via_field')); | |
| 1314 | + add_filter('woocommerce_order_shipping_to_display_shipped_via', array(&$this, 'add_admin_parcelmachine_via_field')); | |
| 1249 | 1315 | } |
| 1250 | 1316 | |
| 1317 | + public function generate_shipping_ui_javascript_html( $key, $data ) { ?> | |
| 1318 | + <script type="text/javascript"> | |
| 1319 | + jQuery(document).ready(function($) { | |
| 1320 | + var country_select = $('#woocommerce_parcelmachine_<?php echo strtolower($this->ext); ?>_countries'); | |
| 1321 | + var prices = [], free_shippings = []; | |
| 1322 | + $.each(country_select.find('option'), function(i, option) { | |
| 1323 | + prices[$(option).val()] = $('#woocommerce_parcelmachine_<?php echo strtolower($this->ext); ?>_price_' + $(option).val().toLowerCase()).closest('tr'); | |
| 1324 | + free_shippings[$(option).val()] = $('#woocommerce_parcelmachine_<?php echo strtolower($this->ext); ?>_free_shipping_min_amount_' + $(option).val().toLowerCase()).closest('tr'); | |
| 1325 | + }); | |
| 1326 | + country_select.on('change', function(){ | |
| 1327 | + var countries = $(this).val(); | |
| 1328 | + if(countries) { | |
| 1329 | + hidePrices(countries); | |
| 1330 | + } | |
| 1331 | + }); | |
| 1332 | + hidePrices(country_select.val()); | |
| 1333 | + function hidePrices(countries) { | |
| 1334 | + for (var key in prices) { | |
| 1335 | + if(countries.indexOf(key) == -1){ | |
| 1336 | + prices[key].hide(); | |
| 1337 | + free_shippings[key].hide(); | |
| 1338 | + } else { | |
| 1339 | + prices[key].show(); | |
| 1340 | + free_shippings[key].show(); | |
| 1341 | + } | |
| 1342 | + } | |
| 1343 | + } | |
| 1344 | + }); | |
| 1345 | + </script> | |
| 1346 | + <?php } | |
| 1347 | + | |
| 1251 | 1348 | function calculate_shipping($package = array()) { |
| 1349 | + $price = $this->settings['price_'.strtolower($package['destination']['country'])]; | |
| 1252 | 1350 | |
| 1253 | - $price = $this->settings['price_'.strtolower($package['destination']['country'])]; | |
| 1254 | - if ($this->free_shipping_min_amount && $package['contents_cost'] >= $this->free_shipping_min_amount) { | |
| 1351 | + $free_shipping_min_amount = $this->settings['free_shipping_min_amount_'.strtolower($package['destination']['country'])]; | |
| 1352 | + | |
| 1353 | + if ($free_shipping_min_amount && $package['contents_cost'] >= $free_shipping_min_amount) { | |
| 1255 | 1354 | $price = 0; |
| 1256 | 1355 | } |
| 1356 | + | |
| 1357 | + $free_shipping = true; | |
| 1358 | + foreach ($package['contents'] as $line) { | |
| 1359 | + $free_shipping = get_post_meta($line['product_id'], '_no_shipping_cost', true) === 'yes' ? $free_shipping : false; | |
| 1360 | + } | |
| 1361 | + if($free_shipping) { | |
| 1362 | + $price = 0; | |
| 1363 | + } | |
| 1257 | 1364 | $rate = array( |
| 1258 | 1365 | 'id' => $this->id, |
| 1259 | 1366 | 'label' => $this->title, |
| 1260 | 1367 | 'cost' => $price, |
| @@ -1328,38 +1435,43 @@ | ||
| 1328 | 1435 | } |
| 1329 | 1436 | return $machines; |
| 1330 | 1437 | } |
| 1331 | 1438 | |
| 1332 | - function add_parcelmachine_checkout_fields($checkout) { | |
| 1439 | + function add_parcelmachine_checkout_fields($fragments) { | |
| 1333 | 1440 | $this->order_country = WC()->customer->get_shipping_country(); |
| 1334 | - echo '<tr style="display: none;" class="parcel_machine_checkout" id="parcel_machine_checkout_parcelmachine_'.mb_strtolower($this->ext).'"><th>' . $this->title . '</th>'; | |
| 1335 | - echo '<td>'; | |
| 1441 | + $res = ''; | |
| 1442 | + $res .= '<tr style="display: none;" class="parcel_machine_checkout parcel_machine_checkout_parcelmachine_'.mb_strtolower($this->ext).'">'; | |
| 1443 | + // echo '<th>' . $this->title . '</th>'; | |
| 1444 | + // echo '<td>'; | |
| 1445 | + $res .= '<td colspan="2">'; | |
| 1336 | 1446 | $options = array(); |
| 1337 | 1447 | $machines = $this->mk_get_machines(); |
| 1338 | - echo '<p class="form-row" id="'.esc_attr($this->id).'_field">'; | |
| 1339 | - echo '<select class="select" name="'.esc_attr($this->id).'" id="'.esc_attr($this->id).'">'; | |
| 1448 | + $res .= '<p class="form-row" id="'.esc_attr($this->id).'_field">'; | |
| 1449 | + $res .= '<select class="select" name="'.esc_attr($this->id).'" id="'.esc_attr($this->id).'">'; | |
| 1450 | + $res .= '<option value="">'.__('-- select parcel machine --', 'wc_makecommerce_domain').'</option>'; | |
| 1340 | 1451 | $pcity = false; |
| 1341 | 1452 | foreach ($machines as $machine) { |
| 1342 | 1453 | $city = strtolower($machine['city']); |
| 1343 | 1454 | if ($city !== $pcity) { |
| 1344 | - if ($pcity) echo '</optgroup>'; | |
| 1345 | - echo '<optgroup label="'.$machine['city'].'">'; | |
| 1455 | + if ($pcity) $res .= '</optgroup>'; | |
| 1456 | + $res .= '<optgroup label="'.$machine['city'].'">'; | |
| 1346 | 1457 | } |
| 1347 | 1458 | $mname = $machine['name']; |
| 1348 | 1459 | if ($this->short_office_names !== 'yes') $mname .= ' - ' . $machine['city'] . ', ' . $machine['address']; |
| 1349 | - echo '<option value="'.esc_attr($machine['provider'].'||'.$machine['id']).'">'.$mname.'</option>'; | |
| 1460 | + $res .= '<option value="'.esc_attr($machine['carrier'].'||'.$machine['id']).'">'.$mname.'</option>'; | |
| 1350 | 1461 | $pcity = $city; |
| 1351 | 1462 | } |
| 1352 | - if ($pcity) echo '</optgroup>'; | |
| 1353 | - echo '</select>'; | |
| 1354 | - echo '</p>'; | |
| 1355 | - echo '</td></tr>'; | |
| 1463 | + if ($pcity) $res .= '</optgroup>'; | |
| 1464 | + $res .= '</select>'; | |
| 1465 | + $res .= '</p>'; | |
| 1466 | + $res .= '</td></tr>'; | |
| 1467 | + echo $res; | |
| 1356 | 1468 | } |
| 1357 | 1469 | |
| 1358 | 1470 | function check_parcelmachine_checkout_fields() { |
| 1359 | 1471 | $shipping_method = !empty($_POST['shipping_method']) ? $_POST['shipping_method'] : false; |
| 1360 | 1472 | if (!empty($shipping_method[0])) { $shipping_method = $shipping_method[0]; } |
| 1361 | - if ($shipping_method === $this->id && empty($_POST['parcel_machine_itella'])) { | |
| 1473 | + if ($shipping_method === $this->id && empty($_POST[$shipping_method])) { | |
| 1362 | 1474 | wc_add_notice(__('<strong>Parcel machine</strong> is a required field.'), 'error'); |
| 1363 | 1475 | } |
| 1364 | 1476 | } |
| 1365 | 1477 | function add_parcelmachine_order_meta($order_id) { |
| @@ -1369,10 +1481,9 @@ | ||
| 1369 | 1481 | update_post_meta($order_id, '_parcel_machine', sanitize_text_field($_POST[$this->id])); |
| 1370 | 1482 | } |
| 1371 | 1483 | } |
| 1372 | 1484 | function add_admin_parcelmachine_via_field($order) { |
| 1373 | - error_log('Via'); | |
| 1374 | - error_log(print_r($order, 1)); | |
| 1485 | + return ' <small>(via '.$this->name_ext.')</small>'; | |
| 1375 | 1486 | } |
| 1376 | 1487 | } |
| 1377 | 1488 | class WC_ParcelMachine_Shipping_Method_Omniva extends WC_ParcelMachine_Shipping_Method { |
| 1378 | 1489 | function __construct($instance_id = 0) { |
| @@ -1381,108 +1492,139 @@ | ||
| 1381 | 1492 | parent::__construct(); |
| 1382 | 1493 | } |
| 1383 | 1494 | function init_form_fields() { |
| 1384 | 1495 | |
| 1385 | - $this->form_fields = array( | |
| 1386 | - 'logo' => array('type' => 'title', 'title' => __get_logo_html()), | |
| 1387 | - 'generic' => array('type' => 'title', 'title' => __('Generic and pricing options', 'wc_makecommerce_domain')), | |
| 1388 | - 'active' => array( | |
| 1496 | + $this->form_fields = array(); | |
| 1497 | + $this->form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html()); | |
| 1498 | + $this->form_fields['generic'] = array( | |
| 1499 | + 'type' => 'title', | |
| 1500 | + 'title' => __('Generic and pricing options', 'wc_makecommerce_domain'), | |
| 1501 | + 'description' => __('You can always exclude a product from being available for the Parcel Machine delivery by clicking "Does not fit parcel machine" in the product\'s shipping options.', 'wc_makecommerce_domain').'<br>'.__('You can mark there also a product as "Free shipping in parcel machine."', 'wc_makecommerce_domain'), | |
| 1502 | + ); | |
| 1503 | + $this->form_fields['active'] = array( | |
| 1389 | 1504 | 'title' => __('Enable', 'wc_makecommerce_domain'), |
| 1390 | 1505 | 'type' => 'checkbox', |
| 1391 | 1506 | 'label' => __('enabled', 'wc_makecommerce_domain'), |
| 1392 | 1507 | 'default' => 'no', |
| 1393 | - 'description' => __('You can always exclude a product from being available for the Parcel Machine delivery by clicking "Does not fit parcel machine" in the product\'s shipping options', 'wc_makecommerce_domain'), | |
| 1394 | - ), | |
| 1395 | - 'price_ee' => array( | |
| 1396 | - 'title' => __('Price EE', 'wc_makecommerce_domain'), | |
| 1508 | + ); | |
| 1509 | + $this->form_fields['countries'] = array( | |
| 1510 | + 'title' => __('Enable Shipping to', 'wc_makecommerce_domain'), | |
| 1511 | + 'type' => 'multiselect', | |
| 1512 | + 'class' => 'wp-enhanced-select', | |
| 1513 | + 'css' => 'width: 450px;', | |
| 1514 | + 'default' => array('EE','LV','LT'), | |
| 1515 | + 'options' => array('EE' => __('Estonia - EE'), 'LV' => __('Latvia - LV'), 'LT' => __('Lithuania - LT')), | |
| 1516 | + 'description' => __('use Shift key to select multiple lines', 'wc_makecommerce_domain'), | |
| 1517 | + ); | |
| 1518 | + $this->form_fields['price_ee'] = array( | |
| 1519 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' EE', | |
| 1397 | 1520 | 'type' => 'text', |
| 1398 | 1521 | 'default' => '2.99' |
| 1399 | - ), | |
| 1400 | - 'price_lv' => array( | |
| 1401 | - 'title' => __('Price LV', 'wc_makecommerce_domain'), | |
| 1522 | + ); | |
| 1523 | + $this->form_fields['free_shipping_min_amount_ee'] = array( | |
| 1524 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain').' EE', | |
| 1525 | + 'type' => 'number', | |
| 1526 | + 'default' => '0', | |
| 1527 | + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1528 | + ); | |
| 1529 | + $this->form_fields['price_lv'] = array( | |
| 1530 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' LV', | |
| 1402 | 1531 | 'type' => 'text', |
| 1403 | 1532 | 'default' => '7.99' |
| 1404 | - ), | |
| 1405 | - 'price_lt' => array( | |
| 1406 | - 'title' => __('Price LT', 'wc_makecommerce_domain'), | |
| 1533 | + ); | |
| 1534 | + $this->form_fields['free_shipping_min_amount_lv'] = array( | |
| 1535 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain').' LV', | |
| 1536 | + 'type' => 'number', | |
| 1537 | + 'default' => '0', | |
| 1538 | + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1539 | + ); | |
| 1540 | + $this->form_fields['price_lt'] = array( | |
| 1541 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' LT', | |
| 1407 | 1542 | 'type' => 'text', |
| 1408 | 1543 | 'default' => '8.99' |
| 1409 | - ), | |
| 1410 | - //'price_fi' => array( | |
| 1411 | - // 'title' => __('Price FI', 'wc_makecommerce_domain'), | |
| 1412 | - // 'type' => 'text', | |
| 1413 | - // 'default' => '10.99' | |
| 1414 | - //), | |
| 1415 | - 'free_shipping_min_amount' => array( | |
| 1416 | - 'title' => __('Minimum amount for free shipping', 'wc_makecommerce_domain'), | |
| 1544 | + ); | |
| 1545 | + $this->form_fields['free_shipping_min_amount_lt'] = array( | |
| 1546 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain').' LT', | |
| 1417 | 1547 | 'type' => 'number', |
| 1418 | 1548 | 'default' => '0', |
| 1419 | - 'description' => '(0 means no free shipping)' | |
| 1420 | - ), | |
| 1421 | - 'maximum_weight' => array( | |
| 1549 | + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1550 | + ); | |
| 1551 | + $this->form_fields['maximum_weight'] = array( | |
| 1422 | 1552 | 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'), |
| 1423 | 1553 | 'type' => 'text', |
| 1424 | 1554 | 'default' => '15' |
| 1425 | - ), | |
| 1426 | - 'countries' => array( | |
| 1427 | - 'title' => __('Specific Countries', 'wc_makecommerce_domain'), | |
| 1428 | - 'type' => 'multiselect', | |
| 1429 | - 'class' => 'wp-enhanced-select', | |
| 1430 | - 'css' => 'width: 450px;', | |
| 1431 | - 'default' => array('EE','LV','LT'), | |
| 1432 | - 'options' => array('EE' => __('Estonia'), 'LV' => __('Latvia'), 'LT' => __('Lithuania')), | |
| 1433 | - ), | |
| 1434 | - 'look_and_feel' => array( 'type' => 'title', 'title' => __('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on check-out page', 'wc_makecommerce_domain')), | |
| 1435 | - 'method_name' => array( | |
| 1436 | - 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'), | |
| 1437 | - 'type' => 'text', | |
| 1438 | - 'default' => __('Omniva Parcel Machine', 'wc_makecommerce_domain') | |
| 1439 | - ), | |
| 1440 | - 'prioritization' => array( | |
| 1555 | + ); | |
| 1556 | + | |
| 1557 | + $this->form_fields['look_and_feel'] = array( 'type' => 'title', 'title' => '<hr><br>'.__('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on check-out page', 'wc_makecommerce_domain')); | |
| 1558 | + $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 1559 | + if (empty($languages)) { | |
| 1560 | + $this->form_fields['method_name'] = array( | |
| 1561 | + 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'), | |
| 1562 | + 'type' => 'text', | |
| 1563 | + 'default' => __('Omniva Parcel Machine', 'wc_makecommerce_domain') | |
| 1564 | + ); | |
| 1565 | + } else { | |
| 1566 | + foreach ($languages as $language_code => $language) { | |
| 1567 | + $language_name = !empty($language['translated_name']) ? $language['translated_name'] : $language_code; | |
| 1568 | + $this->form_fields['method_name_'.$language_code] = array( | |
| 1569 | + 'title' => __('Shipping Method Title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code), | |
| 1570 | + 'type' => 'text', | |
| 1571 | + 'default' => __('Omniva Parcel Machine', 'wc_makecommerce_domain') | |
| 1572 | + ); | |
| 1573 | + } | |
| 1574 | + } | |
| 1575 | + $this->form_fields['prioritization'] = array( | |
| 1441 | 1576 | 'title' => __('Prioritize', 'wc_makecommerce_domain'), |
| 1442 | 1577 | 'type' => 'checkbox', |
| 1443 | 1578 | 'label' => __('Bigger cities will be on top of list, others sorted alphabetically', 'wc_makecommerce_domain'), |
| 1444 | 1579 | 'default' => 'yes' |
| 1445 | - ), | |
| 1446 | - 'short_office_names' => array( | |
| 1580 | + ); | |
| 1581 | + $this->form_fields['short_office_names'] = array( | |
| 1447 | 1582 | 'title' => __('Short names', 'wc_makecommerce_domain'), |
| 1448 | 1583 | 'type' => 'checkbox', |
| 1449 | 1584 | 'label' => __('Display only parcel machine names, without addresses', 'wc_makecommerce_domain'), |
| 1450 | 1585 | 'default' => 'no' |
| 1451 | - ), | |
| 1452 | - 'api_access' => array( 'type' => 'title', 'title' => '<br>'.__('API access for', 'wc_makecommerce_domain').' '.$this->ext, 'description' => sprintf(__('You can automatically create shipments into Omniva system and print the out the package labels right here, at the shop orders view. <br> Please set your Omniva web servises account credentials below here. <br>(see more on <a href="https://makecommerce.net/en/integration-modules/makecommerce-woocommerce-payment-plugin/#carriers-integration">MakeCommerce plugin page</a>. Don\'t forget to enable also <a href="%s">MC API keys</a>!)', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'))), | |
| 1453 | - 'service_user' => array( | |
| 1586 | + ); | |
| 1587 | + $this->form_fields['api_access'] = array( 'type' => 'title', 'title' => '<hr><br>'.__('API access for', 'wc_makecommerce_domain').' '.$this->ext, 'description' => sprintf(__('You can automatically create shipments into Omniva system and print the out the package labels right here, at the shop orders view. <br> Please set your Omniva web servises account credentials below here. <br>(see more on <a href="https://makecommerce.net/en/integration-modules/makecommerce-woocommerce-payment-plugin/#carriers-integration">MakeCommerce plugin page</a>. Don\'t forget to enable also <a href="%s">MC API keys</a>!)', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'))); | |
| 1588 | + $this->form_fields['service_user'] = array( | |
| 1454 | 1589 | 'title' => __('Omniva web services username', 'wc_makecommerce_domain'), |
| 1455 | 1590 | 'type' => 'text', |
| 1456 | 1591 | 'default' => '' |
| 1457 | - ), | |
| 1458 | - 'service_password' => array( | |
| 1592 | + ); | |
| 1593 | + $this->form_fields['service_password'] = array( | |
| 1459 | 1594 | 'title' => __('Omniva web services password', 'wc_makecommerce_domain'), |
| 1460 | 1595 | 'type' => 'text', |
| 1461 | 1596 | 'default' => '' |
| 1462 | - ), | |
| 1463 | - 'return_address' => array( 'type' => 'title', 'title' => __('Return address', 'wc_makecommerce_domain'), 'description' => __('Please define return address for Omniva shipments', 'wc_makecommerce_domain')), | |
| 1464 | - 'shop_name' => array( | |
| 1597 | + ); | |
| 1598 | + $this->form_fields['return_address'] = array( 'type' => 'title', 'title' => __('Return address', 'wc_makecommerce_domain'), 'description' => __('Please define return address for Omniva shipments', 'wc_makecommerce_domain')); | |
| 1599 | + $this->form_fields['shop_name'] = array( | |
| 1465 | 1600 | 'type' => 'text', |
| 1466 | 1601 | 'title' => __('Shop name', 'wc_makecommerce_domain'), |
| 1467 | 1602 | 'class' => 'input-text regular-input', |
| 1468 | - ), | |
| 1469 | - 'shop_phone' => array( | |
| 1603 | + ); | |
| 1604 | + $this->form_fields['shop_phone'] = array( | |
| 1470 | 1605 | 'type' => 'text', |
| 1471 | 1606 | 'title' => __('Shop phone', 'wc_makecommerce_domain'), |
| 1472 | 1607 | 'class' => 'input-text regular-input', |
| 1473 | - ), | |
| 1474 | - 'shop_email' => array( | |
| 1608 | + ); | |
| 1609 | + $this->form_fields['shop_email'] = array( | |
| 1475 | 1610 | 'type' => 'text', |
| 1476 | 1611 | 'title' => __('Shop email', 'wc_makecommerce_domain'), |
| 1477 | 1612 | 'class' => 'input-text regular-input', |
| 1478 | - ), | |
| 1479 | - 'shop_postal_code' => array( | |
| 1613 | + ); | |
| 1614 | + $this->form_fields['shop_address_city'] = array( | |
| 1480 | 1615 | 'type' => 'text', |
| 1616 | + 'title' => __('Shop address city', 'wc_makecommerce_domain'), | |
| 1617 | + 'class' => 'input-text regular-input', | |
| 1618 | + ); | |
| 1619 | + $this->form_fields['shop_postal_code'] = array( | |
| 1620 | + 'type' => 'text', | |
| 1481 | 1621 | 'title' => __('Shop postal code', 'wc_makecommerce_domain'), |
| 1482 | 1622 | 'class' => 'input-text regular-input', |
| 1483 | 1623 | 'description' => __('Put here zip-code of the Parcel Terminal you use for returns, see: <a href="https://www.omniva.ee/era/kaart/asukohad">List of Omniva Terminals</a>', 'wc_makecommerce_domain') |
| 1484 | - ), | |
| 1624 | + ); | |
| 1625 | + $this->form_fields['shipping_ui_javascript'] = array( | |
| 1626 | + 'type' => 'shipping_ui_javascript', | |
| 1485 | 1627 | ); |
| 1486 | 1628 | } |
| 1487 | 1629 | |
| 1488 | 1630 | } |
| @@ -1494,98 +1636,113 @@ | ||
| 1494 | 1636 | } |
| 1495 | 1637 | function init_form_fields() { |
| 1496 | 1638 | global $woocommerce; |
| 1497 | 1639 | |
| 1498 | - $this->form_fields = array( | |
| 1499 | - 'logo' => array('type' => 'title', 'title' => __get_logo_html()), | |
| 1500 | - 'generic' => array( 'type' => 'title', 'title' => __('Generic and pricing options', 'wc_makecommerce_domain')), | |
| 1501 | - 'active' => array( | |
| 1640 | + $this->form_fields = array(); | |
| 1641 | + $this->form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html()); | |
| 1642 | + $this->form_fields['generic'] = array( 'type' => 'title', 'title' => __('Generic and pricing options', 'wc_makecommerce_domain')); | |
| 1643 | + $this->form_fields['active'] = array( | |
| 1502 | 1644 | 'title' => __('Enable', 'wc_makecommerce_domain'), |
| 1503 | 1645 | 'type' => 'checkbox', |
| 1504 | 1646 | 'label' => __('enabled', 'wc_makecommerce_domain'), |
| 1505 | 1647 | 'default' => 'no', |
| 1506 | 1648 | 'description' => __('You can always exclude a product from being available for the Parcel Machine delivery by clicking "Does not fit parcel machine" in the product\'s shipping options', 'wc_makecommerce_domain'), |
| 1507 | - ), | |
| 1508 | - 'price_ee' => array( | |
| 1509 | - 'title' => __('Price EE', 'wc_makecommerce_domain'), | |
| 1649 | + ); | |
| 1650 | + $this->form_fields['countries'] = array( | |
| 1651 | + 'title' => __('Specific Countries', 'wc_makecommerce_domain'), | |
| 1652 | + 'type' => 'multiselect', | |
| 1653 | + 'class' => 'wp-enhanced-select', | |
| 1654 | + 'css' => 'width: 450px;', | |
| 1655 | + 'default' => array('EE','FI'), | |
| 1656 | + 'options' => array('EE' => __('Estonia - EE'), 'FI' => __('Finland - FI')), | |
| 1657 | + ); | |
| 1658 | + $this->form_fields['price_ee'] = array( | |
| 1659 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' EE', | |
| 1510 | 1660 | 'type' => 'text', |
| 1511 | 1661 | 'default' => '2.99' |
| 1512 | - ), | |
| 1513 | - 'price_fi' => array( | |
| 1514 | - 'title' => __('Price FI', 'wc_makecommerce_domain'), | |
| 1662 | + ); | |
| 1663 | + $this->form_fields['free_shipping_min_amount_ee'] = array( | |
| 1664 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain').' EE', | |
| 1665 | + 'type' => 'number', | |
| 1666 | + 'default' => '0', | |
| 1667 | + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1668 | + ); | |
| 1669 | + $this->form_fields['price_fi'] = array( | |
| 1670 | + 'title' => __('Shipping price', 'wc_makecommerce_domain').' FI', | |
| 1515 | 1671 | 'type' => 'text', |
| 1516 | 1672 | 'default' => '10.99' |
| 1517 | - ), | |
| 1518 | - 'free_shipping_min_amount' => array( | |
| 1519 | - 'title' => __('Minimum amount for free shipping', 'wc_makecommerce_domain'), | |
| 1673 | + ); | |
| 1674 | + $this->form_fields['free_shipping_min_amount_fi'] = array( | |
| 1675 | + 'title' => __('Free shipping amount', 'wc_makecommerce_domain'). ' FI', | |
| 1520 | 1676 | 'type' => 'number', |
| 1521 | 1677 | 'default' => '0', |
| 1522 | - 'description' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1523 | - ), | |
| 1524 | - 'maximum_weight' => array( | |
| 1678 | + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'), | |
| 1679 | + ); | |
| 1680 | + $this->form_fields['maximum_weight'] = array( | |
| 1525 | 1681 | 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'), |
| 1526 | 1682 | 'type' => 'text', |
| 1527 | 1683 | 'default' => '15' |
| 1528 | - ), | |
| 1529 | - 'countries' => array( | |
| 1530 | - 'title' => __('Specific Countries', 'wc_makecommerce_domain'), | |
| 1531 | - 'type' => 'multiselect', | |
| 1532 | - 'class' => 'wp-enhanced-select', | |
| 1533 | - 'css' => 'width: 450px;', | |
| 1534 | - 'default' => array('EE','FI'), | |
| 1535 | - 'options' => array('EE' => __('Estonia'), 'FI' => __('Finland')), | |
| 1536 | - ), | |
| 1537 | - 'look_and_feel' => array( 'type' => 'title', 'title' => __('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on checkout page', 'wc_makecommerce_domain')), | |
| 1538 | - 'method_name' => array( | |
| 1539 | - 'title' => __('Method Title', 'wc_makecommerce_domain'), | |
| 1540 | - 'type' => 'text', | |
| 1541 | - 'default' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain') | |
| 1542 | - ), | |
| 1543 | - 'prioritization' => array( | |
| 1684 | + ); | |
| 1685 | + | |
| 1686 | + $this->form_fields['look_and_feel'] = array( 'type' => 'title', 'title' => '<br>'.__('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on checkout page', 'wc_makecommerce_domain')); | |
| 1687 | + $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); | |
| 1688 | + if (empty($languages)) { | |
| 1689 | + $this->form_fields['method_name'] = array( | |
| 1690 | + 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'), | |
| 1691 | + 'type' => 'text', | |
| 1692 | + 'default' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain') | |
| 1693 | + ); | |
| 1694 | + } else { | |
| 1695 | + foreach ($languages as $language_code => $language) { | |
| 1696 | + $language_name = !empty($language['translated_name']) ? $language['translated_name'] : $language_code; | |
| 1697 | + $this->form_fields['method_name_'.$language_code] = array( | |
| 1698 | + 'title' => __('Shipping Method Title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code), | |
| 1699 | + 'type' => 'text', | |
| 1700 | + 'default' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain') | |
| 1701 | + ); | |
| 1702 | + } | |
| 1703 | + } | |
| 1704 | + $this->form_fields['prioritization'] = array( | |
| 1544 | 1705 | 'title' => __('Prioritize', 'wc_makecommerce_domain'), |
| 1545 | 1706 | 'type' => 'checkbox', |
| 1546 | 1707 | 'label' => __('Bigger cities will be on top of list, others sorted alphabetically', 'wc_makecommerce_domain'), |
| 1547 | 1708 | 'default' => 'yes' |
| 1548 | - ), | |
| 1549 | - 'short_office_names' => array( | |
| 1709 | + ); | |
| 1710 | + $this->form_fields['short_office_names'] = array( | |
| 1550 | 1711 | 'title' => __('Short names', 'wc_makecommerce_domain'), |
| 1551 | 1712 | 'type' => 'checkbox', |
| 1552 | 1713 | 'label' => __('Display only parcel machine names, without addresses', 'wc_makecommerce_domain'), |
| 1553 | 1714 | 'default' => 'no' |
| 1554 | - ), | |
| 1555 | - 'api_access' => array( 'type' => 'title', 'title' => '<br>'.__('API access for', 'wc_makecommerce_domain').' '.$this->ext, 'description' => sprintf(__('You can automatically create shipments into smartpost.ee system and print the out the package labels right here, at the shop orders view. <br> Please set your smartpost.ee account credentials below here. <br>(See more on <a href="https://makecommerce.net/en/integration-modules/makecommerce-woocommerce-payment-plugin/#carriers-integration">MakeCommerce plugin page</a>. Don\'t forget to enable also <a href="%s">MC API keys</a>!)', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'))), | |
| 1556 | - 'service_user' => array( | |
| 1715 | + ); | |
| 1716 | + $this->form_fields['api_access'] = array( 'type' => 'title', 'title' => '<br>'.__('API access for', 'wc_makecommerce_domain').' '.$this->ext, 'description' => sprintf(__('You can automatically create shipments into smartpost.ee system and print the out the package labels right here, at the shop orders view. <br> Please set your smartpost.ee account credentials below here. <br>(See more on <a href="https://makecommerce.net/en/integration-modules/makecommerce-woocommerce-payment-plugin/#carriers-integration">MakeCommerce plugin page</a>. Don\'t forget to enable also <a href="%s">MC API keys</a>!)', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'))); | |
| 1717 | + $this->form_fields['service_user'] = array( | |
| 1557 | 1718 | 'title' => __('eteenindus.smartpost.ee username', 'wc_makecommerce_domain'), |
| 1558 | 1719 | 'type' => 'text', |
| 1559 | 1720 | 'default' => '' |
| 1560 | - ), | |
| 1561 | - 'service_password' => array( | |
| 1721 | + ); | |
| 1722 | + $this->form_fields['service_password'] = array( | |
| 1562 | 1723 | 'title' => __('eteenindus.smartpost.ee password', 'wc_makecommerce_domain'), |
| 1563 | 1724 | 'type' => 'text', |
| 1564 | 1725 | 'default' => '' |
| 1565 | - ), | |
| 1566 | - 'return_address' => array( 'type' => 'title', 'title' => __('Return address', 'wc_makecommerce_domain'), 'description' => __('Please define return address for SmartPOST shipments (used on parcel labels)', 'wc_makecommerce_domain')), | |
| 1567 | - 'shop_name' => array( | |
| 1726 | + ); | |
| 1727 | + $this->form_fields['return_address'] = array( 'type' => 'title', 'title' => __('Return address', 'wc_makecommerce_domain'), 'description' => __('Please define return address for SmartPOST shipments (used on parcel labels)', 'wc_makecommerce_domain')); | |
| 1728 | + $this->form_fields['shop_name'] = array( | |
| 1568 | 1729 | 'type' => 'text', |
| 1569 | 1730 | 'title' => __('Shop name', 'wc_makecommerce_domain'), |
| 1570 | 1731 | 'class' => 'input-text regular-input', |
| 1571 | - ), | |
| 1572 | - 'shop_phone' => array( | |
| 1732 | + ); | |
| 1733 | + $this->form_fields['shop_phone'] = array( | |
| 1573 | 1734 | 'type' => 'text', |
| 1574 | 1735 | 'title' => __('Shop phone', 'wc_makecommerce_domain'), |
| 1575 | 1736 | 'class' => 'input-text regular-input', |
| 1576 | - ), | |
| 1577 | - 'shop_email' => array( | |
| 1737 | + ); | |
| 1738 | + $this->form_fields['shop_email'] = array( | |
| 1578 | 1739 | 'type' => 'text', |
| 1579 | 1740 | 'title' => __('Shop email', 'wc_makecommerce_domain'), |
| 1580 | 1741 | 'class' => 'input-text regular-input', |
| 1581 | - ), | |
| 1582 | - /*'shop_postal_code' => array( | |
| 1583 | - 'type' => 'text', | |
| 1584 | - 'title' => __('Shop postal code', 'wc_makecommerce_domain'), | |
| 1585 | - 'class' => 'input-text regular-input', | |
| 1586 | - ), | |
| 1587 | - */ | |
| 1742 | + ); | |
| 1743 | + $this->form_fields['shipping_ui_javascript'] = array( | |
| 1744 | + 'type' => 'shipping_ui_javascript', | |
| 1588 | 1745 | ); |
| 1589 | 1746 | } |
| 1590 | 1747 | |
| 1591 | 1748 | } |
| @@ -1657,17 +1814,17 @@ | ||
| 1657 | 1814 | 'desc' => __('Get it from <a href="https://merchant.maksekeskus.ee/api.html" target="_blank">Merchant Portal</a>','wc_makecommerce_domain'), |
| 1658 | 1815 | 'class' => 'input-text regular-input', |
| 1659 | 1816 | ), |
| 1660 | 1817 | array( |
| 1661 | - 'id' => 'mk_public_key', | |
| 1818 | + 'id' => 'mk_private_key', | |
| 1662 | 1819 | 'type' => 'text', |
| 1663 | - 'title' => __('Public key (live)', 'wc_makecommerce_domain'), | |
| 1820 | + 'title' => __('Secret key (live)', 'wc_makecommerce_domain'), | |
| 1664 | 1821 | 'class' => 'input-text regular-input', |
| 1665 | - ), | |
| 1822 | + ), | |
| 1666 | 1823 | array( |
| 1667 | - 'id' => 'mk_private_key', | |
| 1824 | + 'id' => 'mk_public_key', | |
| 1668 | 1825 | 'type' => 'text', |
| 1669 | - 'title' => __('Private key (live)', 'wc_makecommerce_domain'), | |
| 1826 | + 'title' => __('Publishable key (live)', 'wc_makecommerce_domain'), | |
| 1670 | 1827 | 'class' => 'input-text regular-input', |
| 1671 | 1828 | ), |
| 1672 | 1829 | array( |
| 1673 | 1830 | 'id' => 'mk_test_shop_id', |
| @@ -1674,25 +1831,29 @@ | ||
| 1674 | 1831 | 'type' => 'text', |
| 1675 | 1832 | 'title' => __('Shop ID (test)', 'wc_makecommerce_domain'), |
| 1676 | 1833 | 'class' => 'input-text regular-input', |
| 1677 | 1834 | 'desc' => __('Get it from <a href="https://merchant-test.maksekeskus.ee/api.html" target="_blank">Merchant Portal Test</a>','wc_makecommerce_domain'), |
| 1835 | + ), | |
| 1836 | + array( | |
| 1837 | + 'id' => 'mk_test_private_key', | |
| 1838 | + 'type' => 'text', | |
| 1839 | + 'title' => __('Secret key (test)', 'wc_makecommerce_domain'), | |
| 1840 | + 'class' => 'input-text regular-input', | |
| 1678 | 1841 | ), |
| 1679 | 1842 | array( |
| 1680 | 1843 | 'id' => 'mk_test_public_key', |
| 1681 | 1844 | 'type' => 'text', |
| 1682 | - 'title' => __('Public key (test)', 'wc_makecommerce_domain'), | |
| 1845 | + 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'), | |
| 1683 | 1846 | 'class' => 'input-text regular-input', |
| 1684 | 1847 | ), |
| 1685 | 1848 | array( |
| 1686 | - 'id' => 'mk_test_private_key', | |
| 1687 | - 'type' => 'text', | |
| 1688 | - 'title' => __('Private key (test)', 'wc_makecommerce_domain'), | |
| 1689 | - 'class' => 'input-text regular-input', | |
| 1849 | + 'id' => 'mk_javascript_ui', | |
| 1850 | + 'type' => 'api_javascript_ui', | |
| 1690 | 1851 | ), |
| 1691 | 1852 | array('type' => 'sectionend', 'id' => 'mk_api_settings') |
| 1692 | 1853 | ); |
| 1693 | 1854 | } |
| 1694 | - | |
| 1855 | + | |
| 1695 | 1856 | function mk_admin_save_settings() { |
| 1696 | 1857 | // reload banklinks |
| 1697 | 1858 | global $current_section; |
| 1698 | 1859 | if ($current_section !== 'mk_api') { |
| @@ -1701,25 +1862,52 @@ | ||
| 1701 | 1862 | $wcmc = New woocommerce_makecommerce(true); |
| 1702 | 1863 | $wcmc->mc_banklinks_reload(true); |
| 1703 | 1864 | } |
| 1704 | 1865 | |
| 1705 | - function __get_logo_html() { | |
| 1706 | - return '<div class="makecommerce-info">'. | |
| 1707 | - '<div class="makecommerce-logo">'. | |
| 1708 | - '<a target="_blank" href="http://maksekeskus.ee"><img src="'. plugins_url('/images/makecommerce_logo_en.svg', __FILE__) .'" class="makecommerce-logo"></a>'. | |
| 1709 | - '</div>'. | |
| 1710 | - '<div class="makecommerce-links">'. | |
| 1711 | - '<div class="makecommerce-link"><a target="_blank" href="https://merchant.maksekeskus.ee">Merchant Portal</a></div>'. | |
| 1712 | - '<div class="makecommerce-link"><a target="_blank" href="https://makecommerce.net/">makecommerce.net</a></div>'. | |
| 1713 | - '<div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>'. | |
| 1714 | - '</div>'. | |
| 1715 | - '</div>'; | |
| 1716 | - } | |
| 1866 | + function __get_logo_html() { | |
| 1867 | + return '<div class="makecommerce-info">'. | |
| 1868 | + '<div class="makecommerce-logo">'. | |
| 1869 | + '<a target="_blank" href="http://maksekeskus.ee"><img src="'. plugins_url('/images/makecommerce_logo_en.svg', __FILE__) .'" class="makecommerce-logo"></a>'. | |
| 1870 | + '</div>'. | |
| 1871 | + '<div class="makecommerce-links">'. | |
| 1872 | + '<div class="makecommerce-link"><a target="_blank" href="https://merchant.maksekeskus.ee">Merchant Portal</a></div>'. | |
| 1873 | + '<div class="makecommerce-link"><a target="_blank" href="https://makecommerce.net/">makecommerce.net</a></div>'. | |
| 1874 | + '<div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>'. | |
| 1875 | + '</div>'. | |
| 1876 | + '</div>'; | |
| 1877 | + } | |
| 1717 | 1878 | |
| 1718 | 1879 | add_action('woocommerce_get_sections_api', 'mk_admin_add_settings'); |
| 1719 | 1880 | add_filter('woocommerce_get_settings_api', 'mk_admin_all_settings', 10, 2); |
| 1720 | 1881 | add_action('woocommerce_settings_saved', 'mk_admin_save_settings', 30, 0); |
| 1882 | + add_action('woocommerce_admin_field_api_javascript_ui', 'api_javascript_ui'); | |
| 1883 | + function api_javascript_ui( $data ) { | |
| 1884 | + ?> | |
| 1885 | + <script type="text/javascript"> | |
| 1886 | + jQuery(document).ready(function($) { | |
| 1887 | + var env_select = $('#mk_api_type'); | |
| 1888 | + var test_fields = ['mk_test_shop_id', 'mk_test_private_key', 'mk_test_public_key']; | |
| 1889 | + var live_fields = ['mk_shop_id', 'mk_private_key', 'mk_public_key']; | |
| 1721 | 1890 | |
| 1891 | + env_select.on('change', function(){ | |
| 1892 | + hideFileds($(this).val()); | |
| 1893 | + }); | |
| 1894 | + hideFileds(env_select.val()); | |
| 1895 | + function hideFileds(type) { | |
| 1896 | + var hide = type == 'live' ? test_fields : live_fields; | |
| 1897 | + var show = type == 'live' ? live_fields : test_fields; | |
| 1898 | + $.each(hide, function(i, elem) { | |
| 1899 | + $('#'+elem).closest('tr').hide(); | |
| 1900 | + }); | |
| 1901 | + $.each(show, function(i, elem) { | |
| 1902 | + $('#'+elem).closest('tr').show(); | |
| 1903 | + }); | |
| 1904 | + } | |
| 1905 | + }); | |
| 1906 | + </script> | |
| 1907 | + <?php | |
| 1908 | + } | |
| 1909 | + | |
| 1722 | 1910 | function mk_admin_restrict_manage_posts() { |
| 1723 | 1911 | global $typenow; |
| 1724 | 1912 | if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ) ) ) { |
| 1725 | 1913 | $selected_method = !empty($_REQUEST['_shipping_method']) ? $_REQUEST['_shipping_method'] : false; |
| @@ -1751,10 +1939,9 @@ | ||
| 1751 | 1939 | add_filter('posts_where', 'mk_admin_shipping_filter', 10, 2); |
| 1752 | 1940 | |
| 1753 | 1941 | function mk_admin_bulk_actions() { |
| 1754 | 1942 | global $post_type; |
| 1755 | - if ('shop_order' === $post_type) { | |
| 1756 | -?> | |
| 1943 | + if ('shop_order' === $post_type) { ?> | |
| 1757 | 1944 | <script type="text/javascript"> |
| 1758 | 1945 | jQuery(function() { |
| 1759 | 1946 | jQuery('<option>').val('parcel_machine_labels').text('<?php _e( 'Register parcel machine shipments', 'wc_makecommerce_domain' )?>').appendTo('select[name="action"]'); |
| 1760 | 1947 | jQuery('<option>').val('parcel_machine_labels').text('<?php _e( 'Register parcel machine shipments', 'wc_makecommerce_domain' )?>').appendTo('select[name="action2"]'); |
| @@ -1761,18 +1948,15 @@ | ||
| 1761 | 1948 | jQuery('<option>').val('parcel_machine_print_labels').text('<?php _e( 'Print parcel machine labels', 'wc_makecommerce_domain' )?>').appendTo('select[name="action"]'); |
| 1762 | 1949 | jQuery('<option>').val('parcel_machine_print_labels').text('<?php _e( 'Print parcel machine labels', 'wc_makecommerce_domain' )?>').appendTo('select[name="action2"]'); |
| 1763 | 1950 | }); |
| 1764 | 1951 | </script> |
| 1765 | -<?php | |
| 1766 | - if (!empty($_REQUEST['mk_pdf'])) { | |
| 1767 | -?> | |
| 1768 | - <script type="text/javascript"> | |
| 1769 | - jQuery(function(){ | |
| 1770 | - window.open('<?php echo $_REQUEST['mk_pdf'] ?>', 'pdf'); | |
| 1771 | - }); | |
| 1772 | - </script> | |
| 1773 | -<?php | |
| 1774 | - } | |
| 1952 | + <?php if (!empty($_REQUEST['mk_pdf'])) { ?> | |
| 1953 | + <script type="text/javascript"> | |
| 1954 | + jQuery(function(){ | |
| 1955 | + window.open('<?php echo $_REQUEST['mk_pdf'] ?>', 'pdf'); | |
| 1956 | + }); | |
| 1957 | + </script> | |
| 1958 | + <?php } | |
| 1775 | 1959 | } |
| 1776 | 1960 | } |
| 1777 | 1961 | function mk_admin_bulk_action_labels() { |
| 1778 | 1962 | $wp_list_table = _get_list_table('WP_Posts_List_Table'); |
| @@ -1857,13 +2041,23 @@ | ||
| 1857 | 2041 | 'label' => __('Does not fit parcel machine', 'wc_makecommerce_domain'), |
| 1858 | 2042 | 'description' => __('When this is checked, parcel machine shipping option is not available for a cart with this product', 'wc_makecommerce_domain') |
| 1859 | 2043 | ) |
| 1860 | 2044 | ); |
| 2045 | + woocommerce_wp_checkbox( | |
| 2046 | + array( | |
| 2047 | + 'id' => '_no_shipping_cost', | |
| 2048 | + 'wrapper_class' => 'show_if_simple', | |
| 2049 | + 'label' => __('Free parcel machine', 'wc_makecommerce_domain'), | |
| 2050 | + 'description' => __('When this is checked, parcel machine if free for this product', 'wc_makecommerce_domain') | |
| 2051 | + ) | |
| 2052 | + ); | |
| 1861 | 2053 | echo '</div>'; |
| 1862 | 2054 | } |
| 1863 | 2055 | function mk_admin_product_fields_save($post_id) { |
| 1864 | 2056 | $no_parcel_machine = isset($_POST['_no_parcel_machine']) ? 'yes' : 'no'; |
| 1865 | 2057 | update_post_meta($post_id, '_no_parcel_machine', $no_parcel_machine); |
| 2058 | + $no_shipping_cost = isset($_POST['_no_shipping_cost']) ? 'yes' : 'no'; | |
| 2059 | + update_post_meta($post_id, '_no_shipping_cost', $no_shipping_cost); | |
| 1866 | 2060 | } |
| 1867 | 2061 | |
| 1868 | 2062 | add_action('woocommerce_product_options_shipping', 'mk_admin_product_option_fields'); |
| 1869 | 2063 | add_action('woocommerce_process_product_meta', 'mk_admin_product_fields_save'); |
| @@ -1945,18 +2139,12 @@ | ||
| 1945 | 2139 | } |
| 1946 | 2140 | } |
| 1947 | 2141 | } |
| 1948 | 2142 | |
| 1949 | - function mk_get_labels($post_ids) { | |
| 2143 | + function mk_get_labels($post_ids, $ajax = false) { | |
| 1950 | 2144 | if (!is_array($post_ids)) { |
| 1951 | 2145 | $post_ids = array($post_ids); |
| 1952 | 2146 | } |
| 1953 | - $sender = array( | |
| 1954 | - 'name' => get_option('mk_shop_name', ''), | |
| 1955 | - 'phone' => get_option('mk_shop_phone', ''), | |
| 1956 | - 'email' => get_option('mk_shop_email', ''), | |
| 1957 | - 'postalCode' => get_option('mk_shop_postal_code', '') | |
| 1958 | - ); | |
| 1959 | 2147 | parcelmachine_add_method(); |
| 1960 | 2148 | $shipping_request = array('credentials' => array(), 'orders' => array(), 'printFormat' => 'A4'); |
| 1961 | 2149 | foreach ($post_ids as $post_id) { |
| 1962 | 2150 | $parcel_machine = get_post_meta($post_id, '_parcel_machine', true); |
| @@ -1985,8 +2173,14 @@ | ||
| 1985 | 2173 | } |
| 1986 | 2174 | $order = wc_get_order($post_id); |
| 1987 | 2175 | $shipment_id = get_post_meta($post_id, '_parcel_machine_shipment_id', true); |
| 1988 | 2176 | if (!$shipment_id) { continue; } |
| 2177 | + $sender = array( | |
| 2178 | + 'name' => $transport_class->settings['shop_name'], | |
| 2179 | + 'phone' => $transport_class->settings['shop_phone'], | |
| 2180 | + 'email' => $transport_class->settings['shop_email'], | |
| 2181 | + 'postalCode' => $transport_class->settings['shop_postal_code'] | |
| 2182 | + ); | |
| 1989 | 2183 | $shipping_request['orders'][] = array( |
| 1990 | 2184 | 'carrier' => $provider_uc, |
| 1991 | 2185 | 'orderId' => $order->id, |
| 1992 | 2186 | 'destination' => array('destinationId' => $machine_id), |
| @@ -2011,8 +2205,11 @@ | ||
| 2011 | 2205 | } |
| 2012 | 2206 | if (empty($response->labelUrl)) { |
| 2013 | 2207 | return; |
| 2014 | 2208 | } |
| 2209 | + if($ajax) { | |
| 2210 | + return $response->labelUrl; | |
| 2211 | + } | |
| 2015 | 2212 | $sendback = add_query_arg(array('post_type' => 'shop_order', 'mk_pdf' => urlencode($response->labelUrl)), ''); |
| 2016 | 2213 | wp_redirect(esc_url_raw($sendback)); |
| 2017 | 2214 | exit(); |
| 2018 | 2215 | } |
| @@ -2028,9 +2225,13 @@ | ||
| 2028 | 2225 | $mk_api_type = get_option('mk_api_type', false); |
| 2029 | 2226 | if (!$mk_api_type) { |
| 2030 | 2227 | return false; |
| 2031 | 2228 | } |
| 2032 | - $key_prefix = $mk_api_type.'_'; | |
| 2229 | + if ($mk_api_type !== 'live') { | |
| 2230 | + $key_prefix = $mk_api_type.'_'; | |
| 2231 | + } else { | |
| 2232 | + $key_prefix = ''; | |
| 2233 | + } | |
| 2033 | 2234 | $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', ''); |
| 2034 | 2235 | $mk_public_key = get_option('mk_'.$key_prefix.'public_key', ''); |
| 2035 | 2236 | $mk_private_key = get_option('mk_'.$key_prefix.'private_key', ''); |
| 2036 | 2237 | if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) { |
| @@ -2055,9 +2256,9 @@ | ||
| 2055 | 2256 | } |
| 2056 | 2257 | foreach ($data as $machine) { |
| 2057 | 2258 | if ($machine->country === $country && $machine->type === 'APT' && ($provider === '*' || strtolower($provider) === strtolower($machine->provider))) { |
| 2058 | 2259 | $machines[] = array( |
| 2059 | - 'provider' => strtolower($machine->provider), | |
| 2260 | + 'carrier' => strtolower($machine->provider), | |
| 2060 | 2261 | 'id' => $machine->id, |
| 2061 | 2262 | 'name' => $machine->name, |
| 2062 | 2263 | 'city' => $machine->city, |
| 2063 | 2264 | 'address' => !empty($machine->address) ? $machine->address : '', |
| @@ -2075,9 +2276,9 @@ | ||
| 2075 | 2276 | |
| 2076 | 2277 | function mk_get_machine($provider, $id) { |
| 2077 | 2278 | $machines = mk_get_machines($provider); |
| 2078 | 2279 | foreach ($machines as $machine) { |
| 2079 | - if ($machine['provider'] === $provider && $machine['id'] === $id) { | |
| 2280 | + if ($machine['carrier'] === $provider && $machine['id'] === $id) { | |
| 2080 | 2281 | return $machine; |
| 2081 | 2282 | } |
| 2082 | 2283 | } |
| 2083 | 2284 | return false; |
| @@ -2084,5 +2285,61 @@ | ||
| 2084 | 2285 | } |
| 2085 | 2286 | function mk_admin_error() { |
| 2086 | 2287 | printf( '<div class="%1$s"><p>%2$s</p></div>', 'notice notice-error', __('Please check that you have configured correctly MakeCommerce API accesses', 'wc_makecommerce_domain')); |
| 2087 | 2288 | } |
| 2289 | + | |
| 2290 | + add_filter('query_vars', 'mk_cron_query_vars'); | |
| 2291 | + add_action('parse_request', 'mk_parse_cron_update_vars'); | |
| 2292 | + function mk_cron_query_vars($vars) { | |
| 2293 | + $vars[] = 'mk-action'; | |
| 2294 | + $vars[] = 'mk-shop-id'; | |
| 2295 | + $vars[] = 'mk-test-shop-id'; | |
| 2296 | + return $vars; | |
| 2297 | + } | |
| 2298 | + function mk_parse_cron_update_vars($wp) { | |
| 2299 | + if (array_key_exists('mk-action', $wp->query_vars) && $wp->query_vars['mk-action'] == 'mk-update' | |
| 2300 | + && (array_key_exists('mk-shop-id', $wp->query_vars) || array_key_exists('mk-test-shop-id', $wp->query_vars) ) ) { | |
| 2301 | + if( (strlen($wp->query_vars['mk-shop-id']) && $wp->query_vars['mk-shop-id'] == get_option('mk_shop_id', false) ) | |
| 2302 | + || (strlen($wp->query_vars['mk-test-shop-id']) && $wp->query_vars['mk-test-shop-id'] == get_option('mk_test_shop_id', false) ) ) { | |
| 2303 | + $obj = new woocommerce_makecommerce(); | |
| 2304 | + $obj->mc_banklinks_reload(true); | |
| 2305 | + exit(); | |
| 2306 | + } | |
| 2307 | + } | |
| 2308 | + } | |
| 2309 | + function print_parcel_machine_label_action( $post_id ) { | |
| 2310 | + ?> | |
| 2311 | + <li class="wide"> | |
| 2312 | + <a id="print_parcel_machine_label" href="#" class="button"><?php _e('Print parcel label', 'wc_makecommerce_domain');?></a> | |
| 2313 | + <img class="mc_loading" src="<?php echo site_url('/wp-admin/images/loading.gif');?>"> | |
| 2314 | + <script type="text/javascript"> | |
| 2315 | + jQuery(function($){ | |
| 2316 | + var data = { | |
| 2317 | + 'action': 'print_pml', | |
| 2318 | + 'id': '<?php echo $post_id; ?>' | |
| 2319 | + }; | |
| 2320 | + var loading = $('.mc_loading'); | |
| 2321 | + $('#print_parcel_machine_label').click(function(e){ | |
| 2322 | + e.preventDefault(); | |
| 2323 | + var button = $(this); | |
| 2324 | + button.addClass('disabled'); | |
| 2325 | + loading.show(); | |
| 2326 | + $.post(ajaxurl, data, function(response) { | |
| 2327 | + button.removeClass('disabled'); | |
| 2328 | + loading.hide(); | |
| 2329 | + window.open(response, 'pdf'); | |
| 2330 | + }); | |
| 2331 | + }); | |
| 2332 | + }); | |
| 2333 | + </script> | |
| 2334 | + </li> | |
| 2335 | + <?php | |
| 2336 | + } | |
| 2337 | + add_action('woocommerce_order_actions_end', 'print_parcel_machine_label_action'); | |
| 2338 | + function ajax_print_pml() { | |
| 2339 | + if(!current_user_can('manage_woocommerce') ) { | |
| 2340 | + die(); | |
| 2341 | + } | |
| 2342 | + die(mk_get_labels(intval($_POST['id']), true)); | |
| 2343 | + } | |
| 2344 | + add_action( 'wp_ajax_print_pml', 'ajax_print_pml' ); | |
| 2088 | 2345 | } |