Commit du module Colissimo

This commit is contained in:
2020-09-09 12:52:39 +02:00
parent de4bc540e4
commit b5d5fd110e
123 changed files with 28431 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 SoColissimo\Controller;
use Propel\Runtime\ActiveQuery\Criteria;
use SoColissimo\Form\ExportOrder;
use SoColissimo\Format\CSV;
use SoColissimo\Format\CSVLine;
use SoColissimo\Model\OrderAddressSocolissimoQuery;
use SoColissimo\SoColissimo;
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 SoColissimo\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('SoColissimo'), 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(SoColissimo::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 = OrderAddressSocolissimoQuery::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,195 @@
<?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 SoColissimo\Controller;
use SoColissimo\Model\SocolissimoAreaFreeshippingDom;
use SoColissimo\Model\SocolissimoAreaFreeshippingDomQuery;
use SoColissimo\Model\SocolissimoAreaFreeshippingPr;
use SoColissimo\Model\SocolissimoAreaFreeshippingPrQuery;
use SoColissimo\Model\SocolissimoDeliveryModeQuery;
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
{
public function toggleFreeShippingActivation()
{
if (null !== $response = $this
->checkAuth(array(AdminResources::MODULE), array('SoColissimo'), AccessManager::UPDATE)) {
return $response;
}
$form = new \SoColissimo\Form\FreeShipping($this->getRequest());
$response=null;
try {
$vform = $this->validateForm($form);
$freeshipping = $vform->get('freeshipping')->getData();
$deliveryModeId = $vform->get('delivery_mode')->getData();
$deliveryMode = SocolissimoDeliveryModeQuery::create()->findOneById($deliveryModeId);
$deliveryMode->setFreeshippingActive($freeshipping)
->save();
$response = Response::create('');
} catch (\Exception $e) {
$response = JsonResponse::create(array("error"=>$e->getMessage()), 500);
}
return $response;
}
public function setFreeShippingFrom()
{
if (null !== $response = $this
->checkAuth(array(AdminResources::MODULE), array('SoColissimo'), AccessManager::UPDATE)) {
return $response;
}
$data = $this->getRequest()->request;
$deliveryMode = SocolissimoDeliveryModeQuery::create()->findOneById($data->get('delivery-mode'));
$price = $data->get("price") === "" ? null : $data->get("price");
if ($price < 0) {
$price = null;
}
$deliveryMode->setFreeshippingFrom($price)
->save();
return $this->generateRedirectFromRoute(
"admin.module.configure",
array(),
array (
'current_tab'=>'prices_slices_tab_'.$data->get('delivery-mode'),
'module_code'=>"SoColissimo",
'_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction',
'price_error_id' => null,
'price_error' => null
)
);
}
/**
* @return mixed|null|\Symfony\Component\HttpFoundation\Response
* @throws \Propel\Runtime\Exception\PropelException
*/
public function setAreaFreeShipping()
{
if (null !== $response = $this
->checkAuth(array(AdminResources::MODULE), array('SoColissimo'), AccessManager::UPDATE)) {
return $response;
}
$data = $this->getRequest()->request;
try {
$data = $this->getRequest()->request;
$socolissimo_area_id = $data->get('area-id');
$socolissimo_delivery_id = $data->get('delivery-mode');
$cartAmount = $data->get("cart-amount");
if ($cartAmount < 0 || $cartAmount === '') {
$cartAmount = null;
}
$aeraQuery = AreaQuery::create()->findOneById($socolissimo_area_id);
if (null === $aeraQuery) {
return null;
}
$deliveryModeQuery = SocolissimoDeliveryModeQuery::create()->findOneById($socolissimo_delivery_id);
if (null === $deliveryModeQuery) {
return null;
}
//Price slices for "Domicile"
if ($socolissimo_delivery_id === '1') {
$socolissimoFreeShippingDom = new SocolissimoAreaFreeshippingDom();
$socolissimoAreaFreeshippingDomQuery = SocolissimoAreaFreeshippingDomQuery::create()
->filterByAreaId($socolissimo_area_id)
->filterByDeliveryModeId($socolissimo_delivery_id)
->findOne();
if (null === $socolissimoAreaFreeshippingDomQuery) {
$socolissimoFreeShippingDom
->setAreaId($socolissimo_area_id)
->setDeliveryModeId($socolissimo_delivery_id)
->setCartAmount($cartAmount)
->save();
}
$cartAmountDomQuery = SocolissimoAreaFreeshippingDomQuery::create()
->filterByAreaId($socolissimo_area_id)
->filterByDeliveryModeId($socolissimo_delivery_id)
->findOneOrCreate()
->setCartAmount($cartAmount)
->save();
}
//Price slices for "Point Relais"
if ($socolissimo_delivery_id === '2') {
$socolissimoFreeShippingPr = new SocolissimoAreaFreeshippingPr();
$socolissimoAreaFreeshippingPrQuery = SocolissimoAreaFreeshippingPrQuery::create()
->filterByAreaId($socolissimo_area_id)
->filterByDeliveryModeId($socolissimo_delivery_id)
->findOne();
if (null === $socolissimoAreaFreeshippingPrQuery) {
$socolissimoFreeShippingPr
->setAreaId($socolissimo_area_id)
->setDeliveryModeId($socolissimo_delivery_id)
->setCartAmount($cartAmount)
->save();
}
$cartAmountPrQuery = SocolissimoAreaFreeshippingPrQuery::create()
->filterByAreaId($socolissimo_area_id)
->filterByDeliveryModeId($socolissimo_delivery_id)
->findOneOrCreate()
->setCartAmount($cartAmount)
->save();
}
} catch (\Exception $e) {
}
return $this->generateRedirectFromRoute(
"admin.module.configure",
array(),
array(
'current_tab' => 'prices_slices_tab_' . $data->get('area_freeshipping'),
'module_code' => "SoColissimo",
'_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction',
'price_error_id' => null,
'price_error' => null
)
);
}
}

View File

@@ -0,0 +1,100 @@
<?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 SoColissimo\Controller;
use SoColissimo\WebService\FindById;
use Symfony\Component\HttpFoundation\JsonResponse;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\HttpFoundation\Response;
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(
"getSpecificLocationSoColissimo",
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(ConfigQuery::read('socolissimo_login'))
->setPassword(ConfigQuery::read('socolissimo_pwd'))
;
$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);
}
/**
* @return ParserInterface instance parser
*/
protected function getParser($template = null)
{
$parser = $this->container->get("thelia.parser");
// Define the template that should be used
$parser->setTemplateDefinition(
new TemplateDefinition(
'module_socolissimo',
TemplateDefinition::FRONT_OFFICE
)
);
return $parser;
}
}

