Browse Source

Refactoring services #885

refactoring
Guillaume 1 year ago
parent
commit
e9fa4802fd
8 changed files with 129 additions and 220 deletions
  1. +42
    -41
      backend/controllers/PointSaleController.php
  2. +26
    -85
      backend/controllers/ProducerAdminController.php
  3. +6
    -21
      backend/controllers/ProducerController.php
  4. +22
    -31
      backend/controllers/ProducerPriceRangeAdminController.php
  5. +21
    -30
      backend/controllers/ProductCategoryController.php
  6. +0
    -12
      backend/controllers/ProductController.php
  7. +7
    -0
      common/logic/Producer/ProducerPriceRange/ProducerPriceRangeRepository.php
  8. +5
    -0
      common/logic/Product/ProductCategory/ProductCategoryRepository.php

+ 42
- 41
backend/controllers/PointSaleController.php View File



namespace backend\controllers; namespace backend\controllers;


use common\helpers\GlobalParam;
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution;
use common\logic\Order\Order\Order;
use common\logic\PointSale\PointSale\PointSale; use common\logic\PointSale\PointSale\PointSale;
use common\logic\PointSale\PointSale\PointSaleSearch; use common\logic\PointSale\PointSale\PointSaleSearch;
use common\logic\PointSale\UserPointSale\UserPointSale;
use Yii; use Yii;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\helpers\Html; use yii\helpers\Html;


