src/Entity/OrderProduct.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrderProductRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClassOrderProductRepository::class)]
  6. #[ORM\InheritanceType('SINGLE_TABLE')]
  7. #[ORM\DiscriminatorColumn(name'discriminator'type'string')]
  8. #[ORM\DiscriminatorMap([
  9.     'cadre' => Cadre::class,
  10.     'passe-partout' => PassePartout::class,
  11.     'caisse-americaine' => CaisseAmericaine::class,
  12.     'sujet' => Sujet::class,
  13.     'partial' => Partial::class,
  14. ])]
  15. class OrderProduct
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     protected ?int $id null;
  21.     #[ORM\Column(nullabletrue)]
  22.     protected ?int $quantity null;
  23.     #[ORM\Column(nullabletrue)]
  24.     protected ?float $price null;
  25.     #[ORM\Column(length255nullabletrue)]
  26.     protected ?string $imgUrl null;
  27.     #[ORM\ManyToOne(targetEntityClientOrder::class, inversedBy'orderProducts')]
  28.     #[ORM\JoinColumn(nullablefalse)]
  29.     protected ?ClientOrder $clientOrder null;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     protected ?string $refToSend null;
  32.     public function __construct()
  33.     {
  34.         $this->quantity 1;
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getQuantity(): ?int
  41.     {
  42.         return $this->quantity;
  43.     }
  44.     public function setQuantity(?int $quantity): static
  45.     {
  46.         $this->quantity $quantity;
  47.         return $this;
  48.     }
  49.     public function getPrice(): ?float
  50.     {
  51.         return $this->price;
  52.     }
  53.     public function setPrice(?float $price): static
  54.     {
  55.         $this->price $price;
  56.         return $this;
  57.     }
  58.     public function getImgUrl(): ?string
  59.     {
  60.         return $this->imgUrl;
  61.     }
  62.     public function setImgUrl(?string $imgUrl): static
  63.     {
  64.         $this->imgUrl $imgUrl;
  65.         return $this;
  66.     }
  67.     public function getClientOrder(): ?ClientOrder
  68.     {
  69.         return $this->clientOrder;
  70.     }
  71.     public function setClientOrder(?ClientOrder $clientOrder): static
  72.     {
  73.         $this->clientOrder $clientOrder;
  74.         return $this;
  75.     }
  76.     public function getRefToSend(): ?string
  77.     {
  78.         return $this->refToSend;
  79.     }
  80.     public function setRefToSend(?string $refToSend): static
  81.     {
  82.         $this->refToSend $refToSend;
  83.         return $this;
  84.     }
  85.     /**
  86.      * Extract reference from product name (fallback method)
  87.      */
  88.     public function getReferenceNielsen(): ?string
  89.     {
  90.         $name null;
  91.         
  92.         if ($this instanceof Cadre || $this instanceof CaisseAmericaine || $this instanceof PassePartout || $this instanceof Partial) {
  93.             $name $this->getName();
  94.         }
  95.         
  96.         if ($name) {
  97.             preg_match('#\((.*?)\)#'$name$variant);
  98.             if (!empty($variant)) {
  99.                 return str_replace(["("")"], ""$variant[0]);
  100.             }
  101.             return $name;
  102.         }
  103.         
  104.         return null;
  105.     }
  106.     /**
  107.      * Get the product type for cart system compatibility
  108.      */
  109.     public function getProductType(): string
  110.     {
  111.         $discriminator = [
  112.             Cadre::class => 'cadre',
  113.             PassePartout::class => 'passe-partout'
  114.             CaisseAmericaine::class => 'caisse-americaine',
  115.             Sujet::class => 'sujet',
  116.             Partial::class => 'partial',
  117.         ];
  118.         return $discriminator[static::class] ?? 'unknown';
  119.     }
  120. }