<?php
namespace App\Entity;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use App\Model\LangParamInterface;
use App\Model\LangParamRelationInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Query\Parameter;
use phpDocumentor\Reflection\Types\Self_;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\Table(name="product")
*/
class Product implements TranslatableInterface, LangParamInterface, BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use TranslatableTrait;
use SoftDeletableTrait;
const SMALL_PRODUCT_PHOTO = 'smallProductPhoto';
const SMALL_PRODUCT_TEXTILE = 'smallProductTextile';
const SHIPPING_CATEGORY_A = 'shipping_category_a';
const SHIPPING_CATEGORY_B = 'shipping_category_b';
/**
*
* Small product -> to show textiles or standard gallery product?
*
* @param $translator
* @return array
*/
static public function getSmallProductOptions($translator, $locale) {
return [
$translator->trans(self::SMALL_PRODUCT_PHOTO, [], 'admin', $locale) => self::SMALL_PRODUCT_PHOTO,
$translator->trans(self::SMALL_PRODUCT_TEXTILE, [], 'admin', $locale) => self::SMALL_PRODUCT_TEXTILE,
];
}
static public function getShippingCategories($translator, $locale) {
return [
$translator->trans(self::SHIPPING_CATEGORY_A, [], 'admin', $locale) => self::SHIPPING_CATEGORY_A,
$translator->trans(self::SHIPPING_CATEGORY_B, [], 'admin', $locale) => self::SHIPPING_CATEGORY_B,
];
}
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Obsługa tłumaczeń
* @param $method
* @param $arguments
* @return mixed
*/
public function __call($method, $arguments)
{
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
public function getName()
{
return $this->translate()->getName();
}
public function getDescription()
{
return $this->translate()->getDescription();
}
public function getPhoto3dGalleryUrl()
{
return $this->translate()->getPhoto3dGalleryUrl();
}
public function getYoutubeGalleryUrl()
{
return $this->translate()->getYoutubeGalleryUrl();
}
public function getMetaDescription()
{
return $this->translate()->getMetaDescription();
}
public function getMetaTitle()
{
return $this->translate()->getMetaTitle();
}
public function getMetaKeywords()
{
return $this->translate()->getMetaKeywords();
}
public function getSlug()
{
if ($this->translate()->getSlug()) {
return $this->translate()->getSlug();
} else {
return 'product';
}
}
public function getShortDescription()
{
return $this->translate()->getShortDescription();
}
public function getPhoto3dAdditional()
{
return $this->translate()->getPhoto3dAdditional();
}
public function getDetails()
{
return $this->translate()->getDetails();
}
public function getTransFilm()
{
return $this->translate()->getTransFilm();
}
public function getDescriptionFb() {
$description_facebook = $this->getDescription();
$description_facebook = strip_tags($description_facebook);
$description_facebook = preg_replace( '/\s+/', ' ', $description_facebook);
$description_facebook = str_replace("&oacute;", "ó", $description_facebook);
$description_facebook = str_replace(" ", " ", $description_facebook);
$description_facebook = str_replace("&oacute;", "ó", $description_facebook);
return $description_facebook;
}
/**
* @var string
*
* @ORM\Column(name="symbol", type="string", length=255, nullable=true)
*/
private $symbol;
/**
* @var string
*
* @ORM\Column(name="photo3d", type="text", nullable=true)
*/
private $photo3d;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ProductFamily", cascade={"all"})
* @ORM\JoinColumn(name="product_family_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $productFamily;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ProductProducer", cascade={"all"})
* @ORM\JoinColumn(name="product_producer_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $productProducer;
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Marker", inversedBy="products")
* @Doctrine\ORM\Mapping\JoinTable(name="product_markers")
*/
private $markers;
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\ProductColor", inversedBy="products")
* @Doctrine\ORM\Mapping\JoinTable(name="product_product_color")
*/
private $colors;
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\ListingMarker", inversedBy="products")
* @Doctrine\ORM\Mapping\JoinTable(name="listing_markers")
*/
private $listingMarkers;
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\ProductEquipment")
* @Doctrine\ORM\Mapping\JoinTable(name="product_equipment_relation")
*/
private $equipments;
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\DeliveryMethod")
* @Doctrine\ORM\Mapping\JoinTable(name="product_special_delivery_methods")
*/
private $specialDeliveryMethods;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Availability", cascade={"all"}, inversedBy="products")
* @ORM\JoinColumn(name="availability_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $availability;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Category", cascade={"all"})
* @ORM\JoinColumn(name="main_category_id", referencedColumnName="id")
*/
protected $mainCategory;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductComment", mappedBy="products", cascade={"persist"})
*/
protected $comments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\SubProduct", mappedBy="product", cascade={"persist"})
*/
protected $subProducts;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductFilter", mappedBy="product", cascade={"persist"})
*/
protected $filters;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductPrice", mappedBy="product", cascade={"persist"})
*/
protected $productPrices;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductPriceChangeLog", mappedBy="product", cascade={"persist"})
*/
protected $productPriceChangeLog;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductPriceDraft", mappedBy="product", cascade={"persist"})
*/
protected $productPriceDrafts;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductXml", mappedBy="product", cascade={"persist"})
*/
protected $productXml;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\CompareParameterValue", mappedBy="product", cascade={"persist"})
* @ORM\OrderBy({"parameter" = "ASC"})
*/
protected $compareValues;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductFurnitureType", mappedBy="product", cascade={"persist"})
*/
protected $furnitureTypes;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductPhoto", mappedBy="product", cascade={"persist"})
* @ORM\OrderBy({"position" = "ASC"})
*/
protected $photos;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductCategory", mappedBy="product", cascade={"persist"})
*/
protected $categories;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductRecommendation", mappedBy="product", cascade={"persist"})
*/
protected $recommendations;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductSimilarColors", mappedBy="product", cascade={"persist"})
*/
protected $similarColors;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductCrossSelling", mappedBy="product", cascade={"persist"})
*/
protected $crossSelling;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductLangParam", mappedBy="product", cascade={"all"})
*/
protected $langParams;
/**
* @Doctrine\ORM\Mapping\Column(name="is_variants", type="boolean", options={"default"=0}, nullable=true)
*/
protected $isVariants;
/**
* @Doctrine\ORM\Mapping\Column(name="is_palette_delivery", type="boolean", options={"default"=0}, nullable=true)
*/
protected $isPaletteDelivery;
/**
* @Doctrine\ORM\Mapping\Column(name="payu", type="boolean", options={"default"=0}, nullable=true)
*/
protected $payu;
/**
* @Doctrine\ORM\Mapping\Column(name="automatic_price", type="boolean", options={"default"=1}, nullable=true)
*/
protected $automaticPrice = true;
/**
* @Doctrine\ORM\Mapping\Column(name="halmar_stock_exchange", type="boolean", options={"default"=0}, nullable=true)
*/
protected $halmarStockExchange;
/**
* @Doctrine\ORM\Mapping\Column(name="diablo_stock_exchange", type="boolean", options={"default"=1}, nullable=true)
*/
protected $diabloStockExchange = true;
/**
* @Doctrine\ORM\Mapping\Column(name="jan_nowak_stock_exchange", type="boolean", options={"default"=1}, nullable=true)
*/
protected $janNowakStockExchange = true;
/**
* @Doctrine\ORM\Mapping\Column(name="actona_stock_exchange", type="boolean", options={"default"=1}, nullable=true)
*/
protected $actonaStockExchange = true;
/**
* @Doctrine\ORM\Mapping\Column(name="unique_stock_exchange", type="boolean", options={"default"=1}, nullable=true)
*/
protected $uniqueStockExchange = true;
/**
* @Doctrine\ORM\Mapping\Column(name="is_compare", type="boolean", options={"default"=0}, nullable=true)
*/
protected $isCompare;
/**
* @var string
*
* @ORM\Column(name="priority_search_engine", type="integer", length=255, nullable=true)
*/
private $prioritySearchEngine;
/**
* @Doctrine\ORM\Mapping\Column(name="is_negotiate", type="boolean", options={"default"=0}, nullable=true)
*/
protected $isNegotiate;
/**
* @Doctrine\ORM\Mapping\Column(name="is_rebate_code", type="boolean", options={"default"=0}, nullable=true)
*/
protected $isRebateCode;
/**
* @Doctrine\ORM\Mapping\Column(name="old_price", type="decimal", precision=10, scale=2, nullable=true)
*/
protected $oldPrice;
/**
* DEPRECIATED - Wyłączone pole, nie używane po zmianach (film jako translatable)
* @Doctrine\ORM\Mapping\Column(name="film", type="text", nullable=true)
*/
protected $film;
/**
* @Doctrine\ORM\Mapping\Column(name="small_product_photo", type="string", nullable=true)
*/
protected $smallProductPhoto;
/**
* @var string
*
* @ORM\Column(name="max_quantity", type="integer", length=255, nullable=true)
*/
private $maxQuantity;
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\LandingPage", mappedBy="products")
*/
private $landingPages;
/**
* @var string
*
* @ORM\Column(name="listingMarkersIds", type="text", length=255, nullable=true)
*/
private $listingMarkersIds;
/**
* @Doctrine\ORM\Mapping\Column(name="temporary_unavailable", type="boolean", options={"default"=0}, nullable=true)
*/
protected $temporaryUnavailable;
/**
* Cross selling - skrypt liczący ranking do wyświetlania produktów "inni kupili również"
* @var \DateTime
*
* @ORM\Column(name="last_ranking_update", type="datetime", nullable=true)
*/
private $lastRankingUpdate;
/**
* @var int
*
* @ORM\Column(name="height", type="integer", length=10, nullable=true)
*/
private $height;
/**
* @var int
*
* @ORM\Column(name="width", type="integer", length=10, nullable=true)
*/
private $width;
/**
* @var int
*
* @ORM\Column(name="depth", type="integer", length=10, nullable=true)
*/
private $depth;
/**
* @Doctrine\ORM\Mapping\Column(name="shipping_category", type="string", nullable=true, options={"default"="shipping_category_a"})
*/
protected $shippingCategory = self::SHIPPING_CATEGORY_A;
public $promoPrices;
public function getProductPhotos(SubProduct $subProduct = null) {
$col = new ArrayCollection();
if ($subProduct and $subProduct->getImageName()) {
$sub = new ProductPhoto();
$sub->setProduct($subProduct->getProduct());
$sub->setPosition(1);
$sub->setMain(1);
$sub->setImageName($subProduct->getImageName());
$col->add($sub);
}
foreach ($this->getPhotos() as $photo) {
$photo->setMain(0);
$col->add($photo);
}
return $col;
}
/**
* Constructor
*/
public function __construct()
{
$this->shippingCategory = self::SHIPPING_CATEGORY_A;
$this->colors = new \Doctrine\Common\Collections\ArrayCollection();
$this->comments = new \Doctrine\Common\Collections\ArrayCollection();
$this->productPrices = new \Doctrine\Common\Collections\ArrayCollection();
$this->photos = new \Doctrine\Common\Collections\ArrayCollection();
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
$this->recommendations = new ArrayCollection();
$this->furnitureTypes = new ArrayCollection();
$this->langParams = new ArrayCollection();
$this->compareValues = new ArrayCollection();
$this->filters = new ArrayCollection();
$this->smallProductPhoto = self::SMALL_PRODUCT_PHOTO;
$this->markers = new ArrayCollection();
$this->equipments = new ArrayCollection();
$this->specialDeliveryMethods = new ArrayCollection();
$this->productXml = new ArrayCollection();
$this->landingPages = new ArrayCollection();
$this->listingMarkers = new ArrayCollection();
$this->subProducts = new ArrayCollection();
$this->productPriceDrafts = new ArrayCollection();
$this->productPriceChangeLog = new ArrayCollection();
$this->crossSelling = new ArrayCollection();
$this->promoPrices = [];
$this->similarColors = new ArrayCollection();
}
public function getActiveSubProducts() {
$s = new ArrayCollection();
foreach ($this->getSubProducts() as $subProduct) {
if ($subProduct->getActive()) {
$s->add($subProduct);
}
}
return $s;
}
public function getLandingPagesMarkers() {
$markers = new ArrayCollection();
foreach ($this->getLandingPages() as $landingPage) {
if ($landingPage->getDeletedBy() === null and $landingPage->getVisible()) {
/** @var $marker Marker */
foreach ($landingPage->getMarkers() as $marker) {
$markers->add($marker);
}
}
}
return $markers;
}
public function getActiveLandingPages() {
$lp = new ArrayCollection();
foreach ($this->getLandingPages() as $landingPage) {
if ($landingPage->getDeletedBy() === null and $landingPage->getVisible()) {
$lp->add($landingPage);
}
}
return $lp;
}
/**
* @return string
*/
public function getMaxQuantity()
{
return $this->maxQuantity;
}
/**
* @param string $maxQuantity
*/
public function setMaxQuantity($maxQuantity)
{
$this->maxQuantity = $maxQuantity;
}
/**
* @return mixed
*/
public function getSmallProductPhoto()
{
return $this->smallProductPhoto;
}
/**
* @param mixed $smallProductPhoto
*/
public function setSmallProductPhoto($smallProductPhoto): void
{
$this->smallProductPhoto = $smallProductPhoto;
}
public function mainPhotoExists($locale = 'pl') {
/** @var $photo ProductPhoto */
foreach ($this->getPhotos() as $photo) {
if ($photo->getMain()) {
/** @var $language Language */
foreach ($photo->getLanguages() as $language) {
if ($language->getLocaleShort() == $locale) {
return true;
}
}
}
}
return false;
}
/**
* Get main picture
* @param string $locale
* @return string
*/
public function getMainPhoto($locale = 'pl') {
/** @var $photo ProductPhoto */
foreach ($this->getPhotos() as $photo) {
if ($photo->getMain()) {
/** @var $language Language */
foreach ($photo->getLanguages() as $language) {
if ($language->getLocaleShort() == $locale) {
return $photo->getImageName();
}
}
}
}
foreach ($this->getPhotos() as $photo) {
return $photo->getImageName();
}
return 'nofoto.jpg';
}
public function getOthersProductsPath($locale = 'pl') {
$arr = [];
/** @var $photo ProductPhoto */
foreach ($this->getPhotos() as $photo) {
if (!$photo->getMain()) {
/** @var $language Language */
foreach ($photo->getLanguages() as $language) {
if ($language->getLocaleShort() == $locale) {
$arr[] = '/images/product/'.$photo->getImageName();
}
}
}
}
return $arr;
}
/**
* Gets main photo full path
* @param string $locale
* @return string
*/
public function getMainPhotoPath($locale = 'pl') {
return '/images/product/'.$this->getMainPhoto($locale);
}
/**
* Do not use in product lists - too many queries
* @param int $parameterId
* @return ArrayCollection
*/
public function getAllVariantValues($parameterId = 9) {
$values = new ArrayCollection();
/** @var $productPrice ProductPrice */
foreach ($this->getActiveProductPrices() as $productPrice) {
/** @var $variants ProductPriceVariants */
foreach ($productPrice->getVariants() as $variants) {
if ($variants->getParameterValueGroup()) {
foreach ($variants->getParameterValueGroup()->getVisibleValues() as $value) {
if ($value->getParameter()->getId() == $parameterId) {
$values->add($value);
}
}
} else {
if ($variants->getParameter()->getId() == $parameterId) {
$values->add($variants->getParameterValue());
}
}
}
}
return $values;
}
public function getProductGroups() {
$groups = new ArrayCollection();
/** @var $productPrice ProductPrice */
foreach ($this->getActiveProductPrices() as $productPrice) {
/** @var $variants ProductPriceVariants */
foreach ($productPrice->getVariants() as $variants) {
if ($variants->getParameterValueGroup() and !$groups->contains($variants->getParameterValueGroup())) {
$groups->add($variants->getParameterValueGroup());
}
}
}
return $groups;
}
public function getProductGroupsByParameter($parameterId) {
$groups = new ArrayCollection();
/** @var $productPrice ProductPrice */
foreach ($this->getActiveProductPrices() as $productPrice) {
/** @var $variants ProductPriceVariants */
foreach ($productPrice->getVariants() as $variants) {
if ($variants->getParameterValueGroup() and $variants->getParameter()->getId() == $parameterId and !$groups->contains($variants->getParameterValueGroup())) {
$groups->add($variants->getParameterValueGroup());
}
}
}
return $groups;
}
/**
* Return array - two elements: price decimal and entity of currency
*
* @param null $currency
* @param ProductVat|null $productVat
* @return array
*/
public function getPrice($currency = null, ProductVat $productVat = null) {
if (is_object($productVat)) {
$vatRate = ($productVat->getValue()+100)/100;
} else {
$vatRate = 1;
}
/** @var ProductPrice $price */
foreach ($this->getActiveProductPrices() as $price) {
if (is_object($currency) and $currency->getId() == $price->getCurrency()->getId()) {
$returnPrice = round($price->getPrice() * $vatRate,2);
return ['price'=>$returnPrice, 'currency'=>$price->getCurrency()];
}
}
/** @var ProductPrice $price */
foreach ($this->getActiveProductPrices() as $price) {
if ($price->getCurrency()->getIsDefault() and $price->getCurrency()->getIsActive()) {
$returnPrice = round($price->getPrice() * $vatRate,2);
return ['price'=>$returnPrice, 'currency'=>$price->getCurrency()];
}
}
}
/**
* Gets hover picture full path
* @param string $locale
* @return string
*/
public function getHoverPhotoPath($locale = 'pl') {
return '/images/product/'.$this->getHoverPhoto($locale);
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set symbol
*
* @param string $symbol
*
* @return Product
*/
public function setSymbol($symbol)
{
$this->symbol = $symbol;
return $this;
}
/**
* Get symbol
*
* @return string
*/
public function getSymbol()
{
return $this->symbol;
}
/**
* Add comment
*
* @param \App\Entity\ProductComment $comment
*
* @return Product
*/
public function addComment(\App\Entity\ProductComment $comment)
{
$this->comments[] = $comment;
return $this;
}
/**
* Remove comment
*
* @param \App\Entity\ProductComment $comment
*/
public function removeComment(\App\Entity\ProductComment $comment)
{
$this->comments->removeElement($comment);
}
/**
* Get comments
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getComments()
{
return $this->comments;
}
/**
* Add productPrice
*
* @param \App\Entity\ProductPrice $productPrice
*
* @return Product
*/
public function addProductPrice(LangParamRelationInterface $productPrice)
{
$productPrice->setProduct($this);
$this->productPrices[] = $productPrice;
return $this;
}
/**
* Remove productPrice
*
* @param \App\Entity\ProductPrice $productPrice
*/
public function removeProductPrice(\App\Entity\ProductPrice $productPrice)
{
$this->productPrices->removeElement($productPrice);
}
/**
* Get productPrices
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getActiveProductPrices()
{
$coll = new ArrayCollection();
foreach ($this->getProductPrices() as $productPrice) {
if ($productPrice->getDeletedBy() === null) {
$coll->add($productPrice);
}
}
return $coll;
}
/**
* Get productPrices
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProductPrices()
{
return $this->productPrices;
}
/**
* Add photo
*
* @param \App\Entity\ProductPhoto $photo
*
* @return Product
*/
public function addPhoto(\App\Entity\ProductPhoto $photo)
{
$photo->setProduct($this);
$this->photos[] = $photo;
return $this;
}
/**
* Remove photo
*
* @param \App\Entity\ProductPhoto $photo
*/
public function removePhoto(\App\Entity\ProductPhoto $photo)
{
$this->photos->removeElement($photo);
}
/**
* Get photos
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPhotos()
{
return $this->photos;
}
/**
* Add category
*
* @param \App\Entity\ProductCategory $category
*
* @return Product
*/
public function addCategory(\App\Entity\ProductCategory $category)
{
$this->categories[] = $category;
return $this;
}
/**
* Remove category
*
* @param \App\Entity\ProductCategory $category
*/
public function removeCategory(\App\Entity\ProductCategory $category)
{
$this->categories->removeElement($category);
}
/**
* Get categories
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCategories()
{
return $this->categories;
}
/**
* Add recommendation
*
* @param \App\Entity\ProductRecommendation $recommendation
*
* @return Product
*/
public function addRecommendation(\App\Entity\ProductRecommendation $recommendation)
{
$recommendation->setProduct($this);
$this->recommendations[] = $recommendation;
return $this;
}
/**
* Remove recommendation
*
* @param \App\Entity\ProductRecommendation $recommendation
*/
public function removeRecommendation(\App\Entity\ProductRecommendation $recommendation)
{
$this->recommendations->removeElement($recommendation);
}
/**
* Get recommendations
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRecommendations()
{
return $this->recommendations;
}
public function getRecommendationsIds($locale = 'pl') {
$ids = [];
/** @var $recommendation ProductRecommendation */
foreach ($this->getRecommendations() as $recommendation) {
$visible = false;
foreach ($recommendation->getLanguages() as $language) {
if ($language->getLocale() == $locale) {
$visible = true;
break;
}
}
if ($visible) {
$ids[] = $recommendation->getRecommendation()->getId();
}
}
return $ids;
}
public function getSimilarColorsIds() {
$ids = [];
/** @var $recommendation ProductSimilarColors */
foreach ($this->getSimilarColors() as $recommendation) {
$ids[] = $recommendation->getSimilar()->getId();
}
return $ids;
}
public function getProductFamily(): ?ProductFamily
{
return $this->productFamily;
}
public function setProductFamily(?ProductFamily $productFamily): self
{
$this->productFamily = $productFamily;
return $this;
}
/**
* @return Collection|ProductFurnitureType[]
*/
public function getFurnitureTypes(): Collection
{
return $this->furnitureTypes;
}
public function addFurnitureType(ProductFurnitureType $furnitureType): self
{
if (!$this->furnitureTypes->contains($furnitureType)) {
$this->furnitureTypes[] = $furnitureType;
$furnitureType->setProduct($this);
}
return $this;
}
public function removeFurnitureType(ProductFurnitureType $furnitureType): self
{
if ($this->furnitureTypes->contains($furnitureType)) {
$this->furnitureTypes->removeElement($furnitureType);
// set the owning side to null (unless already changed)
if ($furnitureType->getProduct() === $this) {
$furnitureType->setProduct(null);
}
}
return $this;
}
/**
* @param $locale
* @return ProductLangParam
*/
public function getLangParamByLocale($locale) {
foreach ($this->getLangParams() as $langParam) {
if ($langParam->getLanguage()->getLocale() == $locale) {
return $langParam;
}
}
}
/**
* @return Collection|ProductLangParam[]
*/
public function getLangParams(): Collection
{
return $this->langParams;
}
public function addLangParam(LangParamRelationInterface $langParam): self
{
if (!$this->langParams->contains($langParam)) {
$this->langParams[] = $langParam;
$langParam->setProduct($this);
}
return $this;
}
public function removeLangParam(ProductLangParam $langParam): self
{
if ($this->langParams->contains($langParam)) {
$this->langParams->removeElement($langParam);
// set the owning side to null (unless already changed)
if ($langParam->getProduct() === $this) {
$langParam->setProduct(null);
}
}
return $this;
}
public function getIsVariants(): ?bool
{
return $this->isVariants;
}
public function setIsVariants(?bool $isVariants): self
{
$this->isVariants = $isVariants;
return $this;
}
public function getIsCompare(): ?bool
{
return $this->isCompare;
}
public function setIsCompare(?bool $isCompare): self
{
$this->isCompare = $isCompare;
return $this;
}
public function getPrioritySearchEngine(): ?int
{
return $this->prioritySearchEngine;
}
public function setPrioritySearchEngine(?int $prioritySearchEngine): self
{
$this->prioritySearchEngine = $prioritySearchEngine;
return $this;
}
public function getIsNegotiate(): ?bool
{
return $this->isNegotiate;
}
public function setIsNegotiate(?bool $isNegotiate): self
{
$this->isNegotiate = $isNegotiate;
return $this;
}
public function getIsRebateCode(): ?bool
{
return $this->isRebateCode;
}
public function setIsRebateCode(?bool $isRebateCode): self
{
$this->isRebateCode = $isRebateCode;
return $this;
}
public function setMainCategory(?Category $mainCategory): self
{
$this->mainCategory = $mainCategory;
return $this;
}
public function getMainCategory(): ?Category
{
return $this->mainCategory;
}
/**
* @return Collection|CompareParameterValue[]
*/
public function getCompareValues(): Collection
{
return $this->compareValues;
}
public function addCompareValue(CompareParameterValue $compareValue): self
{
if (!$this->compareValues->contains($compareValue)) {
$this->compareValues[] = $compareValue;
$compareValue->setProduct($this);
}
return $this;
}
public function removeCompareValue(CompareParameterValue $compareValue): self
{
if ($this->compareValues->contains($compareValue)) {
$this->compareValues->removeElement($compareValue);
// set the owning side to null (unless already changed)
if ($compareValue->getProduct() === $this) {
$compareValue->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|ProductFilter[]
*/
public function getFilters(): Collection
{
return $this->filters;
}
public function addFilter(ProductFilter $filter): self
{
if (!$this->filters->contains($filter)) {
$this->filters[] = $filter;
$filter->setProduct($this);
}
return $this;
}
public function removeFilter(ProductFilter $filter): self
{
if ($this->filters->contains($filter)) {
$this->filters->removeElement($filter);
// set the owning side to null (unless already changed)
if ($filter->getProduct() === $this) {
$filter->setProduct(null);
}
}
return $this;
}
public function getAvailability($locale = 'pl')
{
foreach ($this->getLangParams() as $langParam) {
if ($langParam->getLanguage()->getLocaleShort() == $locale) {
return $langParam->getAvailability();
}
}
return null;
}
public function getProducer($locale = 'pl')
{
foreach ($this->getLangParams() as $langParam) {
if ($langParam->getLanguage()->getLocaleShort() == $locale) {
return $langParam->getProductProducer();
}
}
return null;
}
public function setAvailability(?Availability $availability): self
{
$this->availability = $availability;
return $this;
}
public function getOldPrice()
{
return $this->oldPrice;
}
public function setOldPrice($oldPrice): self
{
$this->oldPrice = $oldPrice;
return $this;
}
public function getFilm()
{
return $this->translate()->getTransFilm();
}
public function getProductProducer($locale = 'pl')
{
foreach ($this->getLangParams() as $langParam) {
if ($langParam->getLanguage()->getLocaleShort() == $locale) {
return $langParam->getProductProducer();
}
}
return $this->productProducer;
}
public function setProductProducer(?ProductProducer $productProducer): self
{
$this->productProducer = $productProducer;
return $this;
}
public function getPhoto3d(): ?string
{
return $this->photo3d;
}
public function setPhoto3d(?string $photo3d): self
{
$this->photo3d = $photo3d;
return $this;
}
/**
* @return Collection|Marker[]
*/
public function getMarkers(): Collection
{
return $this->markers;
}
public function addMarker(Marker $marker): self
{
if (!$this->markers->contains($marker)) {
$this->markers[] = $marker;
}
return $this;
}
public function removeMarker(Marker $marker): self
{
if ($this->markers->contains($marker)) {
$this->markers->removeElement($marker);
}
return $this;
}
/**
* @return Collection|DeliveryMethod[]
*/
public function getSpecialDeliveryMethods(): Collection
{
return $this->specialDeliveryMethods;
}
public function addSpecialDeliveryMethod(DeliveryMethod $specialDeliveryMethod): self
{
if (!$this->specialDeliveryMethods->contains($specialDeliveryMethod)) {
$this->specialDeliveryMethods[] = $specialDeliveryMethod;
}
return $this;
}
public function removeSpecialDeliveryMethod(DeliveryMethod $specialDeliveryMethod): self
{
if ($this->specialDeliveryMethods->contains($specialDeliveryMethod)) {
$this->specialDeliveryMethods->removeElement($specialDeliveryMethod);
}
return $this;
}
/**
* @return Collection|ProductXml[]
*/
public function getProductXml(): Collection
{
return $this->productXml;
}
public function addProductXml(ProductXml $productXml): self
{
if (!$this->productXml->contains($productXml)) {
$this->productXml[] = $productXml;
$productXml->setProduct($this);
}
return $this;
}
public function removeProductXml(ProductXml $productXml): self
{
if ($this->productXml->contains($productXml)) {
$this->productXml->removeElement($productXml);
// set the owning side to null (unless already changed)
if ($productXml->getProduct() === $this) {
$productXml->setProduct(null);
}
}
return $this;
}
public function getActiveEquipment() {
$c = new ArrayCollection();
foreach ($this->getEquipments() as $equipment) {
if ($equipment->getDeletedBy() === null && $equipment->isVisible()) {
$c->add($equipment);
}
}
return $c;
}
/**
* @return Collection|ProductEquipment[]
*/
public function getEquipments(): Collection
{
return $this->equipments;
}
public function addEquipment(ProductEquipment $equipment): self
{
if (!$this->equipments->contains($equipment)) {
$this->equipments[] = $equipment;
}
return $this;
}
public function removeEquipment(ProductEquipment $equipment): self
{
if ($this->equipments->contains($equipment)) {
$this->equipments->removeElement($equipment);
}
return $this;
}
public function getAvailableTranslations() {
$current = $this->getTranslations();
$trans = [];
/** @var $tran ProductTranslation */
foreach ($current as $tran) {
$trans[] = $tran->getLocale();
}
$all = ['sk', 'cz', 'pl', 'ro'];
$data = [];
foreach ($all as $lang) {
if (in_array($lang, $trans)) {
$data[] = ['lang'=>$lang, 'available'=>1];
} else {
$data[] = ['lang'=>$lang, 'available'=>0];
}
}
return $data;
}
public function getAvailablePrices() {
$current = $this->getActiveProductPrices();
$trans = [];
/** @var $tran ProductPrice */
foreach ($current as $tran) {
$trans[] = $tran->getLanguage()->getLocale();
}
$all = ['sk', 'cz', 'pl', 'ro'];
$data = [];
foreach ($all as $lang) {
if (in_array($lang, $trans)) {
$data[] = ['lang'=>$lang, 'available'=>1];
} else {
$data[] = ['lang'=>$lang, 'available'=>0];
}
}
return $data;
}
public function setFilm(?string $film): self
{
$this->film = $film;
return $this;
}
/**
* @return Collection|LandingPage[]
*/
public function getLandingPages(): Collection
{
return $this->landingPages;
}
public function addLandingPage(LandingPage $landingPage): self
{
if (!$this->landingPages->contains($landingPage)) {
$this->landingPages[] = $landingPage;
$landingPage->addProduct($this);
}
return $this;
}
public function removeLandingPage(LandingPage $landingPage): self
{
if ($this->landingPages->contains($landingPage)) {
$this->landingPages->removeElement($landingPage);
$landingPage->removeProduct($this);
}
return $this;
}
public function isSetPrice(Language $language) {
/** @var $activeProductPrice ProductPrice */
foreach ($this->getActiveProductPrices() as $activeProductPrice) {
if ($activeProductPrice->getLanguage()->getId() == $language->getId()) {
return true;
}
}
return false;
}
/**
* @return Collection|Marker[]
*/
public function getListingMarkers(): Collection
{
return $this->listingMarkers;
}
public function addListingMarker(Marker $listingMarker): self
{
if (!$this->listingMarkers->contains($listingMarker)) {
$this->listingMarkers[] = $listingMarker;
}
return $this;
}
public function removeListingMarker(Marker $listingMarker): self
{
if ($this->listingMarkers->contains($listingMarker)) {
$this->listingMarkers->removeElement($listingMarker);
}
return $this;
}
/**
* @return string
*/
public function getListingMarkersIds()
{
return $this->listingMarkersIds;
}
/**
* @param string $listingMarkersIds
*/
public function setListingMarkersIds($listingMarkersIds)
{
$this->listingMarkersIds = $listingMarkersIds;
}
/**
* @return mixed
*/
public function getHalmarStockExchange()
{
return $this->halmarStockExchange;
}
/**
* @param mixed $halmarStockExchange
*/
public function setHalmarStockExchange($halmarStockExchange)
{
$this->halmarStockExchange = $halmarStockExchange;
}
/**
* @return Collection|SubProduct[]
*/
public function getSubProducts(): Collection
{
return $this->subProducts;
}
public function addSubProduct(SubProduct $subProduct): self
{
if (!$this->subProducts->contains($subProduct)) {
$this->subProducts[] = $subProduct;
$subProduct->setProduct($this);
}
return $this;
}
public function removeSubProduct(SubProduct $subProduct): self
{
if ($this->subProducts->removeElement($subProduct)) {
// set the owning side to null (unless already changed)
if ($subProduct->getProduct() === $this) {
$subProduct->setProduct(null);
}
}
return $this;
}
/**
* @return bool
*/
public function isAutomaticPrice(): bool
{
return $this->automaticPrice;
}
/**
* @param bool $automaticPrice
*/
public function setAutomaticPrice(bool $automaticPrice): void
{
$this->automaticPrice = $automaticPrice;
}
public function getAutomaticPrice(): ?bool
{
return $this->automaticPrice;
}
/**
* @return Collection|ProductPriceDraft[]
*/
public function getProductPriceDrafts(): Collection
{
return $this->productPriceDrafts;
}
public function addProductPriceDraft(ProductPriceDraft $productPriceDraft): self
{
if (!$this->productPriceDrafts->contains($productPriceDraft)) {
$this->productPriceDrafts[] = $productPriceDraft;
$productPriceDraft->setProduct($this);
}
return $this;
}
public function removeProductPriceDraft(ProductPriceDraft $productPriceDraft): self
{
if ($this->productPriceDrafts->removeElement($productPriceDraft)) {
// set the owning side to null (unless already changed)
if ($productPriceDraft->getProduct() === $this) {
$productPriceDraft->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|ProductPriceChangeLog[]
*/
public function getProductPriceChangeLog(): Collection
{
return $this->productPriceChangeLog;
}
public function addProductPriceChangeLog(ProductPriceChangeLog $productPriceChangeLog): self
{
if (!$this->productPriceChangeLog->contains($productPriceChangeLog)) {
$this->productPriceChangeLog[] = $productPriceChangeLog;
$productPriceChangeLog->setProduct($this);
}
return $this;
}
public function removeProductPriceChangeLog(ProductPriceChangeLog $productPriceChangeLog): self
{
if ($this->productPriceChangeLog->removeElement($productPriceChangeLog)) {
// set the owning side to null (unless already changed)
if ($productPriceChangeLog->getProduct() === $this) {
$productPriceChangeLog->setProduct(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getPayu()
{
return $this->payu;
}
/**
* @param mixed $payu
*/
public function setPayu($payu): void
{
$this->payu = $payu;
}
/**
* @return mixed
*/
public function getTemporaryUnavailable()
{
return $this->temporaryUnavailable;
}
/**
* @param mixed $temporaryUnavailable
*/
public function setTemporaryUnavailable($temporaryUnavailable)
{
$this->temporaryUnavailable = $temporaryUnavailable;
}
/**
* @return Collection|ProductCrossSelling[]
*/
public function getCrossSelling(): Collection
{
return $this->crossSelling;
}
public function addCrossSelling(ProductCrossSelling $crossSelling): self
{
if (!$this->crossSelling->contains($crossSelling)) {
$this->crossSelling[] = $crossSelling;
$crossSelling->setProduct($this);
}
return $this;
}
public function removeCrossSelling(ProductCrossSelling $crossSelling): self
{
if ($this->crossSelling->removeElement($crossSelling)) {
// set the owning side to null (unless already changed)
if ($crossSelling->getProduct() === $this) {
$crossSelling->setProduct(null);
}
}
return $this;
}
/**
* @return \DateTime
*/
public function getLastRankingUpdate(): \DateTime
{
return $this->lastRankingUpdate;
}
/**
* @param \DateTime $lastRankingUpdate
*/
public function setLastRankingUpdate(\DateTime $lastRankingUpdate): void
{
$this->lastRankingUpdate = $lastRankingUpdate;
}
/**
* Add color
*
* @param \App\Entity\ProductColor $color
*
* @return Product
*/
public function addColor(\App\Entity\ProductColor $color)
{
$this->colors[] = $color;
return $this;
}
/**
* Remove color
*
* @param \App\Entity\ProductColor $color
*/
public function removeColor(\App\Entity\ProductColor $color)
{
$this->colors->removeElement($color);
}
/**
* Get colors
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getColors()
{
return $this->colors;
}
public function getColorsIds() {
$ids = [];
/** @var $color ProductColor */
foreach ($this->getColors() as $color) {
if ($color->getDeletedBy() == null) {
$ids[] = $color->getId();
}
}
return $ids;
}
/**
* @return bool
*/
public function isDiabloStockExchange()
{
return $this->diabloStockExchange;
}
public function getDiabloStockExchange() {
return $this->diabloStockExchange;
}
/**
* @param bool $diabloStockExchange
*/
public function setDiabloStockExchange(bool $diabloStockExchange)
{
$this->diabloStockExchange = $diabloStockExchange;
}
/**
* @return mixed
*/
public function getIsPaletteDelivery()
{
return $this->isPaletteDelivery;
}
/**
* @param mixed $isPaletteDelivery
*/
public function setIsPaletteDelivery($isPaletteDelivery)
{
$this->isPaletteDelivery = $isPaletteDelivery;
}
/**
* @return bool
*/
public function isActonaStockExchange(): bool
{
return $this->actonaStockExchange;
}
/**
* @param bool $actonaStockExchange
*/
public function setActonaStockExchange(bool $actonaStockExchange): void
{
$this->actonaStockExchange = $actonaStockExchange;
}
public function getActonaStockExchange(): ?bool
{
return $this->actonaStockExchange;
}
/**
* @return bool
*/
public function isJanNowakStockExchange(): bool
{
return $this->janNowakStockExchange;
}
/**
* @return bool
*/
public function getJanNowakStockExchange(): bool
{
return $this->janNowakStockExchange;
}
/**
* @param bool $janNowakStockExchange
*/
public function setJanNowakStockExchange(bool $janNowakStockExchange): void
{
$this->janNowakStockExchange = $janNowakStockExchange;
}
/**
* @return int
*/
public function getHeight()
{
return $this->height;
}
/**
* @param int $height
*/
public function setHeight($height)
{
$this->height = $height;
}
/**
* @return int
*/
public function getWidth()
{
return $this->width;
}
/**
* @param int $width
*/
public function setWidth($width)
{
$this->width = $width;
}
/**
* @return int
*/
public function getDepth()
{
return $this->depth;
}
/**
* @param int $depth
*/
public function setDepth($depth)
{
$this->depth = $depth;
}
/**
* @return Collection|ProductSimilarColors[]
*/
public function getSimilarColors(): Collection
{
return $this->similarColors;
}
public function addSimilarColor(ProductSimilarColors $similarColor): self
{
if (!$this->similarColors->contains($similarColor)) {
$this->similarColors[] = $similarColor;
$similarColor->setProduct($this);
}
return $this;
}
public function removeSimilarColor(ProductSimilarColors $similarColor): self
{
if ($this->similarColors->removeElement($similarColor)) {
// set the owning side to null (unless already changed)
if ($similarColor->getProduct() === $this) {
$similarColor->setProduct(null);
}
}
return $this;
}
public function getShippingCategory(): ?string
{
return $this->shippingCategory;
}
public function setShippingCategory($shippingCategory): void
{
$this->shippingCategory = $shippingCategory;
}
public function isUniqueStockExchange(): bool
{
return $this->uniqueStockExchange;
}
public function getUniqueStockExchange(): bool
{
return $this->uniqueStockExchange;
}
public function setUniqueStockExchange(bool $uniqueStockExchange): void
{
$this->uniqueStockExchange = $uniqueStockExchange;
}
}