[12/05/2025] Un peu de paramétrage, notamment les frais de port gratuits en fonction de certains seuils

This commit is contained in:
2025-05-12 17:02:55 +02:00
parent 49b1a63ecc
commit 5826bd7942
105 changed files with 18596 additions and 0 deletions

View File

@@ -0,0 +1,249 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace ColissimoPickupPoint\Controller;
use Propel\Runtime\ActiveQuery\Criteria;
use ColissimoPickupPoint\Form\ExportOrder;
use ColissimoPickupPoint\Format\CSV;
use ColissimoPickupPoint\Format\CSVLine;
use ColissimoPickupPoint\Model\OrderAddressColissimoPickupPointQuery;
use ColissimoPickupPoint\ColissimoPickupPoint;
use Symfony\Component\Config\Definition\Exception\Exception;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Model\Base\CountryQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CustomerTitleI18nQuery;
use Thelia\Model\OrderAddressQuery;
use Thelia\Model\OrderQuery;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Model\OrderStatus;
use Thelia\Model\OrderStatusQuery;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Security\AccessManager;
/**
* Class Export
* @package ColissimoPickupPoint\Controller
* @author Thelia <info@thelia.net>
*/
class Export extends BaseAdminController
{
const CSV_SEPARATOR = ';';
const DEFAULT_PHONE = '0100000000';
const DEFAULT_CELLPHONE = '0600000000';
public function export()
{
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), array('ColissimoPickupPoint'), AccessManager::UPDATE)) {
return $response;
}
$csv = new CSV(self::CSV_SEPARATOR);
try {
$form = new ExportOrder($this->getRequest());
$vform = $this->validateForm($form);
// Check status_id
$status_id = $vform->get('new_status_id')->getData();
if (!preg_match('#^nochange|processing|sent$#',$status_id)) {
throw new Exception('Bad value for new_status_id field');
}
$status = OrderStatusQuery::create()
->filterByCode(
array(
OrderStatus::CODE_PAID,
OrderStatus::CODE_PROCESSING,
OrderStatus::CODE_SENT
),
Criteria::IN
)
->find()
->toArray('code')
;
$query = OrderQuery::create()
->filterByDeliveryModuleId(ColissimoPickupPoint::getModCode())
->filterByStatusId(
array(
$status[OrderStatus::CODE_PAID]['Id'],
$status[OrderStatus::CODE_PROCESSING]['Id']),
Criteria::IN
)
->find();
// check form && exec csv
/** @var \Thelia\Model\Order $order */
foreach ($query as $order) {
$value = $vform->get('order_'.$order->getId())->getData();
// If checkbox is checked
if ($value) {
/**
* Retrieve user with the order
*/
$customer = $order->getCustomer();
/**
* Retrieve address with the order
*/
$address = OrderAddressQuery::create()
->findPk($order->getDeliveryOrderAddressId());
if ($address === null) {
throw new Exception("Could not find the order's invoice address");
}
/**
* Retrieve country with the address
*/
$country = CountryQuery::create()
->findPk($address->getCountryId());
if ($country === null) {
throw new Exception("Could not find the order's country");
}
/**
* Retrieve Title
*/
$title = CustomerTitleI18nQuery::create()
->filterById($customer->getTitleId())
->findOneByLocale(
$this->getSession()
->getAdminEditionLang()
->getLocale()
);
/**
* Get user's phone & cellphone
* First get invoice address phone,
* If empty, try to get default address' phone.
* If still empty, set default value
*/
$phone = $address->getPhone();
if (empty($phone)) {
$phone = $customer->getDefaultAddress()->getPhone();
if (empty($phone)) {
$phone = self::DEFAULT_PHONE;
}
}
/**
* Cellphone
*/
$cellphone = $customer->getDefaultAddress()->getCellphone();
if (empty($cellphone)) {
$cellphone = self::DEFAULT_CELLPHONE;
}
/**
* Compute package weight
*/
$weight = 0;
if ($vform->get('order_weight_'.$order->getId())->getData() == 0) {
/** @var \Thelia\Model\OrderProduct $product */
foreach ($order->getOrderProducts() as $product) {
$weight+=(double) $product->getWeight() * $product->getQuantity();
}
} else {
$weight = $vform->get('order_weight_'.$order->getId())->getData();
}
/**
* Get relay ID
*/
$relay_id = OrderAddressColissimoPickupPointQuery::create()
->findPk($order->getDeliveryOrderAddressId());
/**
* Get store's name
*/
$store_name = ConfigQuery::read('store_name');
/**
* Write CSV line
*/
$csv->addLine(
CSVLine::create(
array(
$address->getFirstname(),
$address->getLastname(),
$address->getCompany(),
$address->getAddress1(),
$address->getAddress2(),
$address->getAddress3(),
$address->getZipcode(),
$address->getCity(),
$country->getIsoalpha2(),
$phone,
$cellphone,
$order->getRef(),
$title->getShort(),
// the Expeditor software used to accept a relay id of 0, but no longer does
($relay_id !== null) ? ($relay_id->getCode() == 0) ? '' : $relay_id->getCode() : 0,
$customer->getEmail(),
$weight,
$store_name,
($relay_id !== null) ? $relay_id->getType() : 0
)
)
);
/**
* Then update order's status if necessary
*/
if ($status_id === 'processing') {
$event = new OrderEvent($order);
$event->setStatus($status[OrderStatus::CODE_PROCESSING]['Id']);
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
} elseif ($status_id === 'sent') {
$event = new OrderEvent($order);
$event->setStatus($status[OrderStatus::CODE_SENT]['Id']);
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
}
}
}
} catch (\Exception $e) {
return Response::create($e->getMessage(),500);
}
return Response::create(
utf8_decode($csv->parse()),
200,
array(
'Content-Encoding' => 'ISO-8889-1',
'Content-Type' => 'application/csv-tab-delimited-table',
'Content-disposition' => 'filename=expeditor_thelia.csv'
)
);
}
}

View File

@@ -0,0 +1,150 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace ColissimoPickupPoint\Controller;
use ColissimoPickupPoint\Form\FreeShippingForm;
use ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping;
use ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshippingQuery;
use ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping;
use ColissimoPickupPoint\Model\ColissimoPickupPointFreeshippingQuery;
use Symfony\Component\HttpFoundation\JsonResponse;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Security\AccessManager;
use Thelia\Model\AreaQuery;
class FreeShipping extends BaseAdminController
{
/**
* Toggle on or off free shipping for all areas without minimum cart amount, or set the minimum cart amount to reach for all areas to get free shipping
*
* @return mixed|JsonResponse|Response|null
*/
public function toggleFreeShippingActivation()
{
if (null !== $response = $this
->checkAuth(array(AdminResources::MODULE), array('ColissimoPickupPoint'), AccessManager::UPDATE)) {
return $response;
}
$form = new FreeShippingForm($this->getRequest());
$response=null;
try {
$vform = $this->validateForm($form);
$freeshipping = $vform->get('freeshipping')->getData();
$freeshippingFrom = $vform->get('freeshipping_from')->getData();
if (null === $deliveryFreeshipping = ColissimoPickupPointFreeshippingQuery::create()->findOneById(1)){
$deliveryFreeshipping = new ColissimoPickupPointFreeshipping();
}
$deliveryFreeshipping
->setActive($freeshipping)
->setFreeshippingFrom($freeshippingFrom)
->save()
;
$response = $this->generateRedirectFromRoute(
'admin.module.configure',
array(),
array (
'current_tab'=> 'prices_slices_tab',
'module_code'=> 'ColissimoPickupPoint',
'_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction',
'price_error_id' => null,
'price_error' => null
)
);
} catch (\Exception $e) {
$response = JsonResponse::create(array('error' => $e->getMessage()), 500);
}
return $response;
}
/**
* @return mixed|null|\Symfony\Component\HttpFoundation\Response
*/
public function setAreaFreeShipping()
{
if (null !== $response = $this
->checkAuth(array(AdminResources::MODULE), array('ColissimoPickupPoint'), AccessManager::UPDATE)) {
return $response;
}
$data = $this->getRequest()->request;
try {
$data = $this->getRequest()->request;
$colissimo_pickup_area_id = $data->get('area-id');
$cartAmount = $data->get('cart-amount');
if ($cartAmount < 0 || $cartAmount === '') {
$cartAmount = null;
}
$aeraQuery = AreaQuery::create()->findOneById($colissimo_pickup_area_id);
if (null === $aeraQuery) {
return null;
}
$colissimoPickupPointAreaFreeshippingQuery = ColissimoPickupPointAreaFreeshippingQuery::create()
->filterByAreaId($colissimo_pickup_area_id)
->findOne();
if (null === $colissimoPickupPointAreaFreeshippingQuery) {
$colissimoPickupPointFreeShipping = new ColissimoPickupPointAreaFreeshipping();
$colissimoPickupPointFreeShipping
->setAreaId($colissimo_pickup_area_id)
->setCartAmount($cartAmount)
->save();
}
$cartAmountQuery = ColissimoPickupPointAreaFreeshippingQuery::create()
->filterByAreaId($colissimo_pickup_area_id)
->findOneOrCreate()
->setCartAmount($cartAmount)
->save();
} catch (\Exception $e) {
}
return $this->generateRedirectFromRoute(
'admin.module.configure',
array(),
array(
'current_tab' => 'prices_slices_tab',
'module_code' => 'ColissimoPickupPoint',
'_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction',
'price_error_id' => null,
'price_error' => null
)
);
}
}

View File

@@ -0,0 +1,106 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace ColissimoPickupPoint\Controller;
use ColissimoPickupPoint\ColissimoPickupPoint;
use ColissimoPickupPoint\WebService\FindById;
use Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Template\ParserInterface;
use Thelia\Core\Template\TemplateDefinition;
use Thelia\Model\ConfigQuery;
/**
* Class SearchCityController
* @package IciRelais\Controller
* @author Thelia <info@thelia.net>
*/
class GetSpecificLocation extends BaseFrontController
{
public function get($countryid, $zipcode, $city, $address="")
{
$content = $this->renderRaw(
'getSpecificLocationColissimoPickupPoint',
array(
'_countryid_' => $countryid,
'_zipcode_' => $zipcode,
'_city_' => $city,
'_address_' => $address
)
);
$response = new Response($content, 200, $headers = array('Content-Type' => 'application/json'));
return $response;
}
public function getPointInfo($point_id)
{
$req = new FindById();
$req->setId($point_id)
->setLangue('FR')
->setDate(date('d/m/Y'))
->setAccountNumber(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME))
->setPassword(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD))
;
$response = $req->exec();
$response = new JsonResponse($response);
return $response;
}
public function search()
{
$countryid = $this->getRequest()->query->get('countryid');
$zipcode = $this->getRequest()->query->get('zipcode');
$city = $this->getRequest()->query->get('city');
$addressId = $this->getRequest()->query->get('address');
return $this->get($countryid, $zipcode, $city, $addressId);
}
/**
* @param null $template
* @return ParserInterface instance parser
* @throws Exception
*/
protected function getParser($template = null)
{
$parser = $this->container->get('thelia.parser');
// Define the template that should be used
$parser->setTemplateDefinition(
new TemplateDefinition(
'default',
TemplateDefinition::FRONT_OFFICE
)
);
return $parser;
}
}

View File

