<?php
namespace App\Entity;
use App\Entity\ProductDescription;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use App\Helpers\Encoder;
/**
* Products
*
* @ORM\Table(name="products")
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Product extends TranslatedEntity
{
public const VAT_RATE = 0.2;
public const SEARCH_INDICES = [
'fr' => 'fr-products',
'en' => 'en-products',
];
public const TYPE_PRODUCT = 'product';
public const TYPE_SAV = 'sav';
protected $tranlatedEntity = 'ProductDescription';
/**
* @var int
*
* @ORM\Column(name="products_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductAttribute", mappedBy="product")
*/
private $attributes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="parent")
*/
private $children = [];
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="children")
* @ORM\JoinColumn(name="products_parent_id", referencedColumnName="products_id", nullable=true)
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductDescription", mappedBy="product")
*/
private $descriptions = [];
/**
* @ORM\OneToMany(targetEntity="App\Entity\PictureProduct", mappedBy="product")
* @ORM\OrderBy({"rank" = "ASC", "id" = "ASC"})
*/
private $pictures = [];
/**
* @var App\Entity\Manufacturer|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\Manufacturer")
* @ORM\JoinColumn(name="manufacturers_id", referencedColumnName="manufacturers_id", nullable=true)
*/
private $manufacturer;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductCountryRestriction", mappedBy="product")
*/
private $countryRestrictions;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductToProductExtraField", mappedBy="product")
*/
private $extraFields = [];
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductPrice", mappedBy="product", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $prices = [];
/**
* @var int
*
* @ORM\Column(name="products_quantity", type="integer", nullable=false)
*/
private $quantity = '0';
/**
* @var string|null
*
* @ORM\Column(name="products_model", type="string", length=256, nullable=true)
*/
private $model;
/**
* @var string|null
*
* @ORM\Column(name="products_model_sap", type="string", length=50, nullable=true)
*/
private $modelSAP;
/**
* @var string|null
*
* @ORM\Column(name="products_ean", type="string", length=50, nullable=true)
*/
private $ean;
/**
* @var string|null
*
* @ORM\Column(name="products_image", type="string", length=140, nullable=true)
*/
private $image;
/**
* @var string|null
*
* @ORM\Column(name="products_image_med", type="string", length=140, nullable=true)
*/
private $imageMed;
/**
* @var string|null
*
* @ORM\Column(name="products_image_lrg", type="string", length=140, nullable=true)
*/
private $imageLrg;
/**
* @var string|null
*
* @ORM\Column(name="products_image_sm_1", type="string", length=140, nullable=true)
*/
private $imageSm1;
/**
* @var string|null
*
* @ORM\Column(name="products_image_xl_1", type="string", length=140, nullable=true)
*/
private $imageXl1;
/**
* @var string|null
*
* @ORM\Column(name="products_image_sm_2", type="string", length=140, nullable=true)
*/
private $imageSm2;
/**
* @var string|null
*
* @ORM\Column(name="products_image_xl_2", type="string", length=140, nullable=true)
*/
private $imageXl2;
/**
* @var string|null
*
* @ORM\Column(name="products_image_sm_3", type="string", length=140, nullable=true)
*/
private $imageSm3;
/**
* @var string|null
*
* @ORM\Column(name="products_image_xl_3", type="string", length=140, nullable=true)
*/
private $imageXl3;
/**
* @var string|null
*
* @ORM\Column(name="products_image_sm_4", type="string", length=140, nullable=true)
*/
private $imageSm4;
/**
* @var string|null
*
* @ORM\Column(name="products_image_xl_4", type="string", length=140, nullable=true)
*/
private $imageXl4;
/**
* @var string|null
*
* @ORM\Column(name="products_image_sm_5", type="string", length=140, nullable=true)
*/
private $imageSm5;
/**
* @var string|null
*
* @ORM\Column(name="products_image_xl_5", type="string", length=140, nullable=true)
*/
private $imageXl5;
/**
* @var string|null
*
* @ORM\Column(name="products_image_sm_6", type="string", length=140, nullable=true)
*/
private $imageSm6;
/**
* @var string|null
*
* @ORM\Column(name="products_image_xl_6", type="string", length=140, nullable=true)
*/
private $imageXl6;
/**
* @var float
*
* @ORM\Column(name="products_price", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price = '0.0000';
/**
* @var float
* @ORM\Column(name="products_ecotax", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $ecotax = '0.0000';
/**
* @var \DateTime
*
* @ORM\Column(name="products_date_added", type="datetime", nullable=false)
*/
private $dateAdded;
/**
* @var \DateTime|null
*
* @ORM\Column(name="products_last_modified", type="datetime", nullable=true)
*/
private $lastModified;
/**
* @var \DateTime|null
*
* @ORM\Column(name="products_date_available", type="datetime", nullable=true)
*/
private $dateAvailable;
/**
* @var string
*
* @ORM\Column(name="products_weight", type="decimal", precision=5, scale=2, nullable=false, options={"default"="0.00"})
*/
private $weight = '0.00';
/**
* @var bool
*
* @ORM\Column(name="products_status", type="boolean", nullable=false)
*/
private $status = '0';
/** *
* @ORM\ManyToOne(targetEntity="App\Entity\TaxClass", inversedBy="rates")
* @ORM\JoinColumn(name="products_tax_class_id", referencedColumnName="tax_class_id")
*/
private $taxClass;
/**
* @var int
*
* @ORM\Column(name="products_ordered", type="integer", nullable=false)
*/
private $ordered = '0';
/**
* @var string
*
* @ORM\Column(name="products_price1", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price1 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price2", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price2 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price3", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price3 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price4", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price4 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price5", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price5 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price6", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price6 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price7", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price7 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price8", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price8 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price9", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price9 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price10", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price10 = '0.0000';
/**
* @var string
*
* @ORM\Column(name="products_price11", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price11 = '0.0000';
/**
* @var int
*
* @ORM\Column(name="products_price1_qty", type="integer", nullable=false)
*/
private $price1Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price2_qty", type="integer", nullable=false)
*/
private $price2Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price3_qty", type="integer", nullable=false)
*/
private $price3Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price4_qty", type="integer", nullable=false)
*/
private $price4Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price5_qty", type="integer", nullable=false)
*/
private $price5Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price6_qty", type="integer", nullable=false)
*/
private $price6Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price7_qty", type="integer", nullable=false)
*/
private $price7Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price8_qty", type="integer", nullable=false)
*/
private $price8Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price9_qty", type="integer", nullable=false)
*/
private $price9Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price10_qty", type="integer", nullable=false)
*/
private $price10Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_price11_qty", type="integer", nullable=false)
*/
private $price11Qty = '0';
/**
* @var int
*
* @ORM\Column(name="products_qty_blocks", type="integer", nullable=false, options={"default"="1"})
*/
private $productsQtyBlocks = '1';
/**
* @var bool
*
* @ORM\Column(name="products_soleil", type="integer", nullable=false)
*/
private $soleil = '0';
/**
* @var int
*
* @ORM\Column(name="products_limite_panier", type="integer", nullable=false)
*/
private $limitePanier = '0';
/**
* @var int|null
*
* @ORM\Column(name="products_page", type="integer", nullable=true)
*/
private $page;
/**
* @var bool
*
* @ORM\Column(name="products_garantie", type="integer", nullable=false)
*/
private $guaranty = '0';
/**
* @var int
*
* @ORM\Column(name="products_cat", type="integer", nullable=true)
*/
private $defaultCategoryId = 0;
private $defaultCategory;
/**
* @var int
*
* @ORM\Column(name="products_index", type="integer", nullable=false, options={"default"="1"})
*/
private $index = '1';
/**
* @var int
*
* @ORM\Column(name="products_mvente", type="integer", nullable=false, options={"default"="1"})
*/
private $mvente = '1';
/**
* @var int
*
* @ORM\Column(name="products_strategique", type="integer", nullable=false)
*/
private $strategique = '0';
/**
* @var int
*
* @ORM\Column(name="products_reappro_non", type="integer", nullable=false)
*/
private $reapproNon = '0';
/**
* @var int|null
*
* @ORM\Column(name="products_multiple", type="integer", nullable=true)
*/
private $multiple = 1;
/**
* @var string|null
*
* @ORM\Column(name="products_origin", type="string", length=3, nullable=true)
*/
private $origin = 1;
/**
* @var bool
*
* @ORM\Column(name="products_gift", type="boolean", nullable=true)
*/
private $gift = '0';
/**
* @var ?string
*
* @ORM\Column(name="products_type", type="string", length=20, nullable=true)
*/
private $type;
/**
* @var int
*
* @ORM\Column(name="products_welcome", type="boolean", nullable=false, options={"default"="1"})
*/
private $welcome = '1';
public function __construct()
{
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
$this->prices = new \Doctrine\Common\Collections\ArrayCollection();
$this->descriptions = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId() {
return $this->id;
}
public function getChildren() {
return $this->children;
}
public function getParent() {
if(!empty($this->parent) && !empty($this->languageId)){
$this->parent->setLanguageId($this->languageId);
}
return $this->parent;
}
public function getDescriptions() {
return $this->descriptions;
}
public function getAttributes() {
return $this->attributes;
}
public function getQuantity() {
return $this->quantity;
}
public function getModel() {
return $this->model;
}
public function getModelSAP(): ?string {
return $this->modelSAP;
}
public function getEan(): ?string {
return $this->ean;
}
public function getName() {
if(!empty($this->languageId)){
$description = null;
foreach($this->descriptions as $d){
if($d->getLanguage()->getId()==$this->languageId){
$description = $d;
break;
}
}
}
if(empty($description) && count($this->descriptions)){
$description = $this->descriptions[0];
}
return empty($description)?'':$description->getName();
}
public function getHeadingTitle() {
if(!empty($this->languageId)){
$description = null;
foreach($this->descriptions as $d){
if($d->getLanguage()->getId()==$this->languageId){
$description = $d;
break;
}
}
}
if(empty($description) && count($this->descriptions)){
$description = $this->descriptions[0];
}
return empty($description)?'':$description->getHeadingTitle();
}
public function getDeclinaison() {
$output = '';
if($this->parent){
$name = $this->getName();
$output = substr($name, strlen($this->getParent()->getName())+2, strlen($name));
}
return $output;
}
public function getUrl() {
if(!empty($this->languageId)){
$description = null;
foreach($this->descriptions as $d){
if($d->getLanguage()->getId()==$this->languageId){
$description = $d;
break;
}
}
}
if(empty($description) && count($this->descriptions)){
$description = $this->descriptions[0];
}
return empty($description)?'':$description->getUrl();
}
public function getDescription() {
if(!empty($this->languageId)){
$description = null;
foreach($this->descriptions as $d){
if($d->getLanguage()->getId()==$this->languageId){
$description = $d;
break;
}
}
}
if(empty($description) && count($this->descriptions)){
$description = $this->descriptions[0];
}
return empty($description)?'':$description->getDescription();
}
public function getExtraFields() {
return $this->extraFields;
}
public function getProductDescription($lang='fr') : ?ProductDescription {
foreach($this->getDescriptions() as $desc){
if($desc->getLanguage()->getCode() == $lang)
return $desc;
}
return null;
}
public function getPicture() {
return empty($this->pictures)?null:$this->pictures[0];
}
public function getPictures() {
return $this->pictures;
}
public function getPicturesUrl() {
$output = [];
foreach($this->pictures as $picture){
$output[] = $picture->getUrl();
}
return $output;
}
public function getImage($absolute=false) {
if($absolute)
return 'https://www.dogcat.com/professionnel/images/'.$this->image;
return $this->image;
}
public function getImageMed($absolute=false) {
if($absolute)
return 'https://www.dogcat.com/professionnel/images/'.$this->imageMed;
return $this->imageMed;
}
public function getImageLrg($absolute=false) {
if($absolute)
return 'https://www.dogcat.com/professionnel/images/'.$this->imageLrg;
return $this->imageLrg;
}
public function getImageSm1() {
return $this->imageSm1;
}
public function getImageXl1() {
return $this->imageXl1;
}
public function getImageSm2() {
return $this->imageSm2;
}
public function getImageXl2() {
return $this->imageXl2;
}
public function getImageSm3() {
return $this->imageSm3;
}
public function getImageXl3() {
return $this->imageXl3;
}
public function getImageSm4() {
return $this->imageSm4;
}
public function getImageXl4() {
return $this->imageXl4;
}
public function getImageSm5() {
return $this->imageSm5;
}
public function getImageXl5() {
return $this->imageXl5;
}
public function getImageSm6() {
return $this->imageSm6;
}
public function getImageXl6() {
return $this->imageXl6;
}
public function getPrice($withEcotax = false, ?PriceGroup $priceGroup = null, $withVat = false) {
$price = $this->price;
$tax = 0;
if($this->isGift()) {
return 0;
}
if($priceGroup) {
$price = $this->getPriceByGroup($priceGroup);
}
if($withVat) {
$tax = Encoder::roundPrice($price*self::VAT_RATE);
}
if($withEcotax === true){
return Encoder::roundPrice($price) + Encoder::roundPrice($this->getEcotax()) + $tax;
}
return Encoder::roundPrice($price) + $tax;
}
public function getPrices() {
return $this->prices;
}
public function getPriceByGroup(PriceGroup $priceGroup) {
foreach($this->prices as $price) {
if($price->getGroup() == $priceGroup)
return $price->getPrice();
}
// throw new \App\Exception\PriceGroupException();
}
public function hasPrice(PriceGroup $priceGroup) {
if($this->hasChildren()) {
foreach($this->getChildren() as $child) {
if($child->hasPrice($priceGroup))
return true;
}
}else{
foreach($this->prices as $price) {
if($price->getGroup() == $priceGroup)
return true;
}
}
return false;
}
public function getEcotax() {
return $this->ecotax;
}
public function getFromProduct(?PriceGroup $priceGroup = null) {
$tmp = null;
$from = null;
foreach($this->children as $product){
if(!$product->isStopped() && $product->isActive()){
if(!empty($priceGroup) && !$product->hasPrice($priceGroup)) {
continue;
}
if(is_null($tmp) || ($tmp>$product->getPrice(false, $priceGroup, false))){
$tmp = $product->getPrice(false, $priceGroup, false);
$from = $product;
}
}
}
return $from;
}
public function getFromPrice($withEcotax = true, ?PriceGroup $priceGroup = null, $withVat = false) {
$tmp = null;
foreach($this->children as $product){
if(!$product->isStopped() && $product->isActive()){
if(!empty($priceGroup) && !$product->hasPrice($priceGroup)) {
continue;
}
if(is_null($tmp) || ($tmp>$product->getPrice($withEcotax, $priceGroup, $withVat))){
$tmp = $product->getPrice($withEcotax, $priceGroup, $withVat);
}
}
}
return is_null($tmp)?0:$tmp;
}
public function getSoleilPrice($withEcotax = true) {
if($this->isNonSoleil()){
return Encoder::roundPrice($this->price * 0.9)+($withEcotax?$this->getEcotax():0);
}else if($this->isSoleil()){
return Encoder::roundPrice($this->price * 0.75)+($withEcotax?$this->getEcotax():0);
}
return Encoder::roundPrice($this->price)+($withEcotax?$this->getEcotax():0);
}
public function getDateAdded() {
return $this->dateAdded;
}
public function getLastModified() {
return $this->lastModified;
}
public function getDateAvailable() {
return $this->dateAvailable;
}
public function getWeight() {
return $this->weight;
}
public function getStatus() {
return $this->status;
}
public function getTaxClass() {
return $this->taxClass;
}
public function getManufacturer() {
return $this->manufacturer;
}
public function getOrdered() {
return $this->ordered;
}
public function getPrice1() {
return $this->price1;
}
public function getPrice2() {
return $this->price2;
}
public function getPrice3() {
return $this->price3;
}
public function getPrice4() {
return $this->price4;
}
public function getPrice5() {
return $this->price5;
}
public function getPrice6() {
return $this->price6;
}
public function getPrice7() {
return $this->price7;
}
public function getPrice8() {
return $this->price8;
}
public function getPrice9() {
return $this->price9;
}
public function getPrice10() {
return $this->price10;
}
public function getPrice11() {
return $this->price11;
}
public function getPrice1Qty() {
return $this->price1Qty;
}
public function getPrice2Qty() {
return $this->price2Qty;
}
public function getPrice3Qty() {
return $this->price3Qty;
}
public function getPrice4Qty() {
return $this->price4Qty;
}
public function getPrice5Qty() {
return $this->price5Qty;
}
public function getPrice6Qty() {
return $this->price6Qty;
}
public function getPrice7Qty() {
return $this->price7Qty;
}
public function getPrice8Qty() {
return $this->price8Qty;
}
public function getPrice9Qty() {
return $this->price9Qty;
}
public function getPrice10Qty() {
return $this->price10Qty;
}
public function getPrice11Qty() {
return $this->price11Qty;
}
public function getProductsQtyBlocks() {
return $this->productsQtyBlocks;
}
public function getSoleil() {
return $this->soleil;
}
public function getLimitePanier() {
return $this->limitePanier;
}
public function getPage() {
return $this->page;
}
public function getGuaranty() {
return $this->guaranty;
}
public function getDefaultCategoryId() {
return $this->defaultCategoryId;
}
public function getDefaultCategory() {
return $this->defaultCategory;
}
public function getIndex() {
if(empty($this->index))
return 0;
return $this->index > 0 ? 1 : 0;
}
public function getMvente() {
return $this->mvente;
}
public function getStrategique() {
return $this->strategique;
}
public function getReapproNon() {
return $this->reapproNon;
}
public function getMultiple() {
return empty($this->multiple)?1:$this->multiple;
}
public function getOrigin() {
return $this->origin;
}
public function getReference() {
return $this->getModel();
}
public function getGift() {
return is_null($this->gift) ? 0 : $this->gift;
}
public function getType(): ?string {
return empty($this->type) ? self::TYPE_PRODUCT : $this->type;
}
public function getCountryRestrictions() {
return $this->countryRestrictions;
}
public function getRestrictedCountries() {
$output = [];
foreach($this->getCountryRestrictions() as $rc) {
$output[] = $rc->getCountry();
}
return $output;
}
public function getWelcome(): int {
return $this->welcome;
}
// public function getUrl($absolute=false) {
// if(!empty($this->parent))
// return $this->getParent()->getUrl($absolute);
// if(!empty($this->languageId)){
// $language = $this->languageId==4?'fr':'en';
// }
// if(empty($language)){
// $language = 'fr';
// }
//// $url = '/professionnel/product_info.php?products_id='.$this->getId().'&language='.$language;
//// if($absolute)
//// return 'https://www.dogcat.com'.$url;
// return $this->getUrl();
// }
public function setId($id) {
$this->id = $id;
}
public function setAttributes($attributes) {
$this->attributes = $attributes;
}
public function setChildren($children) {
$this->children = $children;
}
public function setParent($parent) {
$this->parent = $parent;
}
public function setDescriptions($descriptions) {
$this->descriptions = $descriptions;
}
public function setExtraFields($extraFields): void {
$this->extraFields = $extraFields;
}
public function setQuantity($quantity) {
$this->quantity = $quantity;
}
public function setModel($model) {
$this->model = $model;
}
public function setModelSAP(?string $modelSAP): void {
$this->modelSAP = $modelSAP;
}
public function setEan(?string $ean): void {
$this->ean = $ean;
}
public function setImage($image) {
$this->image = $image;
}
public function setImageMed($imageMed) {
$this->imageMed = $imageMed;
}
public function setImageLrg($imageLrg) {
$this->imageLrg = $imageLrg;
}
public function setImageSm1($imageSm1) {
$this->imageSm1 = $imageSm1;
}
public function setImageXl1($imageXl1) {
$this->imageXl1 = $imageXl1;
}
public function setImageSm2($imageSm2) {
$this->imageSm2 = $imageSm2;
}
public function setImageXl2($imageXl2) {
$this->imageXl2 = $imageXl2;
}
public function setImageSm3($imageSm3) {
$this->imageSm3 = $imageSm3;
}
public function setImageXl3($imageXl3) {
$this->imageXl3 = $imageXl3;
}
public function setImageSm4($imageSm4) {
$this->imageSm4 = $imageSm4;
}
public function setImageXl4($imageXl4) {
$this->imageXl4 = $imageXl4;
}
public function setImageSm5($imageSm5) {
$this->imageSm5 = $imageSm5;
}
public function setImageXl5($imageXl5) {
$this->imageXl5 = $imageXl5;
}
public function setImageSm6($imageSm6) {
$this->imageSm6 = $imageSm6;
}
public function setImageXl6($imageXl6) {
$this->imageXl6 = $imageXl6;
}
public function setPrice($price) {
$this->price = $price;
}
public function setEcotax( $ecotax) {
$this->ecotax = $ecotax;
}
public function setDateAdded(\DateTime $dateAdded) {
$this->dateAdded = $dateAdded;
}
public function setLastModified(\DateTime $lastModified) {
$this->lastModified = $lastModified;
}
public function setDateAvailable(\DateTime $dateAvailable) {
$this->dateAvailable = $dateAvailable;
}
public function setWeight($weight) {
$this->weight = $weight;
}
public function setStatus($status) {
$this->status = $status;
}
public function setTaxClass($taxClass) {
$this->taxClass = $taxClass;
}
public function setManufacturer($manufacturer) {
$this->manufacturer = $manufacturer;
}
public function setOrdered($ordered) {
$this->ordered = $ordered;
}
public function setParentId($parentId) {
$this->parentId = $parentId;
}
public function setPrice1($price1) {
$this->price1 = $price1;
}
public function setPrice2($price2) {
$this->price2 = $price2;
}
public function setPrice3($price3) {
$this->price3 = $price3;
}
public function setPrice4($price4) {
$this->price4 = $price4;
}
public function setPrice5($price5) {
$this->price5 = $price5;
}
public function setPrice6($price6) {
$this->price6 = $price6;
}
public function setPrice7($price7) {
$this->price7 = $price7;
}
public function setPrice8($price8) {
$this->price8 = $price8;
}
public function setPrice9($price9) {
$this->price9 = $price9;
}
public function setPrice10($price10) {
$this->price10 = $price10;
}
public function setPrice11($price11) {
$this->price11 = $price11;
}
public function setPrice1Qty($price1Qty) {
$this->price1Qty = $price1Qty;
}
public function setPrice2Qty($price2Qty) {
$this->price2Qty = $price2Qty;
}
public function setPrice3Qty($price3Qty) {
$this->price3Qty = $price3Qty;
}
public function setPrice4Qty($price4Qty) {
$this->price4Qty = $price4Qty;
}
public function setPrice5Qty($price5Qty) {
$this->price5Qty = $price5Qty;
}
public function setPrice6Qty($price6Qty) {
$this->price6Qty = $price6Qty;
}
public function setPrice7Qty($price7Qty) {
$this->price7Qty = $price7Qty;
}
public function setPrice8Qty($price8Qty) {
$this->price8Qty = $price8Qty;
}
public function setPrice9Qty($price9Qty) {
$this->price9Qty = $price9Qty;
}
public function setPrice10Qty($price10Qty) {
$this->price10Qty = $price10Qty;
}
public function setPrice11Qty($price11Qty) {
$this->price11Qty = $price11Qty;
}
public function setProductsQtyBlocks($productsQtyBlocks) {
$this->productsQtyBlocks = $productsQtyBlocks;
}
public function setSoleil($soleil) {
$this->soleil = $soleil;
}
public function setLimitePanier($limitePanier) {
$this->limitePanier = $limitePanier;
}
public function setPage($page) {
$this->page = $page;
}
public function setGuaranty($guaranty) {
$this->guaranty = $guaranty;
}
public function setDefaultCategoryId($defaultCategoryId) {
$this->defaultCategoryId = $defaultCategoryId;
}
public function setIndex($index) {
$this->index = $index;
}
public function setMvente($mvente) {
$this->mvente = $mvente;
}
public function setStrategique($strategique) {
$this->strategique = $strategique;
}
public function setReapproNon($reapproNon) {
$this->reapproNon = $reapproNon;
}
public function setMultiple($multiple) {
return $this->multiple = $multiple;
}
public function setOrigin($origin) {
$this->origin = $origin;
}
public function setPrices($prices) {
$this->prices = $prices;
}
public function setGift($gift) {
$this->gift = $gift;
}
public function setType(?string $type): void {
$this->type = $type;
}
public function setCountryRestrictions($countryRestrictions): void {
$this->countryRestrictions = $countryRestrictions;
}
public function setWelcome(int $welcome): void {
$this->welcome = $welcome;
}
public function hasWelcomeDiscount() {
return !empty($this->welcome);
}
public function isMadeInFrance() {
if(!empty($this->origin))
return strtoupper($this->origin) == 'FR';
if($this->hasChildren()){
foreach($this->children as $child){
if(!$child->isMadeInFrance()){
return false;
}
}
return true;
}
return false;
}
public function isAvailable() {
return $this->quantity > 0;
}
public function hasRestrictionForCountry($country) {
if($country){
if($this->countryRestrictions){
foreach($this->getCountryRestrictions() as $restriction){
if($restriction->getCountry() == $country){
return true;
}
}
}
}
return false;
}
public function isAvailableForCountry($country) {
if($country && $this->countryRestrictions){
foreach($this->getCountryRestrictions() as $restriction) {
if($restriction->getCountry() == $country){
return false;
}
}
}
if($country && $this->getManufacturer()){
return $this->getManufacturer()->isAvailableForCountry($country);
}
return true;
}
public function isStopped() {
return $this->quantity == -800;
}
public function isActive() {
return $this->getStatus() == 1;
}
public function isGift() {
return $this->getGift() == 1;
}
public function isSoleil() {
return $this->soleil == 1;
}
public function isNonSoleil() {
return $this->soleil == 0;
}
public function isVivog() {
return $this->isSoleil() || $this->isNonSoleil();
}
public function isParent() {
return empty($this->parent);
}
public function isProduct() {
return $this->getType() == self::TYPE_PRODUCT;
}
public function hasChildren() {
return count($this->children)>0;
}
public function hasSoleilPrice() {
return $this->isSoleil() || $this->isNonSoleil();
}
public function hasParent() {
return !empty($this->parent);
}
public function hasSoleil() {
if($this->hasChildren()){
foreach($this->children as $child){
if($child->isSoleil()){
return true;
}
}
return false;
}
return $this->isSoleil();
}
public function hasNonSoleil() {
if($this->hasChildren()){
foreach($this->children as $child){
if($child->isNonSoleil()){
return true;
}
}
return false;
}
return $this->isNonSoleil();
}
public function addPrice(ProductPrice $productPrice): self
{
if (!$this->prices->contains($productPrice)) {
$this->prices->add($productPrice);
$productPrice->setProduct($this);
}
return $this;
}
public function removePrice(ProductPrice $productPrice): self
{
if ($this->prices->removeElement($productPrice)) {
if ($productPrice->getProduct() === $this) {
$productPrice->setProduct(null);
}
}
return $this;
}
public function toArray() : array{
$parent = $this->getParent();
$manufacturer = $this->getManufacturer();
$output = [
'id' => $this->getId(),
'model' => $this->getModel(),
'name' => $this->getName(),
'description' => $this->getDescription(),
'quantity' => $this->getQuantity(),
'image' => $this->getImage(),
'price' => $this->getPrice(),
'dateAdded' => $this->getDateAdded(),
'lastModified' => $this->getLastModified(),
'dateAvailable' => $this->getDateAvailable(),
'weight' => $this->getWeight(),
'status' => $this->getStatus()?1:0,
'taxClass ' => $this->getTaxClass()?$this->getTaxClass()->toArray():0,
'ordered' => $this->getOrdered(),
'parent' => empty($parent)?null:$parent->toArray(),
'manufacturer' => empty($manufacturer)?null:$manufacturer->toArray(),
'productsQtyBlocks' => $this->getProductsQtyBlocks(),
'soleil' => $this->getSoleil(),
'nbChildren' => count($this->getChildren()),
'limitePanier' => $this->getLimitePanier(),
'page' => $this->getPage(),
'garantie' => $this->getGuaranty(),
'defaultCategoryId' => $this->getDefaultCategoryId(),
'index' => $this->getIndex(),
'mvente' => $this->getMvente(),
'strategique' => $this->getStrategique(),
'reapproNon' => $this->getReapproNon(),
'multiple' => $this->getMultiple()
];
return $output;
}
/**
* @todo Remove once 0 values in the table are converted to NULL.
*/
public function loadDescriptions(\Doctrine\ORM\EntityManager $em)
{
$conn = $em->getConnection();
$sql = $conn->prepare('select * from products_description where products_id = '.$this->getId());
$sql->execute();
$rows = $sql->fetchAll();
$descriptions = [];
foreach($rows as $desc){
$description = new ProductDescription();
$description->setName($desc['products_name']);
$description->setDescription($desc['products_description']);
$description->setLanguage($em->getRepository('App:Language')->find($desc['language_id']==1?1:4));
$descriptions[] = $description;
}
$this->setDescriptions($descriptions);
}
/**
* @ORM\PostLoad
*
* @todo Remove once 0 values in the table are converted to NULL.
*/
public function postLoad(\Doctrine\ORM\Event\LifecycleEventArgs $args) {
if ($this->parent && $this->parent->getId() == 0) {
$this->parent = null;
}
if ($this->manufacturer && $this->manufacturer->getId() <= 0) {
$this->manufacturer = null;
}
if ($this->taxClass && $this->taxClass->getId() <= 0) {
$this->taxClass = null;
}
if ($this->defaultCategoryId) {
$this->defaultCategory = $args->getObjectManager()->getRepository(Category::class)->find($this->defaultCategoryId);
}
}
public static function getSearchIndex($lang = 'fr')
{
return self::SEARCH_INDICES[$lang];
}
}