Skip to content

Custom option values do not save correctly #5067

Closed
@samtay

Description

@samtay

Certain permutations of product custom options are impossible to save. For example,

  1. First save a product with a custom option dropdown of two values with differing fields:
    2016-06-16-191853_1331x521_scrot
  2. Now try to save the second value to be identical to the first, like so:
    2016-06-16-193922_1344x530_scrot
  3. Notice that many of the values are not saved correctly. For me, this time around only the SKU was problematic, but you will have problems saving any number of these fields.

This is because

  • the abstract resource model generates the UPDATE query based on differences between the new data array being saved and the preexisting $object->storedData array. code reference
  • the OptionValue model loops through setData commands to save multiple OptionValue instances, hence storedData property refers to the previously saved Value instance, which is set during the previous setData()->..->save() iteration. code reference

So, those two reasons result in any identical OptionValue fields not able to be saved consecutively, causing the bug shown in steps 1-3.

I think it is rather odd/lazy that the option value model does not have its own resource model.. it seems like a poor idea to just loop through $this->setData()->save() calls. But, if you want to fix this quickly, just issue a $this->load($this->getOptionTypeId()) before the save. This will set the proper storedData property onto the model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Event: distributed-cdDistributed Contribution DayFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions