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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user