On rajoute un contrôle pour empêcher la suppression d'un secteur ou d'un Pdr s'il existe des commandes sur ce lieu.

This commit is contained in:
2021-04-13 18:08:25 +02:00
parent 32b7b08931
commit e55b25020a
2 changed files with 38 additions and 20 deletions

View File

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