Skip to content
Permalink
Browse files

fixes #353 by checking language of duplicate skis

  • Loading branch information...
Jon007 committed Aug 19, 2018
1 parent cd19fdd commit 2a8f35955016485f07764e2fe7f6d33b6b1ceaae
Showing with 40 additions and 8 deletions.
  1. +40 −8 src/Hyyan/WPI/Product/Meta.php
@@ -815,12 +815,44 @@ protected function syncSelectedproductType($ID = null)
*/
public function suppressInvalidDuplicatedSKUErrorMsg($sku_found, $product_id, $sku)
{
$metas = static::getProductMetaToCopy();
if (in_array('_sku', $metas)) {
return false;
} else {
return $sku_found;
}
}
}
//if the sku is not duplicate, no further check needed
if ( ! $sku_found ) {
return false;
}
/*
* now check the duplicates
* this is the same as woocommerce is_existing_sku but
* gets all the product ids with the matching sku
*/
global $wpdb;
// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery
$postids = $wpdb->get_col(
$wpdb->prepare(
"SELECT $wpdb->posts.ID
FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
WHERE $wpdb->posts.post_type IN ( 'product', 'product_variation' )
AND $wpdb->posts.post_status != 'trash'
AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = %s
AND $wpdb->postmeta.post_id <> %d
", wp_slash( $sku ), $product_id
)
);
$curlang = pll_get_post_language( $product_id );
foreach ( $postids as $post_id ) {
//suppress duplicate sku error on translations only
$duplang = pll_get_post_language( $post_id );
//if there is another product in the same language with the same sku
//disallow and return true from wc_product_has_unique_sku
if ( $post_id != $product_id && $curlang == pll_get_post_language( $post_id ) ) {
return true;
}
}
//if we got here, there were no duplicates in the same language
return false;
}
}

0 comments on commit 2a8f359

Please sign in to comment.
You can’t perform that action at this time.