<?php
namespace Roothirsch\PimBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Form\Types\AttributeOptionDropdownType;
use Roothirsch\PimBundle\Entity\Category;
use Roothirsch\PimBundle\Repository\ArticleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use \Roothirsch\PimBundle\Entity\Product;
use Symfony\Component\Serializer\Annotation\Ignore;
/**
* @ApiResource(
* normalizationContext={"groups"={"list"}, "enable_max_depth"=true},
* denormalizationContext={"groups"={"list"}},
* shortName="Pim/Article"
* )
* @ORM\Entity(repositoryClass=ArticleRepository::class)
* @ORM\Table(name="pim_article")
*/
class Article extends Product
{
/**
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="articles")
* @ORM\JoinColumn(nullable=true)
*/
private $product;
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
$product->addArticle($this);
return $this;
}
public function attributes() {
$attributes = new ArrayCollection();
foreach($this->product->getCategories() as $category) {
/** @var Category $category */
foreach($category->getArticleAttributeGroups() as $attributeGroup) {
foreach($attributeGroup->getAttributes() as $attribute) {
$attributes->add($attribute);
}
}
}
return $attributes;
}
public function getAttributeMap() {
$attributes = [];
foreach($this->attributes() as $attribute) {
$attributes[$attribute->getName()] = $this->__get($attribute->getName());
}
return $attributes;
}
}