PluginProbe
MakeCommerce for WooCommerce / 1.1.7
MakeCommerce for WooCommerce v1.1.7
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 +299 -92 1.1.21.1.7 View file →
@@ -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.1.2
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.2';
75 + public $version = '1.1.7';
76 76
77 77 public $return_url;
78 78 public $return_url_cancel;
79 79
@@ -316,21 +316,10 @@
316 316 'type' => 'checkbox',
317 317 'default' => 'yes',
318 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'),
319 319 );
320 - $this->form_fields['cc_shop_name'] = array(
321 - 'title' => __('Shop name on credit card payment', 'wc_makecommerce_domain'),
322 - 'type' => 'text',
323 - 'desc_tip' => __('This will appear on buyer\'s credit card transaction', 'wc_makecommerce_domain'),
324 - );
325 - $this->form_fields['cc_cart_reference_string'] = array(
326 - 'title' => __('Order reference on credit card payment', 'wc_makecommerce_domain'),
327 - 'type' => 'text',
328 - 'default' => 'Order %s',
329 - 'desc_tip' => __('This will appear on buyer\'s credit card transaction where "%s" is the order number', 'wc_makecommerce_domain'),
330 - );
331 320 $this->form_fields['adv_title'] = array(
332 - 'title' => '<br>'.__('Advanced Settings', 'wc_makecommerce_domain'),
321 + 'title' => '<hr><br>'.__('Advanced Settings', 'wc_makecommerce_domain'),
333 322 'type' => 'title',
334 323 );
335 324 $this->form_fields['reload_links'] = array(
336 325 'type' => 'mc_banklinks_reload',
@@ -337,8 +326,13 @@
337 326 'title' => __('Update payment methods', 'wc_makecommerce_domain'),
338 327 'description' => __('Update', 'wc_makecommerce_domain'),
339 328 'desc_tip' => __('This will update shop configuration from MakeCommerce servers.', 'wc_makecommerce_domain'),
340 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 + );
341 335 }
342 336
343 337 public function generate_mc_hidden_html( $key, $data ) {
344 338 $field_key = $this->get_field_key($key);
@@ -351,9 +345,43 @@
351 345 </tr>
352 346 <?php
353 347 return ob_get_clean();
354 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 + );
355 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 +
356 384 public function generate_mc_banklinks_reload_html( $key, $data ) {
357 385
358 386 $field = $this->get_field_key( $key );
359 387 $defaults = array(
@@ -491,9 +519,9 @@
491 519 }
492 520
493 521 public function mc_banklinks_reload($force = false) {
494 522 if ($force || (defined('DOING_AJAX') && DOING_AJAX)) {
495 -
523 +
496 524 global $wpdb;
497 525 global $mkDbTable;
498 526 global $wp_version;
499 527
@@ -511,13 +539,15 @@
511 539 return false;
512 540 }
513 541
514 542 try {
515 - $methods = $this->_api->getShopConfig($request_params)->payment_methods;
543 + $shopConfig = $this->_api->getShopConfig($request_params);
544 + $methods = $shopConfig->payment_methods;
516 545 } catch (Exception $e) {
517 546 error_log(print_r($e, 1));
518 547 return false;
519 548 }
549 +
520 550 if(isset($methods->banklinks)) {
521 551 foreach($methods->banklinks as $method) {
522 552 $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url));
523 553 }
@@ -529,11 +559,17 @@
529 559 $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name));
530 560 }
531 561 $updated = true;
532 562 }
563 +
564 + if(isset($shopConfig) && strlen($shopConfig->name)) {
565 + update_option( 'mc_shop_name', $shopConfig->name );
566 + }
567 +
533 568 if ($updated) {
534 569 update_option( 'mc_banklinks_api_type', get_option('mk_api_type', false) );
535 570 }
571 +
536 572 if ($force) {
537 573 $this->initBankLinks();
538 574 return $updated;
539 575 }
@@ -664,8 +700,9 @@
664 700 <?php
665 701 }
666 702 ?>
667 703 </ul>
704 + <div class="mc-clear-both"></div>
668 705 <script type="text/javascript">
669 706 var makecommerceId = '<?php echo $this->id; ?>';
670 707 var selectedCountry = jQuery('input[name=makecommerce_country_picker]:checked').val();
671 708
@@ -955,10 +992,10 @@
955 992 'locale' => !empty($_GET['lang']) ? $_GET['lang'] : (defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))),
956 993 'open-on-load' => 'true',
957 994 'client-name' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) ($order->billing_first_name . ' ' . $order->billing_last_name) : ''),
958 995 'email' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) $order->billing_email : ''),
959 - 'name' => $this->settings['cc_shop_name'],
960 - 'description' => (string)sprintf($this->settings['cc_cart_reference_string'], (string) $idReference),
996 + 'name' => get_option('mc_shop_name', ''),
997 + 'description' => __('Order', 'woocommerce') . '&nbsp;' . (string) $idReference,
961 998 'completed' => 'makecommerce_cc_complete',
962 999 'currency' => 'EUR',
963 1000 );
964 1001 ?>
@@ -1271,18 +1308,60 @@
1271 1308 add_action('woocommerce_update_options_shipping_' . $this->id, array(&$this, 'process_admin_options'));
1272 1309 add_filter('woocommerce_review_order_after_shipping' , array(&$this, 'add_parcelmachine_checkout_fields'));
1273 1310 //add_filter('woocommerce_update_order_review_fragments' , array(&$this, 'add_parcelmachine_checkout_fields'));
1274 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'));
1275 1313 add_action('woocommerce_checkout_update_order_meta', array(&$this, 'add_parcelmachine_order_meta'));
1276 - 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'));
1277 1315 }
1278 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 +
1279 1348 function calculate_shipping($package = array()) {
1349 + $price = $this->settings['price_'.strtolower($package['destination']['country'])];
1280 1350
1281 - $price = $this->settings['price_'.strtolower($package['destination']['country'])];
1282 - 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) {
1283 1354 $price = 0;
1284 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 + }
1285 1364 $rate = array(
1286 1365 'id' => $this->id,
1287 1366 'label' => $this->title,
1288 1367 'cost' => $price,
@@ -1377,9 +1456,9 @@
1377 1456 $res .= '<optgroup label="'.$machine['city'].'">';
1378 1457 }
1379 1458 $mname = $machine['name'];
1380 1459 if ($this->short_office_names !== 'yes') $mname .= ' - ' . $machine['city'] . ', ' . $machine['address'];
1381 - $res .= '<option value="'.esc_attr($machine['provider'].'||'.$machine['id']).'">'.$mname.'</option>';
1460 + $res .= '<option value="'.esc_attr($machine['carrier'].'||'.$machine['id']).'">'.$mname.'</option>';
1382 1461 $pcity = $city;
1383 1462 }
1384 1463 if ($pcity) $res .= '</optgroup>';
1385 1464 $res .= '</select>';
@@ -1390,10 +1469,8 @@
1390 1469
1391 1470 function check_parcelmachine_checkout_fields() {
1392 1471 $shipping_method = !empty($_POST['shipping_method']) ? $_POST['shipping_method'] : false;
1393 1472 if (!empty($shipping_method[0])) { $shipping_method = $shipping_method[0]; }
1394 - error_log($shipping_method);
1395 - error_log(print_r($_POST, 1));
1396 1473 if ($shipping_method === $this->id && empty($_POST[$shipping_method])) {
1397 1474 wc_add_notice(__('<strong>Parcel machine</strong> is a required field.'), 'error');
1398 1475 }
1399 1476 }
@@ -1404,10 +1481,9 @@
1404 1481 update_post_meta($order_id, '_parcel_machine', sanitize_text_field($_POST[$this->id]));
1405 1482 }
1406 1483 }
1407 1484 function add_admin_parcelmachine_via_field($order) {
1408 - error_log('Via');
1409 - error_log(print_r($order, 1));
1485 + return ' <small>(via '.$this->name_ext.')</small>';
1410 1486 }
1411 1487 }
1412 1488 class WC_ParcelMachine_Shipping_Method_Omniva extends WC_ParcelMachine_Shipping_Method {
1413 1489 function __construct($instance_id = 0) {
@@ -1418,36 +1494,60 @@
1418 1494 function init_form_fields() {
1419 1495
1420 1496 $this->form_fields = array();
1421 1497 $this->form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html());
1422 - $this->form_fields['generic'] = array('type' => 'title', 'title' => __('Generic and pricing options', 'wc_makecommerce_domain'));
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 + );
1423 1503 $this->form_fields['active'] = array(
1424 1504 'title' => __('Enable', 'wc_makecommerce_domain'),
1425 1505 'type' => 'checkbox',
1426 1506 'label' => __('enabled', 'wc_makecommerce_domain'),
1427 1507 'default' => 'no',
1428 - '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'),
1429 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 + );
1430 1518 $this->form_fields['price_ee'] = array(
1431 - 'title' => __('Price EE', 'wc_makecommerce_domain'),
1519 + 'title' => __('Shipping price', 'wc_makecommerce_domain').' EE',
1432 1520 'type' => 'text',
1433 1521 'default' => '2.99'
1434 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 + );
1435 1529 $this->form_fields['price_lv'] = array(
1436 - 'title' => __('Price LV', 'wc_makecommerce_domain'),
1530 + 'title' => __('Shipping price', 'wc_makecommerce_domain').' LV',
1437 1531 'type' => 'text',
1438 1532 'default' => '7.99'
1439 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 + );
1440 1540 $this->form_fields['price_lt'] = array(
1441 - 'title' => __('Price LT', 'wc_makecommerce_domain'),
1541 + 'title' => __('Shipping price', 'wc_makecommerce_domain').' LT',
1442 1542 'type' => 'text',
1443 1543 'default' => '8.99'
1444 1544 );
1445 - $this->form_fields['free_shipping_min_amount'] = array(
1446 - 'title' => __('Minimum amount for free shipping', 'wc_makecommerce_domain'),
1545 + $this->form_fields['free_shipping_min_amount_lt'] = array(
1546 + 'title' => __('Free shipping amount', 'wc_makecommerce_domain').' LT',
1447 1547 'type' => 'number',
1448 1548 'default' => '0',
1449 - 'description' => '(0 means no free shipping)'
1549 + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'),
1450 1550 );
1451 1551 $this->form_fields['maximum_weight'] = array(
1452 1552 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'),
1453 1553 'type' => 'text',
@@ -1452,17 +1552,10 @@
1452 1552 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'),
1453 1553 'type' => 'text',
1454 1554 'default' => '15'
1455 1555 );
1456 - $this->form_fields['countries'] = array(
1457 - 'title' => __('Specific Countries', 'wc_makecommerce_domain'),
1458 - 'type' => 'multiselect',
1459 - 'class' => 'wp-enhanced-select',
1460 - 'css' => 'width: 450px;',
1461 - 'default' => array('EE','LV','LT'),
1462 - 'options' => array('EE' => __('Estonia'), 'LV' => __('Latvia'), 'LT' => __('Lithuania')),
1463 - );
1464 - $this->form_fields['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'));
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'));
1465 1558 $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0');
1466 1559 if (empty($languages)) {
1467 1560 $this->form_fields['method_name'] = array(
1468 1561 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'),
@@ -1490,9 +1583,9 @@
1490 1583 'type' => 'checkbox',
1491 1584 'label' => __('Display only parcel machine names, without addresses', 'wc_makecommerce_domain'),
1492 1585 'default' => 'no'
1493 1586 );
1494 - $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 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&section=mk_api')));
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&section=mk_api')));
1495 1588 $this->form_fields['service_user'] = array(
1496 1589 'title' => __('Omniva web services username', 'wc_makecommerce_domain'),
1497 1590 'type' => 'text',
1498 1591 'default' => ''
@@ -1517,8 +1610,13 @@
1517 1610 'type' => 'text',
1518 1611 'title' => __('Shop email', 'wc_makecommerce_domain'),
1519 1612 'class' => 'input-text regular-input',
1520 1613 );
1614 + $this->form_fields['shop_address_city'] = array(
1615 + 'type' => 'text',
1616 + 'title' => __('Shop address city', 'wc_makecommerce_domain'),
1617 + 'class' => 'input-text regular-input',
1618 + );
1521 1619 $this->form_fields['shop_postal_code'] = array(
1522 1620 'type' => 'text',
1523 1621 'title' => __('Shop postal code', 'wc_makecommerce_domain'),
1524 1622 'class' => 'input-text regular-input',
@@ -1523,8 +1621,11 @@
1523 1621 'title' => __('Shop postal code', 'wc_makecommerce_domain'),
1524 1622 'class' => 'input-text regular-input',
1525 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')
1526 1624 );
1625 + $this->form_fields['shipping_ui_javascript'] = array(
1626 + 'type' => 'shipping_ui_javascript',
1627 + );
1527 1628 }
1528 1629
1529 1630 }
1530 1631 class WC_ParcelMachine_Shipping_Method_Smartpost extends WC_ParcelMachine_Shipping_Method {
@@ -1545,23 +1646,37 @@
1545 1646 'label' => __('enabled', 'wc_makecommerce_domain'),
1546 1647 'default' => 'no',
1547 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'),
1548 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 + );
1549 1658 $this->form_fields['price_ee'] = array(
1550 - 'title' => __('Price EE', 'wc_makecommerce_domain'),
1659 + 'title' => __('Shipping price', 'wc_makecommerce_domain').' EE',
1551 1660 'type' => 'text',
1552 1661 'default' => '2.99'
1553 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 + );
1554 1669 $this->form_fields['price_fi'] = array(
1555 - 'title' => __('Price FI', 'wc_makecommerce_domain'),
1670 + 'title' => __('Shipping price', 'wc_makecommerce_domain').' FI',
1556 1671 'type' => 'text',
1557 1672 'default' => '10.99'
1558 1673 );
1559 - $this->form_fields['free_shipping_min_amount'] = array(
1560 - 'title' => __('Minimum amount for free shipping', 'wc_makecommerce_domain'),
1674 + $this->form_fields['free_shipping_min_amount_fi'] = array(
1675 + 'title' => __('Free shipping amount', 'wc_makecommerce_domain'). ' FI',
1561 1676 'type' => 'number',
1562 1677 'default' => '0',
1563 - 'description' => __('(0 means no free shipping)', 'wc_makecommerce_domain'),
1678 + 'desc_tip' => __('(0 means no free shipping)', 'wc_makecommerce_domain'),
1564 1679 );
1565 1680 $this->form_fields['maximum_weight'] = array(
1566 1681 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'),
1567 1682 'type' => 'text',
@@ -1566,17 +1681,10 @@
1566 1681 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'),
1567 1682 'type' => 'text',
1568 1683 'default' => '15'
1569 1684 );
1570 - $this->form_fields['countries'] = array(
1571 - 'title' => __('Specific Countries', 'wc_makecommerce_domain'),
1572 - 'type' => 'multiselect',
1573 - 'class' => 'wp-enhanced-select',
1574 - 'css' => 'width: 450px;',
1575 - 'default' => array('EE','FI'),
1576 - 'options' => array('EE' => __('Estonia'), 'FI' => __('Finland')),
1577 - );
1578 - $this->form_fields['look_and_feel'] = array( 'type' => 'title', 'title' => __('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on checkout page', 'wc_makecommerce_domain'));
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'));
1579 1687 $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0');
1580 1688 if (empty($languages)) {
1581 1689 $this->form_fields['method_name'] = array(
1582 1690 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'),
@@ -1631,8 +1739,11 @@
1631 1739 'type' => 'text',
1632 1740 'title' => __('Shop email', 'wc_makecommerce_domain'),
1633 1741 'class' => 'input-text regular-input',
1634 1742 );
1743 + $this->form_fields['shipping_ui_javascript'] = array(
1744 + 'type' => 'shipping_ui_javascript',
1745 + );
1635 1746 }
1636 1747
1637 1748 }
1638 1749 }
@@ -1733,12 +1844,16 @@
1733 1844 'type' => 'text',
1734 1845 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'),
1735 1846 'class' => 'input-text regular-input',
1736 1847 ),
1848 + array(
1849 + 'id' => 'mk_javascript_ui',
1850 + 'type' => 'api_javascript_ui',
1851 + ),
1737 1852 array('type' => 'sectionend', 'id' => 'mk_api_settings')
1738 1853 );
1739 1854 }
1740 -
1855 +
1741 1856 function mk_admin_save_settings() {
1742 1857 // reload banklinks
1743 1858 global $current_section;
1744 1859 if ($current_section !== 'mk_api') {
@@ -1747,25 +1862,52 @@
1747 1862 $wcmc = New woocommerce_makecommerce(true);
1748 1863 $wcmc->mc_banklinks_reload(true);
1749 1864 }
1750 1865
1751 - function __get_logo_html() {
1752 - return '<div class="makecommerce-info">'.
1753 - '<div class="makecommerce-logo">'.
1754 - '<a target="_blank" href="http://maksekeskus.ee"><img src="'. plugins_url('/images/makecommerce_logo_en.svg', __FILE__) .'" class="makecommerce-logo"></a>'.
1755 - '</div>'.
1756 - '<div class="makecommerce-links">'.
1757 - '<div class="makecommerce-link"><a target="_blank" href="https://merchant.maksekeskus.ee">Merchant Portal</a></div>'.
1758 - '<div class="makecommerce-link"><a target="_blank" href="https://makecommerce.net/">makecommerce.net</a></div>'.
1759 - '<div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>'.
1760 - '</div>'.
1761 - '</div>';
1762 - }
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 + }
1763 1878
1764 1879 add_action('woocommerce_get_sections_api', 'mk_admin_add_settings');
1765 1880 add_filter('woocommerce_get_settings_api', 'mk_admin_all_settings', 10, 2);
1766 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'];
1767 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 +
1768 1910 function mk_admin_restrict_manage_posts() {
1769 1911 global $typenow;
1770 1912 if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ) ) ) {
1771 1913 $selected_method = !empty($_REQUEST['_shipping_method']) ? $_REQUEST['_shipping_method'] : false;
@@ -1797,10 +1939,9 @@
1797 1939 add_filter('posts_where', 'mk_admin_shipping_filter', 10, 2);
1798 1940
1799 1941 function mk_admin_bulk_actions() {
1800 1942 global $post_type;
1801 - if ('shop_order' === $post_type) {
1802 -?>
1943 + if ('shop_order' === $post_type) { ?>
1803 1944 <script type="text/javascript">
1804 1945 jQuery(function() {
1805 1946 jQuery('<option>').val('parcel_machine_labels').text('<?php _e( 'Register parcel machine shipments', 'wc_makecommerce_domain' )?>').appendTo('select[name="action"]');
1806 1947 jQuery('<option>').val('parcel_machine_labels').text('<?php _e( 'Register parcel machine shipments', 'wc_makecommerce_domain' )?>').appendTo('select[name="action2"]');
@@ -1807,18 +1948,15 @@
1807 1948 jQuery('<option>').val('parcel_machine_print_labels').text('<?php _e( 'Print parcel machine labels', 'wc_makecommerce_domain' )?>').appendTo('select[name="action"]');
1808 1949 jQuery('<option>').val('parcel_machine_print_labels').text('<?php _e( 'Print parcel machine labels', 'wc_makecommerce_domain' )?>').appendTo('select[name="action2"]');
1809 1950 });
1810 1951 </script>
1811 -<?php
1812 - if (!empty($_REQUEST['mk_pdf'])) {
1813 -?>
1814 - <script type="text/javascript">
1815 - jQuery(function(){
1816 - window.open('<?php echo $_REQUEST['mk_pdf'] ?>', 'pdf');
1817 - });
1818 - </script>
1819 -<?php
1820 - }
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 }
1821 1959 }
1822 1960 }
1823 1961 function mk_admin_bulk_action_labels() {
1824 1962 $wp_list_table = _get_list_table('WP_Posts_List_Table');
@@ -1903,13 +2041,23 @@
1903 2041 'label' => __('Does not fit parcel machine', 'wc_makecommerce_domain'),
1904 2042 'description' => __('When this is checked, parcel machine shipping option is not available for a cart with this product', 'wc_makecommerce_domain')
1905 2043 )
1906 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 + );
1907 2053 echo '</div>';
1908 2054 }
1909 2055 function mk_admin_product_fields_save($post_id) {
1910 2056 $no_parcel_machine = isset($_POST['_no_parcel_machine']) ? 'yes' : 'no';
1911 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);
1912 2060 }
1913 2061
1914 2062 add_action('woocommerce_product_options_shipping', 'mk_admin_product_option_fields');
1915 2063 add_action('woocommerce_process_product_meta', 'mk_admin_product_fields_save');
@@ -1991,18 +2139,12 @@
1991 2139 }
1992 2140 }
1993 2141 }
1994 2142
1995 - function mk_get_labels($post_ids) {
2143 + function mk_get_labels($post_ids, $ajax = false) {
1996 2144 if (!is_array($post_ids)) {
1997 2145 $post_ids = array($post_ids);
1998 2146 }
1999 - $sender = array(
2000 - 'name' => get_option('mk_shop_name', ''),
2001 - 'phone' => get_option('mk_shop_phone', ''),
2002 - 'email' => get_option('mk_shop_email', ''),
2003 - 'postalCode' => get_option('mk_shop_postal_code', '')
2004 - );
2005 2147 parcelmachine_add_method();
2006 2148 $shipping_request = array('credentials' => array(), 'orders' => array(), 'printFormat' => 'A4');
2007 2149 foreach ($post_ids as $post_id) {
2008 2150 $parcel_machine = get_post_meta($post_id, '_parcel_machine', true);
@@ -2031,8 +2173,14 @@
2031 2173 }
2032 2174 $order = wc_get_order($post_id);
2033 2175 $shipment_id = get_post_meta($post_id, '_parcel_machine_shipment_id', true);
2034 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 + );
2035 2183 $shipping_request['orders'][] = array(
2036 2184 'carrier' => $provider_uc,
2037 2185 'orderId' => $order->id,
2038 2186 'destination' => array('destinationId' => $machine_id),
@@ -2057,8 +2205,11 @@
2057 2205 }
2058 2206 if (empty($response->labelUrl)) {
2059 2207 return;
2060 2208 }
2209 + if($ajax) {
2210 + return $response->labelUrl;
2211 + }
2061 2212 $sendback = add_query_arg(array('post_type' => 'shop_order', 'mk_pdf' => urlencode($response->labelUrl)), '');
2062 2213 wp_redirect(esc_url_raw($sendback));
2063 2214 exit();
2064 2215 }
@@ -2105,9 +2256,9 @@
2105 2256 }
2106 2257 foreach ($data as $machine) {
2107 2258 if ($machine->country === $country && $machine->type === 'APT' && ($provider === '*' || strtolower($provider) === strtolower($machine->provider))) {
2108 2259 $machines[] = array(
2109 - 'provider' => strtolower($machine->provider),
2260 + 'carrier' => strtolower($machine->provider),
2110 2261 'id' => $machine->id,
2111 2262 'name' => $machine->name,
2112 2263 'city' => $machine->city,
2113 2264 'address' => !empty($machine->address) ? $machine->address : '',
@@ -2125,9 +2276,9 @@
2125 2276
2126 2277 function mk_get_machine($provider, $id) {
2127 2278 $machines = mk_get_machines($provider);
2128 2279 foreach ($machines as $machine) {
2129 - if ($machine['provider'] === $provider && $machine['id'] === $id) {
2280 + if ($machine['carrier'] === $provider && $machine['id'] === $id) {
2130 2281 return $machine;
2131 2282 }
2132 2283 }
2133 2284 return false;
@@ -2134,5 +2285,61 @@
2134 2285 }
2135 2286 function mk_admin_error() {
2136 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'));
2137 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' );
2138 2345 }