src/Entity/Product.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Traits\PictureTrait;
  4. use App\Traits\ProductTrait;
  5. use App\Traits\SortTrait;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Criteria;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use App\Entity\Vat;
  10. use App\Entity\Picture;
  11. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  12. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  13. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  14. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  15. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  16. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  17. use Symfony\Component\VarDumper\VarDumper;
  18. /**
  19.  * Product
  20.  *
  21.  * @ORM\Table(name="catalog_product")
  22.  * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
  23.  * @ORM\AssociationOverrides({
  24.  *      @ORM\AssociationOverride(name="pictures",
  25.  *          joinTable=@ORM\JoinTable(
  26.  *              name="catalog_product_pictures"
  27.  *          ),
  28.  *          joinColumns=@ORM\JoinColumn(
  29.  *              name="product_id", referencedColumnName="id"
  30.  *          )
  31.  *      )
  32.  * })
  33.  */
  34. class Product implements TimestampableInterfaceTranslatableInterfaceSoftDeletableInterface
  35. {
  36.     use TimestampableTrait,
  37.         TranslatableTrait,
  38.         SoftDeletableTrait,
  39.         SortTrait,
  40.         ProductTrait,
  41.         PictureTrait;
  42.     /**
  43.      * @var int
  44.      *
  45.      * @ORM\Column(name="id", type="integer")
  46.      * @ORM\Id
  47.      * @ORM\GeneratedValue(strategy="AUTO")
  48.      */
  49.     private $id;
  50.     /**
  51.      * @ORM\ManyToOne(targetEntity="Category", inversedBy="products", cascade={"persist"})
  52.      **/
  53.     private $category;
  54.     /**
  55.      * @ORM\ManyToMany(targetEntity="Product")
  56.      * @ORM\JoinTable(name="catalog_product_related_product",
  57.      *      joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")},
  58.      *      inverseJoinColumns={@ORM\JoinColumn(name="related_product_id", referencedColumnName="id")}
  59.      *      )
  60.      */
  61.     private $relatedProducts;
  62.     /**
  63.      * @var boolean
  64.      *
  65.      * @ORM\Column(type="boolean", name="display_on_shop", nullable=true)
  66.      */
  67.     private $displayOnShop;
  68.     public function __construct()
  69.     {
  70.         $this->relatedProducts = new ArrayCollection();
  71.     }
  72.     public function __toString()
  73.     {
  74.         $result "";
  75.         $i 1;
  76.         foreach ($this->getTranslations() as $translation) {
  77.             $result .= $translation->getTitle();
  78.             if ($i != count($this->getTranslations())) {
  79.                 $result .= " - ";
  80.             }
  81.             $i++;
  82.         }
  83.         return $result;
  84.     }
  85.     /**
  86.      * Get id
  87.      *
  88.      * @return int
  89.      */
  90.     public function getId()
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function addRelatedProduct(Product $p)
  95.     {
  96.         $this->relatedProducts[] = $p;
  97.     }
  98.     public function removeRelatedProduct(Product $p)
  99.     {
  100.         $this->relatedProducts->removeElement($p);
  101.     }
  102.     /**
  103.      * @return mixed
  104.      */
  105.     public function getRelatedProducts()
  106.     {
  107.         return $this->relatedProducts;
  108.     }
  109.     public function getRelatedProductsOnline()
  110.     {
  111.         $criteria Criteria::create()
  112.             ->andWhere(Criteria::expr()->eq('deletedAt'null));
  113.         return $this->relatedProducts->matching($criteria);
  114.     }
  115.     /**
  116.      * Get Category
  117.      *
  118.      * @return Category
  119.      *
  120.      */
  121.     public function getCategory()
  122.     {
  123.         return $this->category;
  124.     }
  125.     /**
  126.      * Set Category
  127.      *
  128.      * @param Category $category
  129.      * @return Product
  130.      */
  131.     public function setCategory(Category $category)
  132.     {
  133.         $this->category $category;
  134.         return $this;
  135.     }
  136.     public function isDisplayOnShop(): bool
  137.     {
  138.         return $this->displayOnShop;
  139.     }
  140.     public function setDisplayOnShop(bool $displayOnShop): void
  141.     {
  142.         $this->displayOnShop $displayOnShop;
  143.     }
  144. }