|
|
@@ -14,7 +14,6 @@ use Lc\ShopBundle\Context\ProductPropertyInterface; |
|
|
|
/** |
|
|
|
* @ORM\MappedSuperclass() |
|
|
|
*/ |
|
|
|
|
|
|
|
abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, PriceInterface, FilterMerchantInterface |
|
|
|
{ |
|
|
|
use ProductPropertyTrait; |
|
|
@@ -63,7 +62,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr |
|
|
|
/** |
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
|
|
|
*/ |
|
|
|
private $warningMessageType; |
|
|
|
protected $warningMessageType; |
|
|
|
|
|
|
|
/** |
|
|
|
* @ORM\Column(type="text", nullable=true) |
|
|
@@ -105,6 +104,21 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr |
|
|
|
*/ |
|
|
|
protected $propertyFragrances; |
|
|
|
|
|
|
|
/** |
|
|
|
* @ORM\Column(type="text", nullable=true) |
|
|
|
*/ |
|
|
|
protected $propertyWeightQuantity; |
|
|
|
|
|
|
|
/** |
|
|
|
* @ORM\Column(type="text", nullable=true) |
|
|
|
*/ |
|
|
|
protected $propertyPackaging; |
|
|
|
|
|
|
|
/** |
|
|
|
* @ORM\Column(type="text", nullable=true) |
|
|
|
*/ |
|
|
|
protected $propertyCharacteristics; |
|
|
|
|
|
|
|
/** |
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
|
|
|
*/ |
|
|
@@ -128,11 +142,10 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr |
|
|
|
|
|
|
|
public function getTaxRateInherited() |
|
|
|
{ |
|
|
|
if($this->getTaxRate()) { |
|
|
|
return $this->getTaxRate() ; |
|
|
|
} |
|
|
|
else { |
|
|
|
return $this->getMerchant()->getTaxRate() ; |
|
|
|
if ($this->getTaxRate()) { |
|
|
|
return $this->getTaxRate(); |
|
|
|
} else { |
|
|
|
return $this->getMerchant()->getTaxRate(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -236,26 +249,26 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr |
|
|
|
|
|
|
|
public function getProductCategoryParent() |
|
|
|
{ |
|
|
|
$productCategories = $this->getProductCategories() ; |
|
|
|
$productCategories = $this->getProductCategories(); |
|
|
|
|
|
|
|
if(count($productCategories) > 0) { |
|
|
|
return $productCategories[0]->getParent() ; |
|
|
|
if (count($productCategories) > 0) { |
|
|
|
return $productCategories[0]->getParent(); |
|
|
|
} |
|
|
|
|
|
|
|
return false ; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public function getProductCategoryChild() |
|
|
|
{ |
|
|
|
$productCategories = $this->getProductCategories() ; |
|
|
|
$productCategories = $this->getProductCategories(); |
|
|
|
|
|
|
|
foreach($productCategories as $productCategory) { |
|
|
|
if($productCategory->getParent()) { |
|
|
|
return $productCategory ; |
|
|
|
foreach ($productCategories as $productCategory) { |
|
|
|
if ($productCategory->getParent()) { |
|
|
|
return $productCategory; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false ; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public function getSupplierTaxRate(): ?TaxRate |
|
|
@@ -345,54 +358,51 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function getCheapestOrMostExpensiveProduct($comparisonFunction, $returnSelfIfNotActiveProducts) |
|
|
|
{ |
|
|
|
$products = $this->getProducts()->getValues() ; |
|
|
|
if(count($products) > 0) { |
|
|
|
usort($products, $comparisonFunction) ; |
|
|
|
return $products[0] ; |
|
|
|
$products = $this->getProducts()->getValues(); |
|
|
|
if (count($products) > 0) { |
|
|
|
usort($products, $comparisonFunction); |
|
|
|
return $products[0]; |
|
|
|
} |
|
|
|
if($returnSelfIfNotActiveProducts) { |
|
|
|
return $this ; |
|
|
|
} |
|
|
|
else { |
|
|
|
return false ; |
|
|
|
if ($returnSelfIfNotActiveProducts) { |
|
|
|
return $this; |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function getCheapestProduct() |
|
|
|
{ |
|
|
|
return $this->getCheapestOrMostExpensiveProduct(function($a, $b) { |
|
|
|
return $a->getPriceInherited() > $b->getPriceInherited() ; |
|
|
|
},true) ; |
|
|
|
return $this->getCheapestOrMostExpensiveProduct(function ($a, $b) { |
|
|
|
return $a->getPriceInherited() > $b->getPriceInherited(); |
|
|
|
}, true); |
|
|
|
} |
|
|
|
|
|
|
|
public function getCheapestProductByUnitRef() |
|
|
|
{ |
|
|
|
return $this->getCheapestOrMostExpensiveProduct(function($a, $b) { |
|
|
|
return $a->getPriceByUnitRef() > $b->getPriceByUnitRef() ; |
|
|
|
},false) ; |
|
|
|
return $this->getCheapestOrMostExpensiveProduct(function ($a, $b) { |
|
|
|
return $a->getPriceByUnitRef() > $b->getPriceByUnitRef(); |
|
|
|
}, false); |
|
|
|
} |
|
|
|
|
|
|
|
public function getMostExpensiveProductByUnitRef() |
|
|
|
{ |
|
|
|
return $this->getCheapestOrMostExpensiveProduct(function($a, $b) { |
|
|
|
return $a->getPriceByUnitRef() < $b->getPriceByUnitRef() ; |
|
|
|
},false) ; |
|
|
|
return $this->getCheapestOrMostExpensiveProduct(function ($a, $b) { |
|
|
|
return $a->getPriceByUnitRef() < $b->getPriceByUnitRef(); |
|
|
|
}, false); |
|
|
|
} |
|
|
|
|
|
|
|
public function isPropertyNoveltyOnline(): ?bool |
|
|
|
{ |
|
|
|
if($this->getPropertyNoveltyExpirationDate()) { |
|
|
|
$now = new \DateTime() ; |
|
|
|
if($now <= $this->getPropertyNoveltyExpirationDate()) { |
|
|
|
return true ; |
|
|
|
if ($this->getPropertyNoveltyExpirationDate()) { |
|
|
|
$now = new \DateTime(); |
|
|
|
if ($now <= $this->getPropertyNoveltyExpirationDate()) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false ; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public function getPropertyNoveltyExpirationDate(): ?\DateTimeInterface |
|
|
@@ -457,15 +467,15 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr |
|
|
|
|
|
|
|
public function countProperties(): bool |
|
|
|
{ |
|
|
|
$count = 0 ; |
|
|
|
$count = 0; |
|
|
|
|
|
|
|
$count += (int) strlen($this->getPropertyAllergens()) > 0 ; |
|
|
|
$count += (int) strlen($this->getPropertyComposition()) > 0 ; |
|
|
|
$count += (int) strlen($this->getPropertyFragrances()) > 0 ; |
|
|
|
$count += (int) strlen($this->getPropertyOrganicLabel()) > 0 ; |
|
|
|
$count += (int) ($this->getPropertyExpirationDate() != null) ; |
|
|
|
$count += (int)strlen($this->getPropertyAllergens()) > 0; |
|
|
|
$count += (int)strlen($this->getPropertyComposition()) > 0; |
|
|
|
$count += (int)strlen($this->getPropertyFragrances()) > 0; |
|
|
|
$count += (int)strlen($this->getPropertyOrganicLabel()) > 0; |
|
|
|
$count += (int)($this->getPropertyExpirationDate() != null); |
|
|
|
|
|
|
|
return $count ; |
|
|
|
return $count; |
|
|
|
} |
|
|
|
|
|
|
|
public function getBehaviorExpirationDate(): ?string |
|
|
@@ -492,6 +502,43 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr |
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getPropertyWeightQuantity(): ?string |
|
|
|
{ |
|
|
|
return $this->propertyWeightQuantity; |
|
|
|
} |
|
|
|
|
|
|
|
public function setPropertyWeightQuantity(?string $propertyWeightQuantity): self |
|
|
|
{ |
|
|
|
$this->propertyWeightQuantity = $propertyWeightQuantity; |
|
|
|
|
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
|
public function getPropertyPackaging(): ?string |
|
|
|
{ |
|
|
|
return $this->propertyPackaging; |
|
|
|
} |
|
|
|
|
|
|
|
public function setPropertyPackaging(?string $propertyPackaging): self |
|
|
|
{ |
|
|
|
$this->propertyPackaging = $propertyPackaging; |
|
|
|
|
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
|
public function getPropertyCharacteristics(): ?string |
|
|
|
{ |
|
|
|
return $this->propertyCharacteristics; |
|
|
|
} |
|
|
|
|
|
|
|
public function setPropertyCharacteristics(?string $propertyCharacteristics): self |
|
|
|
{ |
|
|
|
$this->propertyCharacteristics = $propertyCharacteristics; |
|
|
|
|
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
|
public function getBehaviorAddToCart(): ?string |
|
|
|
{ |
|
|
|
return $this->behaviorAddToCart; |
|
|
@@ -506,42 +553,42 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr |
|
|
|
|
|
|
|
public function hasProductsWithVariousWeight() |
|
|
|
{ |
|
|
|
if($this->getActiveProducts()) { |
|
|
|
$arrayCountProducts = [] ; |
|
|
|
$products = $this->getProducts() ; |
|
|
|
if ($this->getActiveProducts()) { |
|
|
|
$arrayCountProducts = []; |
|
|
|
$products = $this->getProducts(); |
|
|
|
|
|
|
|
foreach($products as $product) { |
|
|
|
$titleProduct = $product->getTitleInherited() ; |
|
|
|
if(!isset($arrayCountProducts[$titleProduct])) { |
|
|
|
$arrayCountProducts[$titleProduct] = [] ; |
|
|
|
foreach ($products as $product) { |
|
|
|
$titleProduct = $product->getTitleInherited(); |
|
|
|
if (!isset($arrayCountProducts[$titleProduct])) { |
|
|
|
$arrayCountProducts[$titleProduct] = []; |
|
|
|
} |
|
|
|
|
|
|
|
if(!in_array($product->getQuantityLabelInherited(), $arrayCountProducts[$titleProduct])) { |
|
|
|
$arrayCountProducts[$titleProduct][] = $product->getQuantityLabelInherited() ; |
|
|
|
if (!in_array($product->getQuantityLabelInherited(), $arrayCountProducts[$titleProduct])) { |
|
|
|
$arrayCountProducts[$titleProduct][] = $product->getQuantityLabelInherited(); |
|
|
|
} |
|
|
|
|
|
|
|
if(count($arrayCountProducts[$titleProduct]) > 1) { |
|
|
|
return true ; |
|
|
|
if (count($arrayCountProducts[$titleProduct]) > 1) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false ; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public function getProductsGroupByTitle() |
|
|
|
{ |
|
|
|
$arrayProductsGroupByTitle = [] ; |
|
|
|
$products = $this->getProducts() ; |
|
|
|
$arrayProductsGroupByTitle = []; |
|
|
|
$products = $this->getProducts(); |
|
|
|
|
|
|
|
foreach($products as $product) { |
|
|
|
$titleProduct = $product->getTitleInherited() ; |
|
|
|
if(!isset($arrayProductsGroupByTitle[$titleProduct])) { |
|
|
|
$arrayProductsGroupByTitle[$titleProduct] = [] ; |
|
|
|
foreach ($products as $product) { |
|
|
|
$titleProduct = $product->getTitleInherited(); |
|
|
|
if (!isset($arrayProductsGroupByTitle[$titleProduct])) { |
|
|
|
$arrayProductsGroupByTitle[$titleProduct] = []; |
|
|
|
} |
|
|
|
$arrayProductsGroupByTitle[$titleProduct][] = $product ; |
|
|
|
$arrayProductsGroupByTitle[$titleProduct][] = $product; |
|
|
|
} |
|
|
|
|
|
|
|
return $arrayProductsGroupByTitle ; |
|
|
|
return $arrayProductsGroupByTitle; |
|
|
|
} |
|
|
|
} |