Ajout des modules ColissimoWs et ColissimoLabel.php
Ne pas oublier de vérifier si les tables nécessaires sont bien créées en BDD.
This commit is contained in:
@@ -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 ColissimoWs\Controller;
|
||||
|
||||
use ColissimoWs\ColissimoWs;
|
||||
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, ColissimoWs::DOMAIN_NAME, AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$configurationForm = $this->createForm('colissimows_configuration_form');
|
||||
|
||||
$message = false;
|
||||
|
||||
$url = '/admin/module/ColissimoWs';
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ColissimoWs::setConfigValue($name, $value);
|
||||
}
|
||||
|
||||
// Log configuration modification
|
||||
$this->adminLogAppend(
|
||||
"colissimoWs.configuration.message",
|
||||
AccessManager::UPDATE,
|
||||
"ColissimoWs 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("ColissimoWs configuration", [], ColissimoWs::DOMAIN_NAME),
|
||||
$message,
|
||||
$configurationForm,
|
||||
$ex
|
||||
);
|
||||
}
|
||||
|
||||
return $this->generateRedirect(URL::getInstance()->absoluteUrl($url, [ 'tab' => 'config', 'success' => $message === false ]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?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 ColissimoWs\Controller;
|
||||
|
||||
use ColissimoWs\Form\FreeShippingForm;
|
||||
use ColissimoWs\Model\ColissimowsFreeshipping;
|
||||
use ColissimoWs\Model\ColissimowsFreeshippingQuery;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
|
||||
class FreeShippingController extends BaseAdminController
|
||||
{
|
||||
public function toggleFreeShippingActivation()
|
||||
{
|
||||
if (null !== $response = $this
|
||||
->checkAuth(array(AdminResources::MODULE), array('ColissimoWs'), AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$form = new FreeShippingForm($this->getRequest());
|
||||
$response=null;
|
||||
|
||||
try {
|
||||
$vform = $this->validateForm($form);
|
||||
$freeshipping = $vform->get('freeshipping')->getData();
|
||||
|
||||
if (null === $isFreeShippingActive = ColissimowsFreeshippingQuery::create()->findOneById(1)){
|
||||
$isFreeShippingActive = new ColissimowsFreeshipping();
|
||||
}
|
||||
|
||||
$isFreeShippingActive->setActive($freeshipping);
|
||||
|
||||
$isFreeShippingActive->save();
|
||||
|
||||
$response = JsonResponse::create(array("success"=>"Freeshipping activated"), 200);
|
||||
} catch (\Exception $e) {
|
||||
$response = JsonResponse::create(array("error"=>$e->getMessage()), 500);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
370
local/modules/ColissimoWs/Controller/LabelController.php
Normal file
370
local/modules/ColissimoWs/Controller/LabelController.php
Normal file
@@ -0,0 +1,370 @@
|
||||
<?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 ColissimoWs\Controller;
|
||||
|
||||
use ColissimoLabel\Model\ColissimoLabelQuery;
|
||||
use ColissimoWs\ColissimoWs;
|
||||
use ColissimoWs\Event\LabelEvent;
|
||||
use ColissimoWs\Model\ColissimowsLabel;
|
||||
use ColissimoWs\Model\ColissimowsLabelQuery;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
use Thelia\Core\Event\PdfEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Exception\TheliaProcessException;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class LabelController extends BaseAdminController
|
||||
{
|
||||
/** @TODO : Compatibility with colissimo_label module */
|
||||
const LABEL_DIRECTORY = THELIA_LOCAL_DIR . 'colissimo-label';
|
||||
|
||||
/**
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response|StreamedResponse
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
static $codesPaysEurope = [
|
||||
'DE',
|
||||
'AT',
|
||||
'BE',
|
||||
'BG',
|
||||
'CY',
|
||||
'HR',
|
||||
'DK',
|
||||
'ES',
|
||||
'EE',
|
||||
'FI',
|
||||
'FR',
|
||||
'GR',
|
||||
'HU',
|
||||
'IE',
|
||||
'IT',
|
||||
'LV',
|
||||
'LT',
|
||||
'MT',
|
||||
'LU',
|
||||
'NL',
|
||||
'PL',
|
||||
'PT',
|
||||
'CZ',
|
||||
'RO',
|
||||
'GB',
|
||||
'SK',
|
||||
'SI',
|
||||
'SE '
|
||||
];
|
||||
|
||||
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), array('ColissimoWs'), AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$exportForm = $this->createForm('colissimows_export_form');
|
||||
|
||||
$files = $params = [];
|
||||
|
||||
if (!@mkdir(self::LABEL_DIRECTORY) && !is_dir(self::LABEL_DIRECTORY)) {
|
||||
throw new TheliaProcessException("Failed to create directory " . self::LABEL_DIRECTORY);
|
||||
}
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($exportForm);
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
// Check status_id
|
||||
$newStatus = OrderStatusQuery::create()->findOneByCode($data['new_status']);
|
||||
|
||||
ColissimoWs::setConfigValue("new_status", $data['new_status']);
|
||||
|
||||
$weight_array = $data['weight'];
|
||||
$signed_array = $data['signed'];
|
||||
|
||||
foreach($data['order_id'] as $orderId) {
|
||||
if (null !== $order = OrderQuery::create()->findPk($orderId)) {
|
||||
if (! isset($weight_array[$orderId]) || 0 === (float)$weight_array[$orderId]) {
|
||||
$weight = $order->getWeight();
|
||||
} else {
|
||||
$weight = (float) $weight_array[$orderId];
|
||||
}
|
||||
|
||||
if ($weight === null) {
|
||||
throw new \Exception($this->getTranslator()->trans("Please enter a weight for every selected order"));
|
||||
}
|
||||
|
||||
if (array_key_exists ($orderId , $signed_array)){
|
||||
$signed = $signed_array[$orderId];
|
||||
} else {
|
||||
$signed = false;
|
||||
}
|
||||
|
||||
$event = (new LabelEvent($orderId))
|
||||
->setWeight($weight)
|
||||
->setSigned($signed);
|
||||
|
||||
$this->getDispatcher()->dispatch(ColissimoWs::GENERATE_LABEL_EVENT, $event);
|
||||
|
||||
if ($event->hasLabel() && $event->getColissimoWsLabel()->getError() === false) {
|
||||
$fileType = ColissimoWs::getLabelFileType();
|
||||
|
||||
$labelFileName = self::LABEL_DIRECTORY . DS . $order->getRef() . '.' . $fileType;
|
||||
|
||||
file_put_contents($labelFileName, $event->getColissimoWsLabel()->getLabelData());
|
||||
|
||||
$files[] = $labelFileName;
|
||||
|
||||
$destinationEurope =
|
||||
in_array(
|
||||
strtoupper($order->getOrderAddressRelatedByDeliveryOrderAddressId()->getCountry()->getIsoalpha2()),
|
||||
$codesPaysEurope
|
||||
)
|
||||
;
|
||||
|
||||
/** Comment this to disable "no customs invoice template" error */
|
||||
// Generate customs invoice for non-FR foreign shipping
|
||||
if (!$destinationEurope) {
|
||||
$files[] = $this->createCustomsInvoice($orderId, $order->getRef());
|
||||
|
||||
// We have a customs invoice !
|
||||
$event
|
||||
->getColissimoWsLabel()
|
||||
->setWithCustomsInvoice(true)
|
||||
->setSigned(true)
|
||||
->save();
|
||||
}
|
||||
|
||||
if (null !== $newStatus) {
|
||||
$event = new OrderEvent($order);
|
||||
$event->setStatus($newStatus->getId());
|
||||
|
||||
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
|
||||
}
|
||||
|
||||
// Ajouter la facture au zip
|
||||
$labelFileName = self::LABEL_DIRECTORY . DS . $order->getRef() . '-invoice.pdf';
|
||||
|
||||
$response = $this->generateOrderPdf($orderId, ConfigQuery::read('pdf_invoice_file', 'invoice'));
|
||||
|
||||
if (file_put_contents($labelFileName, $response->getContent())) {
|
||||
$files[] = $labelFileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($files) > 0) {
|
||||
$zip = new \ZipArchive();
|
||||
$zipFilename = sys_get_temp_dir() .DS. uniqid('colissimo-labels-', false);
|
||||
|
||||
if (true !== $zip->open($zipFilename, \ZipArchive::CREATE)) {
|
||||
throw new TheliaProcessException("Cannot open zip file $zipFilename\n");
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$zip->addFile($file, basename($file));
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
// Perform cleanup
|
||||
/*
|
||||
foreach ($files as $file) {
|
||||
@unlink($file);
|
||||
}
|
||||
*/
|
||||
|
||||
$params = [ 'zip' => base64_encode($zipFilename) ];
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
$this->setupFormErrorContext("Generation étiquettes Colissimo", $ex->getMessage(), $exportForm, $ex);
|
||||
}
|
||||
|
||||
return $this->generateRedirect(URL::getInstance()->absoluteUrl("admin/module/ColissimoWs", $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $orderId
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function getLabelZip($base64EncodedZipFilename)
|
||||
{
|
||||
$zipFilename = base64_decode($base64EncodedZipFilename);
|
||||
|
||||
if (file_exists($zipFilename)) {
|
||||
return new StreamedResponse(
|
||||
function () use ($zipFilename) {
|
||||
readfile($zipFilename);
|
||||
@unlink($zipFilename);
|
||||
},
|
||||
200,
|
||||
[
|
||||
'Content-Type' => 'application/zip',
|
||||
"Content-disposition" => "attachement; filename=colissimo-labels.zip",
|
||||
"Content-Length" => filesize($zipFilename)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return new \Symfony\Component\HttpFoundation\Response("File no longer exists");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $orderId
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function getLabel($orderId)
|
||||
{
|
||||
if (null !== $labelInfo = ColissimowsLabelQuery::create()->findOneByOrderId($orderId)) {
|
||||
return $this->generateResponseForLabel($labelInfo);
|
||||
}
|
||||
|
||||
return $this->generateRedirect(URL::getInstance()->absoluteUrl("admin/module/ColissimoWs"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $orderId
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getCustomsInvoice($orderId)
|
||||
{
|
||||
if (null !== $order = OrderQuery::create()->findPk($orderId)) {
|
||||
$fileName = $this->createCustomsInvoice($orderId, $order->getRef());
|
||||
|
||||
return Response::create(
|
||||
file_get_contents($fileName),
|
||||
200,
|
||||
[
|
||||
"Content-Type" => "application/pdf",
|
||||
"Content-disposition" => "Attachement;filename=" . basename($fileName)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->generateRedirect(URL::getInstance()->absoluteUrl("admin/module/ColissimoWs"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $orderId
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function clearLabel($orderId)
|
||||
{
|
||||
/** @var ColissimowsLabel $order */
|
||||
$order = ColissimowsLabelQuery::create()->filterByOrderId($orderId)->findOne();
|
||||
|
||||
$orderRef = $order->getOrderRef();
|
||||
$fileType = $order->getLabelType();
|
||||
$order->delete();
|
||||
|
||||
$file = self::LABEL_DIRECTORY . DS . $orderRef;
|
||||
$invoice = $file . '-invoice.pdf';
|
||||
$file .= ".$fileType";
|
||||
@unlink($file);
|
||||
@unlink($invoice);
|
||||
|
||||
///** Compatibility with module SoColissimoLabel /!\ Do not use strict comparison */
|
||||
//if (ModuleQuery::create()->findOneByCode('ColissimoLabel')->getActivate() == true)
|
||||
//{
|
||||
// ColissimoLabelQuery::create()->findOneByOrderId($orderId)->delete();
|
||||
//}
|
||||
|
||||
return $this->generateRedirect(URL::getInstance()->absoluteUrl("admin/module/ColissimoWs") . '#order-' . $orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ColissimowsLabel $labelInfo
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
protected function generateResponseForLabel($labelInfo)
|
||||
{
|
||||
$fileType = $labelInfo->getLabelType();
|
||||
|
||||
if ($fileType === 'pdf') {
|
||||
return new BinaryFileResponse(
|
||||
self::LABEL_DIRECTORY . DS . $labelInfo->getOrderRef() . ".$fileType",
|
||||
200,
|
||||
[
|
||||
"Content-Type" => "application/pdf",
|
||||
"Content-disposition" => "Attachement;filename=" . $labelInfo->getOrder()->getRef() . ".pdf"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return new BinaryFileResponse(
|
||||
self::LABEL_DIRECTORY . DS . $labelInfo->getOrderRef() . ".$fileType",
|
||||
200,
|
||||
[
|
||||
"Content-Type" => "application/octet-stream",
|
||||
"Content-disposition" => "Attachement;filename=" . $labelInfo->getOrder()->getRef() . ".$fileType"
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
184
local/modules/ColissimoWs/Controller/PriceSliceController.php
Normal file
184
local/modules/ColissimoWs/Controller/PriceSliceController.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ColissimoWs\Controller;
|
||||
|
||||
|
||||
|
||||
use ColissimoWs\ColissimoWs;
|
||||
use ColissimoWs\Model\ColissimowsPriceSlices;
|
||||
use ColissimoWs\Model\ColissimowsPriceSlicesQuery;
|
||||
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([], ['colissimows'], 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 = ColissimowsPriceSlicesQuery::create()->findPk($id);
|
||||
} else {
|
||||
$slice = new ColissimowsPriceSlices();
|
||||
}
|
||||
|
||||
|
||||
if (0 !== $areaId = (int)$requestData->get('area', 0)) {
|
||||
$slice->setAreaId($areaId);
|
||||
} else {
|
||||
$messages[] = $this->getTranslator()->trans(
|
||||
'The area is not valid',
|
||||
[],
|
||||
ColissimoWs::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.',
|
||||
[],
|
||||
ColissimoWs::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',
|
||||
[],
|
||||
ColissimoWs::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',
|
||||
[],
|
||||
ColissimoWs::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',
|
||||
[],
|
||||
ColissimoWs::DOMAIN_NAME
|
||||
);
|
||||
}
|
||||
|
||||
if (0 === count($messages)) {
|
||||
$slice->save();
|
||||
$messages[] = $this->getTranslator()->trans(
|
||||
'Your slice has been saved',
|
||||
[],
|
||||
ColissimoWs::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([], ['colissimows'], 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 = ColissimowsPriceSlicesQuery::create()->findPk($id);
|
||||
$priceSlice->delete();
|
||||
$responseData['success'] = true;
|
||||
} else {
|
||||
$responseData['message'] = $this->getTranslator()->trans(
|
||||
'The slice has not been deleted',
|
||||
[],
|
||||
ColissimoWs::DOMAIN_NAME
|
||||
);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$responseData['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return $this->jsonResponse(json_encode($responseData));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user