src/Entity/Product.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. // 追加
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use App\Entity\SaleType;
  10. use App\Entity\ProductImage;
  11. use App\Entity\Member;
  12. use App\Entity\ProductTag;
  13. use App\Entity\ProductStatus;
  14. #[ORM\Entity(repositoryClassProductRepository::class)]
  15. #[ORM\Table(name"dtb_product")]
  16. // #[ORM\Entity(repositoryClass: "Eccube\Repository\ProductRepository")]
  17. #[ORM\HasLifecycleCallbacks]
  18. class Product
  19. {
  20.     // private $_calc = false;
  21.     // private $stockFinds = [];
  22.     // private $stocks = [];
  23.     // private $stockUnlimiteds = [];
  24.     // private $price01 = [];
  25.     private $price02 = [];
  26.     // private $price01IncTaxs = [];
  27.     // private $price02IncTaxs = [];
  28.     // private $codes = [];
  29.     // private $classCategories1 = [];
  30.     // private $classCategories2 = [];
  31.     // private $className1;
  32.     // private $className2;
  33.     // #[ORM\Id]
  34.     // #[ORM\GeneratedValue(strategy: "IDENTITY")]
  35.     // #[ORM\Column(type: "integer", options: ["unsigned" => true])]
  36.     #[ORM\Id]
  37.     #[ORM\GeneratedValue]
  38.     #[ORM\Column]
  39.     private ?int $id null;
  40.     #[ORM\OneToMany(targetEntityProductImage::class, mappedBy'Product'cascade: ['persist''remove'])]
  41.     private Collection $productImages;
  42.     /**
  43.      * ProductCategoryエンティティとのリレーション
  44.      * 削除連鎖(cascade: ['remove'])を設定しており、Productが削除されると関連するProductCategoryも削除される
  45.      *
  46.      * @var Collection<int, ProductCategory> $productCategories
  47.      */
  48.     #[ORM\OneToMany(targetEntityProductCategory::class, mappedBy'Product'cascade: ['remove'])]
  49.     private Collection $productCategories;
  50.     public function __construct()
  51.     {
  52.         $this->productCategories = new ArrayCollection();
  53.         $this->ProductClasses = new ArrayCollection();
  54.         $this->ProductImage = new ArrayCollection();
  55.         $this->ProductTag = new ArrayCollection();
  56.         // $this->CustomerFavoriteProducts = new ArrayCollection();
  57.     }
  58.     /**
  59.      * 中間テーブル(ProductCategory)経由で関連するカテゴリ名(category_name)のリストを取得する
  60.      *
  61.      * @return array<string> 関連カテゴリ名の配列
  62.      */
  63.     public function getCategoryNames(): array
  64.     {
  65.         return $this->productCategories->map(function (ProductCategory $productCategory) {
  66.             return $productCategory->getCategory()->getCategoryName();
  67.         })->toArray();
  68.     }
  69.     /**
  70.      * ProductCategoryエンティティのコレクションを取得します。
  71.      * このメソッドは、ProductType.phpおよびProductController.phpで使用され、
  72.      * ProductエンティティとCategoryエンティティの関係を管理します。
  73.      *
  74.      * @return Collection<int, ProductCategory> ProductCategoryエンティティのコレクション
  75.      */
  76.     public function getProductCategories(): Collection
  77.     {
  78.         return $this->productCategories;
  79.     }
  80.     #[ORM\Column(typeTypes::SMALLINTnullabletrue)]
  81.     private ?int $product_status_id null;
  82.     /**
  83.      * SaleTypeエンティティとのManyToOne関係
  84.      * product_status_idカラムをリレーションキーとして使用
  85.      *
  86.      * @var SaleType|null $saleType 関連するSaleTypeエンティティ
  87.      */
  88.     #[ORM\ManyToOne(targetEntitySaleType::class)]
  89.     #[ORM\JoinColumn(name"product_status_id"referencedColumnName"id")]
  90.     private ?SaleType $saleType null;
  91.     public function getSaleType(): ?SaleType
  92.     {
  93.         return $this->saleType;
  94.     }
  95.     public function setSaleType(?SaleType $saleType): self
  96.     {
  97.         $this->saleType $saleType;
  98.         return $this;
  99.     }
  100.     #[ORM\Column(type"string"length255)]
  101.     private string $name;
  102.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  103.     private ?string $note null;
  104.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  105.     private ?string $description_list null;
  106.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  107.     private ?string $description_detail null;
  108.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  109.     private ?string $search_word null;
  110.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  111.     private ?string $free_area null;
  112.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  113.     private ?\DateTimeInterface $create_date null;
  114.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  115.     private ?\DateTimeInterface $update_date null;
  116.     #[ORM\OneToMany(mappedBy"Product"targetEntityProductCategory::class, cascade: ["persist""remove"])]
  117.     private Collection $ProductCategories;
  118.     #[ORM\OneToMany(mappedBy"Product"targetEntityProductClass::class, cascade: ["persist""remove"])]
  119.     private Collection $ProductClasses;
  120.     #[ORM\OneToMany(mappedBy"Product"targetEntityProductImage::class, cascade: ["remove"])]
  121.     #[ORM\OrderBy(["sort_no" => "ASC"])]
  122.     private Collection $ProductImage;
  123.     #[ORM\OneToMany(mappedBy"Product"targetEntityProductTag::class, cascade: ["remove"])]
  124.     private Collection $ProductTag;
  125.     // #[ORM\OneToMany(mappedBy: "Product", targetEntity: CustomerFavoriteProduct::class)]
  126.     // private Collection $CustomerFavoriteProducts;
  127.     #[ORM\ManyToOne(targetEntityMember::class)]
  128.     #[ORM\JoinColumn(name"creator_id"referencedColumnName"id")]
  129.     private ?Member $Creator null;
  130.     #[ORM\ManyToOne(targetEntityProductStatus::class)]
  131.     #[ORM\JoinColumn(name"product_status_id"referencedColumnName"id")]
  132.     private ?ProductStatus $Status null;
  133.     #[ORM\Column(length255)]
  134.     private ?string $discriminator_type 'product';
  135.     // 一度、コメントアウト
  136.     // #[ORM\Column(length: 32, nullable: true)]
  137.     // private ?string $supplier_code = null;
  138.     // private bool $_calc = false;
  139.     // private array $stockFinds = [];
  140.     // private array $stocks = [];
  141.     // private array $stockUnlimiteds = [];
  142.     // private array $price01 = [];
  143.     // private array $price02 = [];
  144.     // private array $price01IncTaxs = [];
  145.     // private array $price02IncTaxs = [];
  146.     // private array $codes = [];
  147.     // private array $classCategories1 = [];
  148.     // private array $classCategories2 = [];
  149.     // private ?string $className1 = null;
  150.     // private ?string $className2 = null;
  151.     public function getId(): ?int
  152.     {
  153.         return $this->id;
  154.     }
  155.     /**
  156.      * Set the creator.
  157.      *
  158.      * @param Member|null $creator
  159.      * @return self
  160.      */
  161.     public function setCreator(?Member $creator): self
  162.     {
  163.         $this->Creator $creator;
  164.         return $this;
  165.     }
  166.     /**
  167.      * Get the creator.
  168.      *
  169.      * @return Member|null
  170.      */
  171.     public function getCreator(): ?Member
  172.     {
  173.         return $this->Creator;
  174.     }
  175.     public function getName(): ?string
  176.     {
  177.         return $this->name;
  178.     }
  179.     public function setName(string $name): self
  180.     {
  181.         $this->name $name;
  182.         return $this;
  183.     }
  184.     public function getNote(): ?string
  185.     {
  186.         return $this->note;
  187.     }
  188.     public function setNote(?string $note): self
  189.     {
  190.         $this->note $note;
  191.         return $this;
  192.     }
  193.     public function setDescriptionList(?string $descriptionList): self
  194.     {
  195.         $this->description_list $descriptionList;
  196.         return $this;
  197.     }
  198.     public function getDescriptionList(): ?string
  199.     {
  200.         return $this->description_list;
  201.     }
  202.     public function setDescriptionDetail(?string $descriptionDetail): self
  203.     {
  204.         $this->description_detail $descriptionDetail;
  205.         return $this;
  206.     }
  207.     public function getDescriptionDetail(): ?string
  208.     {
  209.         return $this->description_detail;
  210.     }
  211.     public function setSearchWord(?string $searchWord): self
  212.     {
  213.         $this->search_word $searchWord;
  214.         return $this;
  215.     }
  216.     public function getSearchWord(): ?string
  217.     {
  218.         return $this->search_word;
  219.     }
  220.     public function getFreeArea(): ?string
  221.     {
  222.         return $this->free_area;
  223.     }
  224.     public function setFreeArea(?string $freeArea): self
  225.     {
  226.         $this->free_area $freeArea;
  227.         return $this;
  228.     }
  229.     public function getCreateDate(): ?\DateTimeInterface
  230.     {
  231.         return $this->create_date;
  232.     }
  233.     public function setCreateDate(\DateTimeInterface $createDate): self
  234.     {
  235.         $this->create_date $createDate;
  236.         return $this;
  237.     }
  238.     public function getUpdateDate(): ?\DateTimeInterface
  239.     {
  240.         return $this->update_date;
  241.     }
  242.     public function setUpdateDate(\DateTimeInterface $updateDate): self
  243.     {
  244.         $this->update_date $updateDate;
  245.         return $this;
  246.     }
  247.     public function addProductCategory(ProductCategory $productCategory): self
  248.     {
  249.         $this->ProductCategories[] = $productCategory;
  250.         return $this;
  251.     }
  252.     public function removeProductCategory(ProductCategory $productCategory): bool
  253.     {
  254.         return $this->ProductCategories->removeElement($productCategory);
  255.     }
  256.     public function addProductClass(ProductClass $productClass): self
  257.     {
  258.         $this->ProductClasses[] = $productClass;
  259.         return $this;
  260.     }
  261.     public function getDiscriminatorType(): ?string
  262.     {
  263.         return $this->discriminator_type;
  264.     }
  265.     protected function setDiscriminatorType(string $discriminator_type): static
  266.     {
  267.         $this->discriminator_type $discriminator_type;
  268.         return $this;
  269.     }
  270.     public function removeProductClass(ProductClass $productClass): bool
  271.     {
  272.         return $this->ProductClasses->removeElement($productClass);
  273.     }
  274.     public function getProductClasses(): Collection
  275.     {
  276.         return $this->ProductClasses;
  277.     }
  278.     public function addProductImage(ProductImage $productImage): self
  279.     {
  280.         $this->ProductImage[] = $productImage;
  281.         return $this;
  282.     }
  283.     // 一度コメントアウト
  284.     // public function getSupplierCode(): ?string
  285.     // {
  286.     //     return $this->supplier_code;
  287.     // }
  288.     // public function setSupplierCode(?string $supplier_code): static
  289.     // {
  290.     //     $this->supplier_code = $supplier_code;
  291.     //     return $this;
  292.     // }
  293.     public function removeProductImage(ProductImage $productImage): bool
  294.     {
  295.         return $this->ProductImage->removeElement($productImage);
  296.     }
  297.     /**
  298.      * ProductImageのコレクションを取得するメソッド
  299.      */
  300.     public function getProductImages(): Collection
  301.     {
  302.         return $this->productImages;
  303.     }
  304.     /**
  305.      * Add productTag.
  306.      *
  307.      * @param ProductTag $productTag
  308.      *
  309.      * @return Product
  310.      */
  311.     public function addProductTag(ProductTag $productTag): self
  312.     {
  313.         if (!$this->ProductTag->contains($productTag)) {
  314.             $this->ProductTag[] = $productTag;
  315.             $productTag->setProduct($this); // リレーションの逆側を設定
  316.         }
  317.         return $this;
  318.     }
  319.     /**
  320.      * Remove productTag.
  321.      *
  322.      * @param ProductTag $productTag
  323.      *
  324.      * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  325.      */
  326.     public function removeProductTag(ProductTag $productTag): bool
  327.     {
  328.         if ($this->ProductTag->contains($productTag)) {
  329.             $this->ProductTag->removeElement($productTag);
  330.             // 関連の削除時に逆側も切断
  331.             if ($productTag->getProduct() === $this) {
  332.                 $productTag->setProduct(null);
  333.             }
  334.             return true;
  335.         }
  336.         return false;
  337.     }
  338.     /**
  339.      * Get productTag.
  340.      *
  341.      * @return Collection
  342.      */
  343.     public function getProductTag(): Collection
  344.     {
  345.         return $this->ProductTag;
  346.     }
  347.     // public function addCustomerFavoriteProduct(CustomerFavoriteProduct $customerFavoriteProduct): self
  348.     // {
  349.     //     $this->CustomerFavoriteProducts[] = $customerFavoriteProduct;
  350.     //     return $this;
  351.     // }
  352.     // public function removeCustomerFavoriteProduct(CustomerFavoriteProduct $customerFavoriteProduct): bool
  353.     // {
  354.     //     return $this->CustomerFavoriteProducts->removeElement($customerFavoriteProduct);
  355.     // }
  356.     // public function getCustomerFavoriteProducts(): Collection
  357.     // {
  358.     //     return $this->CustomerFavoriteProducts;
  359.     // }
  360.     /**
  361.      * Set status.
  362.      *
  363.      * @param ProductStatus|null $status
  364.      *
  365.      * @return Product
  366.      */
  367.     public function setStatus(?ProductStatus $status): self
  368.     {
  369.         $this->Status $status;
  370.         return $this;
  371.     }
  372.     /**
  373.      * Get status.
  374.      *
  375.      * @return ProductStatus|null
  376.      */
  377.     public function getStatus(): ?ProductStatus
  378.     {
  379.         return $this->Status;
  380.     }
  381.     public function __toString(): string
  382.     {
  383.         return $this->name;
  384.     }
  385.     /**
  386.      * エンティティの初回保存時に create_date と update_date を自動設定
  387.      */
  388.     #[ORM\PrePersist]
  389.     public function onPrePersist(): void
  390.     {
  391.         $this->create_date = new \DateTime();
  392.         $this->update_date = new \DateTime();
  393.     }
  394.     /**
  395.      * エンティティの更新時に update_date のみを自動設定
  396.      */
  397.     #[ORM\PreUpdate]
  398.     public function onPreUpdate(): void
  399.     {
  400.         $this->update_date = new \DateTime();
  401.     }
  402. // ★
  403.     public function getPrice02(): ?array
  404.     {
  405.         $price02Values = [];
  406.     
  407.         foreach ($this->getProductClasses() as $ProductClass) {
  408.             $price02Values[] = $ProductClass->getPrice02();
  409.         }
  410.     
  411.         return $price02Values;
  412.     }    
  413. }