Procházet zdrojové kódy

Produits : disponibilité pour les abonnements

feature/rotating_product
Guillaume Bourgeois před 6 měsíci
rodič
revize
f8d4df741d
3 změnil soubory, kde provedl 16 přidání a 10 odebrání
  1. +1
    -2
      backend/controllers/ProductController.php
  2. +4
    -8
      domain/Subscription/Subscription/SubscriptionManager.php
  3. +11
    -0
      domain/Subscription/Subscription/SubscriptionSolver.php

+ 1
- 2
backend/controllers/ProductController.php Zobrazit soubor

@@ -197,8 +197,7 @@ class ProductController extends BackendController

$subscriptionsWithProductArray = $subscriptionModule->getRepository()->findSubscriptionsWithProduct($model);
if(!$model->is_available_for_subscriptions && count($subscriptionsWithProductArray)) {
$subscriptionsListString = implode(', ', array_map(function($subscription) use ($subscriptionModule) { return $subscriptionModule->getSolver()->getUsername($subscription); }, $subscriptionsWithProductArray));
$this->addFlash('warning', 'Attention, le produit est encore présent dans les abonnements suivants : '.$subscriptionsListString);
$this->addFlash('warning', 'Attention, le produit est encore présent dans les abonnements suivants : '.$subscriptionModule->getSolver()->getSubscriptionsListAsHtml($subscriptionsWithProductArray));
}

return $this->render('update/update', [

+ 4
- 8
domain/Subscription/Subscription/SubscriptionManager.php Zobrazit soubor

@@ -19,23 +19,19 @@ class SubscriptionManager extends AbstractManager

public function deleteProductInSubscriptionsIfUnavailableForSubscriptions(Product $product): void
{
$messageFlashSubscriptionsWithProductDeleted = '';
$subscriptionsWithProductDeletedArray = [];
if(!$product->is_available_for_subscriptions) {
$subscriptionsArray = $this->subscriptionRepository->findSubscriptions();

foreach($subscriptionsArray as $subscription) {
if($this->deleteProductUnavailableInSubscriptions($subscription, $product)) {
$messageFlashSubscriptionsWithProductDeleted .= $this->subscriptionSolver->getUsername($subscription).', ';
$subscriptionsWithProductDeletedArray[] = $subscription;
}
}
}

if(strlen($messageFlashSubscriptionsWithProductDeleted)) {
$messageFlashSubscriptionsWithProductDeleted = substr($messageFlashSubscriptionsWithProductDeleted, 0, strlen($messageFlashSubscriptionsWithProductDeleted) - 2);
}

if(strlen($messageFlashSubscriptionsWithProductDeleted) > 0) {
\Yii::$app->session->addFlash('warning', 'Pour information, le produit a été supprimé des abonnements suivants : '.$messageFlashSubscriptionsWithProductDeleted);
if(count($subscriptionsWithProductDeletedArray)) {
\Yii::$app->session->addFlash('warning', 'Le produit a été supprimé des abonnements suivants : '.$this->subscriptionSolver->getSubscriptionsListAsHtml($subscriptionsWithProductDeletedArray));
}
}


+ 11
- 0
domain/Subscription/Subscription/SubscriptionSolver.php Zobrazit soubor

@@ -169,4 +169,15 @@ class SubscriptionSolver extends AbstractService implements SolverInterface

return false;
}

public function getSubscriptionsListAsHtml(array $subscriptionsArray): string
{
$subscriptionSolver = $this;
return implode(
', ',
array_map(function($subscription) use ($subscriptionSolver) {
return Html::a($subscriptionSolver->getUsername($subscription), ['subscription/update', 'id' => $subscription->id]);
}, $subscriptionsArray)
);
}
}

Načítá se…
Zrušit
Uložit