@@ -0,0 +1,129 @@
<?php
namespace ColissimoPickupPoint\Controller;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
use ColissimoPickupPoint\ColissimoPickupPoint;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Translation\Translator;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Map\OrderTableMap;
use Thelia\Model\OrderQuery;
use Thelia\Model\OrderStatusQuery;
use Thelia\Tools\URL;
/**
* Class ImportController
* @package ColissimoPickupPoint\Controller
* @author Etienne Perriere - OpenStudio <eperriere@openstudio.fr>
*/
class ImportController extends BaseAdminController
{
public function importAction()
{
$i = 0;
$con = Propel::getWriteConnection(OrderTableMap::DATABASE_NAME);
$con->beginTransaction();
$form = $this->createForm('colissimo.pickup.point.import');
try {
$vForm = $this->validateForm($form);
// Get file
$importedFile = $vForm->getData()['import_file'];
// Check extension
if (strtolower($importedFile->getClientOriginalExtension()) !='csv') {
throw new FormValidationException(
Translator::getInstance()->trans('Bad file format. CSV expected.',
[],
ColissimoPickupPoint::DOMAIN)
);
}
$csvData = file_get_contents($importedFile);
$lines = explode(PHP_EOL, $csvData);
// For each line, parse columns
foreach ($lines as $line) {
$parsedLine = str_getcsv($line, ";");
// Get delivery and order ref
$deliveryRef = $parsedLine[ColissimoPickupPoint::IMPORT_DELIVERY_REF_COL];
$orderRef = $parsedLine[ColissimoPickupPoint::IMPORT_ORDER_REF_COL];
// Save delivery ref if there is one
if (!empty($deliveryRef)) {
$this->importDeliveryRef($deliveryRef, $orderRef, $i);
}
}
$con->commit();
// Get number of affected rows to display
$this->getSession()->getFlashBag()->add(
'import-result',
Translator::getInstance()->trans(
'Operation successful. %i orders affected.',
['%i' => $i],
ColissimoPickupPoint::DOMAIN
)
);
// Redirect
return $this->generateRedirect(URL::getInstance()->absoluteUrl($form->getSuccessUrl(), ['current_tab' => 'import']));
} catch (FormValidationException $e) {
$con->rollback();
$this->setupFormErrorContext(null, $e->getMessage(), $form);
return $this->render(
'module-configure',
[
'module_code' => ColissimoPickupPoint::getModuleCode(),
'current_tab' => 'import'
]
);
}
}
/**
* Update order's delivery ref
*
* @param string $deliveryRef
* @param string $orderRef
* @param int $i
* @throws PropelException
*/
public function importDeliveryRef($deliveryRef, $orderRef, &$i)
{
// Check if the order exists
if (null !== $order = OrderQuery::create()->findOneByRef($orderRef)) {
$event = new OrderEvent($order);
// Check if delivery refs are different
if ($order->getDeliveryRef() != $deliveryRef) {
$event->setDeliveryRef($deliveryRef);
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_DELIVERY_REF, $event);
$sentStatusId = OrderStatusQuery::create()
->filterByCode('sent')
->select('ID')
->findOne();
// Set 'sent' order status if not already sent
if ($sentStatusId != null && $order->getStatusId() != $sentStatusId) {
$event->setStatus($sentStatusId);
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
}
$i++;
}
}
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace ColissimoPickupPoint\Controller;
use ColissimoPickupPoint\ColissimoPickupPoint;
use Thelia\Controller\Admin\BaseAdminController;
use ColissimoPickupPoint\Form\ConfigureColissimoPickupPoint;
use Thelia\Core\Translation\Translator;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Security\AccessManager;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL;
class SaveConfig extends BaseAdminController
{
public function save()
{
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), array('ColissimoPickupPoint'), AccessManager::UPDATE)) {
return $response;
}
$form = new ConfigureColissimoPickupPoint($this->getRequest());
try {
$vform = $this->validateForm($form);
ColissimoPickupPoint::setConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME, $vform->get(ColissimoPickupPoint::COLISSIMO_USERNAME)->getData());
ColissimoPickupPoint::setConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD, $vform->get(ColissimoPickupPoint::COLISSIMO_PASSWORD)->getData());
ColissimoPickupPoint::setConfigValue(ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY, $vform->get(ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY)->getData());
ColissimoPickupPoint::setConfigValue(ColissimoPickupPoint::COLISSIMO_ENDPOINT, $vform->get(ColissimoPickupPoint::COLISSIMO_ENDPOINT)->getData());
return $this->generateRedirect(
URL::getInstance()->absoluteUrl('/admin/module/ColissimoPickupPoint', ['current_tab' => 'configure'])
);
} catch (\Exception $e) {
$this->setupFormErrorContext(
Translator::getInstance()->trans('Colissimo Pickup Point update config'),
$e->getMessage(),
$form,
$e
);
return $this->render(
'module-configure',
[
'module_code' => 'ColissimoPickupPoint',
'current_tab' => 'configure',
]
);
}
}
}

View File

