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

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