vendor/roothirsch/pim-bundle/Entity/Article.php line 26

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\PimBundle\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Form\Types\AttributeOptionDropdownType;
  5. use Roothirsch\PimBundle\Entity\Category;
  6. use Roothirsch\PimBundle\Repository\ArticleRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use \Roothirsch\PimBundle\Entity\Product;
  11. use Symfony\Component\Serializer\Annotation\Ignore;
  12. use Symfony\Component\Serializer\Annotation\MaxDepth;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. /**
  15. * @ApiResource(
  16. * normalizationContext={"groups"={"list"}, "enable_max_depth"=true},
  17. * denormalizationContext={"groups"={"list"}},
  18. * shortName="Pim/Article"
  19. * )
  20. * @ORM\Entity(repositoryClass=ArticleRepository::class)
  21. * @ORM\Table(name="pim_article")
  22. */
  23. class Article extends Product
  24. {
  25. /**
  26. * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="articles")
  27. * @ORM\JoinColumn(nullable=true)
  28. * @Groups({"list"})
  29. * @MaxDepth(1)
  30. */
  31. private $product;
  32. public function getProduct(): ?Product
  33. {
  34. return $this->product;
  35. }
  36. public function setProduct(?Product $product): self
  37. {
  38. $this->product = $product;
  39. $product->addArticle($this);
  40. return $this;
  41. }
  42. public function attributes() {
  43. $attributes = new ArrayCollection();
  44. if ($this->product) {
  45. foreach($this->product->getCategories() as $category) {
  46. /** @var Category $category */
  47. foreach($category->getArticleAttributeGroups() as $attributeGroup) {
  48. foreach($attributeGroup->getAttributes() as $attribute) {
  49. $attributes->add($attribute);
  50. }
  51. }
  52. }
  53. }
  54. // Add own individual attributes (inherited from Product class)
  55. foreach($this->individualAttributes as $attribute) {
  56. if (!$attributes->contains($attribute)) {
  57. $attributes->add($attribute);
  58. }
  59. }
  60. return $attributes;
  61. }
  62. public function getAttributeMap() {
  63. $attributes = [];
  64. foreach($this->attributes() as $attribute) {
  65. $attributes[$attribute->getName()] = $this->__get($attribute->getName());
  66. }
  67. return $attributes;
  68. }
  69. }