-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BugFix] Little bug fix inside product model #1616
Conversation
return $this; | ||
} else { | ||
$masterVariant->setProduct($this); | ||
$this->variants->add($masterVariant); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need this else
, cause we have the return statement above. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I need to wrap the second condition in a seperate if statement. Had it like that before but refactored without thinking. :P
@pjedrzejewski Ready for merge |
@@ -353,14 +353,16 @@ public function getMasterVariant() | |||
*/ | |||
public function setMasterVariant(BaseVariantInterface $masterVariant) | |||
{ | |||
if ($this->variants->contains($masterVariant)) { | |||
if (true === $masterVariant->isMaster()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for true ===
as isMaster()
returns boolean.
@stloyd Removed |
@pjedrzejewski @stloyd Can you review please. I think it is ready for merging. |
@@ -354,14 +354,16 @@ public function getMasterVariant() | |||
public function setMasterVariant(BaseVariantInterface $masterVariant) | |||
{ | |||
if ($this->variants->contains($masterVariant)) { | |||
return $this; | |||
if ($masterVariant->isMaster()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH. I would merge both if
s as there no point to split cause in first if
you do nothing if second one will not pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then you would end up with two if
statements checking if the product contains the variant. If that is cleaner, I can do it like this. Is this what you're proposing: (performance wise, this would be slower)
if ($this->variants->contains($masterVariant) && $masterVariant->isMaster()) {
return $this;
}
if (!$this->variants->contains($masterVariant)) {
$masterVariant->setProduct($this);
$this->variants->add($masterVariant);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm sleepy so I can be wrong =) but what about?
if (!$masterVariant->isMaster()) {
$masterVariant->setMaster(true);
}
if (!$this->variants->contains($masterVariant)) {
$masterVariant->setProduct($this);
$this->variants->add($masterVariant);
}
ps. phpspec would be your friend here =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah me too. But this would be better, we do not even need the top lines. Also, the check for isMaster
is also not really necessary, right?
You could not set a master variant if the variant was already included and not master. This patch fixed it.
@stloyd Code is cleaned up now, I removed the if statement for |
@pjedrzejewski Looks good for me. |
[BugFix] Little bug fix inside product model
Thanks @steffenbrem! |
@pjedrzejewski @stloyd But what if the product already had a |
You could not set a master variant if the non-master variant was already added to the product. This patch fixed it.