Browse Source

[backend] Suppression des commandes liées à un abonnement lors de la suppression d'un abonnement

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
6cf31b7698
2 changed files with 19 additions and 1 deletions
  1. +5
    -1
      backend/controllers/SubscriptionController.php
  2. +14
    -0
      common/models/Subscription.php

+ 5
- 1
backend/controllers/SubscriptionController.php View File

*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
$subscription = Subscription::searchOne([
'subscription.id' => $id
]) ;
$subscription->deleteOrdersIncomingDistributions() ;
$subscription->delete();
ProductSubscription::deleteAll(['id_subscription' => $id]); ProductSubscription::deleteAll(['id_subscription' => $id]);
Subscription::findOne($id)->delete();
Yii::$app->getSession()->setFlash('success', 'Abonnement supprimé'); Yii::$app->getSession()->setFlash('success', 'Abonnement supprimé');
return $this->redirect(['subscription/index']); return $this->redirect(['subscription/index']);
} }

+ 14
- 0
common/models/Subscription.php View File

$orders->params($params) ; $orders->params($params) ;
$ordersArray = $orders->all() ; $ordersArray = $orders->all() ;
$configCredit = Producer::getConfig('credit') ;
if($ordersArray && count($ordersArray)) { if($ordersArray && count($ordersArray)) {
foreach($ordersArray as $order) { foreach($ordersArray as $order) {
$theOrder = Order::searchOne(['id' => $order->id]) ;
// remboursement de la commande
if ($theOrder->id_user && $theOrder->getAmount(Order::AMOUNT_PAID) && $configCredit) {
$theOrder->saveCreditHistory(
CreditHistory::TYPE_REFUND,
$theOrder->getAmount(Order::AMOUNT_PAID),
$theOrder->distribution->id_producer,
$theOrder->id_user,
User::getCurrentId()
);
}
ProductOrder::deleteAll(['id_order' => $order->id]) ; ProductOrder::deleteAll(['id_order' => $order->id]) ;
$order->delete() ; $order->delete() ;
} }

Loading…
Cancel
Save