Skip to content

BUG: Unpublishing/deleting ProductPages permanently destroys all OptionItems #419

@jsirish

Description

@jsirish

Summary

When a ProductPage is unpublished or deleted, all associated OptionItem records are permanently destroyed. Since OptionItem is an unversioned DataObject, this data loss is irreversible without a database backup.

Root Cause

ProductPage::onBeforeDelete() contains logic that checks $this->Status != 'Published' and then deletes all ProductOptions:

public function onBeforeDelete()
{
    if ($this->Status != 'Published') {
        if ($this->ProductOptions()) {
            $options = $this->getComponents('ProductOptions');
            foreach ($options as $option) {
                $option->delete();
            }
        }
    }
    parent::onBeforeDelete();
}

Problems

  1. $this->Status is a legacy SS3 property — it doesn't exist reliably in SS4/SS5's versioning model, so the condition evaluates to true almost always
  2. OptionItem is unversioned — once deleted, there's no recovery
  3. OptionItem has a belongs_many_many to OrderDetail — deleting options also corrupts historical order records
  4. Even just deleting the draft version of a page fires onBeforeDelete, nuking all options

Impact

  • All product options (color, size, type, etc.) are permanently lost
  • Historical order data is corrupted (can't determine what customers purchased)
  • No recovery path without database backup

Proposed Fix

  1. Remove the destructive onBeforeDelete from ProductPage
  2. Add Versioned extension to OptionItem so options follow the same draft/live lifecycle as pages
  3. Add a protective onBeforeDelete guard on OptionItem to prevent deletion of options linked to orders
  4. Create a BuildTask to publish all existing OptionItem records (data migration)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions