Commerce: Hard deleting products doesn't hard delete it's variant and purchasable

Created on 18 Dec 2019  路  7Comments  路  Source: craftcms/commerce

Description

Hard deleting products only hard deletes the product itself and not the purchasable + variant.
This in turn leads to users not being able to use the same SKU after the product has been hard deleted.

Steps to reproduce

  1. Add a product with variant
  2. Hard delete the product
  3. Add a new product using the same variant SKU used in step 1

Additional info

  • Craft version: 3.3.18.2
  • PHP version: 7.3.12
  • Database driver & version: PostgreSQL 11.5
  • Plugins & versions: -
馃悶 bug

Most helpful comment

This has been fixed for the next release.

Thank you for bringing this to our attention.

A fix has been pushed and will be included in the next release.

To get this early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "dev-develop#fb041defb32ca21265923483efb01114188cfe58 as 3.1.1",
  "...": "..."
}

Then run composer update

Thanks.

All 7 comments

The delete events should also transfer if an element is hard/soft-deleted.

A related issue is with Neo: see https://github.com/spicywebau/craft-neo/blob/master/src/Field.php#L678-L690

馃憖

To get around this i'm just additionally hard deleting variants before I delete their products.
For reference, purchasables seem to get deleted with products, just not variants.

Craft version: 3.4.9
Craft Commerce version: 3.0.11

Craft::$app->getElements()->deleteElement($variant, true)

Yes this is our current approach as well

cc @lukeholder

Thanks, will get this fixed.

This has been fixed for the next release.

Thank you for bringing this to our attention.

A fix has been pushed and will be included in the next release.

To get this early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "dev-develop#fb041defb32ca21265923483efb01114188cfe58 as 3.1.1",
  "...": "..."
}

Then run composer update

Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

palomamtnez picture palomamtnez  路  5Comments

Anubarak picture Anubarak  路  3Comments

lazlo-bonin picture lazlo-bonin  路  5Comments

sjcallender picture sjcallender  路  6Comments

brandonkelly picture brandonkelly  路  3Comments