Files
domokits/local/modules/ColissimoWs/Controller/FreeShippingController.php
Laurent LE CORRE 649c92e52f Ajout des modules ColissimoWs et ColissimoLabel.php
Ne pas oublier de vérifier si les tables nécessaires sont bien créées en BDD.
2020-05-07 11:45:31 +02:00

66 lines
3.2 KiB
PHP

<?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;
}
}