Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View 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'));
}
}

View File

@@ -11,9 +11,13 @@
/*************************************************************************************/
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
@@ -22,7 +26,6 @@ use Thelia\Controller\Admin\BaseAdminController;
*/
class EditPrices extends BaseAdminController
{
public function editprices()
{
// Get data & treat
@@ -31,49 +34,51 @@ class EditPrices extends BaseAdminController
$area = $post->get('area');
$weight = $post->get('weight');
$price = $post->get('price');
if( preg_match("#^add|delete$#", $operation) &&
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) {
$json_path= __DIR__."/../".Colissimo::JSON_PRICE_RESOURCE;
if (is_readable($json_path)) {
$json_data = json_decode(file_get_contents($json_path),true);
} elseif(!file_exists($json_path)) {
$json_data = array();
} else {
throw new \Exception("Can't read Colissimo".Colissimo::JSON_PRICE_RESOURCE.". Please change the rights on the file.");
if (null !== $data = Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null)) {
$json_data = json_decode(
$data,
true
);
}
if((float) $weight > 0 && $operation == "add"
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]))
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']);
if ((file_exists($json_path) ?is_writable($json_path):is_writable(__DIR__."/../"))) {
$file = fopen($json_path, 'w');
fwrite($file, json_encode($json_data));;
fclose($file);
} else {
throw new \Exception("Can't write Colissimo".Colissimo::JSON_PRICE_RESOURCE.". Please change the rights on the file.");
}
Colissimo::setConfigValue(ColissimoConfigValue::PRICES, json_encode($json_data));
} else {
throw new \Exception("Area not found");
}
} else {
} else {
throw new \ErrorException("Arguments are missing or invalid");
}
}
return $this->redirectToRoute("admin.module.configure",array(),
array ( 'module_code'=>"Colissimo",
'_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction'));
return $this->redirectToConfigurationPage();
}
/**
* Redirect to the configuration page
*/
protected function redirectToConfigurationPage()
{
return RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/Colissimo'));
}
}

View File

@@ -14,7 +14,6 @@ namespace Colissimo\Controller;
use Colissimo\Colissimo;
use Colissimo\Model\ColissimoQuery;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
@@ -27,15 +26,12 @@ use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CountryQuery;
use Thelia\Model\CustomerTitleQuery;
use Thelia\Model\OrderQuery;
use Thelia\Model\OrderStatus;
use Thelia\Model\OrderStatusQuery;
/**
* Class Export
* @package Colissimo\Controller
* @author Manuel Raynaud <mraynaud@openstudio.fr>
* @author Manuel Raynaud <manu@raynaud.io>
*/
class Export extends BaseAdminController
{
@@ -53,17 +49,18 @@ class Export extends BaseAdminController
try {
$exportForm = $this->validateForm($form);
// Get new status
$status_id = $exportForm->get('status_id')->getData();
$status = OrderStatusQuery::create()
->filterByCode($status_id)
->findOne();
$orders = ColissimoQuery::getOrders()
->find();
// Get Colissimo orders
$orders = ColissimoQuery::getOrders()->find();
$export = "";
$store_name = ConfigQuery::read("store_name");
$store_name = ConfigQuery::getStoreName();
/** @var $order \Thelia\Model\Order */
foreach ($orders as $order) {
@@ -71,6 +68,7 @@ class Export extends BaseAdminController
if ($value) {
// Get order information
$customer = $order->getCustomer();
$locale = $order->getLang()->getLocale();
$address = $order->getOrderAddressRelatedByDeliveryOrderAddressId();
@@ -78,6 +76,14 @@ class Export extends BaseAdminController
$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
@@ -94,9 +100,7 @@ class Export extends BaseAdminController
}
}
/**
* Cellp
*/
// Cellphone
$cellphone = $customer->getDefaultAddress()->getCellphone();
if (empty($cellphone)) {
@@ -107,32 +111,37 @@ class Export extends BaseAdminController
}
}
/**
* Compute package weight
*/
$weight = 0;
/** @var \Thelia\Model\OrderProduct $product */
foreach ($order->getOrderProducts() as $product) {
$weight+=(double) $product->getWeight();
}
$export .= "\"".$order->getRef()."\";\"".$address->getLastname()."\";\"".$address->getFirstname()."\";\"".$address->getAddress1()."\";\"".$address->getAddress2()."\";\"".$address->getAddress3()."\";\"".$address->getZipcode()."\";\"".$address->getCity()."\";\"".$country->getTitle()."\";\"".$phone."\";\"".$cellphone."\";\"".$weight."\";\"\";\"\";\"".$store_name."\";\"DOM\";\r\n";
$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(
$export,
utf8_decode($export),
200,
array(
"Content-Encoding"=>"ISO-8889-1",
"Content-Type"=>"application/csv-tab-delimited-table",
"Content-disposition"=>"filename=export.csv"
)
@@ -140,7 +149,7 @@ class Export extends BaseAdminController
} catch (FormValidationException $e) {
$this->setupFormErrorContext(
Translator::getInstance()->trans("colissimo expeditor export", [], Colissimo::MESSAGE_DOMAIN),
Translator::getInstance()->trans("colissimo expeditor export", [], Colissimo::DOMAIN_NAME),
$e->getMessage(),
$form,
$e
@@ -154,5 +163,4 @@ class Export extends BaseAdminController
);
}
}
}
}

View File

@@ -12,26 +12,51 @@
namespace Colissimo\Controller;
use Colissimo\Model\ColissimoFreeshipping;
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\HttpFoundation\Response;
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');
class FreeShipping extends BaseAdminController {
public function set() {
$form = new \Colissimo\Form\FreeShipping($this->getRequest());
$response=null;
try {
$vform = $this->validateForm($form);
$data = $vform->get('freeshipping')->getData();
$validateForm = $this->validateForm($form);
$data = $validateForm->getData();
Colissimo::setConfigValue(ColissimoConfigValue::FREE_SHIPPING, (int) ($data["freeshipping"]));
return $this->redirectToConfigurationPage();
$save = new ColissimoFreeshipping();
$save->setActive(!empty($data))->save();
$response = Response::create('');
} 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'));
}
}