Printful Integration for WooCommerce - Version 2.1.5

Version Description

Fixed issues with personalization tool and other minor improvements

Download this release

Release Info

Developer printful
Plugin Icon 128x128 Printful Integration for WooCommerce
Version 2.1.5
Comparing to
See all releases

Code changes from version 2.1.4 to 2.1.5

assets/js/product-customizer.js CHANGED
@@ -168,10 +168,21 @@ setInterval(function () {
168
  return carry;
169
  }, {});
170
 
 
 
 
 
 
 
 
 
 
 
 
171
  // if pending (loading) images exist, request image urls
172
  if (Object.keys(hashes).length > 0) {
173
  jQuery.ajax({
174
- url: '/wp-admin/admin-ajax.php',
175
  type: 'GET',
176
  data: {
177
  action: 'printful_customized_thumb',
168
  return carry;
169
  }, {});
170
 
171
+ // Resolve admin base URL
172
+ var adminURL = window.pfGlobal && window.pfGlobal.admin_url && window.pfGlobal.admin_url.length
173
+ ? window.pfGlobal.admin_url
174
+ : '/wp-admin/';
175
+
176
+ // rtrim('/') + '/'
177
+ var hasSlash = adminURL.substring(adminURL.length - 1) === '/';
178
+ if (!hasSlash) {
179
+ adminURL += '/';
180
+ }
181
+
182
  // if pending (loading) images exist, request image urls
183
  if (Object.keys(hashes).length > 0) {
184
  jQuery.ajax({
185
+ url: adminURL + 'admin-ajax.php',
186
  type: 'GET',
187
  data: {
188
  action: 'printful_customized_thumb',
includes/class-printful-admin-status.php CHANGED
@@ -6,6 +6,7 @@ class Printful_Admin_Status {
6
  const PF_STATUS_OK = 1;
7
  const PF_STATUS_WARNING = 0;
8
  const PF_STATUS_FAIL = -1;
 
9
 
10
  const API_KEY_SEARCH_STRING = 'Printful';
11
  const PF_WEBHOOK_NAME = 'Printful Integration';
@@ -13,6 +14,12 @@ class Printful_Admin_Status {
13
  const PF_REMOTE_REQUEST_TOPIC = 'woo.plugin.test';
14
  const PF_STATUS_ISSUE_COUNT = 'printful_status_issue_count';
15
  const PF_CACHED_CHECKLIST = 'printful_cached_checklist';
 
 
 
 
 
 
16
 
17
  public static $_instance;
18
 
@@ -155,11 +162,12 @@ class Printful_Admin_Status {
155
  exit;
156
  }
157
 
158
- /**
159
- * Run the tests
160
- * @param bool $only_cached_results
161
- * @return array
162
- */
 
163
  public static function get_checklist( $only_cached_results = false ) {
164
 
165
  $status = self::instance();
@@ -182,11 +190,16 @@ class Printful_Admin_Status {
182
  if ( method_exists( $status, $item['method'] ) ) {
183
  $list_item['status'] = $status->{$item['method']}();
184
 
 
 
 
 
 
185
  if ( $status->should_result_be_visible( $list_item['status'], $item ) ) {
186
  $list['items'][] = $list_item;
187
  }
188
 
189
- if ( $list_item['status'] == self::PF_STATUS_FAIL) {
190
  $list['overall_status'] = false;
191
  $issueCount ++;
192
  }
@@ -384,16 +397,17 @@ class Printful_Admin_Status {
384
  return self::PF_STATUS_FAIL;
385
  }
386
 
387
- /**
388
- * @return int
389
- */
 
390
  private function check_PF_API_connect() {
391
 
392
  if ( Printful_Integration::instance()->is_connected(true) ) {
393
  return self::PF_STATUS_OK;
394
  }
395
 
396
- return self::PF_STATUS_FAIL;
397
  }
398
 
399
  /**
@@ -555,11 +569,17 @@ class Printful_Admin_Status {
555
  private function check_site_url_redirect()
556
  {
557
  $regular_site_url_req = wp_remote_head( get_option( 'siteurl' ), array('redirection' => 0));
558
- /** @var WP_HTTP_Requests_Response $response */
559
- $regular_response = $regular_site_url_req['http_response'];
560
 
561
  //need to not trigger issues for subfolder wordpress setups
562
  $slashed_site_url_req = wp_remote_head( trailingslashit(get_option( 'siteurl' )), array('redirection' => 0));
 
 
 
 
 
 
 
 
563
  /** @var WP_HTTP_Requests_Response $slashed_response */
564
  $slashed_response = $slashed_site_url_req['http_response'];
565
 
6
  const PF_STATUS_OK = 1;
7
  const PF_STATUS_WARNING = 0;
8
  const PF_STATUS_FAIL = -1;
9
+ const PF_STATUS_NOT_CONNECTED = 2;
10
 
11
  const API_KEY_SEARCH_STRING = 'Printful';
12
  const PF_WEBHOOK_NAME = 'Printful Integration';
14
  const PF_REMOTE_REQUEST_TOPIC = 'woo.plugin.test';
15
  const PF_STATUS_ISSUE_COUNT = 'printful_status_issue_count';
16
  const PF_CACHED_CHECKLIST = 'printful_cached_checklist';
17
+ const STATUS_CONNECTED_DISPLAYABLE_METHODS = array(
18
+ 'check_PF_webhooks',
19
+ 'check_PF_sync_errors',
20
+ 'check_PF_API_key',
21
+ 'check_WC_API_access'
22
+ );
23
 
24
  public static $_instance;
25
 
162
  exit;
163
  }
164
 
165
+ /**
166
+ * Run the tests
167
+ * @param bool $only_cached_results
168
+ * @return array
169
+ * @throws PrintfulException
170
+ */
171
  public static function get_checklist( $only_cached_results = false ) {
172
 
173
  $status = self::instance();
190
  if ( method_exists( $status, $item['method'] ) ) {
191
  $list_item['status'] = $status->{$item['method']}();
192
 
193
+ // Do not display status for methods that are depending on connection status to Printful
194
+ if ( ! Printful_Integration::instance()->is_connected(true) && in_array( $item['method'], self::STATUS_CONNECTED_DISPLAYABLE_METHODS ) ) {
195
+ continue;
196
+ }
197
+
198
  if ( $status->should_result_be_visible( $list_item['status'], $item ) ) {
199
  $list['items'][] = $list_item;
200
  }
201
 
202
+ if ( $list_item['status'] == self::PF_STATUS_FAIL || $list_item['status'] == self::PF_STATUS_NOT_CONNECTED ) {
203
  $list['overall_status'] = false;
204
  $issueCount ++;
205
  }
397
  return self::PF_STATUS_FAIL;
398
  }
399
 
400
+ /**
401
+ * @return int
402
+ * @throws PrintfulException
403
+ */
404
  private function check_PF_API_connect() {
405
 
406
  if ( Printful_Integration::instance()->is_connected(true) ) {
407
  return self::PF_STATUS_OK;
408
  }
409
 
410
+ return self::PF_STATUS_NOT_CONNECTED;
411
  }
412
 
413
  /**
569
  private function check_site_url_redirect()
570
  {
571
  $regular_site_url_req = wp_remote_head( get_option( 'siteurl' ), array('redirection' => 0));
 
 
572
 
573
  //need to not trigger issues for subfolder wordpress setups
574
  $slashed_site_url_req = wp_remote_head( trailingslashit(get_option( 'siteurl' )), array('redirection' => 0));
575
+
576
+ if (is_wp_error($regular_site_url_req) || is_wp_error($slashed_site_url_req)) {
577
+ return self::PF_STATUS_FAIL;
578
+ }
579
+
580
+ /** @var WP_HTTP_Requests_Response $response */
581
+ $regular_response = $regular_site_url_req['http_response'];
582
+
583
  /** @var WP_HTTP_Requests_Response $slashed_response */
584
  $slashed_response = $slashed_site_url_req['http_response'];
585
 
includes/class-printful-admin-support.php CHANGED
@@ -51,10 +51,11 @@ class Printful_Admin_Support {
51
  exit;
52
  }
53
 
54
- /**
55
  * Create system status report
56
- * @return string
57
- */
 
58
  public function generate_report() {
59
 
60
  if ( ! class_exists( 'WC_REST_System_Status_Controller' ) ) {
@@ -73,7 +74,9 @@ class Printful_Admin_Support {
73
  $status = 'WARNING';
74
  } else if($item['status'] == Printful_Admin_Status::PF_STATUS_FAIL) {
75
  $status = 'FAIL';
76
- }
 
 
77
  echo "* ";
78
  echo esc_html( str_pad( esc_html( $item['name'] ), 30 ) ) . '=> ' . esc_html( $status ) . "\n";
79
  }
51
  exit;
52
  }
53
 
54
+ /**
55
  * Create system status report
56
+ * @return string
57
+ * @throws PrintfulException
58
+ */
59
  public function generate_report() {
60
 
61
  if ( ! class_exists( 'WC_REST_System_Status_Controller' ) ) {
74
  $status = 'WARNING';
75
  } else if($item['status'] == Printful_Admin_Status::PF_STATUS_FAIL) {
76
  $status = 'FAIL';
77
+ } else if ($item['status'] == Printful_Admin_Status::PF_STATUS_NOT_CONNECTED) {
78
+ $status = 'NOT CONNECTED';
79
+ }
80
  echo "* ";
81
  echo esc_html( str_pad( esc_html( $item['name'] ), 30 ) ) . '=> ' . esc_html( $status ) . "\n";
82
  }
includes/class-printful-api-resource.php DELETED
@@ -1,135 +0,0 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
3
-
4
- /**
5
- * Class Printful_API_Resource
6
- * @deprecated 2.0.3
7
- */
8
- class Printful_API_Resource extends WC_API_Resource {
9
-
10
- /** @var string $base the route base */
11
- protected $base = '/printful';
12
-
13
- public function register_routes( $routes ) {
14
-
15
- $routes[ $this->base . '/version' ] = array(
16
- array( array( $this, 'get_status' ), WC_API_Server::READABLE | WC_API_Server::ACCEPT_DATA ),
17
- );
18
-
19
- $routes[ $this->base . '/access' ] = array(
20
- array( array( $this, 'put_access_data' ), WC_API_Server::EDITABLE | WC_API_Server::ACCEPT_DATA ),
21
- );
22
-
23
- $routes[ $this->base . '/products/(?P<product_id>\d+)/size-chart' ] = array(
24
- array( array( $this, 'post_size_chart' ), WC_API_Server::EDITABLE | WC_API_Server::ACCEPT_DATA ),
25
- );
26
-
27
- return $routes;
28
- }
29
-
30
- /**
31
- * Push size chart to meta property
32
- * @param $product_id
33
- * @param $data
34
- * @return array|WP_Error
35
- */
36
- public function post_size_chart( $product_id, $data ) {
37
-
38
- if ( empty( $data['size_chart'] ) ) {
39
- return new WP_Error( 'printful_api_size_chart_empty', __( 'No size chart was provided', 'printful' ), array( 'status' => 400 ) );
40
- }
41
-
42
- //product id is valid
43
- $product_id = intval( $product_id );
44
- if ( $product_id < 1 ) {
45
- return new WP_Error( 'printful_api_product_not_found', __( 'The product ID is invalid', 'printful' ), array( 'status' => 400 ) );
46
- }
47
-
48
- //product exists
49
- $product = get_post( $product_id );
50
- if ( empty( $product ) || $product->post_type != 'product' ) {
51
- return new WP_Error( 'printful_api_product_not_found', __( 'The product is not found', 'printful' ), array( 'status' => 400 ) );
52
- }
53
-
54
- //how about permissions?
55
- $post_type = get_post_type_object( $product->post_type );
56
- if ( ! current_user_can( $post_type->cap->edit_post, $product->ID ) ) {
57
- return new WP_Error( 'printful_api_user_cannot_edit_product_size_chart', __( 'You do not have permission to edit the size chart', 'printful' ), array( 'status' => 401 ) );
58
- }
59
-
60
- //lets do this
61
- update_post_meta( $product_id, 'pf_size_chart', htmlspecialchars( $data['size_chart'] ) );
62
-
63
- return array(
64
- 'product' => $product,
65
- 'size_chart' => $data['size_chart'],
66
- );
67
- }
68
-
69
- /**
70
- * Allow remotely get plugin version for debug purposes
71
- */
72
- public function get_status() {
73
-
74
- $error = false;
75
- try {
76
- $client = Printful_Integration::instance()->get_client();
77
- $storeData = $client->get( 'store' );
78
- } catch ( Exception $e ) {
79
- $error = $e->getMessage();
80
- }
81
-
82
- $checklist = Printful_Admin_Status::get_checklist();
83
- $checklist['overall_status'] = ( $checklist['overall_status'] ? 'OK' : 'FAIL' );
84
-
85
- foreach ( $checklist['items'] as $key => $item ) {
86
-
87
- if ( $item['status'] == Printful_Admin_Status::PF_STATUS_OK ) {
88
- $item['status'] = 'OK';
89
- } elseif ( $item['status'] == Printful_Admin_Status::PF_STATUS_WARNING ) {
90
- $item['status'] = 'WARNING';
91
- } else {
92
- $item['status'] = 'FAIL';
93
- }
94
-
95
- $checklist['items'][ $key ] = $item;
96
- }
97
-
98
- return array(
99
- 'version' => Printful_Base::VERSION,
100
- 'store_id' => ! empty( $storeData['id'] ) ? $storeData['id'] : false,
101
- 'error' => $error,
102
- 'status_checklist' => $checklist,
103
- );
104
- }
105
-
106
- /**
107
- * @param $data
108
- *
109
- * @return array
110
- */
111
- public function put_access_data( $data ) {
112
-
113
- $error = false;
114
-
115
- $options = get_option( 'woocommerce_printful_settings', array() );
116
-
117
- $apiKey = $data['accessKey'];
118
- $storeId = $data['storeId'];
119
- $storeId = intval( $storeId );
120
-
121
- if ( ! is_string( $apiKey ) || strlen( $apiKey ) == 0 || $storeId == 0 ) {
122
- $error = 'Failed to update access data';
123
- }
124
-
125
- $options['printful_key'] = $apiKey;
126
- $options['printful_store_id'] = $storeId;
127
-
128
- Printful_Integration::instance()->update_settings( $options );
129
-
130
- return array(
131
- 'error' => $error,
132
- );
133
- }
134
-
135
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-printful-customizer.php CHANGED
@@ -37,7 +37,11 @@ class Printful_Customizer {
37
 
38
  $is_customized_product = $post && get_post_meta( $post->ID, 'pf_customizable', true );
39
  if ($is_customized_product || is_cart()) {
40
- wp_enqueue_script( 'printful-product-customizer', plugins_url( '../assets/js/product-customizer.js', __FILE__ ) );
 
 
 
 
41
  }
42
  }
43
 
37
 
38
  $is_customized_product = $post && get_post_meta( $post->ID, 'pf_customizable', true );
39
  if ($is_customized_product || is_cart()) {
40
+ $customizer_script_handle = 'printful-product-customizer';
41
+ wp_enqueue_script( $customizer_script_handle, plugins_url( '../assets/js/product-customizer.js', __FILE__ ) );
42
+ wp_localize_script( $customizer_script_handle, 'pfGlobal', [
43
+ 'admin_url' => esc_url(admin_url())
44
+ ] );
45
  }
46
  }
47
 
includes/class-printful-rest-api-controller.php CHANGED
@@ -171,6 +171,8 @@ class Printful_REST_API_Controller extends WC_REST_Controller
171
  $checklist_item['status'] = 'OK';
172
  } elseif ( $checklist_item['status'] == Printful_Admin_Status::PF_STATUS_WARNING ) {
173
  $checklist_item['status'] = 'WARNING';
 
 
174
  } else {
175
  $checklist_item['status'] = 'FAIL';
176
  }
171
  $checklist_item['status'] = 'OK';
172
  } elseif ( $checklist_item['status'] == Printful_Admin_Status::PF_STATUS_WARNING ) {
173
  $checklist_item['status'] = 'WARNING';
174
+ } elseif ( $checklist_item['status'] == Printful_Admin_Status::PF_STATUS_NOT_CONNECTED ) {
175
+ $checklist_item['status'] = 'NOT CONNECTED';
176
  } else {
177
  $checklist_item['status'] = 'FAIL';
178
  }
includes/templates/status-table.php CHANGED
@@ -34,7 +34,9 @@
34
  echo '<span class="pass">' . esc_html__('OK', 'printful') .'</span>';
35
  } else if ( $item['status'] == 0 ) {
36
  echo '<span class="warning">' . esc_html__('WARNING', 'printful') .'&#42;</span>';
37
- } else {
 
 
38
  echo '<span class="fail">' . esc_html__('FAIL', 'printful') .'</span>';
39
  }
40
  ?>
34
  echo '<span class="pass">' . esc_html__('OK', 'printful') .'</span>';
35
  } else if ( $item['status'] == 0 ) {
36
  echo '<span class="warning">' . esc_html__('WARNING', 'printful') .'&#42;</span>';
37
+ } else if ( $item['status'] == 2 ) {
38
+ echo '<span class="fail">' . esc_html__('NOT CONNECTED', 'printful') .'</span>';
39
+ } else {
40
  echo '<span class="fail">' . esc_html__('FAIL', 'printful') .'</span>';
41
  }
42
  ?>
printful-shipping.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Printful Integration for WooCommerce
4
  Plugin URI: https://wordpress.org/plugins/printful-shipping-for-woocommerce/
5
  Description: Calculate correct shipping and tax rates for your Printful-Woocommerce integration.
6
- Version: 2.1.4
7
  Author: Printful
8
  Author URI: http://www.printful.com
9
  License: GPL2 http://www.gnu.org/licenses/gpl-2.0.html
@@ -20,7 +20,7 @@ if ( ! defined( 'PF_PLUGIN_FILE' ) ) {
20
 
21
  class Printful_Base {
22
 
23
- const VERSION = '2.1.4';
24
  const PF_HOST = 'https://www.printful.com/';
25
  const PF_API_HOST = 'https://api.printful.com/';
26
 
@@ -88,7 +88,6 @@ class Printful_Base {
88
  load_plugin_textdomain( 'printful', false, plugin_basename( dirname( PF_PLUGIN_FILE ) ) . '/i18n/languages' );
89
  }
90
 
91
-
92
  /**
93
  * @return string
94
  */
3
  Plugin Name: Printful Integration for WooCommerce
4
  Plugin URI: https://wordpress.org/plugins/printful-shipping-for-woocommerce/
5
  Description: Calculate correct shipping and tax rates for your Printful-Woocommerce integration.
6
+ Version: 2.1.5
7
  Author: Printful
8
  Author URI: http://www.printful.com
9
  License: GPL2 http://www.gnu.org/licenses/gpl-2.0.html
20
 
21
  class Printful_Base {
22
 
23
+ const VERSION = '2.1.5';
24
  const PF_HOST = 'https://www.printful.com/';
25
  const PF_API_HOST = 'https://api.printful.com/';
26
 
88
  load_plugin_textdomain( 'printful', false, plugin_basename( dirname( PF_PLUGIN_FILE ) ) . '/i18n/languages' );
89
  }
90
 
 
91
  /**
92
  * @return string
93
  */
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: girts_u, kievins, kberzins
3
  Tags: woocommerce, printful, drop shipping, shipping, shipping rates, fulfillment, printing, fedex, carriers, checkout, t-shirts
4
  Requires at least: 4.4
5
  Tested up to: 5.2
6
- Stable tag: 2.1.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -64,6 +64,9 @@ Go to https://www.printful.com/dashboard/store , select your WooCommerce store,
64
 
65
  == Upgrade Notice ==
66
 
 
 
 
67
  = 2.1.4 =
68
  Fixed an issue with personalized order submit
69
 
@@ -153,6 +156,9 @@ First release
153
 
154
  == Changelog ==
155
 
 
 
 
156
  = 2.1.4 =
157
  * Fixed an issue with personalized order submit
158
 
3
  Tags: woocommerce, printful, drop shipping, shipping, shipping rates, fulfillment, printing, fedex, carriers, checkout, t-shirts
4
  Requires at least: 4.4
5
  Tested up to: 5.2
6
+ Stable tag: 2.1.5
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
64
 
65
  == Upgrade Notice ==
66
 
67
+ = 2.1.5 =
68
+ Fixed issues with personalization tool and other minor improvements
69
+
70
  = 2.1.4 =
71
  Fixed an issue with personalized order submit
72
 
156
 
157
  == Changelog ==
158
 
159
+ = 2.1.5 =
160
+ * Fixed issues with personalization tool and other minor improvements
161
+
162
  = 2.1.4 =
163
  * Fixed an issue with personalized order submit
164