Przeglądaj źródła

[Espace producteur] Accueil : enlever produits présents uniquement sur un point de vente à accès restreint #909

feature/souke
Guillaume Bourgeois 1 rok temu
rodzic
commit
e47168ab00
3 zmienionych plików z 35 dodań i 3 usunięć
  1. +7
    -0
      common/logic/PointSale/PointSale/Service/PointSaleSolver.php
  2. +19
    -0
      common/logic/Product/Product/Service/ProductSolver.php
  3. +9
    -3
      producer/controllers/SiteController.php

+ 7
- 0
common/logic/PointSale/PointSale/Service/PointSaleSolver.php Wyświetl plik

@@ -82,5 +82,12 @@ class PointSaleSolver extends AbstractService implements SolverInterface
return $str;
}

public function isPublic(PointSale $pointSale): bool
{
if($pointSale->restricted_access || ($pointSale->code && strlen($pointSale->code))) {
return false;
}

return true;
}
}

+ 19
- 0
common/logic/Product/Product/Service/ProductSolver.php Wyświetl plik

@@ -6,6 +6,7 @@ use common\helpers\GlobalParam;
use common\helpers\Price;
use common\logic\AbstractService;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\PointSale\Service\PointSaleSolver;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\ProductPrice\Service\ProductPriceSolver;
use common\logic\SolverInterface;
@@ -13,10 +14,12 @@ use common\logic\SolverInterface;
class ProductSolver extends AbstractService implements SolverInterface
{
protected ProductPriceSolver $productPriceSolver;
protected PointSaleSolver $pointSaleSolver;

public function loadDependencies(): void
{
$this->productPriceSolver = $this->loadService(ProductPriceSolver::class);
$this->pointSaleSolver = $this->loadService(PointSaleSolver::class);
}

public function getPrice(Product $product, array $params = []): ?float
@@ -211,4 +214,20 @@ class ProductSolver extends AbstractService implements SolverInterface
return $quantityMax;
}

public function isPublic(Product $product): bool
{
if($product->available_on_points_sale) {
return true;
}
else {
foreach($product->productPointSale as $productPointSale) {
if($productPointSale->pointSale && $this->pointSaleSolver->isPublic($productPointSale->pointSale)) {
return true;
}
}
}

return false;
}
}

+ 9
- 3
producer/controllers/SiteController.php Wyświetl plik

@@ -118,6 +118,7 @@ class SiteController extends ProducerBaseController
'active' => true,
'id_product_category' => null,
])
->with('productPointSale')
->orderBy('order ASC');

$dataProviderProducts = new ActiveDataProvider([
@@ -128,6 +129,14 @@ class SiteController extends ProducerBaseController
'sort' => false,
]);

$models = $dataProviderProducts->getModels();
foreach($models as $index => $product) {
if(!$productManager->isPublic($product)) {
unset($models[$index]);
}
}
$dataProviderProducts->setModels($models);

$products = $queryProducts->all();
foreach ($dataProviderProductsByCategories as $dataProvider) {
$products = array_merge(
@@ -173,9 +182,6 @@ class SiteController extends ProducerBaseController
if (strlen($email) && $model->sendEmail($email)) {
$isSent = true;
}
else {
die('email : '.$email);
}
}

if ($isSent) {

Ładowanie…
Anuluj
Zapisz