View File

@@ -0,0 +1,127 @@
<?php
namespace SoColissimo\Controller;
use Propel\Runtime\Propel;
use SoColissimo\SoColissimo;
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 SoColissimo\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('socolissimo.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.',
[],
SoColissimo::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[SoColissimo::IMPORT_DELIVERY_REF_COL];
$orderRef = $parsedLine[SoColissimo::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],
SoColissimo::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' => SoColissimo::getModuleCode(),
'current_tab' => 'import'
]
);
}
}
/**
* Update order's delivery ref
*
* @param string $deliveryRef
* @param string $orderRef
* @param int $i
*/
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,52 @@
<?php
namespace SoColissimo\Controller;
use Thelia\Controller\Admin\BaseAdminController;
use SoColissimo\Form\ConfigureSoColissimo;
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('SoColissimo'), AccessManager::UPDATE)) {
return $response;
}
$form = new ConfigureSoColissimo($this->getRequest());
try {
$vform = $this->validateForm($form);
ConfigQuery::write('socolissimo_login', $vform->get('accountnumber')->getData(), 1, 1);
ConfigQuery::write('socolissimo_pwd', $vform->get('password')->getData(), 1, 1);
ConfigQuery::write('socolissimo_google_map_key', $vform->get('google_map_key')->getData(), 1, 1);
ConfigQuery::write('socolissimo_url_prod', $vform->get('url_prod')->getData(), 1, 1);
ConfigQuery::write('socolissimo_url_test', $vform->get('url_test')->getData(), 1, 1);
ConfigQuery::write('socolissimo_test_mode', $vform->get('test_mode')->getData(), 1, 1);
return $this->generateRedirect(
URL::getInstance()->absoluteUrl('/admin/module/SoColissimo', ['current_tab' => 'configure'])
);
} catch (\Exception $e) {
$this->setupFormErrorContext(
Translator::getInstance()->trans("So Colissimo update config"),
$e->getMessage(),
$form,
$e
);
return $this->render(
'module-configure',
[
'module_code' => 'SoColissimo',
'current_tab' => 'configure',
]
);
}
}
}

View File

@@ -0,0 +1,192 @@
<?php
namespace SoColissimo\Controller;
use Propel\Runtime\Map\TableMap;
use SoColissimo\Model\SocolissimoPrice;
use SoColissimo\Model\SocolissimoPriceQuery;
use SoColissimo\SoColissimo;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
class SliceController extends BaseAdminController
{
public function saveSliceAction()
{
$response = $this->checkAuth([], ['socolissimo'], 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 = intval($requestData->get('id', 0))) {
$slice = SocolissimoPriceQuery::create()->findPk($id);
} else {
$slice = new SocolissimoPrice();
}
if (0 !== $areaId = intval($requestData->get('area', 0))) {
$slice->setAreaId($areaId);
} else {
$messages[] = $this->getTranslator()->trans(
'The area is not valid',
[],
SoColissimo::DOMAIN
);
}
if (0 !== $deliveryMode = intval($requestData->get('deliveryModeId', 0))) {
$slice->setDeliveryModeId($deliveryMode);
} else {
$messages[] = $this->getTranslator()->trans(
'The delivery mode is not valid',
[],
SoColissimo::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.',
[],
SoColissimo::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',
[],
SoColissimo::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',
[],
SoColissimo::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',
[],
SoColissimo::DOMAIN
);
}
if (0 === count($messages)) {
$slice->save();
$messages[] = $this->getTranslator()->trans(
'Your slice has been saved',
[],
SoColissimo::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 = floatval($val);
return $val;
}
return $default;
}
public function deleteSliceAction()
{
$response = $this->checkAuth([], ['socolissimo'], 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 = intval($requestData->get('id', 0))) {
$slice = SocolissimoPriceQuery::create()->findPk($id);
$slice->delete();
$responseData['success'] = true;
} else {
$responseData['message'] = $this->getTranslator()->trans(
'The slice has not been deleted',
[],
SoColissimo::DOMAIN
);
}
} catch (\Exception $e) {
$responseData['message'] = $e->getMessage();
}
return $this->jsonResponse(json_encode($responseData));
}
}