Skip to content

Commit

Permalink
Fixing a mess that led to variations being deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
aldavigdis committed Jul 10, 2024
1 parent 45dc963 commit 3c2e89f
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/Import/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ public static function json_to_new_product(
$wc_product->update_meta_data( '1984_dk_woo_origin', 'product' );
$wc_product->update_meta_data( '1984_dk_woo_variant_code', '' );
$wc_product->update_meta_data( '1984_dk_woo_variations', '' );
$wc_product->set_attributes( array() );
}

if ( ! $json_object->ShowItemInWebShop ) {
Expand Down Expand Up @@ -348,6 +347,21 @@ public static function update_product_from_json(
): WC_Product|false {
$wc_product = wc_get_product( $product_id );

if ( ! ( $wc_product instanceof WC_Product ) ) {
return false;
}

if (
$json_object->Inactive ||
(
property_exists( $json_object, 'Deleted' ) &&
true === $json_object->Deleted
)
) {
wp_delete_post( $wc_product->get_id() );
return false;
}

if ( true === $json_object->IsVariation ) {
$variant_code = ProductVariations::get_product_variant_code_by_sku(
$json_object->ItemCode
Expand All @@ -373,23 +387,8 @@ public static function update_product_from_json(
$wc_product->update_meta_data( '1984_dk_woo_origin', 'product' );
$wc_product->update_meta_data( '1984_dk_woo_variant_code', '' );
$wc_product->update_meta_data( '1984_dk_woo_variations', '' );
$wc_product->set_attributes( array() );
}

if ( ! ( $wc_product instanceof WC_Product ) ) {
return false;
}

if (
$json_object->Inactive ||
(
property_exists( $json_object, 'Deleted' ) &&
true === $json_object->Deleted
)
) {
wp_delete_post( $wc_product->get_id() );
return false;
}

if ( true === $json_object->ShowItemInWebShop ) {
$wc_product->set_status( 'Publish' );
Expand Down

0 comments on commit 3c2e89f

Please sign in to comment.