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

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. /**
  14. * @ApiResource(
  15. * normalizationContext={"groups"={"list"}, "enable_max_depth"=true},
  16. * denormalizationContext={"groups"={"list"}},
  17. * shortName="Pim/Article"
  18. * )
  19. * @ORM\Entity(repositoryClass=ArticleRepository::class)
  20. * @ORM\Table(name="pim_article")
  21. */
  22. class Article extends Product
  23. {
  24. /**
  25. * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="articles")
  26. * @ORM\JoinColumn(nullable=true)
  27. * @MaxDepth(1)
  28. */
  29. private $product;
  30. public function getProduct(): ?Product
  31. {
  32. return $this->product;
  33. }
  34. public function setProduct(?Product $product): self
  35. {
  36. $this->product = $product;
  37. $product->addArticle($this);
  38. return $this;
  39. }
  40. public function attributes() {
  41. $attributes = new ArrayCollection();
  42. if ($this->product) {
  43. foreach($this->product->getCategories() as $category) {
  44. /** @var Category $category */
  45. foreach($category->getArticleAttributeGroups() as $attributeGroup) {
  46. foreach($attributeGroup->getAttributes() as $attribute) {
  47. $attributes->add($attribute);
  48. }
  49. }
  50. }
  51. }
  52. // Add own individual attributes (inherited from Product class)
  53. foreach($this->individualAttributes as $attribute) {
  54. if (!$attributes->contains($attribute)) {
  55. $attributes->add($attribute);
  56. }
  57. }
  58. return $attributes;
  59. }
  60. public function getAttributeMap() {
  61. $attributes = [];
  62. foreach($this->attributes() as $attribute) {
  63. $attributes[$attribute->getName()] = $this->__get($attribute->getName());
  64. }
  65. return $attributes;
  66. }
  67. }