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

Enable images for Taxonomy/Taxon #92

Merged
merged 14 commits into from
May 31, 2013

Conversation

piotrantosik
Copy link
Contributor

See #83
Any comments welcome :)

@@ -78,17 +78,20 @@ liip_doctrine_cache:

knp_gaufrette:
adapters:
variant_image:
sylius_image:
Copy link
Member

Choose a reason for hiding this comment

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

👍

@pjedrzejewski
Copy link
Member

Nice work Piotr! I'll review this soon - the build is failing, on every page so perhaps there is some configuration bug.
I have few remark regarding that, I'll take a deeper look but I already see that - Every taxonomy always has it's root Taxon, so it would be enough to have image on Taxon entity, for Taxonomy (root) it would available through that taxon. Also the listener code looks a bit complex, if there are no specs for it, then it's my fault. :)

Thanks!

}
}
else {
if (null === $subject->getId()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This if can be merged with elseif below, and probably as replacement for else line above.

@piotrantosik
Copy link
Contributor Author

@pjedrzejewski so remove image for Taxonomy - we must use image from root Taxon,you agree?

foreach ($variant->getImages() as $image) {
if (null === $image->getId()) {
$this->uploader->upload($image);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

} elseif (null === $subject->getId() || (($subject instanceof TaxonInterface || $subject instanceof TaxonomyInterface) && $subject->hasFile())) {
    $this->uploader->upload($subject); 
}

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I think we could simply have 2 separate methods on this listener. One for products, one for taxons, this will simplify method complexity by removing all this conditions. uploadProductImage & uploadTaxonImage. This would involve simple change in listeners config. @Antek88 @stloyd

Copy link
Contributor

Choose a reason for hiding this comment

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

@pjedrzejewski TBH. I didn't check code in such details =) Just looked at how it looks etc. =)

Copy link
Contributor

Choose a reason for hiding this comment

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

@pjedrzejewski maybe this is a good time to create SyliusFileUploader? Universal tool that handle file uploading with doctrine entities?

@pjedrzejewski
Copy link
Member

@Antek88 Yes, exactly! For taxonomy we will simply use $taxonomy->getRoot() to get the root taxon and then the image. But I think we can also introduce proxy methods like $taxonomy->getImagePath().

And btw. the getFile and getPath methods alone can be confusing on Taxon, could we rename them to getImagePath() and getImageFile(), then it's clear, what do you think?

@pjedrzejewski
Copy link
Member

To upload image for root taxon on Taxonomy form, you can simply change the property_path option of the file field. So it will save the image to root taxon, not the taxonomy which will no longer have the image / path properties.

@piotrantosik
Copy link
Contributor Author

@pjedrzejewski @stloyd ping

throw new \InvalidArgumentException('TaxonomyInterface expected.');
}

if ($subject->getRoot()->hasImageFile()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if root is empty? (not sure it's possible =)) Or what if file is already uploaded in root?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

root is always created:

$this->setRoot(new Taxon());

if file already exist uploader firstly remove file and upload new:

if (null !== $image->getImagePath()) {
            $this->remove($image->getImagePath());
        }

@pjedrzejewski
Copy link
Member

Only problems I see is the removing typehint (maybe there is a reason but I'm pretty sure we should do it, maybe change the interface) and that during rebase, you reverted some other PR's.

@@ -161,6 +161,9 @@ public function createTaxonomiesMenu(Request $request)

foreach ($taxonomies as $taxonomy) {
$child = $menu->addChild($taxonomy->getName(), $childOptions);
if ($taxonomy->getRoot()->getPath()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO you should add hasPath() as you already have hasFile() method, or at least use variable here to avoid twice get* call (same below).

@piotrantosik
Copy link
Contributor Author

@pjedrzejewski ping, tests fixed 😄

</many-to-one>
</entity>

</doctrine-mapping>
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to re-define this if we add image only to taxon?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need this because in DefaultTaxonomy (Taxonomies bundle) class we have:

$this->setRoot(new DefaultTaxon());

and after remove Taxonomy mapping from core bundle i have error when creating new taxonomy:

[Doctrine\ORM\ORMException]                                                                                                                  
  Found entity of type Sylius\Bundle\TaxonomiesBundle\Entity\DefaultTaxon on association Sylius\Bundle\TaxonomiesBundle\Entity\DefaultTaxonom  
  y#root, but expecting Sylius\Bundle\CoreBundle\Entity\Taxon

pjedrzejewski pushed a commit that referenced this pull request May 31, 2013
Enable images for Taxonomy/Taxon
@pjedrzejewski pjedrzejewski merged commit cbefbd4 into Sylius:master May 31, 2013
@pjedrzejewski
Copy link
Member

Woohoo, thank you Piotr! Great work! 👍

@okwinza okwinza mentioned this pull request May 24, 2016
8 tasks
CoderMaggie pushed a commit to CoderMaggie/Sylius that referenced this pull request Jun 1, 2016
[CJMAX-82] Added more fields to Customer
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

4 participants