craftcms / digital-products

Sell digital products with Craft Commerce.
https://plugins.craftcms.com/digital-products
MIT License
18 stars 9 forks source link

Unable to save Licenses #63

Closed Coysh closed 3 years ago

Coysh commented 3 years ago

Description

When updating a license, modifying any of the following fields does not update:

Though updating the following fields does work:

This bug appears in the front end, but also attempting to programatically edit fields fails:

$license = Craft::$app->getElements()->getElementById($licenseID, License::class);

if (!$license) {
    throw new Exception('No license with the ID “{id}”', ['id' => $licenseID]);
}

$license->productId = $newProductId;

$success = Craft::$app->getElements()->saveElement($license);
if (!$success) {
    Craft::error('Couldn’t save the license ', __METHOD__);
    return false;
} else {
    Craft::info('Saved the license', __METHOD__);
}
return $this->redirectToPostedUrl();

The log shows "Saved the license", but the license in digitalproducts_license has not been updated. However the element for the licenese in elements has been update with a new dateUpdated date.

lukeholder commented 3 years ago

Those properties are immutable after first save of the license

https://github.com/craftcms/digital-products/blob/22fc70b6ce47345f257e81f6d18a416fb5f4277e/src/elements/License.php#L395-L399

You should create a new license and remove the old one if you want to create a new license.