Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/code/Magento/Swatches/Model/Plugin/EavAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected function prepareOptionIds(array $optionsArray)
{
if (isset($optionsArray['value']) && is_array($optionsArray['value'])) {
foreach (array_keys($optionsArray['value']) as $optionId) {
if (isset($optionsArray['delete']) && $optionsArray['delete'][$optionId] == 1) {
if (isset($optionsArray['delete'][$optionId]) && $optionsArray['delete'][$optionId] == 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Php 500 Error when $optionsArray['delete'][$optionId] is not set

This is just a notice, 500 will be displayed only in developer mode.

Can $optionsArray['delete'][$optionId] contain anything but 1? Why not do unconditional unset($optionsArray['value'][$optionId])?

Copy link
Copy Markdown
Member Author

@angelo983 angelo983 Oct 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply misunderstood! Read the function definition comment: "Get options array without deleted items"
so... not all array_keys($optionsArray['value']) are present in $optionsArray['delete'][$optionId] as indexes of the $optionsArray['delete']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've got the point of bugfix, just trying to simplify the code.

Is check for == 1 essential or we can simply do unset without condition?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance I would say yes, but checking getData() method of Attribute I can't be totally sure.
Anyway a condition must be verified, so the choice should be between:
(isset($optionsArray['delete'][$optionId]))
and
(isset($optionsArray['delete'][$optionId]) && $optionsArray['delete'][$optionId] == 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it is already merged, I was trying to understand if it can be just if (!empty($optionsArray['delete'][$optionId])).

unset($optionsArray['value'][$optionId]);
}
}
Expand Down