Bladeren bron

Refactoring services #885

refactoring
Guillaume 1 jaar geleden
bovenliggende
commit
6a97f779ae
7 gewijzigde bestanden met toevoegingen van 49 en 24 verwijderingen
  1. +2
    -2
      common/helpers/Opendistrib.php
  2. +15
    -0
      common/logic/Order/Order/Repository/OrderRepository.php
  3. +0
    -15
      common/logic/Order/Order/Service/OrderSolver.php
  4. +1
    -1
      common/logic/Producer/Producer/Service/ProducerBuilder.php
  5. +8
    -1
      common/logic/Product/Product/Repository/ProductRepository.php
  6. +18
    -0
      common/logic/Product/ProductPrice/Service/ProductPriceSolver.php
  7. +5
    -5
      producer/controllers/OrderController.php

+ 2
- 2
common/helpers/Opendistrib.php Bestand weergeven

@@ -43,7 +43,7 @@ class Opendistrib
public static function getVersions()
{
$versionsArray = [];
$pathVersions = Yii::getAlias('@common/versions');
$pathVersions = \Yii::getAlias('@common/versions');

if(is_dir($pathVersions))
{
@@ -56,7 +56,7 @@ class Opendistrib
}
}

krsort($versionsArray);
ksort($versionsArray);

return $versionsArray;
}

+ 15
- 0
common/logic/Order/Order/Repository/OrderRepository.php Bestand weergeven

@@ -252,6 +252,21 @@ class OrderRepository extends AbstractRepository
return Order::STATE_PREPARATION;
}

public function isOrderStateOpen(Order $order): bool
{
return Order::STATE_OPEN == $this->getState($order);
}

public function isOrderStatePreparation(Order $order): bool
{
return Order::STATE_PREPARATION == $this->getState($order);
}

public function isOrderStateDelivered(Order $order): bool
{
return Order::STATE_DELIVERED == $this->getState($order);
}

public function findOneOrderLastOfYear(Producer $producer)
{
return Order::find()->innerJoinWith('distribution', true)

+ 0
- 15
common/logic/Order/Order/Service/OrderSolver.php Bestand weergeven

@@ -361,21 +361,6 @@ class OrderSolver extends AbstractService implements SolverInterface
}
}

public function isOrderStateOpen(Order $order): bool
{
return Order::STATE_OPEN == $order->getState();
}

public function isOrderStatePreparation(Order $order): bool
{
return Order::STATE_PREPARATION == $order->getState();
}

public function isOrderStateDelivered(Order $order): bool
{
return Order::STATE_DELIVERED == $order->getState();
}

// belongsToUser
public function isOrderBelongsToUser(Order $order, User $user = null): bool
{

+ 1
- 1
common/logic/Producer/Producer/Service/ProducerBuilder.php Bestand weergeven

@@ -80,7 +80,7 @@ class ProducerBuilder extends AbstractBuilder
public function updateOpendistribVersion(Producer $producer): void
{
$versionsArray = Opendistrib::getVersions();
$producer->latest_version_opendistrib = array_values($versionsArray)[0];
$producer->latest_version_opendistrib = $versionsArray[0];

$this->saveUpdate($producer);
}

+ 8
- 1
common/logic/Product/Product/Repository/ProductRepository.php Bestand weergeven

@@ -66,7 +66,7 @@ class ProductRepository extends AbstractRepository
// getByDistribution
public function findProductsByDistribution(Distribution $distribution)
{
return Product::find()
$productArray = Product::find()
->leftJoin('product_distribution', 'product.id = product_distribution.id_product')
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
@@ -74,6 +74,13 @@ class ProductRepository extends AbstractRepository
])
->orderBy('product_distribution.active DESC, product.order ASC')
->all();

$productArrayById = [];
foreach($productArray as $product) {
$productArrayById[$product->id] = $product;
}

return $productArrayById;
}

// queryByProductCategory

+ 18
- 0
common/logic/Product/ProductPrice/Service/ProductPriceSolver.php Bestand weergeven

@@ -8,6 +8,7 @@ use common\logic\Product\ProductPrice\Model\ProductPrice;
use common\logic\SolverInterface;
use common\logic\User\User\Model\User;
use common\logic\User\User\Service\UserSolver;
use common\logic\User\UserGroup\Model\UserGroup;

class ProductPriceSolver extends AbstractService implements SolverInterface
{
@@ -87,8 +88,17 @@ class ProductPriceSolver extends AbstractService implements SolverInterface

public function matchUserGroup(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool
{
// @TODO : trouver une solution pour hydrater autrement cette donnée
if($productPrice->id_user_group && !$productPrice->userGroup) {
$userGroup = UserGroup::searchOne(['id' => $productPrice->id_user_group]);
if($userGroup) {
$productPrice->populateUserGroup($userGroup);
}
}

return $user
&& $productPrice->id_user_group
&& $productPrice->userGroup
&& !$productPrice->id_point_sale
&& !$productPrice->id_user
&& $this->userSolver->isUserBelongsToUserGroup($user, $productPrice->userGroup);
@@ -114,6 +124,14 @@ class ProductPriceSolver extends AbstractService implements SolverInterface

public function matchUserGroupPointSale(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool
{
// @TODO : trouver une solution pour hydrater autrement cette donnée
if($productPrice->id_user_group && !$productPrice->userGroup) {
$userGroup = UserGroup::searchOne(['id' => $productPrice->id_user_group]);
if($userGroup) {
$productPrice->populateUserGroup($userGroup);
}
}

return $user
&& $pointSale
&& $productPrice->id_user_group

+ 5
- 5
producer/controllers/OrderController.php Bestand weergeven

@@ -93,7 +93,7 @@ class OrderController extends ProducerBaseController
public function actionHistory($type = 'incoming')
{
$queryHistoryArray = $this->getOrderManager()
->queryOrdersHistory($this->getProducerCurrent(), $this->getUserCurrent(), $type);
->queryOrdersHistory($this->getProducerCurrent(), $this->getUserCurrent());
$queryHistoryIncoming = $queryHistoryArray['incoming'];
$queryHistoryPassed = $queryHistoryArray['passed'];

@@ -405,7 +405,7 @@ class OrderController extends ProducerBaseController
$quantity = $availableProducts[$product->id]['quantity_remaining'];
}
$productOrder->quantity = $quantity;
$productOrder->price = $product->getPrice([
$productOrder->price = $productManager->getPrice($product, [
'user' => GlobalParam::getCurrentUser(),
'user_producer' => $userProducer,
'point_sale' => $pointSale,
@@ -540,7 +540,7 @@ class OrderController extends ProducerBaseController
throw new \yii\web\NotFoundHttpException('Commande introuvable');
}

if ($orderManager->isOrderStateOpen($order)) {
if (!$orderManager->isOrderStateOpen($order)) {
throw new UserException('Vous ne pouvez plus annuler cette commande.');
}

@@ -752,7 +752,7 @@ class OrderController extends ProducerBaseController
return $jsonUser;
}

private function ajaxInfosPointsSale($idProducer, $distribution = false)
private function ajaxInfosPointsSale($producer, $distribution = false)
{
$userManager = $this->getUserManager();
$producerManager = $this->getProducerManager();
@@ -785,7 +785,7 @@ class OrderController extends ProducerBaseController
]);
}

$pointsSaleArray = $pointsSaleArray->where(['id_producer' => $idProducer])
$pointsSaleArray = $pointsSaleArray->where(['id_producer' => $producer->id])
->andWhere(
'status = 1 AND (restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0))'
)

Laden…
Annuleren
Opslaan