Version Description
- 2020.09.15 =
- Fix - Don't import a new copy of each product image from Square when updating products during the import process. PR#513
Download this release
Release Info
| Developer | automattic |
| Plugin | |
| Version | 2.2.2 |
| Comparing to | |
| See all releases | |
Code changes from version 2.2.1 to 2.2.2
- i18n/languages/woocommerce-square.pot +3 -3
- includes/Handlers/Product.php +18 -1
- includes/Plugin.php +1 -1
- includes/Sync/Product_Import.php +2 -2
- readme.txt +4 -1
- woocommerce-square.php +1 -1
i18n/languages/woocommerce-square.pot
CHANGED
|
@@ -2,10 +2,10 @@
|
|
| 2 |
# This file is distributed under the GNU General Public License v3.0.
|
| 3 |
msgid ""
|
| 4 |
msgstr ""
|
| 5 |
-
"Project-Id-Version: WooCommerce Square 2.2.
|
| 6 |
"Report-Msgid-Bugs-To: "
|
| 7 |
"https://github.com/woocommerce/woocommerce-square/issues\n"
|
| 8 |
-
"POT-Creation-Date: 2020-09-
|
| 9 |
"MIME-Version: 1.0\n"
|
| 10 |
"Content-Type: text/plain; charset=utf-8\n"
|
| 11 |
"Content-Transfer-Encoding: 8bit\n"
|
|
@@ -519,7 +519,7 @@ msgid ""
|
|
| 519 |
"Import Products from Square settings."
|
| 520 |
msgstr ""
|
| 521 |
|
| 522 |
-
#: includes/Handlers/Product.php:
|
| 523 |
msgid "Product not synced with Square"
|
| 524 |
msgstr ""
|
| 525 |
|
| 2 |
# This file is distributed under the GNU General Public License v3.0.
|
| 3 |
msgid ""
|
| 4 |
msgstr ""
|
| 5 |
+
"Project-Id-Version: WooCommerce Square 2.2.2\n"
|
| 6 |
"Report-Msgid-Bugs-To: "
|
| 7 |
"https://github.com/woocommerce/woocommerce-square/issues\n"
|
| 8 |
+
"POT-Creation-Date: 2020-09-15 02:53:36+00:00\n"
|
| 9 |
"MIME-Version: 1.0\n"
|
| 10 |
"Content-Type: text/plain; charset=utf-8\n"
|
| 11 |
"Content-Transfer-Encoding: 8bit\n"
|
| 519 |
"Import Products from Square settings."
|
| 520 |
msgstr ""
|
| 521 |
|
| 522 |
+
#: includes/Handlers/Product.php:312
|
| 523 |
msgid "Product not synced with Square"
|
| 524 |
msgstr ""
|
| 525 |
|
includes/Handlers/Product.php
CHANGED
|
@@ -224,10 +224,11 @@ class Product {
|
|
| 224 |
*
|
| 225 |
* @param \WC_Product|int $given_product product object or product ID
|
| 226 |
* @param string $image_id
|
|
|
|
| 227 |
* @todo Look at ussages of this function. Does it even need to return anything?
|
| 228 |
* @return \WC_Product|int The product id of object that was passed in.
|
| 229 |
*/
|
| 230 |
-
public static function update_image_from_square( $given_product, $image_id ) {
|
| 231 |
|
| 232 |
$product = is_numeric( $given_product ) ? wc_get_product( $given_product ) : $given_product;
|
| 233 |
|
|
@@ -256,6 +257,20 @@ class Product {
|
|
| 256 |
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
| 257 |
}
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
// grab remote image to upload into WordPress before attaching to product
|
| 260 |
$attachment_id = media_sideload_image( $image_url, $product->get_id(), $product->get_title(), 'id' );
|
| 261 |
|
|
@@ -266,6 +281,8 @@ class Product {
|
|
| 266 |
// attach the newly updated image to product
|
| 267 |
$product->set_image_id( $attachment_id );
|
| 268 |
|
|
|
|
|
|
|
| 269 |
} catch ( Framework\SV_WC_Plugin_Exception $e ) {
|
| 270 |
|
| 271 |
wc_square()->log( sprintf( 'Could not import image from Square at %1$s for attaching to product #%2$s. %3$s.', $image_url, $product->get_id(), $e->getMessage() ) );
|
| 224 |
*
|
| 225 |
* @param \WC_Product|int $given_product product object or product ID
|
| 226 |
* @param string $image_id
|
| 227 |
+
* @param bool $force_update If true, always import and update the product image from Square. If false, check if the image already exists on the given product before uploading a possible
|
| 228 |
* @todo Look at ussages of this function. Does it even need to return anything?
|
| 229 |
* @return \WC_Product|int The product id of object that was passed in.
|
| 230 |
*/
|
| 231 |
+
public static function update_image_from_square( $given_product, $image_id, $force_update = true ) {
|
| 232 |
|
| 233 |
$product = is_numeric( $given_product ) ? wc_get_product( $given_product ) : $given_product;
|
| 234 |
|
| 257 |
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
| 258 |
}
|
| 259 |
|
| 260 |
+
$product_image_id = $product->get_image_id();
|
| 261 |
+
|
| 262 |
+
// if the product has an image but doesn't have any Square image ID meta set, check we're not uploading a duplicate image src from Square
|
| 263 |
+
if ( ! $force_update && $product_image_id && ! $product->get_meta( '_square_item_image_id' ) ) {
|
| 264 |
+
$product_image_src = get_post_meta( $product_image_id, '_source_url', true );
|
| 265 |
+
|
| 266 |
+
if ( empty( $product_image_src ) ) {
|
| 267 |
+
throw new Framework\SV_WC_Plugin_Exception( 'Cannot compare existing product image src with new upload. Exiting to avoid uploading duplicate' );
|
| 268 |
+
} elseif ( $product_image_src === $image_url ) {
|
| 269 |
+
$product->update_meta_data( '_square_item_image_id', $image_id );
|
| 270 |
+
throw new Framework\SV_WC_Plugin_Exception( 'This image has already been uploaded to WordPress and is now set on the product' );
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
// grab remote image to upload into WordPress before attaching to product
|
| 275 |
$attachment_id = media_sideload_image( $image_url, $product->get_id(), $product->get_title(), 'id' );
|
| 276 |
|
| 281 |
// attach the newly updated image to product
|
| 282 |
$product->set_image_id( $attachment_id );
|
| 283 |
|
| 284 |
+
self::set_square_image_id( $product, $image_id );
|
| 285 |
+
|
| 286 |
} catch ( Framework\SV_WC_Plugin_Exception $e ) {
|
| 287 |
|
| 288 |
wc_square()->log( sprintf( 'Could not import image from Square at %1$s for attaching to product #%2$s. %3$s.', $image_url, $product->get_id(), $e->getMessage() ) );
|
includes/Plugin.php
CHANGED
|
@@ -42,7 +42,7 @@ class Plugin extends Framework\SV_WC_Payment_Gateway_Plugin {
|
|
| 42 |
|
| 43 |
|
| 44 |
/** plugin version number */
|
| 45 |
-
const VERSION = '2.2.
|
| 46 |
|
| 47 |
/** plugin ID */
|
| 48 |
const PLUGIN_ID = 'square';
|
| 42 |
|
| 43 |
|
| 44 |
/** plugin version number */
|
| 45 |
+
const VERSION = '2.2.2';
|
| 46 |
|
| 47 |
/** plugin ID */
|
| 48 |
const PLUGIN_ID = 'square';
|
includes/Sync/Product_Import.php
CHANGED
|
@@ -404,8 +404,8 @@ class Product_Import extends Stepped_Job {
|
|
| 404 |
$this->save_product_meta( $product_id, $data );
|
| 405 |
|
| 406 |
// save the image, if included
|
| 407 |
-
if ( ! empty( $data['image_id'] ) ) {
|
| 408 |
-
Product::update_image_from_square( $product_id, $data['image_id'] );
|
| 409 |
}
|
| 410 |
|
| 411 |
// save/update variations
|
| 404 |
$this->save_product_meta( $product_id, $data );
|
| 405 |
|
| 406 |
// save the image, if included
|
| 407 |
+
if ( ! empty( $data['image_id'] ) && ( $data['image_id'] !== $product->get_meta( '_square_item_image_id' ) || ! $product->get_image_id() ) ) {
|
| 408 |
+
Product::update_image_from_square( $product_id, $data['image_id'], false );
|
| 409 |
}
|
| 410 |
|
| 411 |
// save/update variations
|
readme.txt
CHANGED
|
@@ -4,7 +4,7 @@ Tags: credit card, square, woocommerce, inventory sync
|
|
| 4 |
Requires at least: 4.6
|
| 5 |
Tested up to: 5.5
|
| 6 |
Requires PHP: 5.6
|
| 7 |
-
Stable tag: 2.2.
|
| 8 |
License: GPLv3
|
| 9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
| 10 |
|
|
@@ -72,6 +72,9 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
|
|
| 72 |
|
| 73 |
== Changelog ==
|
| 74 |
|
|
|
|
|
|
|
|
|
|
| 75 |
= 2.2.1 - 2020.09.11 =
|
| 76 |
* New - Make the "Update existing products" part of the new import process optional by adding a new checkbox on Import Products modal. PR#508
|
| 77 |
* Fix - Stop the import process from getting stuck in a loop when reaching the time limit. PR#511
|
| 4 |
Requires at least: 4.6
|
| 5 |
Tested up to: 5.5
|
| 6 |
Requires PHP: 5.6
|
| 7 |
+
Stable tag: 2.2.2
|
| 8 |
License: GPLv3
|
| 9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
| 10 |
|
| 72 |
|
| 73 |
== Changelog ==
|
| 74 |
|
| 75 |
+
= 2.2.2 - 2020.09.15 =
|
| 76 |
+
* Fix - Don't import a new copy of each product image from Square when updating products during the import process. PR#513
|
| 77 |
+
|
| 78 |
= 2.2.1 - 2020.09.11 =
|
| 79 |
* New - Make the "Update existing products" part of the new import process optional by adding a new checkbox on Import Products modal. PR#508
|
| 80 |
* Fix - Stop the import process from getting stuck in a loop when reaching the time limit. PR#511
|
woocommerce-square.php
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Plugin Name: WooCommerce Square
|
| 4 |
-
* Version: 2.2.
|
| 5 |
* Plugin URI: https://woocommerce.com/products/square/
|
| 6 |
* Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
|
| 7 |
* Author: WooCommerce
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Plugin Name: WooCommerce Square
|
| 4 |
+
* Version: 2.2.2
|
| 5 |
* Plugin URI: https://woocommerce.com/products/square/
|
| 6 |
* Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
|
| 7 |
* Author: WooCommerce
|
