Skip to content
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

Merged
merged 1 commit into from
Jun 17, 2014

Conversation

koemeet
Copy link
Contributor

@koemeet koemeet commented Jun 16, 2014

You could not set a master variant if the non-master variant was already added to the product. This patch fixed it.

return $this;
} else {
$masterVariant->setProduct($this);
$this->variants->add($masterVariant);
}
Copy link
Member

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. :)

Copy link
Contributor Author

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

@koemeet
Copy link
Contributor Author

koemeet commented Jun 16, 2014

@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()) {
Copy link
Contributor

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.

@koemeet
Copy link
Contributor Author

koemeet commented Jun 16, 2014

@stloyd Removed true === from condition.

@koemeet
Copy link
Contributor Author

koemeet commented Jun 16, 2014

@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()) {
Copy link
Contributor

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 ifs as there no point to split cause in first if you do nothing if second one will not pass.

Copy link
Contributor Author

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);
}

Copy link
Contributor

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 =)

Copy link
Contributor Author

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.
@koemeet
Copy link
Contributor Author

koemeet commented Jun 17, 2014

@stloyd Code is cleaned up now, I removed the if statement for isMaster, because it will always be true.

@stloyd
Copy link
Contributor

stloyd commented Jun 17, 2014

@pjedrzejewski Looks good for me.

pjedrzejewski pushed a commit that referenced this pull request Jun 17, 2014
[BugFix] Little bug fix inside product model
@pjedrzejewski pjedrzejewski merged commit 1afbff1 into Sylius:master Jun 17, 2014
@pjedrzejewski
Copy link
Member

Thanks @steffenbrem!

@koemeet koemeet deleted the product-model-bugfix branch June 17, 2014 16:59
@koemeet
Copy link
Contributor Author

koemeet commented Jun 22, 2014

@pjedrzejewski @stloyd But what if the product already had a masterVariant which has isMaster set to true? Wouldn't this fail when you call getMasterVariants? You could get unexpected results then. I think we first have to make sure that when the product contains any masterVariant, it's isMaster property is set to false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants