[11/05/2025] On remplace les modules Colissimo par le combo ColissimoHomeDelivery + ColissimoPickupPoint + ColissimoLabel

This commit is contained in:
2025-05-11 23:38:10 +02:00
parent a09aa11f16
commit 49b1a63ecc
1528 changed files with 18449 additions and 62 deletions

View File

@@ -0,0 +1,80 @@
<?php
/*************************************************************************************/
/* Copyright (c) Franck Allimant, CQFDev */
/* email : thelia@cqfdev.fr */
/* web : http://www.cqfdev.fr */
/* */
/* For the full copyright and license information, please view the LICENSE */
/* file that was distributed with this source code. */
/*************************************************************************************/
/**
* Created by Franck Allimant, CQFDev <franck@cqfdev.fr>
* Date: 17/08/2019 12:26
*/
namespace ColissimoHomeDelivery\Controller;
use ColissimoHomeDelivery\ColissimoHomeDelivery;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Tools\URL;
class ConfigurationController extends BaseAdminController
{
public function configure()
{
if (null !== $response = $this->checkAuth(AdminResources::MODULE, ColissimoHomeDelivery::DOMAIN_NAME, AccessManager::UPDATE)) {
return $response;
}
$configurationForm = $this->createForm('colissimo.homedelivery.configuration.form');
$message = false;
$url = '/admin/module/ColissimoHomeDelivery';
try {
$form = $this->validateForm($configurationForm);
// Get the form field values
$data = $form->getData();
foreach ($data as $name => $value) {
if (is_array($value)) {
$value = implode(';', $value);
}
ColissimoHomeDelivery::setConfigValue($name, $value);
}
// Log configuration modification
$this->adminLogAppend(
'colissimo.home.delivery.configuration.message',
AccessManager::UPDATE,
'ColissimoHomeDelivery configuration updated'
);
// Redirect to the success URL,
if (! $this->getRequest()->get('save_mode') === 'stay') {
$url = '/admin/modules';
}
} catch (FormValidationException $ex) {
$message = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
$message = $ex->getMessage();
}
if ($message !== false) {
$this->setupFormErrorContext(
$this->getTranslator()->trans('ColissimoHomeDelivery configuration', [], ColissimoHomeDelivery::DOMAIN_NAME),
$message,
$configurationForm,
$ex
);
}
return $this->generateRedirect(URL::getInstance()->absoluteUrl($url, [ 'tab' => 'config', 'success' => $message === false ]));
}
}

View File

@@ -0,0 +1,123 @@
<?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 ColissimoHomeDelivery\Controller;
use ColissimoHomeDelivery\Form\FreeShippingForm;
use ColissimoHomeDelivery\Model\ColissimoHomeDeliveryAreaFreeshippingQuery;
use ColissimoHomeDelivery\Model\ColissimoHomeDeliveryFreeshipping;
use ColissimoHomeDelivery\Model\ColissimoHomeDeliveryFreeshippingQuery;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Security\AccessManager;
use Thelia\Model\AreaQuery;
use Thelia\Tools\URL;
class FreeShippingController extends BaseAdminController
{
public function toggleFreeShippingActivation()
{
if (null !== $response = $this
->checkAuth(array(AdminResources::MODULE), array('ColissimoHomeDelivery'), 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 === $isFreeShippingActive = ColissimoHomeDeliveryFreeshippingQuery::create()->findOneById(1)){
$isFreeShippingActive = new ColissimoHomeDeliveryFreeshipping();
}
$isFreeShippingActive
->setActive($freeshipping)
->setFreeshippingFrom($freeshippingFrom)
;
$isFreeShippingActive->save();
$response = $this->generateRedirectFromRoute(
'admin.module.configure',
array(),
array (
'current_tab'=> 'prices_slices_tab',
'module_code'=> 'ColissimoHomeDelivery',
'_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|Response|null
*/
public function setAreaFreeShipping()
{
if (null !== $response = $this
->checkAuth(array(AdminResources::MODULE), array('ColissimoHomeDelivery'), AccessManager::UPDATE)) {
return $response;
}
try {
$data = $this->getRequest()->request;
$colissimo_homedelivery_area_id = $data->get('area-id');
$cartAmount = $data->get('cart-amount');
if ($cartAmount < 0 || $cartAmount === '') {
$cartAmount = null;
}
$areaQuery = AreaQuery::create()->findOneById($colissimo_homedelivery_area_id);
if (null === $areaQuery) {
return null;
}
$colissimoHomeDeliveryAreaFreeshippingQuery = ColissimoHomeDeliveryAreaFreeshippingQuery::create()
->filterByAreaId($colissimo_homedelivery_area_id)
->findOneOrCreate();
$colissimoHomeDeliveryAreaFreeshippingQuery
->setAreaId($colissimo_homedelivery_area_id)
->setCartAmount($cartAmount)
->save();
} catch (\Exception $e) {
}
return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/ColissimoHomeDelivery'));
}
}

View File

@@ -0,0 +1,68 @@
<?php
/*************************************************************************************/
/* Copyright (c) Franck Allimant, CQFDev */
/* email : thelia@cqfdev.fr */
/* web : http://www.cqfdev.fr */
/* */
/* For the full copyright and license information, please view the LICENSE */
/* file that was distributed with this source code. */
/*************************************************************************************/
/**
* Created by Franck Allimant, CQFDev <franck@cqfdev.fr>
* Date: 04/09/2019 21:51
*/
namespace ColissimoHomeDelivery\Controller;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Event\PdfEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Log\Tlog;
class LabelController extends BaseAdminController
{
const LABEL_DIRECTORY = THELIA_LOCAL_DIR . 'colissimo-label';
/**
* [DEPRECATED] Generates the customs invoice.
* /!\ COMPATIBILITY /!\ DO NOT REMOVE
*
*
* @param $orderId
* @param $orderRef
* @return string
* @throws \Exception
*/
public function createCustomsInvoice($orderId, $orderRef)
{
$html = $this->renderRaw(
'customs-invoice',
array(
'order_id' => $orderId
),
$this->getTemplateHelper()->getActivePdfTemplate()
);
try {
$pdfEvent = new PdfEvent($html);
$this->dispatch(TheliaEvents::GENERATE_PDF, $pdfEvent);
$pdfFileName = self::LABEL_DIRECTORY . DS . $orderRef . '-customs-invoice.pdf';
file_put_contents($pdfFileName, $pdfEvent->getPdf());
return $pdfFileName;
} catch (\Exception $e) {
Tlog::getInstance()->error(
sprintf(
'error during generating invoice pdf for order id : %d with message "%s"',
$orderId,
$e->getMessage()
)
);
throw $e;
}
}
}

View File

@@ -0,0 +1,184 @@
<?php
namespace ColissimoHomeDelivery\Controller;
use ColissimoHomeDelivery\ColissimoHomeDelivery;
use ColissimoHomeDelivery\Model\ColissimoHomeDeliveryPriceSlices;
use ColissimoHomeDelivery\Model\ColissimoHomeDeliveryPriceSlicesQuery;
use Propel\Runtime\Map\TableMap;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
class PriceSliceController extends BaseAdminController
{
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 savePriceSliceAction()
{
$response = $this->checkAuth([], ['colissimohomedelivery'], AccessManager::UPDATE);
if (null !== $response) {
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 = ColissimoHomeDeliveryPriceSlicesQuery::create()->findPk($id);
} else {
$slice = new ColissimoHomeDeliveryPriceSlices();
}
if (0 !== $areaId = (int)$requestData->get('area', 0)) {
$slice->setAreaId($areaId);
} else {
$messages[] = $this->getTranslator()->trans(
'The area is not valid',
[],
ColissimoHomeDelivery::DOMAIN_NAME
);
}
$requestPriceMax = $requestData->get('maxPrice', null);
$requestmaxWeight = $requestData->get('maxWeight', null);
if (empty($requestPriceMax) && empty($requestmaxWeight)) {
$messages[] = $this->getTranslator()->trans(
'You must specify at least a price max or a weight max value.',
[],
ColissimoHomeDelivery::DOMAIN_NAME
);
} else {
if (!empty($requestPriceMax)) {
$maxPrice = $this->getFloatVal($requestPriceMax);
if (0 < $maxPrice) {
$slice->setMaxPrice($maxPrice);
} else {
$messages[] = $this->getTranslator()->trans(
'The price max value is not valid',
[],
ColissimoHomeDelivery::DOMAIN_NAME
);
}
} else {
$slice->setMaxPrice(null);
}
if (!empty($requestmaxWeight)) {
$maxWeight = $this->getFloatVal($requestmaxWeight);
if (0 < $maxWeight) {
$slice->setMaxWeight($maxWeight);
} else {
$messages[] = $this->getTranslator()->trans(
'The weight max value is not valid',
[],
ColissimoHomeDelivery::DOMAIN_NAME
);
}
} else {
$slice->setMaxWeight(null);
}
}
$price = $this->getFloatVal($requestData->get('shipping', 0));
if (0 <= $price) {
$slice->setShipping($price);
} else {
$messages[] = $this->getTranslator()->trans(
'The price value is not valid',
[],
ColissimoHomeDelivery::DOMAIN_NAME
);
}
if (0 === count($messages)) {
$slice->save();
$messages[] = $this->getTranslator()->trans(
'Your slice has been saved',
[],
ColissimoHomeDelivery::DOMAIN_NAME
);
$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));
}
public function deletePriceSliceAction()
{
$response = $this->checkAuth([], ['colissimohomedelivery'], 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)) {
$priceSlice = ColissimoHomeDeliveryPriceSlicesQuery::create()->findPk($id);
$priceSlice->delete();
$responseData['success'] = true;
} else {
$responseData['message'] = $this->getTranslator()->trans(
'The slice has not been deleted',
[],
ColissimoHomeDelivery::DOMAIN_NAME
);
}
} catch (\Exception $e) {
$responseData['message'] = $e->getMessage();
}
return $this->jsonResponse(json_encode($responseData));
}
}