$this->innerJoin('.products', 'products'); | $this->innerJoin('.products', 'products'); | ||||
if ($addSelect) { | if ($addSelect) { | ||||
// Décommenté sinon doctrine n'hydrate pas correctement les produits liés au ProductFamily (exemple : un seul sur deux) | // Décommenté sinon doctrine n'hydrate pas correctement les produits liés au ProductFamily (exemple : un seul sur deux) | ||||
// $this->addSelect('products'); | |||||
//$this->addSelect('products'); | |||||
} | } | ||||
} | } | ||||
return $this; | return $this; |
} | } | ||||
} | } | ||||
public function getCheapestProduct(ProductFamilyInterface $productFamily, OrderShopInterface $orderShop) | |||||
public function getCheapestProduct(ProductFamilyInterface $productFamily, OrderShopInterface $orderShop = null) | |||||
{ | { | ||||
$priceSolver = $this->priceSolver; | $priceSolver = $this->priceSolver; | ||||
); | ); | ||||
} | } | ||||
public function getCheapestProductByRefUnit(ProductFamilyInterface $productFamily, OrderShopInterface $orderShop) | |||||
public function getCheapestProductByRefUnit(ProductFamilyInterface $productFamily, OrderShopInterface $orderShop = null) | |||||
{ | { | ||||
$priceSolver = $this->priceSolver; | $priceSolver = $this->priceSolver; | ||||
); | ); | ||||
} | } | ||||
public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily, OrderShopInterface $orderShop) | |||||
public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily, OrderShopInterface $orderShop = null) | |||||
{ | { | ||||
$priceSolver = $this->priceSolver; | $priceSolver = $this->priceSolver; | ||||
ProductFamilyInterface $productFamily, | ProductFamilyInterface $productFamily, | ||||
$comparisonFunction, | $comparisonFunction, | ||||
$returnSelfIfNotActiveProducts, | $returnSelfIfNotActiveProducts, | ||||
OrderShopInterface $orderShop | |||||
OrderShopInterface $orderShop = null | |||||
) | ) | ||||
{ | { | ||||
if ($productFamily->getActiveProducts()) { | if ($productFamily->getActiveProducts()) { | ||||
if (count($products) > 0) { | if (count($products) > 0) { | ||||
usort($products, $comparisonFunction); | usort($products, $comparisonFunction); | ||||
foreach ($products as $product) { | |||||
if ($this->orderShopSolver->isProductAvailable($orderShop->getSection(), $orderShop, $product, 1, true)) { | |||||
return $product; | |||||
if($orderShop) { | |||||
foreach ($products as $product) { | |||||
if ($this->orderShopSolver->isProductAvailable($orderShop->getSection(), $orderShop, $product, 1, true)) { | |||||
return $product; | |||||
} | |||||
} | } | ||||
} | } | ||||
// isProductAvailable | // isProductAvailable | ||||
public function isProductAvailable( | public function isProductAvailable( | ||||
SectionInterface $section, | SectionInterface $section, | ||||
OrderShopInterface $orderShop, | |||||
?OrderShopInterface $orderShop, | |||||
ProductInterface $product, | ProductInterface $product, | ||||
int $quantityOrder = 0, | int $quantityOrder = 0, | ||||
bool $checkCart = false | bool $checkCart = false | ||||
} | } | ||||
} | } | ||||
public function isOneProductAvailable(SectionInterface $section, $productArray): bool | |||||
{ | |||||
foreach($productArray as $product) { | |||||
if($this->isProductAvailable($section, null, $product, 1, false)) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
public function isOneProductAvailableAddCart(OrderShopInterface $orderShop, $products): bool | public function isOneProductAvailableAddCart(OrderShopInterface $orderShop, $products): bool | ||||
{ | { | ||||
foreach ($products as $product) { | foreach ($products as $product) { |
public function getProductFamilySectionProperty(ProductFamilyInterface $productFamily, SectionInterface $section):? ProductFamilySectionPropertyInterface | public function getProductFamilySectionProperty(ProductFamilyInterface $productFamily, SectionInterface $section):? ProductFamilySectionPropertyInterface | ||||
{ | { | ||||
foreach ($productFamily->getProductFamilySectionProperties() as $productFamilySectionProperty) { | foreach ($productFamily->getProductFamilySectionProperties() as $productFamilySectionProperty) { | ||||
if ($productFamilySectionProperty->getSection() === $section) { | |||||
if ($productFamilySectionProperty->getSection()->getId() == $section->getId()) { | |||||
return $productFamilySectionProperty; | return $productFamilySectionProperty; | ||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||