From e55b25020ae4184ad0efa0e73c4119d3fa41868f Mon Sep 17 00:00:00 2001 From: TheCoreDev Date: Tue, 13 Apr 2021 18:08:25 +0200 Subject: [PATCH] =?UTF-8?q?On=20rajoute=20un=20contr=C3=B4le=20pour=20emp?= =?UTF-8?q?=C3=AAcher=20la=20suppression=20d'un=20secteur=20ou=20d'un=20Pd?= =?UTF-8?q?r=20s'il=20existe=20des=20commandes=20sur=20ce=20lieu.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/backOffice/PlaceController.php | 32 ++++++++++++------- .../backOffice/GeneralController.php | 26 +++++++++------ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/local/modules/ClickAndCollect/Controller/backOffice/PlaceController.php b/local/modules/ClickAndCollect/Controller/backOffice/PlaceController.php index 2fd79dfd..7d74925d 100644 --- a/local/modules/ClickAndCollect/Controller/backOffice/PlaceController.php +++ b/local/modules/ClickAndCollect/Controller/backOffice/PlaceController.php @@ -3,6 +3,7 @@ namespace ClickAndCollect\Controller\backOffice; use ClickAndCollect\ClickAndCollect; +use PlanificationLivraison\Model\OrderDeliveryScheduleQuery; use PointRetrait\Model\PdrPlacesQuery; use PointRetrait\Model\PdrPlaces; use PointRetrait\Model\PdrScheduleQuery; @@ -13,6 +14,7 @@ use Thelia\Controller\Admin\BaseAdminController; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; use Thelia\Form\Exception\FormValidationException; +use Thelia\Form\OrderDelivery; use Thelia\Tools\URL; /** @@ -107,22 +109,30 @@ class PlaceController extends BaseAdminController return $response; $placeId = $this->getRequest()->get('attr-place-id'); - $query1 = PdrScheduleQuery::create()->findByIdPlace($placeId); - if ($query1 === null) - $error_msg = "Place not found by Id"; - else { - $con = Propel::getConnection(); - $con->beginTransaction(); - $query1->delete($con); - $con->commit(); - $query2 = PdrPlacesQuery::create()->findById($placeId); - if ($query2 === null) + // Comme il est impossible de supprimer un point si une commande a déjà été retirée sur ce Pdr, alors on vérifie au préalable les commandes. + $ordersAlreadyPlaced = OrderDeliveryScheduleQuery::create()->findByDeliveryPlaceId($placeId)->count(); + if ($ordersAlreadyPlaced > 0) { + $error_msg = "Existing orders delivered at the placeId : impossible to delete the place"; + } + else { + $query1 = PdrScheduleQuery::create()->findByIdPlace($placeId); + if ($query1 === null) $error_msg = "Place not found by Id"; else { + $con = Propel::getConnection(); $con->beginTransaction(); - $query2->delete($con); + $query1->delete($con); $con->commit(); + + $query2 = PdrPlacesQuery::create()->findById($placeId); + if ($query2 === null) + $error_msg = "Place not found by Id"; + else { + $con->beginTransaction(); + $query2->delete($con); + $con->commit(); + } } } diff --git a/local/modules/LivraisonParSecteurs/Controller/backOffice/GeneralController.php b/local/modules/LivraisonParSecteurs/Controller/backOffice/GeneralController.php index 38621a8e..6b0dbb5d 100644 --- a/local/modules/LivraisonParSecteurs/Controller/backOffice/GeneralController.php +++ b/local/modules/LivraisonParSecteurs/Controller/backOffice/GeneralController.php @@ -5,6 +5,7 @@ namespace LivraisonParSecteurs\Controller\backOffice; use LivraisonParSecteurs\LivraisonParSecteurs; use LivraisonParSecteurs\Model\LpsArea; use LivraisonParSecteurs\Model\LpsAreaQuery; +use PlanificationLivraison\Model\OrderDeliveryScheduleQuery; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Propel; @@ -114,15 +115,22 @@ class GeneralController extends BaseAdminController return $response; $areaCity_id = $this->getRequest()->get('attr-area-id'); - $query = LpsAreaQuery::create()->findById($areaCity_id); - if ($query === null) - $error_msg = "Area not found by Id"; - else - { - $con = Propel::getConnection(); - $con->beginTransaction(); - $query->delete($con); - $con->commit(); + + // Comme il est impossible de supprimer un secteur de livraison si au moins une commande a déjà été livrée dans ce secteur, alors on vérifie au préalable les commandes. + $ordersAlreadyPlaced = OrderDeliveryScheduleQuery::create()->findByDeliveryAddressId($areaCity_id)->count(); + if ($ordersAlreadyPlaced > 0) { + $error_msg = "Existing orders delivered at the area : impossible to delete the area"; + } + else { + $query = LpsAreaQuery::create()->findById($areaCity_id); + if ($query === null) + $error_msg = "Area not found by Id"; + else { + $con = Propel::getConnection(); + $con->beginTransaction(); + $query->delete($con); + $con->commit(); + } } if ($this->getRequest()->request->get("success_url") == null) {