Initial Commit
This commit is contained in:
77
local/modules/Colissimo/Controller/Configuration.php
Normal file
77
local/modules/Colissimo/Controller/Configuration.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Colissimo\Controller;
|
||||
|
||||
use Colissimo\Colissimo;
|
||||
use Colissimo\Model\Config\ColissimoConfigValue;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
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 Configuration
|
||||
* @package Colissimo\Controller
|
||||
* @author Thomas Arnaud <tarnaud@openstudio.fr>
|
||||
*/
|
||||
class Configuration extends BaseAdminController
|
||||
{
|
||||
public function editConfiguration()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(
|
||||
AdminResources::MODULE,
|
||||
[Colissimo::DOMAIN_NAME],
|
||||
AccessManager::UPDATE
|
||||
)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$form = $this->createForm('colissimo.configuration');
|
||||
$error_message = null;
|
||||
|
||||
try {
|
||||
$validateForm = $this->validateForm($form);
|
||||
$data = $validateForm->getData();
|
||||
|
||||
Colissimo::setConfigValue(
|
||||
ColissimoConfigValue::ENABLED,
|
||||
is_bool($data["enabled"]) ? (int) ($data["enabled"]) : $data["enabled"]
|
||||
);
|
||||
|
||||
return $this->redirectToConfigurationPage();
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$error_message = $this->createStandardFormValidationErrorMessage($e);
|
||||
}
|
||||
|
||||
if (null !== $error_message) {
|
||||
$this->setupFormErrorContext(
|
||||
'configuration',
|
||||
$error_message,
|
||||
$form
|
||||
);
|
||||
$response = $this->render("module-configure", ['module_code' => 'Colissimo']);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the configuration page
|
||||
*/
|
||||
protected function redirectToConfigurationPage()
|
||||
{
|
||||
return RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/Colissimo'));
|
||||
}
|
||||
}
|
||||
84
local/modules/Colissimo/Controller/EditPrices.php
Normal file
84
local/modules/Colissimo/Controller/EditPrices.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Colissimo\Controller;
|
||||
|
||||
use Colissimo\Colissimo;
|
||||
use Colissimo\Model\Config\ColissimoConfigValue;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Thelia\Model\AreaQuery;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class EditPrices
|
||||
* @package Colissimo\Controller
|
||||
* @author Thelia <info@thelia.net>
|
||||
*/
|
||||
class EditPrices extends BaseAdminController
|
||||
{
|
||||
public function editprices()
|
||||
{
|
||||
// Get data & treat
|
||||
$post = $this->getRequest();
|
||||
$operation = $post->get('operation');
|
||||
$area = $post->get('area');
|
||||
$weight = $post->get('weight');
|
||||
$price = $post->get('price');
|
||||
|
||||
if (preg_match("#^add|delete$#", $operation) &&
|
||||
preg_match("#^\d+$#", $area) &&
|
||||
preg_match("#^\d+\.?\d*$#", $weight)
|
||||
) {
|
||||
// check if area exists in db
|
||||
$exists = AreaQuery::create()
|
||||
->findPK($area);
|
||||
if ($exists !== null) {
|
||||
|
||||
if (null !== $data = Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null)) {
|
||||
$json_data = json_decode(
|
||||
$data,
|
||||
true
|
||||
);
|
||||
}
|
||||
if ((float) $weight > 0 && $operation == "add"
|
||||
&& preg_match("#\d+\.?\d*#", $price)) {
|
||||
$json_data[$area]['slices'][$weight] = $price;
|
||||
} elseif ($operation == "delete") {
|
||||
if (isset($json_data[$area]['slices'][$weight])) {
|
||||
unset($json_data[$area]['slices'][$weight]);
|
||||
}
|
||||
} else {
|
||||
throw new \Exception("Weight must be superior to 0");
|
||||
}
|
||||
ksort($json_data[$area]['slices']);
|
||||
|
||||
Colissimo::setConfigValue(ColissimoConfigValue::PRICES, json_encode($json_data));
|
||||
|
||||
} else {
|
||||
throw new \Exception("Area not found");
|
||||
}
|
||||
} else {
|
||||
throw new \ErrorException("Arguments are missing or invalid");
|
||||
}
|
||||
|
||||
return $this->redirectToConfigurationPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the configuration page
|
||||
*/
|
||||
protected function redirectToConfigurationPage()
|
||||
{
|
||||
return RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/Colissimo'));
|
||||
}
|
||||
}
|
||||
166
local/modules/Colissimo/Controller/Export.php
Normal file
166
local/modules/Colissimo/Controller/Export.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Colissimo\Controller;
|
||||
|
||||
use Colissimo\Colissimo;
|
||||
use Colissimo\Model\ColissimoQuery;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Colissimo\Form\Export as FormExport;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\CustomerTitleQuery;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
|
||||
/**
|
||||
* Class Export
|
||||
* @package Colissimo\Controller
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class Export extends BaseAdminController
|
||||
{
|
||||
const DEFAULT_PHONE = "0100000000";
|
||||
const DEFAULT_CELLPHONE = "0600000000";
|
||||
|
||||
public function exportAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), array('Colissimo'), AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$form = new FormExport($this->getRequest());
|
||||
|
||||
try {
|
||||
$exportForm = $this->validateForm($form);
|
||||
|
||||
// Get new status
|
||||
$status_id = $exportForm->get('status_id')->getData();
|
||||
$status = OrderStatusQuery::create()
|
||||
->filterByCode($status_id)
|
||||
->findOne();
|
||||
|
||||
// Get Colissimo orders
|
||||
$orders = ColissimoQuery::getOrders()->find();
|
||||
|
||||
$export = "";
|
||||
$store_name = ConfigQuery::getStoreName();
|
||||
|
||||
/** @var $order \Thelia\Model\Order */
|
||||
foreach ($orders as $order) {
|
||||
|
||||
$value = $exportForm->get('order_'.$order->getId())->getData();
|
||||
|
||||
if ($value) {
|
||||
|
||||
// Get order information
|
||||
$customer = $order->getCustomer();
|
||||
$locale = $order->getLang()->getLocale();
|
||||
$address = $order->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||
$country = CountryQuery::create()->findPk($address->getCountryId());
|
||||
$country->setLocale($locale);
|
||||
$customerTitle = CustomerTitleQuery::create()->findPk($address->getCustomerTitleId());
|
||||
$customerTitle->setLocale($locale);
|
||||
$weight = $exportForm->get('order_weight_'.$order->getId())->getData();
|
||||
|
||||
if ($weight == 0) {
|
||||
/** @var \Thelia\Model\OrderProduct $product */
|
||||
foreach ($order->getOrderProducts() as $product) {
|
||||
$weight += (double)$product->getWeight();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = $customer->getDefaultAddress()->getCellphone();
|
||||
|
||||
if (empty($cellphone)) {
|
||||
$cellphone = self::DEFAULT_CELLPHONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$export .=
|
||||
"\"".$order->getRef()
|
||||
."\";\"".$address->getLastname()
|
||||
."\";\"".$address->getFirstname()
|
||||
."\";\"".$address->getAddress1()
|
||||
."\";\"".$address->getAddress2()
|
||||
."\";\"".$address->getAddress3()
|
||||
."\";\"".$address->getZipcode()
|
||||
."\";\"".$address->getCity()
|
||||
."\";\"".$country->getIsoalpha2()
|
||||
."\";\"".$phone
|
||||
."\";\"".$cellphone
|
||||
."\";\"".$weight
|
||||
."\";\"".$customer->getEmail()
|
||||
."\";\"\";\"".$store_name
|
||||
."\";\"DOM\";\r\n";
|
||||
|
||||
if ($status) {
|
||||
$event = new OrderEvent($order);
|
||||
$event->setStatus($status->getId());
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Response::create(
|
||||
utf8_decode($export),
|
||||
200,
|
||||
array(
|
||||
"Content-Encoding"=>"ISO-8889-1",
|
||||
"Content-Type"=>"application/csv-tab-delimited-table",
|
||||
"Content-disposition"=>"filename=export.csv"
|
||||
)
|
||||
);
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$this->setupFormErrorContext(
|
||||
Translator::getInstance()->trans("colissimo expeditor export", [], Colissimo::DOMAIN_NAME),
|
||||
$e->getMessage(),
|
||||
$form,
|
||||
$e
|
||||
);
|
||||
|
||||
return $this->render(
|
||||
"module-configure",
|
||||
array(
|
||||
"module_code" => "Colissimo",
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
62
local/modules/Colissimo/Controller/FreeShipping.php
Normal file
62
local/modules/Colissimo/Controller/FreeShipping.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Colissimo\Controller;
|
||||
|
||||
use Colissimo\Colissimo;
|
||||
use Colissimo\Model\Config\ColissimoConfigValue;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class FreeShipping
|
||||
* @package Colissimo\Controller
|
||||
* @author Thomas Arnaud <tarnaud@openstudio.fr>
|
||||
*/
|
||||
class FreeShipping extends BaseAdminController
|
||||
{
|
||||
public function set()
|
||||
{
|
||||
$response = $this->checkAuth(AdminResources::MODULE, [Colissimo::DOMAIN_NAME], AccessManager::UPDATE);
|
||||
if (null !== $response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$form = $this->createForm('colissimo.freeshipping.form');
|
||||
|
||||
|
||||
try {
|
||||
$validateForm = $this->validateForm($form);
|
||||
$data = $validateForm->getData();
|
||||
|
||||
Colissimo::setConfigValue(ColissimoConfigValue::FREE_SHIPPING, (int) ($data["freeshipping"]));
|
||||
return $this->redirectToConfigurationPage();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$response = JsonResponse::create(array("error"=>$e->getMessage()), 500);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the configuration page
|
||||
*/
|
||||
protected function redirectToConfigurationPage()
|
||||
{
|
||||
return RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/Colissimo'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user