Browse Source

Produits : disponibilité pour les abonnements

feature/rotating_product
Guillaume Bourgeois 6 months ago
parent
commit
f8d4df741d
3 changed files with 16 additions and 10 deletions
  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 View File



$subscriptionsWithProductArray = $subscriptionModule->getRepository()->findSubscriptionsWithProduct($model); $subscriptionsWithProductArray = $subscriptionModule->getRepository()->findSubscriptionsWithProduct($model);
if(!$model->is_available_for_subscriptions && count($subscriptionsWithProductArray)) { 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', [ return $this->render('update/update', [

+ 4
- 8
domain/Subscription/Subscription/SubscriptionManager.php View File



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


foreach($subscriptionsArray as $subscription) { foreach($subscriptionsArray as $subscription) {
if($this->deleteProductUnavailableInSubscriptions($subscription, $product)) { 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 View File



return false; 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)
);
}
} }

Loading…
Cancel
Save