PluginProbe
MakeCommerce for WooCommerce / 2.6.0
MakeCommerce for WooCommerce v2.6.0
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
← All changes | makecommerce.php +96 -21 2.2.12.6.0 View file →
@@ -1,12 +1,14 @@
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: 2.2.1
5 + Version: 2.6.0
6 6 Author: Maksekeskus AS
7 7 Author URI: https://MakeCommerce.net/
8 8 Text Domain: wc_makecommerce_domain
9 + WC requires at least: 3.0
10 + WC tested up to: 4.3.1
9 11 */
10 12
11 13 if (!defined('ABSPATH')) {
12 14 exit; // Exit if accessed directly.
@@ -49,8 +51,11 @@
49 51 type varchar(10) NOT NULL,
50 52 country char(2) NOT NULL,
51 53 name varchar(25) NOT NULL,
52 54 url varchar(250) NOT NULL,
55 + logo_url varchar(250),
56 + min_amount mediumint(9),
57 + max_amount mediumint(9),
53 58 UNIQUE KEY id (id)
54 59 ) $charset;";
55 60
56 61 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
@@ -73,9 +78,9 @@
73 78 // Assign schedule if not set, update compatible no need to reactivate, format('U') php 5.2 compatible
74 79 // Assigns task at 23.59.59 by local time, task runs if time has passed and somebody navigates the site
75 80 if (! wp_next_scheduled ( 'mc_banklinks_update_cron' )) {
76 81 $date = new DateTime();
77 - $date->setTime(04,10,00);
82 + $date->setTime(rand(0,23),rand(0,59),00);
78 83 $timestamp = intval($date->format('U'));
79 84 //$local = 3600 * intval(get_option('gmt_offset'));
80 85 //wp_schedule_event($timestamp - $local, 'twicedaily', 'mc_banklinks_update_cron');
81 86 wp_schedule_event($timestamp, 'twicedaily', 'mc_banklinks_update_cron');
@@ -85,13 +90,26 @@
85 90 require_once('includes/vendor/autoload.php');
86 91 require_once('includes/Maksekeskus.php');
87 92 }
88 93
89 - function mk_check_payment() {
94 + function mk_check_payment() {
90 95
91 96 global $woocommerce;
92 97 $api = mk_get_api();
93 98
99 + //set the correct language
100 + if (isset($_GET["lang1"])) {
101 + //set wpml language
102 + if (function_exists('icl_object_id')) {
103 + do_action('wpml_switch_language', $_GET["lang1"]);
104 + } else {
105 + //set polylang language
106 + if (function_exists('pll_current_language')) {
107 + //not implemented yet
108 + }
109 + }
110 + }
111 +
94 112 $returnUrl = home_url();
95 113
96 114 $request = stripslashes_deep($_POST);
97 115 if ($api->verifyMac($request)) {
@@ -128,9 +146,9 @@
128 146 $paymentStatus = $transaction->status;
129 147
130 148 if ($paymentStatus == 'PENDING') {
131 149 $paymentRequest = array(
132 - 'amount' => $transaction->amount,
150 + 'amount' => (string)sprintf("%.2f", $transaction->amount),
133 151 'currency' => $transaction->currency,
134 152 'token' => $data['token']['id']
135 153 );
136 154 $payment = $api->createPayment($transactionId, $paymentRequest);
@@ -150,9 +168,9 @@
150 168 if (!$reference) { return $returnUrl; }
151 169
152 170 $order = new WC_Order($reference);
153 171 // if we din't find the Order, we send user to shop landing-page. TODO: could be improved
154 - if (!$order->id) { return $returnUrl; }
172 + if (!$order->get_id()) { return $returnUrl; }
155 173
156 174 $returnUrl = $order->get_checkout_order_received_url();
157 175
158 176 switch($paymentStatus) {
@@ -159,22 +177,25 @@
159 177
160 178 case 'CANCELLED':
161 179 $order->update_status( 'cancelled' );
162 180 wc_add_notice(__('Payment transaction cancelled', 'wc_makecommerce_domain'), 'error');
163 - $returnUrl = $woocommerce->cart->get_cart_url();
181 + $returnUrl = wc_get_cart_url();
164 182 break;
165 183
166 184 case 'COMPLETED':
167 185 $orderNote = array();
168 186 $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': <a target=_blank href="'.$api->getEnvUrls()->merchantUrl.'/merchant/shop/deals/detail.html?id='. $transactionId .'">'.$transactionId.'</a>';
169 - $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->id, '_makecommerce_preselected_method', true);
187 + $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->get_id(), '_makecommerce_preselected_method', true);
170 188 $order->add_order_note(implode("\r\n", $orderNote));
189 + if (!empty($data['token']) && !empty($data['token']['multiuse'])) {
190 + update_post_meta($order->get_id(), '_makecommerce_payment_token', $data['token']['id']);
191 + update_post_meta($order->get_id(), '_makecommerce_payment_token_valid_until', $data['token']['valid_until']);
192 + }
171 193
194 + if( isset($_GET['lang1']) ) $order->update_meta_data('wpml_language', $_GET["lang1"]);
172 195 $order->payment_complete( $transactionId );
173 - $order->update_status( 'processing' );
174 196 $woocommerce->cart->empty_cart();
175 197 break;
176 -
177 198 }
178 199
179 200 return $returnUrl;
180 201 }
@@ -361,17 +382,17 @@
361 382 'title' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain'),
362 383 'desc' => __('enable SmartPOST parcel machines shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping&section=parcelmachine_smartpost')).')',
363 384 'class' => '',
364 385 ),
365 - // array(
366 - // 'id' => 'mk_transport_apt_dpd',
367 - // 'type' => 'checkbox',
368 - // 'default' => 'no',
369 - // 'title' => __('DPD Pickup Network', 'wc_makecommerce_domain'),
370 - // 'desc' => __('enable DPD Pickup network shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping&section=parcelmachine_dpd')).')',
371 - // 'class' => '',
372 - // ),
373 386 array(
387 + 'id' => 'mk_transport_apt_dpd',
388 + 'type' => 'checkbox',
389 + 'default' => 'no',
390 + 'title' => __('DPD Pickup Network', 'wc_makecommerce_domain'),
391 + 'desc' => __('enable DPD Pickup network shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping&section=parcelmachine_dpd')).')',
392 + 'class' => '',
393 + ),
394 + array(
374 395 'id' => 'mk_transport_courier_omniva',
375 396 'type' => 'checkbox',
376 397 'default' => 'yes',
377 398 'title' => __('Omniva Courier', 'wc_makecommerce_domain'),
@@ -393,8 +414,15 @@
393 414 'desc' => __('enable SimpleCheckout&trade; Checkout method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=checkout&section=makecommerce_sc')).')',
394 415 'class' => '',
395 416 ),
396 417 array(
418 + 'id' => 'mk_product_slice',
419 + 'type' => 'checkbox',
420 + 'title' => __('Slice in 3 information in product view', 'wc_makecommerce_domain'),
421 + 'desc' => __('enable Slice in product view', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=checkout&section=makecommerce_sc')).')',
422 + 'class' => '',
423 + ),
424 + array(
397 425 'id' => 'mk_javascript_ui',
398 426 'type' => 'api_javascript_ui',
399 427 ),
400 428 array('type' => 'sectionend', 'id' => 'mk_api_settings')
@@ -400,8 +428,17 @@
400 428 array('type' => 'sectionend', 'id' => 'mk_api_settings')
401 429 );
402 430 }
403 431
432 + function mk_wc_version($version) {
433 + global $woocommerce;
434 + if ( version_compare( $woocommerce->version, "3.4.0", ">=" ) ) {
435 + return true;
436 + } else {
437 + return false;
438 + }
439 + }
440 +
404 441 function mk_admin_save_api_settings() {
405 442 // reload banklinks
406 443 global $current_section;
407 444 if ($current_section !== 'mk_api') {
@@ -409,17 +446,55 @@
409 446 }
410 447 update_mc_banklinks();
411 448 }
412 449
413 - function mk_admin_plugin_settings_link($links) {
414 - $settings_link = '<a href="admin.php?page=wc-settings&tab=api&section=mk_api">API '.__('Settings').'</a>';
415 - array_unshift($links, $settings_link);
416 - return $links;
450 + function mk_admin_plugin_settings_link($links) {
451 + if (mk_wc_version("3.4.0"))
452 + $settings_link = '<a href="admin.php?page=wc-settings&tab=advanced&section=mk_api">API '.__('Settings').'</a>';
453 + else
454 + $settings_link = '<a href="admin.php?page=wc-settings&tab=api&section=mk_api">API '.__('Settings').'</a>';
455 + array_unshift($links, $settings_link);
456 + return $links;
417 457 }
458 +
459 + function wc_mc_shop_slice_button() {
460 + if (get_option('mk_product_slice', 'no') == 'yes') {
461 + global $product;
462 + // $price_excl_tax = wc_get_price_excluding_tax( $product ); // price without VAT
463 + $price_incl_tax = wc_get_price_including_tax( $product ); // price with VAT
464 + global $wpdb;
465 + global $mkDbTable;
466 + $tableName = $wpdb->prefix . $mkDbTable;
467 + $methods = $wpdb->get_results('SELECT * FROM '.$tableName);
468 + $slice = false;
469 + if(count($methods)) {
470 + foreach ($methods as $method) {
471 + if ($method->name =="slice") {
472 + if ( $price_incl_tax >= $method->min_amount ) {
473 + if ( $price_incl_tax <= $method->max_amount ) {
474 + $slice = true;
475 + }
476 + }
477 + }
478 + }
479 + }
480 + if ($slice == true) {
481 + echo '<div style="width:100%; margin-top: 20px; margin-bottom: auto;"><img src="'.plugins_url('/images/slice_logo_dark_176x62.svg', __FILE__).'" width="88" weight="31"/>&nbsp;&nbsp;Osta kohe, maksa hiljem. Kolmes võrdses osas 3 x '.sprintf("%.2f",$price_incl_tax/3).' €</div>'; // sprintf("%.2f",$price_incl_tax/3).' in month
482 + }
483 + }
484 + }
485 + // Slice Promo 1
486 + add_action( 'woocommerce_after_add_to_cart_button', 'wc_mc_shop_slice_button', 20 );
487 +
488 + // if (mk_wc_version("3.4.0")) {
489 + add_filter('woocommerce_get_settings_advanced', 'mk_admin_api_settings', 10, 2);
490 + add_action('woocommerce_get_sections_advanced', 'mk_admin_add_api_settings');
418 491 add_filter('woocommerce_get_settings_api', 'mk_admin_api_settings', 10, 2);
492 + // } else {
419 493 add_action('woocommerce_get_sections_api', 'mk_admin_add_api_settings');
420 494 add_action('woocommerce_settings_saved', 'mk_admin_save_api_settings', 30, 0);
421 495 add_filter("plugin_action_links_".plugin_basename(__FILE__), 'mk_admin_plugin_settings_link' );
496 + // }
422 497
423 498 function __get_logo_html() {
424 499 return '<div class="makecommerce-info">'.
425 500 '<div class="makecommerce-logo">'.