vendor/roothirsch/pim-bundle/Entity/Attribute.php line 22

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\PimBundle\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeOption\AttributeOptionAwareTrait;
  5. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeValue\AttributeValueAwareTrait;
  6. use Roothirsch\CoreBundle\Behaviors\Attributable\MappedSuperclass\AbstractAttribute;
  7. use Roothirsch\CoreBundle\Behaviors\Translatable\TranslatableFieldInterface;
  8. use Roothirsch\PimBundle\Entity\AttributeOption;
  9. use Roothirsch\PimBundle\Repository\AttributeRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Serializer\Annotation\Ignore;
  14. use \Roothirsch\PimBundle\Entity\AttributeGroup;
  15. /**
  16. * @ApiResource(shortName="Pim/Attribute")
  17. * @ORM\Entity(repositoryClass=AttributeRepository::class)
  18. * @ORM\Table(name="pim_attribute")
  19. */
  20. class Attribute extends AbstractAttribute implements TranslatableFieldInterface
  21. {
  22. use AttributeOptionAwareTrait;
  23. use AttributeValueAwareTrait;
  24. /**
  25. * @ORM\OneToMany(targetEntity=AttributeValue::class, mappedBy="attribute", orphanRemoval=true)
  26. * @Ignore
  27. */
  28. private $attributeValues;
  29. /**
  30. * @ORM\OneToMany(targetEntity=AttributeOption::class, mappedBy="attribute", orphanRemoval=true, cascade={"persist"})
  31. */
  32. private $attributeOptions;
  33. /**
  34. * @ORM\ManyToOne(targetEntity=AttributeGroup::class, inversedBy="attributes")
  35. * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  36. */
  37. private $attributeGroup;
  38. /**
  39. * @ORM\Column(type="boolean")
  40. */
  41. private $valuePerChannel = false;
  42. /**
  43. * @ORM\Column(type="boolean")
  44. */
  45. private $valuePerLanguage = false;
  46. /**
  47. * @ORM\ManyToMany(targetEntity=Product::class, mappedBy="individualAttributes")
  48. */
  49. private $products;
  50. public function __construct()
  51. {
  52. parent::__construct();
  53. $this->products = new ArrayCollection();
  54. }
  55. public function __toString()
  56. {
  57. return $this->title ?? '';
  58. }
  59. public function getValuePerChannel(): ?bool
  60. {
  61. return $this->valuePerChannel;
  62. }
  63. public function setValuePerChannel(bool $valuePerChannel): self
  64. {
  65. $this->valuePerChannel = $valuePerChannel;
  66. return $this;
  67. }
  68. public function getValuePerLanguage(): ?bool
  69. {
  70. return $this->valuePerLanguage;
  71. }
  72. public function setValuePerLanguage(bool $valuePerLanguage): self
  73. {
  74. $this->valuePerLanguage = $valuePerLanguage;
  75. return $this;
  76. }
  77. public function getAttributeGroup(): ?AttributeGroup
  78. {
  79. return $this->attributeGroup;
  80. }
  81. public function setAttributeGroup(?AttributeGroup $attributeGroup): self
  82. {
  83. $this->attributeGroup = $attributeGroup;
  84. return $this;
  85. }
  86. public function isTranslatable(): bool
  87. {
  88. return $this->getValuePerLanguage();
  89. }
  90. public function getTranslatableKey(): string
  91. {
  92. return $this->getName();
  93. }
  94. /**
  95. * @return Collection|Product[]
  96. */
  97. public function getProducts(): Collection
  98. {
  99. return $this->products;
  100. }
  101. }