/**
* PointVenteController implements the CRUD actions for PointVente model.
*/
class PointSaleController extends BackendController class PointSaleController extends BackendController
{ {

public function behaviors() public function behaviors()
{ {
return [ return [


/** /**
* Liste les points de vente. * Liste les points de vente.
*
* @return mixed
*/ */
public function actionIndex() public function actionIndex()
{ {
*/ */
public function actionCreate() public function actionCreate()
{ {
$model = new PointSale();
$pointSaleManager = $this->getPointSaleManager();
$distributionManager = $this->getDistributionManager();

$pointSale = $pointSaleManager->instanciatePointSale();

if ($pointSale->load(\Yii::$app->request->post()) && $pointSale->save()) {
$pointSaleManager->updatePointSalePointProduction($pointSale);
$pointSaleManager->processRestrictedAccess($pointSale);
$distributionManager->addPointSaleIncomingDistributions($pointSale);


if ($model->load(\Yii::$app->request->post()) && $model->save()) {
$model->processPointProduction();
$model->processRestrictedAccess();
DistributionModel::linkPointSaleIncomingDistributions($model);
return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('create', array_merge($this->initForm(), [ return $this->render('create', array_merge($this->initForm(), [
'model' => $model,
'model' => $pointSale,
])); ]));
} }
} }


/** /**
* Modifie un point de vente. * Modifie un point de vente.
*
* @param integer $id
* @return mixed
*/ */
public function actionUpdate($id)
public function actionUpdate(int $id)
{ {
$distributionManager = $this->getDistributionManager();
$pointSaleManager = $this->getPointSaleManager();

$model = PointSale::find() $model = PointSale::find()
->with('userPointSale') ->with('userPointSale')
->where(['id' => $id]) ->where(['id' => $id])
} }


if ($model->load(\Yii::$app->request->post()) && $model->save()) { if ($model->load(\Yii::$app->request->post()) && $model->save()) {
$model->processPointProduction();
$model->processRestrictedAccess();
DistributionModel::linkPointSaleIncomingDistributions($model);

$pointSaleManager->updatePointSalePointProduction($model);
$pointSaleManager->processRestrictedAccess($model);
$distributionManager->addPointSaleIncomingDistributions($model);

$this->setFlash('success', 'Point de vente modifié.'); $this->setFlash('success', 'Point de vente modifié.');

return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('update', array_merge($this->initForm($id), [ return $this->render('update', array_merge($this->initForm($id), [


/** /**
* Initialise le formulaire de création/modification. * Initialise le formulaire de création/modification.
*
* @param integer $id
* @return mixed
*/ */
public function initForm($id = 0)
public function initForm(int $id = 0)
{ {
$users = User::findBy()
$userManager = $this->getUserManager();

$users = $userManager->queryUsersBy()
->leftJoin('user_point_sale', 'user_point_sale.id_user = user.id AND user_point_sale.id_point_sale = :id_point_sale', [':id_point_sale' => $id]) ->leftJoin('user_point_sale', 'user_point_sale.id_user = user.id AND user_point_sale.id_point_sale = :id_point_sale', [':id_point_sale' => $id])
->orderBy('user_point_sale.id_point_sale DESC, lastname ASC, name ASC') ->orderBy('user_point_sale.id_point_sale DESC, lastname ASC, name ASC')
->all(); ->all();


/** /**
* Supprime un point de vente et redirige vers la liste des points de vente. * Supprime un point de vente et redirige vers la liste des points de vente.
*
* @param integer $id
* @return mixed
*/ */
public function actionDelete($id, $confirm = false)
public function actionDelete(int $id, $confirm = false)
{ {
$orderManager = $this->getOrderManager();
$distributionManager = $this->getDistributionManager();

$pointSale = $this->findModel($id); $pointSale = $this->findModel($id);


if ($confirm) { if ($confirm) {
UserPointSale::deleteAll(['id_point_sale' => $id]); UserPointSale::deleteAll(['id_point_sale' => $id]);


// Suppression du lien PointSaleDistribution pour toutes les distributions à venir // Suppression du lien PointSaleDistribution pour toutes les distributions à venir
$incomingDistributions = DistributionModel::getIncoming();
$incomingDistributions = $distributionManager->findDistributionsIncoming();
foreach ($incomingDistributions as $distribution) { foreach ($incomingDistributions as $distribution) {
PointSaleDistributionModel::deleteAll(['id_point_sale' => $id, 'id_distribution' => $distribution->id]);
PointSaleDistribution::deleteAll(['id_point_sale' => $id, 'id_distribution' => $distribution->id]);
} }


// Suppression de toutes les commandes à venir de ce point de vente // Suppression de toutes les commandes à venir de ce point de vente


if ($ordersArray) { if ($ordersArray) {
foreach ($ordersArray as $order) { foreach ($ordersArray as $order) {
$order->delete(true);
$orderManager->deleteOrder($order, true);
} }
} }




/** /**
* Définit un point de vente par défaut. * Définit un point de vente par défaut.
*
* @param integer $id
*/ */
public function actionDefault($id)
public function actionDefault(int $id)
{ {
$pointSaleManager = $this->getPointSaleManager();

$pointSale = $this->findModel($id); $pointSale = $this->findModel($id);
if ($pointSale) { if ($pointSale) {
PointSale::updateAll(['default' => 0], 'id_producer = :id_producer', [':id_producer' => GlobalParam::getCurrentProducerId()]); PointSale::updateAll(['default' => 0], 'id_producer = :id_producer', [':id_producer' => GlobalParam::getCurrentProducerId()]);

if (!$pointSale->default) { if (!$pointSale->default) {
$pointSale->default = 1; $pointSale->default = 1;
$pointSale->save();
$pointSaleManager->saveUpdate($pointSale);

$this->setFlash('success', 'Point de vente <strong>' . Html::encode($pointSale->name) . '</strong> défini par défaut.'); $this->setFlash('success', 'Point de vente <strong>' . Html::encode($pointSale->name) . '</strong> défini par défaut.');
} else { } else {
$this->setFlash('success', 'Aucun point de vente défini par défaut'); $this->setFlash('success', 'Aucun point de vente défini par défaut');


/** /**
* Recherche un point de vente en fonction de son ID. * Recherche un point de vente en fonction de son ID.
*
* @param integer $id
* @return PointVente
* @throws NotFoundHttpException si le modèle n'est pas trouvé
*/ */
protected function findModel($id)
protected function findModel(int $id)
{ {
if (($model = PointSale::findOne($id)) !== null) { if (($model = PointSale::findOne($id)) !== null) {
return $model; return $model;
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');
} }
} }

} }

+ 26
- 85
backend/controllers/ProducerAdminController.php View File



namespace backend\controllers; namespace backend\controllers;


use common\helpers\GlobalParam;
use common\logic\Order\Order\Order;
use common\logic\Producer\Producer\Producer;
use common\logic\Product\Product\Product;
use Yii; use Yii;
use common\models\ User;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\filters\AccessControl; use yii\filters\AccessControl;
*/ */
class ProducerAdminController extends BackendController class ProducerAdminController extends BackendController
{ {

public function behaviors() public function behaviors()
{ {
return [ return [
*/ */
public function actionIndex() public function actionIndex()
{ {
$producerManager = $this->getProducerManager();

$dataProviderProducer = new ActiveDataProvider([ $dataProviderProducer = new ActiveDataProvider([
'query' => Producer::find() 'query' => Producer::find()
->with('userProducer', 'user') ->with('userProducer', 'user')
], ],
]); ]);


$producersArray = Producer::find()->where('active = 1')->all();

$producersArray = $producerManager->findProducersActive();
$sumPrices = 0; $sumPrices = 0;
foreach ($producersArray as $producer) { foreach ($producersArray as $producer) {
$sumPrices += $producer->getAmountBilledLastMonth();
$sumPrices += $producerManager->getAmountBilledLastMonth($producer);
} }


return $this->render('index', [ return $this->render('index', [


/** /**
* Crée un producteur. * Crée un producteur.
*
* @return mixed
*/ */
public function actionCreate() public function actionCreate()
{ {
$model = new Producer();
$producerManager = $this->getProducerManager();
$producer = $producerManager->instanciateProducer();


if ($model->load(\Yii::$app->request->post()) && $model->save()) {
if ($producer->load(\Yii::$app->request->post()) && $producerManager->saveCreate($producer)) {
$this->setFlash('success', 'Producteur créé.'); $this->setFlash('success', 'Producteur créé.');
return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('create', [ return $this->render('create', [
'model' => $model,
'model' => $producer,
]); ]);
} }
} }


/** /**
* Modification d'un producteur. * Modification d'un producteur.
*
* @return mixed
*/ */
public function actionUpdate($id)
public function actionUpdate(int $id)
{ {
$model = $this->findModel($id);
$producerManager = $this->getProducerManager();
$producer = $this->findModel($id);


if ($model->load(\Yii::$app->request->post()) && $model->save()) {
if ($producer->load(\Yii::$app->request->post()) && $producerManager->saveCreate($producer)) {
$this->setFlash('success', 'Producteur modifié.'); $this->setFlash('success', 'Producteur modifié.');
return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('update', [ return $this->render('update', [
'model' => $model,
'model' => $producer,
]); ]);
} }
} }


public function actionUserTransfer($fromProducerId, $toProducerId, $withOrders = 1) public function actionUserTransfer($fromProducerId, $toProducerId, $withOrders = 1)
{ {
$producerManager = $this->getProducerManager();
$userManager = $this->getUserManager();

$fromProducerId = (int)$fromProducerId; $fromProducerId = (int)$fromProducerId;
$toProducerId = (int)$toProducerId; $toProducerId = (int)$toProducerId;
$count = 0; $count = 0;
$usersArray = User::findBy(['id_producer' => $fromProducerId])->all();
$usersArray = $userManager->queryUsersBy(['id_producer' => $fromProducerId])->all();


foreach ($usersArray as $user) { foreach ($usersArray as $user) {
$idUser = $user['user_id']; $idUser = $user['user_id'];
} }


if (($withOrders && $countOrders) || !$withOrders) { if (($withOrders && $countOrders) || !$withOrders) {
Producer::addUser($idUser, $toProducerId);
$producerManager->addUser(
$userManager->findOneUserById($idUser),
$producerManager->findOneProducerById($toProducerId)
);
$count++; $count++;
} }
} }
return $this->redirect(['producer-admin/index']); return $this->redirect(['producer-admin/index']);
} }


/**
* Génère la facture mensuelle d'un producteur.
*
* @param integer $idProducer
*/
public function actionBill($idProducer)
{
$producer = Producer::findOne($idProducer);

if ($producer) {
$period = date('Y-m', strtotime('-1 month'));

$last_invoice = Invoice::getLastInvoice();
if (!$last_invoice) {
$reference = 'BAP000001';
} else {
$reference = str_replace('BAP', '', $last_invoice->reference);
$reference++;
$reference = 'BAP' . $reference;
}

$invoice = new Invoice;
$invoice->id_producer = $idProducer;
$invoice->date = date('Y-m-d H:i:s');
$invoice->reference = $reference;
$invoice->turnover = $producer->getTurnover($period);
$invoice->amount_ht = $producer->getFreePrice();
$invoice->wording = 'Facture ' . date('m/Y', strtotime('-1 month'));
$invoice->text = 'Utilisation de la plateforme <strong>distrib</strong> pour le mois : ' . date('m/Y', strtotime('-1 month')) . '<br />'
. 'Chiffre d\'affaire réalisé sur la plateforme : <strong>' . number_format($facture->ca, 2) . ' €</strong> commissionné à <strong>1%</strong>.';
$invoice->paid = 0;
$invoice->period = $period;
$invoice->save();
}

$this->redirect(['producer-admin/index']);
}

/**
* Liste les factures des producteurs.
*
* @return mxied
*/
public function actionBilling()
{
$dataProviderInvoice = new ActiveDataProvider([
'query' => Invoice::find()
->with('producer')
->orderBy('reference DESC'),
'pagination' => [
'pageSize' => 1000,
],
]);

return $this->render('billing', [
'dataProviderInvoice' => $dataProviderInvoice,
]);
}

public function actionProducerInstallTaxUpdatePrices($idProducer) public function actionProducerInstallTaxUpdatePrices($idProducer)
{ {
// product
$productsArray = Product::searchAll([ $productsArray = Product::searchAll([
'id_producer' => $idProducer 'id_producer' => $idProducer
]); ]);
} }


/** /**
* Recherche un établissement.
*
* @param integer $id
* @return Etablissement
* @throws NotFoundHttpException
* Recherche un producteur.
*/ */
protected function findModel($id)
protected function findModel(int $id)
{ {
if (($model = Producer::findOne($id)) !== null) { if (($model = Producer::findOne($id)) !== null) {
return $model; return $model;

+ 6
- 21
backend/controllers/ProducerController.php View File

namespace backend\controllers; namespace backend\controllers;


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Producer\Producer\Producer;
use common\logic\Producer\ProducerPriceRange\ProducerPriceRange;
use Yii; use Yii;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;


/** /**
* Modifie un producteur. * Modifie un producteur.
*
* @return mixed
*/ */
public function actionUpdate() public function actionUpdate()
{ {
/** /**
* Affiche le formulaire permettant au producteur de définir le montant * Affiche le formulaire permettant au producteur de définir le montant
* de son abonnement. * de son abonnement.
*
* @return mixed
*/ */
public function actionBilling() public function actionBilling()
{ {
$datasInvoices = new ActiveDataProvider([
'query' => Invoice::find()
->where(['id_producer' => GlobalParam::getCurrentProducerId()])
->orderBy('reference DESC'),
'pagination' => [
'pageSize' => 1000,
],
]);

$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); $producer = Producer::findOne(GlobalParam::getCurrentProducerId());


if ($producer->load(\Yii::$app->request->post())) { if ($producer->load(\Yii::$app->request->post())) {


return $this->render('billing', [ return $this->render('billing', [
'dataProviderPrices' => $dataProviderPrices, 'dataProviderPrices' => $dataProviderPrices,
'datasInvoices' => $datasInvoices,
'producer' => $producer, 'producer' => $producer,
'alertFreePrice' => (isset($alertFreeprice)) ? true : false 'alertFreePrice' => (isset($alertFreeprice)) ? true : false
]); ]);


/** /**
* Recherche un établissement via son ID. * Recherche un établissement via son ID.
*
* @param integer $id
* @return Etablissement
* @throws NotFoundHttpException
*/ */
protected function findModel($id)
protected function findModel(int $id)
{ {
if (($model = Producer::findOne($id)) !== null) { if (($model = Producer::findOne($id)) !== null) {
return $model; return $model;


public function actionUpdateOpendistribVersion() public function actionUpdateOpendistribVersion()
{ {
$producer = GlobalParam::getCurrentProducer();
$producer->updateOpendistribVersion();
$producerManager = $this->getProducerManager();
$producerManager->updateOpendistribVersion(GlobalParam::getCurrentProducer());

return $this->redirect(\Yii::$app->request->referrer); return $this->redirect(\Yii::$app->request->referrer);
} }
} }

+ 22
- 31
backend/controllers/ProducerPriceRangeAdminController.php View File



namespace backend\controllers; namespace backend\controllers;


use common\logic\Producer\ProducerPriceRange\ProducerPriceRange;
use Yii; use Yii;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;


/** /**
* TaxRateAdminController implements the CRUD actions for TaxRate model.
* ProducerPriceRangeAdminController implements the CRUD actions for ProducerPriceRange model.
*/ */
class ProducerPriceRangeAdminController extends BackendController class ProducerPriceRangeAdminController extends BackendController
{ {

public function behaviors() public function behaviors()
{ {
return [ return [


/** /**
* Liste les tranches de prix. * Liste les tranches de prix.
*
* @return mixed
*/ */
public function actionIndex() public function actionIndex()
{ {


/** /**
* Crée une tranche de prix. * Crée une tranche de prix.
*
* @return mixed
*/ */
public function actionCreate() public function actionCreate()
{ {
$model = new ProducerPriceRange();
$producerPriceRangeManager = $this->getProducerPriceRangeManager();
$producerPriceRange = $producerPriceRangeManager->instanciateProducerPriceRange();

if ($producerPriceRange->load(\Yii::$app->request->post())
&& $producerPriceRangeManager->saveCreate($producerPriceRange)) {


if ($model->load(\Yii::$app->request->post()) && $model->save()) {
$this->setFlash('success', 'Tranche de prix créée.'); $this->setFlash('success', 'Tranche de prix créée.');

return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('create', [ return $this->render('create', [
'model' => $model,
'model' => $producerPriceRange,
]); ]);
} }
} }


/** /**
* Édition d'une tranche de prix. * Édition d'une tranche de prix.
*
* @return mixed
*/ */
public function actionUpdate($id)
public function actionUpdate(int $id)
{ {
$model = $this->findModel($id);
$producerPriceRangeManager = $this->getProducerPriceRangeManager();
$producerPriceRange = $this->findModel($id);


if ($model->load(\Yii::$app->request->post()) && $model->save()) {
if ($producerPriceRange->load(\Yii::$app->request->post()) && $producerPriceRangeManager->saveUpdate($producerPriceRange)) {
$this->setFlash('success', 'Tranche de prix éditée.'); $this->setFlash('success', 'Tranche de prix éditée.');
return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('update', [ return $this->render('update', [
'model' => $model,
'model' => $producerPriceRange,
]); ]);
} }
} }


/** /**
* Supprime une tranche de prix. * Supprime une tranche de prix.
*
* @param integer $id
*/ */
public function actionDelete($id)
public function actionDelete(int $id)
{ {
$producerPriceRange = ProducerPriceRange::searchOne([
'id' => $id
]);
$producerPriceRange->delete();
$producerPriceRangeManager = $this->getProducerPriceRangeManager();


$producerPriceRange = $this->findModel($id);
$producerPriceRangeManager->delete($producerPriceRange);
$this->setFlash('success', 'Tranche de prix supprimée.'); $this->setFlash('success', 'Tranche de prix supprimée.');

return $this->redirect(['producer-price-range-admin/index']); return $this->redirect(['producer-price-range-admin/index']);
} }


/**
* Finds the Developpement model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return ProducerPriceRange the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) protected function findModel($id)
{ {
if (($model = ProducerPriceRange::findOne($id)) !== null) {
return $model;
$producerPriceRangeManager = $this->getProducerPriceRangeManager();
if (($producerPriceRange = $producerPriceRangeManager->findOneProducerPriceRangeById($id)) !== null) {
return $producerPriceRange;
} else { } else {
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');
} }

+ 21
- 30
backend/controllers/ProductCategoryController.php View File

namespace backend\controllers; namespace backend\controllers;


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Product\Product\Product;
use common\logic\Product\ProductCategory\ProductCategorySearch;
use Yii; use Yii;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\helpers\Html; use yii\helpers\Html;


/** /**
* PointVenteController implements the CRUD actions for PointVente model.
* ProductCategoryController implements the CRUD actions for ProductCategory model.
*/ */
class ProductCategoryController extends BackendController class ProductCategoryController extends BackendController
{ {
} }


/** /**
* Liste les points de vente.
*
* @return mixed
* Liste les catégories.
*/ */
public function actionIndex() public function actionIndex()
{ {


/** /**
* Crée une catégorie. * Crée une catégorie.
*
* @return mixed
*/ */
public function actionCreate() public function actionCreate()
{ {
$model = new ProductCategory();
$productCategoryManager = $this->getProductCategoryManager();
$productCategory = $productCategoryManager->instanciateProductCategory();


$model->id_producer = GlobalParam::getCurrentProducerId();
$productCategory->id_producer = GlobalParam::getCurrentProducerId();


if ($model->load(\Yii::$app->request->post()) && $model->save()) {
if ($productCategory->load(\Yii::$app->request->post()) && $productCategoryManager->saveCreate($productCategory)) {
$this->setFlash('success', "Catégorie ajoutée."); $this->setFlash('success', "Catégorie ajoutée.");
return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('create', [ return $this->render('create', [
'model' => $model,
'model' => $productCategory,
]); ]);
} }
} }


/** /**
* Modifie une catégorie. * Modifie une catégorie.
*
* @param integer $id
* @return mixed
*/ */
public function actionUpdate($id)
public function actionUpdate(int $id)
{ {
$model = $this->findModel($id);
$productCategoryManager = $this->getProductCategoryManager();
$productCategory = $this->findModel($id);


if ($model->load(\Yii::$app->request->post()) && $model->save()) {
if ($productCategory->load(\Yii::$app->request->post()) && $productCategoryManager->saveUpdate($productCategory)) {
$this->setFlash('success', "Catégorie modifiée."); $this->setFlash('success', "Catégorie modifiée.");
return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('update', [ return $this->render('update', [
'model' => $model,
'model' => $productCategory,
]); ]);
} }
} }


/** /**
* Supprime une catégorie
*
* @param integer $id
* @return mixed
* Supprime une catégorie.
*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
$productCategoryManager = $this->getProductCategoryManager();
$productCategory = $this->findModel($id); $productCategory = $this->findModel($id);


$productCategory->delete();
$productCategoryManager->delete($productCategory);
Product::updateAll(['id_product_category' => null], ['id_product_category' => $id]); Product::updateAll(['id_product_category' => null], ['id_product_category' => $id]);

$this->setFlash('success', 'Catégorie <strong>' . Html::encode($productCategory->name) . '</strong> supprimée.'); $this->setFlash('success', 'Catégorie <strong>' . Html::encode($productCategory->name) . '</strong> supprimée.');


return $this->redirect(['index']); return $this->redirect(['index']);


/** /**
* Modifie l'ordre des catégories. * Modifie l'ordre des catégories.
*
* @param array $array
*/ */
public function actionPosition() public function actionPosition()
{ {


/** /**
* Recherche une catégorie en fonction de son ID. * Recherche une catégorie en fonction de son ID.
*
* @param integer $id
* @return ProductCategory
* @throws NotFoundHttpException si le modèle n'est pas trouvé
*/ */
protected function findModel($id) protected function findModel($id)
{ {
if (($model = ProductCategory::findOne($id)) !== null) {
return $model;
$productCategoryManager = $this->getProductCategoryManager();
if (($productCategory = $productCategoryManager->findOneProductCategoryById($id)) !== null) {
return $productCategory;
} else { } else {
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');
} }

+ 0
- 12
backend/controllers/ProductController.php View File

namespace backend\controllers; namespace backend\controllers;


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\models\ProductDistribution;
use common\models\ProductPrice;
use common\models\ProductPriceSearch;
use common\models\ProductSearch;
use common\models\ UserSearch;
use Yii; use Yii;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use common\models\Product;
use common\models\Distribution;
use common\models\ User;
use common\logic\UserProducer\ UserProducer;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use common\helpers\Upload; use common\helpers\Upload;


/** /**

+ 7
- 0
common/logic/Producer/ProducerPriceRange/ProducerPriceRangeRepository.php View File

]; ];
} }


public function findOneProducerPriceRangeById(int $id)
{
return ProducerPriceRange::searchOne([
'id' => $id
]);
}

public function queryProducerPriceRanges() public function queryProducerPriceRanges()
{ {
return ProducerPriceRange::find()->orderBy('range_begin ASC'); return ProducerPriceRange::find()->orderBy('range_begin ASC');

+ 5
- 0
common/logic/Product/ProductCategory/ProductCategoryRepository.php View File

]; ];
} }


public function findOneProductCategoryById(int $id)
{
return ProductCategory::searchOne(['id' => $id]);
}

public function findProductCategories() public function findProductCategories()
{ {
return ProductCategory::searchAll([], ['orderby' => 'product_category.position ASC']); return ProductCategory::searchAll([], ['orderby' => 'product_category.position ASC']);

Loading…
Cancel
Save