src/Entity/Product/Product.php line 34

  1. <?php
  2. /*
  3.  * This file is part of the Pellipop project.
  4.  *
  5.  * (c) Mobizel
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\Entity\Product;
  12. use App\Entity\IdentifiableTrait;
  13. use App\Repository\Product\ProductRepository;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Gedmo\Timestampable\Traits\TimestampableEntity;
  16. use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;
  17. use Sylius\Component\Resource\Model\ResourceInterface;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. #[ORM\Entity(repositoryClassProductRepository::class)]
  20. #[ORM\Table(name'app_product')]
  21. #[SyliusCrudRoutes(alias'app.product'path'/admin/products'section'backend'templates'backend/crud'grid'app_backend_product'except: ['show'], vars: [
  22.     'all' => [
  23.         'subheader' => 'app.ui.manage_your_products',
  24.     ],
  25.     'index' => [
  26.         'icon' => 'cube',
  27.     ],
  28. ])]
  29. class Product implements ResourceInterface
  30. {
  31.     use IdentifiableTrait;
  32.     use TimestampableEntity;
  33.     #[ORM\Column(type'string'length255)]
  34.     #[Assert\NotBlank]
  35.     private ?string $name null;
  36.     #[ORM\Column(type'integer')]
  37.     #[Assert\NotBlankAssert\PositiveOrZero]
  38.     private int $credits 0;
  39.     #[ORM\Column(type'integer')]
  40.     #[Assert\NotBlankAssert\Positive]
  41.     private int $albumSize 0;
  42.     /** Direct payment price in cents (€). When set, user can pay by card without credits. */
  43.     #[ORM\Column(type'integer'nullabletrue)]
  44.     private ?int $directPriceCents null;
  45.     /** Shipping displayed for France in cents (€), for direct payment. */
  46.     #[ORM\Column(type'integer'nullabletrue)]
  47.     private ?int $shippingDisplayCents null;
  48.     /** International shipping supplement in cents (€), for direct payment. */
  49.     #[ORM\Column(type'integer'nullabletrue)]
  50.     private ?int $internationalShippingSupplementCents null;
  51.     #[ORM\Column(type'boolean')]
  52.     private bool $enabled true;
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): self
  58.     {
  59.         $this->name $name;
  60.         return $this;
  61.     }
  62.     public function getCredits(): int
  63.     {
  64.         return $this->credits;
  65.     }
  66.     public function setCredits(int $credits): self
  67.     {
  68.         $this->credits $credits;
  69.         return $this;
  70.     }
  71.     public function getAlbumSize(): int
  72.     {
  73.         return $this->albumSize;
  74.     }
  75.     public function setAlbumSize(int $albumSize): self
  76.     {
  77.         $this->albumSize $albumSize;
  78.         return $this;
  79.     }
  80.     public function getDirectPriceCents(): ?int
  81.     {
  82.         return $this->directPriceCents;
  83.     }
  84.     public function setDirectPriceCents(?int $directPriceCents): self
  85.     {
  86.         $this->directPriceCents $directPriceCents;
  87.         return $this;
  88.     }
  89.     public function getShippingDisplayCents(): ?int
  90.     {
  91.         return $this->shippingDisplayCents;
  92.     }
  93.     public function setShippingDisplayCents(?int $shippingDisplayCents): self
  94.     {
  95.         $this->shippingDisplayCents $shippingDisplayCents;
  96.         return $this;
  97.     }
  98.     public function getInternationalShippingSupplementCents(): ?int
  99.     {
  100.         return $this->internationalShippingSupplementCents;
  101.     }
  102.     public function setInternationalShippingSupplementCents(?int $internationalShippingSupplementCents): self
  103.     {
  104.         $this->internationalShippingSupplementCents $internationalShippingSupplementCents;
  105.         return $this;
  106.     }
  107.     /** Whether this product can be paid directly (in €). */
  108.     public function supportsDirectPayment(): bool
  109.     {
  110.         return $this->directPriceCents !== null && $this->directPriceCents 0;
  111.     }
  112.     public function __toString(): string
  113.     {
  114.         return (string) ($this->getName() ?? $this->getId());
  115.     }
  116.     public function getEnabled(): bool
  117.     {
  118.         return $this->enabled;
  119.     }
  120.     public function setEnabled(bool $enabled): self
  121.     {
  122.         $this->enabled $enabled;
  123.         return $this;
  124.     }
  125. }