@@ -0,0 +1,180 @@
<?php
namespace ColissimoPickupPoint\Controller;
use Propel\Runtime\Map\TableMap;
use ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices;
use ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlicesQuery;
use ColissimoPickupPoint\ColissimoPickupPoint;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
class SliceController extends BaseAdminController
{
public function saveSliceAction()
{
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), ['ColissimoPickupPoint'], AccessManager::UPDATE)) {
return $response;
}
$this->checkXmlHttpRequest();
$responseData = [
'success' => false,
'message' => '',
'slice' => null
];
$messages = [];
$response = null;
try {
$requestData = $this->getRequest()->request;
if (0 !== $id = (int)$requestData->get('id', 0)) {
$slice = ColissimoPickupPointPriceSlicesQuery::create()->findPk($id);
} else {
$slice = new ColissimoPickupPointPriceSlices();
}
if (0 !== $areaId = (int)$requestData->get('area', 0)) {
$slice->setAreaId($areaId);
} else {
$messages[] = $this->getTranslator()->trans(
'The area is not valid',
[],
ColissimoPickupPoint::DOMAIN
);
}
$requestPriceMax = $requestData->get('priceMax', null);
$requestWeightMax = $requestData->get('weightMax', null);
if (empty($requestPriceMax) && empty($requestWeightMax)) {
$messages[] = $this->getTranslator()->trans(
'You must specify at least a price max or a weight max value.',
[],
ColissimoPickupPoint::DOMAIN
);
} else {
if (!empty($requestPriceMax)) {
$priceMax = $this->getFloatVal($requestPriceMax);
if (0 < $priceMax) {
$slice->setPriceMax($priceMax);
} else {
$messages[] = $this->getTranslator()->trans(
'The price max value is not valid',
[],
ColissimoPickupPoint::DOMAIN
);
}
} else {
$slice->setPriceMax(null);
}
if (!empty($requestWeightMax)) {
$weightMax = $this->getFloatVal($requestWeightMax);
if (0 < $weightMax) {
$slice->setWeightMax($weightMax);
} else {
$messages[] = $this->getTranslator()->trans(
'The weight max value is not valid',
[],
ColissimoPickupPoint::DOMAIN
);
}
} else {
$slice->setWeightMax(null);
}
}
$price = $this->getFloatVal($requestData->get('price', 0));
if (0 <= $price) {
$slice->setPrice($price);
} else {
$messages[] = $this->getTranslator()->trans(
'The price value is not valid',
[],
ColissimoPickupPoint::DOMAIN
);
}
if (0 === count($messages)) {
$slice->save();
$messages[] = $this->getTranslator()->trans(
'Your slice has been saved',
[],
ColissimoPickupPoint::DOMAIN
);
$responseData['success'] = true;
$responseData['slice'] = $slice->toArray(TableMap::TYPE_STUDLYPHPNAME);
}
} catch (\Exception $e) {
$message[] = $e->getMessage();
}
$responseData['message'] = $messages;
return $this->jsonResponse(json_encode($responseData));
}
protected function getFloatVal($val, $default = -1)
{
if (preg_match("#^([0-9\.,]+)$#", $val, $match)) {
$val = $match[0];
if (strstr($val, ",")) {
$val = str_replace(".", "", $val);
$val = str_replace(",", ".", $val);
}
$val = (float)$val;
return $val;
}
return $default;
}
public function deleteSliceAction()
{
$response = $this->checkAuth([], ['ColissimoPickupPoint'], AccessManager::DELETE);
if (null !== $response) {
return $response;
}
$this->checkXmlHttpRequest();
$responseData = [
'success' => false,
'message' => '',
'slice' => null
];
$response = null;
try {
$requestData = $this->getRequest()->request;
if (0 !== $id = (int)$requestData->get('id', 0)) {
$slice = ColissimoPickupPointPriceSlicesQuery::create()->findPk($id);
$slice->delete();
$responseData['success'] = true;
} else {
$responseData['message'] = $this->getTranslator()->trans(
'The slice has not been deleted',
[],
ColissimoPickupPoint::DOMAIN
);
}
} catch (\Exception $e) {
$responseData['message'] = $e->getMessage();
}
return $this->jsonResponse(json_encode($responseData));
}
}