<?php
namespace App\Entity\Product;
use App\Validator\Constraints as AppAssert;
use App\Entity\Category;
use App\Entity\CustomerGroup;
use App\Entity\Label;
use App\Entity\PriceHistory;
use App\Entity\PriceSpecialOffer;
use App\Entity\ProductSalesUnit;
use App\Entity\ProductService;
use App\Entity\ProductVariation;
use App\Entity\Tag;
use App\Entity\Unit;
use Beelab\TagBundle\Tag\TaggableInterface;
use Beelab\TagBundle\Tag\TagInterface;
use DateTime;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\PreSerialize;
use JMS\Serializer\Annotation\Type;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* Class ConfirmedProduct
*
* @UniqueEntity(fields={"code", "supplier"})
* @ORM\Table(name="malys_confirmed_product")
* @ORM\Entity(repositoryClass="App\Repository\ConfirmedProductRepository")
* @AppAssert\ProductPriceEmpty
* @AppAssert\ProductPricesCoherence
* @package App\Entity
* @Vich\Uploadable
*/
class ConfirmedProduct extends Product implements TaggableInterface {
const PROMOTION_TYPE_TO = "PROMOTION_TYPE_TO"; // Tarif Optimisé
const PROMOTION_TYPE_TM = "PROMOTION_TYPE_TM"; // Tarif Malys
const PROMOTION_TYPE_TP = "PROMOTION_TYPE_TP"; // Tarif Perso
/**
* @var string
* @Assert\NotBlank()
* @Groups({"api"})
*/
protected $code;
/**
* @var Category
*
* @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="products")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=true)
* @Groups({"api"})
*/
protected $category;
/**
* @var string
*
* @ORM\Column(name="sales_unit_value", type="string", length=255, nullable=true)
*/
protected $salesUnitValue;
/**
*
* @var ProductSalesUnit
*
* @ORM\ManyToOne(targetEntity="App\Entity\Unit")
* @ORM\JoinColumn(name="sales_unit_id", referencedColumnName="id", nullable=true)
* @Groups({"api"})
*/
protected $salesUnit;
/**
* @var string
*
* @ORM\Column(name="weight", type="string", nullable=true)
*/
protected $weight;
/**
* @var string
*
* @ORM\Column(name="packaging", type="string", nullable=true)
*/
protected $packaging;
/**
* @var string
*
* @ORM\Column(name="size", type="string", nullable=true)
*/
protected $size;
/**
* @var float
*
* @ORM\Column(name="price_tg", type="float", nullable=true)
* @Groups({"api"})
*/
protected $priceTG;
/**
* @var float
*
* @ORM\Column(name="price_tgr", type="float", nullable=true)
* @Groups({"api"})
*/
protected $priceTGR;
/**
* @var float
*
* @ORM\Column(name="price_t1", type="float", nullable=true)
* @Groups({"api"})
*/
protected $priceT1;
/**
* @var float
*
* @ORM\Column(name="price_t2", type="float", nullable=true)
* @Groups({"api"})
*/
protected $priceT2;
/**
* @var float
*
* @ORM\Column(name="price_t3", type="float", nullable=true)
* @Groups({"api"})
*/
protected $priceT3;
/**
* @var float
*
* @ORM\Column(name="price_t4", type="float", nullable=true)
* @Groups({"api"})
*/
protected $priceT4;
/**
* @var float
*
* @ORM\Column(name="price_tm", type="float", nullable=true)
* @Groups({"api"})
*/
protected $priceTM;
/**
* @var string
*
* @ORM\Column(name="picture", type="string", nullable=true)
*/
protected $picture;
/**
* Not persisted
* @Vich\UploadableField(mapping="product_picture", fileNameProperty="picture")
* @Assert\Image(detectCorrupted=true, groups={"imageOnly", "Default"})
*/
private $pictureFile;
/**
* @var string|null
* @Type("string")
* @Groups({"api"})
*/
private $pictureUrl;
/**
* @var string
*
* @ORM\Column(name="fsa", type="string", length=255, nullable=true)
* @Groups({"api"})
*/
protected $fsa;
/**
* @var boolean
*
* @ORM\Column(name="bio", type="boolean", options={"default" : false})
* @Groups({"api"})
*/
protected $bio = false;
/**
* @var boolean
*
* @ORM\Column(name="locavore", type="boolean", options={"default" : false})
*/
protected $locavore = false;
/**
* @var DateTime
*
* @ORM\Column(name="dluo", type="integer", nullable=true)
* @Groups({"api"})
*/
protected $dluo;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
* @Groups({"api"})
*/
protected $description;
/**
* @var string
*
* @ORM\Column(name="preparation", type="text", nullable=true)
* @Groups({"api"})
*/
protected $preparation;
/**
* @var string
*
* @ORM\Column(name="label", type="string", nullable=true)
*/
protected $label;
/**
* @var string
*
* @ORM\Column(name="grower", type="string", nullable=true)
* @Groups({"api"})
*/
protected $grower;
/**
* @var string
*
* @ORM\Column(name="origin", type="string", nullable=true)
*/
protected $origin;
/**
* @var string
*
* @ORM\Column(name="more_products", type="string", nullable=true)
*/
protected $moreProducts;
/**
* @var string
*
* @ORM\Column(name="brand", type="string", nullable=true)
* @Groups({"api"})
*/
protected $brand;
/**
* One Product has Many Price history.
* @ORM\OneToMany(targetEntity="App\Entity\PriceHistory", mappedBy="product", cascade={"remove"})
*/
protected $priceHistories;
/**
* @var DateTime
*
* @ORM\Column(name="verifiedAt", type="datetime", nullable=true)
*/
protected $verifiedAt;
/**
* One Product has Many PriceOptimized
* @ORM\OneToMany(targetEntity="App\Entity\PriceOptimized", mappedBy="product", cascade={"remove"})
*/
protected $optimizedPrices;
/**
* One Product has Many PriceSpecialOffer
* @ORM\OneToMany(targetEntity="App\Entity\PriceSpecialOffer", mappedBy="product", cascade={"remove"})
*/
protected $specialOffers;
/**
* @var boolean
*
* * @ORM\Column(name="flash", type="boolean", options={"default" : false})
*/
protected $flash = false;
/**
* @var float
*
* @ORM\Column(name="price_promo", type="float", nullable=true)
*/
protected $pricePromo;
/**
* @var DateTime
*
* @ORM\Column(name="date_start_validity", type="datetime", nullable=true)
*/
protected $dateStartValidity;
/**
* @var DateTime
*
* @ORM\Column(name="date_end_validity", type="datetime", nullable=true)
*/
protected $dateEndValidity;
/**
* @var float $bundling
* @ORM\Column(name="bundling", type="float", nullable=true, options={"default" : 1})
*/
protected $bundling = 1;
/**
*
* @var Unit
*
* @ORM\ManyToOne(targetEntity="App\Entity\Unit")
* @ORM\JoinColumn(name="order_unit_id", referencedColumnName="id", nullable=true)
*/
protected $orderUnit;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Tag")
* @ORM\JoinTable(name="product_tag",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="cascade")}
* )
*/
private $tags;
private $tagsText;
/******************************* FIELDS FOR VIEW ******************************/
/**
* @var boolean
*/
protected $calculated;
/**
* @var float
*/
protected $priceProduct;
/**
* @var float
*/
protected $percentagePromotion;
/**
* @var PriceSpecialOffer
*/
protected $priceSpecialOffer;
/**
* @var boolean
*/
protected $priceOptimized = false;
/**
* @var float
*/
protected $oldPrice;
/**
* One Product has Many OldPrice
* @ORM\OneToMany(targetEntity="App\Entity\OldPrice", mappedBy="product", cascade={"remove"}, orphanRemoval=true)
*/
protected $oldPrices;
protected $file;
protected $promotionType = null;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\ProductService")
* @ORM\JoinTable(name="malys_products_services",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="cascade")}
* )
*/
protected $services;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductVariation", mappedBy="product", cascade={"all"}, orphanRemoval=true)
* @ORM\OrderBy({"priority" = "ASC"})
* @AppAssert\ProductVariation
* @Assert\Valid
* @Groups({"api"})
*/
protected $variations;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Label")
* @ORM\JoinTable(name="malys_product_label",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="cascade")}
* )
* @Groups({"api"})
*/
protected $labels;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\CustomerGroup", mappedBy="mercuProducts")
* @ORM\JoinTable(name="malys_customer_groups_products")
*/
protected $mercuCustomerGroups;
/**
* @var DateTime|null
* @ORM\Column(name="noveltyUntil", type="date", nullable=true)
*/
protected $noveltyUntil;
// Calculated fields for ES
protected $customerRecentCount;
protected $autoUpdateDate;
/**
* Product constructor.
*/
public function __construct() {
$this->priceHistories = new ArrayCollection();
$this->optimizedPrices = new ArrayCollection();
$this->specialOffers = new ArrayCollection();
$this->variations = new ArrayCollection();
$this->services = new ArrayCollection();
$this->labels = new ArrayCollection();
$this->mercuCustomerGroups = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->autoUpdateDate = true;
}
/**
* @PreSerialize
*/
public function preSerialize() {
$this->priceTG = number_format($this->priceTG, 3, '.', '');
$this->priceTGR = number_format($this->priceTGR, 3, '.', '');
$this->priceTM = number_format($this->priceTM, 3, '.', '');
$this->priceT1 = number_format($this->priceT1, 3, '.', '');
$this->priceT2 = number_format($this->priceT2, 3, '.', '');
$this->priceT3 = number_format($this->priceT3, 3, '.', '');
$this->priceT4 = number_format($this->priceT4, 3, '.', '');
}
/**
* @return string
*/
public function getCode() {
return $this->code;
}
/**
* @param string $code
*/
public function setCode( $code ) {
$this->code = $code;
}
/**
* @return Category
*/
public function getCategory() {
return $this->category;
}
/**
* @param Category $category
*/
public function setCategory( $category ) {
$this->category = $category;
}
/**
* @return string
*/
public function getSalesUnitValue() {
return $this->salesUnitValue;
}
/**
* @param string $salesUnitValue
*/
public function setSalesUnitValue( $salesUnitValue ) {
$this->salesUnitValue = $salesUnitValue;
}
/**
* @return ProductSalesUnit
*/
public function getSalesUnit() {
return $this->salesUnit;
}
/**
* @param ProductSalesUnit $salesUnit
*/
public function setSalesUnit( $salesUnit ) {
$this->salesUnit = $salesUnit;
}
public function getSalesUnitToString() {
$toString = $this->getSalesUnitValue();
if ( $this->getSalesUnit() instanceof Unit ) {
$toString .= ' ' . $this->getSalesUnit()->getLabel();
}
return $toString;
}
/**
* @return string
*/
public function getWeight() {
return $this->weight;
}
/**
* @param string $weight
*/
public function setWeight( $weight ) {
$this->weight = $weight;
}
/**
* @return string
*/
public function getPackaging() {
return $this->packaging;
}
/**
* @param string $packaging
*/
public function setPackaging( $packaging ) {
$this->packaging = $packaging;
}
/**
* @return string
*/
public function getFsa() {
return $this->fsa;
}
/**
* @param string $fsa
*/
public function setFsa( $fsa ) {
$this->fsa = $fsa;
}
/**
* @return float
*/
public function getPriceTG() {
return $this->priceTG;
}
/**
* @param float $priceTG
*/
public function setPriceTG( $priceTG ) {
$this->priceTG = $priceTG;
}
/**
* @return float
*/
public function getPriceTGR() {
return $this->priceTGR;
}
/**
* @param float $priceTGR
*/
public function setPriceTGR( $priceTGR ) {
$this->priceTGR = $priceTGR;
}
/**
* @return float
*/
public function getPriceT1() {
return $this->priceT1;
}
/**
* @param float $priceT1
*/
public function setPriceT1( $priceT1 ) {
$this->priceT1 = $priceT1;
}
/**
* @return float
*/
public function getPriceT2() {
return $this->priceT2;
}
/**
* @param float $priceT2
*/
public function setPriceT2( $priceT2 ) {
$this->priceT2 = $priceT2;
}
/**
* @return float
*/
public function getPriceT3() {
return $this->priceT3;
}
/**
* @param float $priceT3
*/
public function setPriceT3( $priceT3 ) {
$this->priceT3 = $priceT3;
}
/**
* @return float
*/
public function getPriceT4() {
return $this->priceT4;
}
/**
* @param float $priceT4
*/
public function setPriceT4( $priceT4 ) {
$this->priceT4 = $priceT4;
}
/**
* @return float
*/
public function getPriceTM() {
return $this->priceTM;
}
/**
* @param float $priceTM
*/
public function setPriceTM( $priceTM ) {
$this->priceTM = $priceTM;
}
/**
* @return string
*/
public function getPicture() {
return $this->picture;
}
/**
* @param string $picture
*/
public function setPicture( $pictureName ) {
$this->picture = $pictureName;
}
public function setPictureFile( $pictureFile = null ) {
$this->pictureFile = $pictureFile;
if ( null !== $pictureFile ) {
$this->updatedAt = new DateTimeImmutable();
}
}
public function getPictureFile() {
return $this->pictureFile;
}
/**
* @return bool
*/
public function isBio() {
return $this->bio;
}
/**
* @param bool $bio
*/
public function setBio( $bio ) {
$this->bio = $bio;
}
/**
* @return bool
*/
public function isLocavore() {
return $this->locavore;
}
/**
* @param bool $locavore
*/
public function setLocavore( $locavore ) {
$this->locavore = $locavore;
}
/**
* @return DateTime
*/
public function getDluo() {
return $this->dluo;
}
/**
* @param DateTime $dluo
*/
public function setDluo( $dluo ) {
$this->dluo = $dluo;
}
/**
* @return string
*/
public function getDescription() {
return $this->description;
}
/**
* @param string $description
*/
public function setDescription( $description ) {
$this->description = $description;
}
/**
* @return string
*/
public function getLabel() {
return $this->label;
}
/**
* @param string $label
*/
public function setLabel( $label ) {
$this->label = $label;
}
/**
* @return float
*/
public function getSize() {
return $this->size;
}
/**
* @param float $size
*/
public function setSize( $size ) {
$this->size = $size;
}
/**
* @return string
*/
public function getOrigin() {
return $this->origin;
}
/**
* @param string $origin
*/
public function setOrigin( $origin ) {
$this->origin = $origin;
}
/**
* @return string
*/
public function getMoreProducts() {
return $this->moreProducts;
}
/**
* @param string $moreProducts
*/
public function setMoreProducts( $moreProducts ) {
$this->moreProducts = $moreProducts;
}
/**
* @return string
*/
public function getBrand() {
return $this->brand;
}
/**
* @param string $brand
*/
public function setBrand( $brand ) {
$this->brand = $brand;
}
/**
* @return string
*/
public function getGrower() {
return $this->grower;
}
/**
* @param string $grower
*/
public function setGrower( $grower ) {
$this->grower = $grower;
}
/**
* @return ArrayCollection
*/
public function getPriceHistories() {
return $this->priceHistories;
}
/**
* @param ArrayCollection $priceHistories
*/
public function setPriceHistories( $priceHistories ) {
$this->priceHistories = $priceHistories;
}
/**
* @param PriceHistory $priceHistory
*/
public function addPriceHistory( $priceHistory ) {
$this->priceHistories->add( $priceHistory );
}
/**
* @param PriceHistory $priceHistory
*/
public function removePriceHistory( $priceHistory ) {
if ( ! $this->priceHistories->contains( $priceHistory ) ) {
$this->priceHistories->removeElement( $priceHistory );
}
}
/**
* @return mixed
*/
public function getOptimizedPrices() {
return $this->optimizedPrices;
}
/**
* @param mixed $optimizedPrices
*/
public function setOptimizedPrices( $optimizedPrices ) {
$this->optimizedPrices = $optimizedPrices;
}
/**
* @return mixed
*/
public function getSpecialOffers() {
return $this->specialOffers;
}
/**
* @param mixed $specialOffers
*/
public function setSpecialOffers( $specialOffers ) {
$this->specialOffers = $specialOffers;
}
/**
* @return bool
*/
public function isCalculated() {
return $this->calculated;
}
/**
* @param bool $calculated
*/
public function setCalculated( $calculated ) {
$this->calculated = $calculated;
}
/**
* @return float
* @throws Exception
*/
public function getPriceProduct() {
if ( $this->isCalculated() ) {
return $this->priceProduct;
} else {
throw new Exception( 'Le montant n\'a pas été calculé BB' );
}
}
/**
* @param float $priceProduct
*/
public function setPriceProduct( $priceProduct ) {
$this->priceProduct = $priceProduct;
}
/**
* @return float
* @throws Exception
*/
public function getPercentagePromotion() {
if ( $this->isCalculated() ) {
return $this->percentagePromotion;
} else {
throw new Exception( 'PP Le montant n\'a pas été calculé CC' );
}
}
/**
* @param float $percentagePromotion
*/
public function setPercentagePromotion( $percentagePromotion ) {
$this->percentagePromotion = $percentagePromotion;
}
/**
* @return bool
*/
public function isPriceOptimized() {
return $this->priceOptimized;
}
/**
* @param bool $priceOptimized
*/
public function setPriceOptimized( $priceOptimized ) {
$this->priceOptimized = $priceOptimized;
}
/**
* @return PriceSpecialOffer
* @throws Exception
*/
public function getPriceSpecialOffer() {
if ( $this->isCalculated() ) {
return $this->priceSpecialOffer;
} else {
throw new Exception( 'Le montant n\'a pas été calculé DD' );
}
}
/**
* @param PriceSpecialOffer $priceSpecialOffer
*/
public function setPriceSpecialOffer( $priceSpecialOffer ) {
$this->priceSpecialOffer = $priceSpecialOffer;
}
/**
* @return float
* @throws Exception
*/
public function getOldPrice() {
if ( $this->isCalculated() ) {
return $this->oldPrice;
} else {
throw new Exception( 'Le montant n\'a pas été calculé EE' );
}
}
/**
* @param float $oldPrice
*/
public function setOldPrice( $oldPrice ) {
$this->oldPrice = $oldPrice;
}
public function getFile() {
return $this->file;
}
public function setFile( $file ) {
$this->file = $file;
}
/**
* @return bool
*/
public function isFlash() {
return $this->flash;
}
/**
* @param bool $flash
*/
public function setFlash( $flash ) {
$this->flash = $flash;
}
/**
* @return float
*/
public function getPricePromo() {
return $this->pricePromo;
}
/**
* @param float $pricePromo
*/
public function setPricePromo( $pricePromo ) {
$this->pricePromo = $pricePromo;
}
/**
* @return DateTime
*/
public function getDateStartValidity() {
return $this->dateStartValidity;
}
/**
* @param DateTime $dateStartValidity
*/
public function setDateStartValidity( $dateStartValidity ) {
$this->dateStartValidity = $dateStartValidity;
}
/**
* @return DateTime
*/
public function getDateEndValidity() {
return $this->dateEndValidity;
}
/**
* @param DateTime $dateEndValidity
*/
public function setDateEndValidity( $dateEndValidity ) {
$this->dateEndValidity = $dateEndValidity;
}
/**
* @return float
*/
public function getBundling() {
return $this->bundling;
}
/**
* @param float $bundling
*/
public function setBundling( $bundling ) {
$this->bundling = $bundling;
}
// public function getPositiveBundling() {
// if ( ! empty( $this->bundling ) && $this->bundling > 0 ) {
// $bundling = $this->bundling;
// } else {
// $bundling = 1;
// }
//
// return $bundling;
// }
/**
* @return mixed
*/
public function getOldPrices() {
return $this->oldPrices;
}
/**
* @param mixed $oldPrices
*/
public function setOldPrices( $oldPrices ) {
$this->oldPrices = $oldPrices;
}
/**
* @return null
* @throws Exception
*/
public function getPromotionType() {
if ( $this->isCalculated() ) {
return $this->promotionType;
} else {
//throw new \Exception( 'Le montant n\'a pas été calculé FF' );
}
}
/**
* @param mixed $promotionType
*/
public function setPromotionType( $promotionType ) {
$this->promotionType = $promotionType;
}
/**
* @return Unit
*/
public function getOrderUnit() {
return $this->orderUnit;
}
/**
* @param Unit $orderUnit
*/
public function setOrderUnit( $orderUnit ) {
$this->orderUnit = $orderUnit;
}
/**
* @return mixed
*/
public function getVariations() {
return $this->variations;
}
/**
* @param mixed $variations
*/
public function setVariations( $variations ) {
$this->variations = $variations;
}
public function addVariation( ProductVariation $productVariation ) {
$this->variations->add( $productVariation );
$productVariation->setProduct( $this );
return $this;
}
public function removeVariation( ProductVariation $productVariation ) {
$this->variations->removeElement( $productVariation );
$productVariation->setProduct( null );
return $this;
}
/**
* @return mixed
*/
public function getServices() {
return $this->services;
}
/**
* @param mixed $services
*/
public function setServices( $services ) {
$this->services = $services;
}
public function addService( ProductService $productService ) {
if ( ! $this->services->contains( $productService ) ) {
$this->services->add( $productService );
}
return $this;
}
public function removeService( ProductService $productService ) {
$this->services->removeElement( $productService );
return $this;
}
/**
* @return mixed
*/
public function getCustomerRecentCount() {
return $this->customerRecentCount;
}
/**
* @param mixed $customerRecentCount
*/
public function setCustomerRecentCount( $customerRecentCount ) {
$this->customerRecentCount = $customerRecentCount;
}
/**
* @return string
*/
public function getPreparation() {
return $this->preparation;
}
/**
* @param string $preparation
*/
public function setPreparation( $preparation ) {
$this->preparation = $preparation;
}
/**
* @return mixed
*/
public function getLabels() {
return $this->labels;
}
/**
* @param mixed $labels
*/
public function setLabels( $labels ) {
$this->labels = $labels;
}
public function addLabel( Label $label ) {
if ( ! $this->labels->contains( $label ) ) {
$this->labels->add( $label );
}
return $this;
}
/**
* @return DateTime
*/
public function getVerifiedAt() {
return $this->verifiedAt;
}
/**
* @param DateTime $verifiedAt
*/
public function setVerifiedAt( DateTime $verifiedAt ) {
$this->verifiedAt = $verifiedAt;
}
/**
* @return bool
*/
public function isAutoUpdateDate(): bool {
return $this->autoUpdateDate;
}
/**
* @param bool $autoUpdateDate
*/
public function setAutoUpdateDate( bool $autoUpdateDate ) {
$this->autoUpdateDate = $autoUpdateDate;
}
public function addTag( TagInterface $tag ): void {
if ( ! $this->tags->contains( $tag ) ) {
$this->tags->add( $tag );
}
}
public function addTagNames( array $tagNamesToAdd ): void {
$currentTagNames = [];
$currentTags = $this->getTags();
foreach ( $currentTags as $currentTag ) {
$currentTagNames[] = $currentTag->getName();
}
foreach ( $tagNamesToAdd as $tagNameToAdd ) {
if ( ! in_array( $tagNameToAdd, $currentTagNames ) ) {
$currentTagNames[] = trim( $tagNameToAdd );
}
}
$this->setTagsText( implode( Tag::DELIMITER, $currentTagNames ) );
}
public function removeTagNames( array $tagNamesToRemove ): void {
$currentTagNames = [];
$currentTags = $this->getTags();
foreach ( $currentTags as $currentTag ) {
$currentTagNames[] = $currentTag->getName();
}
foreach ( $tagNamesToRemove as $tagNameToRemove ) {
if ( ( $key = array_search( $tagNameToRemove, $currentTagNames ) ) !== false ) {
unset( $currentTagNames[ $key ] );
}
}
$this->setTagsText( implode( Tag::DELIMITER, $currentTagNames ) );
}
public function removeTag( TagInterface $tag ): void {
$this->tags->removeElement( $tag );
}
public function hasTag( TagInterface $tag ): bool {
return $this->tags->contains( $tag );
}
public function getTags(): iterable {
return $this->tags;
}
public function getTagNames(): array {
return empty( $this->tagsText ) ? [] : \array_map( 'trim', explode( Tag::DELIMITER, $this->tagsText ) );
}
public function setTagsText( ?string $tagsText ): void {
$this->tagsText = $tagsText;
$this->updatedAt = new DateTime();
}
public function getTagsText(): ?string {
$this->tagsText = \implode( Tag::DELIMITER, $this->tags->toArray() );
return $this->tagsText;
}
public function getType() {
return parent::TYPE_CONFIRMED;
}
/**
* @return mixed
*/
public function getMercuCustomerGroups() {
return $this->mercuCustomerGroups;
}
/**
* @param $mercuCustomerGroups
*/
public function setMercuCustomerGroups( $mercuCustomerGroups ) {
$this->mercuCustomerGroups = $mercuCustomerGroups;
$this->forceUpdateAt();
}
public function addMercuCustomerGroup( CustomerGroup $group ) {
if ( ! $this->mercuCustomerGroups->contains( $group ) ) {
$this->mercuCustomerGroups->add( $group );
$group->addMercuProduct( $this );
$this->forceUpdateAt();
}
return $this;
}
public function removeMercuCustomerGroup( CustomerGroup $group ) {
if ( $this->mercuCustomerGroups->contains( $group ) ) {
$this->mercuCustomerGroups->removeElement( $group );
$this->forceUpdateAt();
$group->removeMercuProduct( $this );
}
return $this;
}
public function forceUpdateAt() {
$this->setUpdatedAt( new DateTime() );
}
/**
* @return null|DateTime
*/
public function getNoveltyUntil(): ?DateTime {
return $this->noveltyUntil;
}
/**
* @param DateTime $noveltyUntil
*/
public function setNoveltyUntil( ?DateTime $noveltyUntil ): void {
if ( $noveltyUntil instanceof DateTime ) {
$noveltyUntil->setTime( 23, 59, 59 );
}
$this->noveltyUntil = $noveltyUntil;
}
/**
* @return string|null
*/
public function getPictureUrl(): ?string
{
return $this->pictureUrl;
}
/**
* @param string|null $pictureUrl
*/
public function setPictureUrl(?string $pictureUrl): void
{
$this->pictureUrl = $pictureUrl;
}
}