Add unique sku option to error data when setting product sku (#36612)

* Add unique sku option to error data when setting product sku

* Add changelog entry

* Add permalink template to the sku error data

* Revert "Add permalink template to the sku error data"

This reverts commit a49ee1d878.
This commit is contained in:
Joshua T Flowers 2023-01-30 13:07:05 -08:00 committed by GitHub
parent f601b0d8a5
commit 83faf8d328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add unique sku option to error data when setting product sku

View File

@ -820,7 +820,15 @@ class WC_Product extends WC_Abstract_Legacy_Product {
if ( $this->get_object_read() && ! empty( $sku ) && ! wc_product_has_unique_sku( $this->get_id(), $sku ) ) {
$sku_found = wc_get_product_id_by_sku( $sku );
$this->error( 'product_invalid_sku', __( 'Invalid or duplicated SKU.', 'woocommerce' ), 400, array( 'resource_id' => $sku_found ) );
$this->error(
'product_invalid_sku',
__( 'Invalid or duplicated SKU.', 'woocommerce' ),
400,
array(
'resource_id' => $sku_found,
'unique_sku' => wc_product_generate_unique_sku( $this->get_id(), $sku ),
)
);
}
$this->set_prop( 'sku', $sku );
}