src/Entity/SupplierWarehouseItem.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Interface\ItemInterface;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Exception;
  6. /**
  7.  * @ORM\Table(name="suppliers__warehouses_items",
  8.  *       uniqueConstraints={
  9.  *            @ORM\UniqueConstraint(columns={"item_id", "warehouse_id"}),
  10.  *        })
  11.  * @ORM\Entity(repositoryClass="App\Repository\SupplierWarehouseItemRepository")
  12.  */
  13. class SupplierWarehouseItem implements ItemInterface
  14. {
  15.     use IdTrait;
  16.     use UpdatedAtTrait;
  17.     /**
  18.      * @ORM\ManyToOne(targetEntity="SupplierItem")
  19.      * @ORM\JoinColumn(name="item_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  20.      */
  21.     private SupplierItem $item;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity="SupplierWarehouse")
  24.      * @ORM\JoinColumn(name="warehouse_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  25.      */
  26.     private SupplierWarehouse $warehouse;
  27.     /**
  28.      * @ORM\Column(name="stock", type="integer", options={"default":0})
  29.      */
  30.     private int $stock 0;
  31.     /**
  32.      * @ORM\Column(name="show_in_search", type="boolean", options={"default":1})
  33.      */
  34.     private bool $showInSearch true;
  35.     /**
  36.      * @ORM\Column(name="parsing_task", type="string", nullable=true)
  37.      */
  38.     private ?string $parsingTask null;
  39.     /**
  40.      * @throws Exception
  41.      */
  42.     public function __construct(SupplierItem $itemSupplierWarehouse $warehouse)
  43.     {
  44.         if($item->getSupplier() !== $warehouse->getSupplier()) throw new Exception('Diff supplier');
  45.         $this->item $item;
  46.         $this->warehouse $warehouse;
  47.     }
  48.     public function getProduct(): Product
  49.     {
  50.         return $this->item->getProduct();
  51.     }
  52.     public function getWarehouse(): SupplierWarehouse
  53.     {
  54.         return $this->warehouse;
  55.     }
  56.     public function getStock(): int
  57.     {
  58.         return $this->stock;
  59.     }
  60.     public function setStock(int $stock): SupplierWarehouseItem
  61.     {
  62.         $this->stock $stock;
  63.         return $this;
  64.     }
  65.     public function getPrice(): int
  66.     {
  67.         return $this->item->getPrice();
  68.     }
  69.     public function isShowInSearch(): bool
  70.     {
  71.         return $this->showInSearch;
  72.     }
  73. }