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