Skip to content

Commit

Permalink
Merge pull request #28 from thelia-modules/feature/stop_json
Browse files Browse the repository at this point in the history
Feature/stop json
  • Loading branch information
Yochima authored Jan 11, 2017
2 parents 1aa27ba + c087402 commit 00d164a
Showing 18 changed files with 3,022 additions and 141 deletions.
2 changes: 1 addition & 1 deletion AdminIncludes/module_configuration.html
Original file line number Diff line number Diff line change
@@ -363,7 +363,7 @@
{$label} :
</label>

<input type="text" id="{$label_attr.for}" name="{$name}" value="{$value}" placeholder="{intl d='dpdpickup.ai' l='expcode'}" class="form-control" {literal}pattern="\d{8}"{/literal}/>
<input type="text" id="{$label_attr.for}" name="{$name}" value="{$value}" placeholder="{intl d='dpdpickup.ai' l='expcode'}" class="form-control" />
</div>
{/form_field}

13 changes: 8 additions & 5 deletions Config/config.xml
Original file line number Diff line number Diff line change
@@ -5,10 +5,10 @@
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">

<loops>
<loop name="delivery.dpdpickup" class="DpdPickup\Loop\DpdPickupDelivery" />
<loop name="address.dpdpickup" class="DpdPickup\Loop\DpdPickupAddress" />
<loop name="dpdpickup" class="DpdPickup\Loop\DpdPickupPrice" />
<loop name="dpdpickup.relais.around" class="DpdPickup\Loop\DpdPickupAround" />
<loop name="delivery.dpdpickup" class="DpdPickup\Loop\DpdPickupDelivery" />
<loop name="address.dpdpickup" class="DpdPickup\Loop\DpdPickupAddress" />
<loop name="dpdpickup" class="DpdPickup\Loop\DpdPickupPrice" />
<loop name="dpdpickup.relais.around" class="DpdPickup\Loop\DpdPickupAround" />
<loop name="dpdpickup.check.rights" class="DpdPickup\Loop\CheckRightsLoop" />
<loop name="dpdpickup.orders" class="DpdPickup\Loop\DpdPickupOrders" />
<loop name="dpdpickup.urltracking" class="DpdPickup\Loop\DpdPickupUrlTracking" />
@@ -25,7 +25,10 @@
</forms>

<services>
<service id="hook.order.module" class="DpdPickup\Listener\SetDeliveryModule" scope="request">
<service id="dpd.pickup.price.action" class="DpdPickup\Listener\DpdPickupPriceListener">
<tag name="kernel.event_subscriber"/>
</service>
<service id="hook.order.module" class="DpdPickup\Listener\SetDeliveryModule" scope="request">
<argument type="service" id="request"/>
<tag name="kernel.event_subscriber"/>
</service>
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.4.4</version>
<version>1.4.5</version>
<author>
<name>Thelia</name>
<email>info@thelia.net</email>
22 changes: 21 additions & 1 deletion Config/thelia.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;
@@ -68,6 +67,27 @@ CREATE TABLE `icirelais_freeshipping`

INSERT INTO `icirelais_freeshipping`(`active`, `created_at`, `updated_at`) VALUES(0, NOW(), NOW());

-- ---------------------------------------------------------------------
-- dpdpickup_price
-- ---------------------------------------------------------------------

CREATE TABLE IF NOT EXISTS `dpdpickup_price`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`area_id` INTEGER NOT NULL,
`weight_max` FLOAT NOT NULL,
`price` DECIMAL(16,6) DEFAULT 0.000000,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
INDEX `FI_dpdpickup_price_area_id` (`area_id`),
CONSTRAINT `fk_dpdpickup_price_area_id`
FOREIGN KEY (`area_id`)
REFERENCES `area` (`id`)
ON UPDATE RESTRICT
ON DELETE RESTRICT
) ENGINE=InnoDB;

-- ---------------------------------------------------------------------
-- Mail templates for icirelais
-- ---------------------------------------------------------------------
25 changes: 25 additions & 0 deletions Config/update/1.4.5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
SET FOREIGN_KEY_CHECKS = 0;
-- ---------------------------------------------------------------------
-- dpdpickup_price
-- ---------------------------------------------------------------------

DROP TABLE IF EXISTS `dpdpickup_price`;

CREATE TABLE `dpdpickup_price`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`area_id` INTEGER NOT NULL,
`weight_max` FLOAT NOT NULL,
`price` DECIMAL(16,6) DEFAULT 0.000000,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
INDEX `FI_dpdpickup_price_area_id` (`area_id`),
CONSTRAINT `fk_dpdpickup_price_area_id`
FOREIGN KEY (`area_id`)
REFERENCES `area` (`id`)
ON UPDATE RESTRICT
ON DELETE RESTRICT
) ENGINE=InnoDB;

SET FOREIGN_KEY_CHECKS = 1;
43 changes: 19 additions & 24 deletions Controller/EditPrices.php
Original file line number Diff line number Diff line change
@@ -23,7 +23,10 @@

namespace DpdPickup\Controller;

use DpdPickup\DpdPickup;
use DpdPickup\Event\DpdPickupEvents;
use DpdPickup\Event\DpdPickupPriceEvent;
use DpdPickup\Model\DpdpickupPrice;
use DpdPickup\Model\DpdpickupPriceQuery;
use Thelia\Model\AreaQuery;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\Resource\AdminResources;
@@ -50,38 +53,30 @@ public function editprices()
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__."/../".DpdPickup::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 DpdPickup".DpdPickup::JSON_PRICE_RESOURCE.". Please change the rights on the file.");
}
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 {
if ((float) $weight <= 0) {
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));

if (null === $dpdPickupPrice = DpdpickupPriceQuery::create()->filterByAreaId($area)->filterByWeightMax($weight)->findOne()) {
$dpdPickupPrice = new DpdpickupPrice();
$dpdPickupPrice
->setAreaId($area)
->setWeightMax($weight)
;
fclose($file);
}
$dpdPickupPrice->setPrice($price);
$dpdPickupPriceEvent = new DpdPickupPriceEvent($dpdPickupPrice);

if ($operation === 'delete') {
$this->getDispatcher()->dispatch(DpdPickupEvents::DPDPICKUP_PRICE_DELETE, $dpdPickupPriceEvent);
} else {
throw new \Exception("Can't write DpdPickup".DpdPickup::JSON_PRICE_RESOURCE.". Please change the rights on the file.");
$this->getDispatcher()->dispatch(DpdPickupEvents::DPDPICKUP_PRICE_UPDATE, $dpdPickupPriceEvent);
}
} else {
throw new \Exception("Area not found");
71 changes: 37 additions & 34 deletions Controller/Export.php
Original file line number Diff line number Diff line change
@@ -51,8 +51,8 @@
*/
class Export extends BaseAdminController
{
// FONCTION POUR LE FICHIER D'EXPORT BY Maitre eroudeix@openstudio.fr
// extended by bperche9@gmail.com
// L'arrivée de Maitre Guigit détrône les anciens maitres pour corriger le soucis de json qui se supprime à chaque composer install
// Esclaves : Ex Maitre Roudeix @ Espeche
public static function harmonise($value, $type, $len)
{
switch ($type) {
@@ -94,48 +94,51 @@ public static function harmonise($value, $type, $len)
public function exportfile()
{
if (null !== $response = $this->checkAuth(
array(AdminResources::MODULE),
array('DpdPickup'),
AccessManager::UPDATE
)) {
array(AdminResources::MODULE),
array('DpdPickup'),
AccessManager::UPDATE
)) {
return $response;
}
if (is_readable(ExportExaprint::getJSONpath())) {
$admici = json_decode(file_get_contents(ExportExaprint::getJSONpath()), true);
$keys = array("name", "addr", "zipcode", "city", "tel", "mobile", "mail", "expcode");
$valid = true;
foreach ($keys as $key) {
$valid &= isset($admici[$key]) && ($key === "assur" ? true : !empty($admici[$key]));
}
if (!$valid) {
return Response::create(
Translator::getInstance()->trans(
"The file DpdPickup/Config/exportdat.json is not valid. Please correct it.",
[],
DpdPickup::DOMAIN
),
500
);

$keys = array(
DpdPickup::CONF_EXA_NAME,
DpdPickup::CONF_EXA_ADDR,
DpdPickup::CONF_EXA_ZIPCODE,
DpdPickup::CONF_EXA_CITY,
DpdPickup::CONF_EXA_TEL,
DpdPickup::CONF_EXA_MOBILE,
DpdPickup::CONF_EXA_MAIL,
DpdPickup::CONF_EXA_EXPCODE
);
$valid = true;
foreach ($keys as $key) {
if (null === DpdPickup::getConfigValue($key)) {
$valid = false;
break;
}
} else {
}

if (!$valid) {
return Response::create(
Translator::getInstance()->trans(
"Can't read DpdPickup/Config/exportdat.json. Did you save the export information ?",
"The EXAPRINT configuration is missing. Please correct it.",
[],
DpdPickup::DOMAIN
),
500
);
}
$exp_name = $admici['name'];
$exp_address1 = $admici['addr'];
$exp_address2 = isset($admici['addr2']) ? $admici['addr2'] : "";
$exp_zipcode = $admici['zipcode'];
$exp_city = $admici['city'];
$exp_phone = $admici['tel'];
$exp_cellphone = $admici['mobile'];
$exp_email = $admici['mail'];
$exp_code = $admici['expcode'];

$exp_name = DpdPickup::getConfigValue(DpdPickup::CONF_EXA_NAME);
$exp_address1 = DpdPickup::getConfigValue(DpdPickup::CONF_EXA_ADDR);
$exp_address2 = DpdPickup::getConfigValue(DpdPickup::CONF_EXA_ADDR2, '');
$exp_zipcode = DpdPickup::getConfigValue(DpdPickup::CONF_EXA_ZIPCODE);
$exp_city = DpdPickup::getConfigValue(DpdPickup::CONF_EXA_CITY);
$exp_phone = DpdPickup::getConfigValue(DpdPickup::CONF_EXA_TEL);
$exp_cellphone = DpdPickup::getConfigValue(DpdPickup::CONF_EXA_MOBILE);
$exp_email = DpdPickup::getConfigValue(DpdPickup::CONF_EXA_MAIL);
$exp_code = DpdPickup::getConfigValue(DpdPickup::CONF_EXA_EXPCODE);;
$res = self::harmonise('$' . "VERSION=110", 'alphanumeric', 12) . "\r\n";

$orders = OrderQuery::create()
@@ -176,7 +179,7 @@ public function exportfile()

// Get if the package is assured, how many packages there are & their weight
$assur_package = array_key_exists($collectionKey, $vform->getData()['assur']) ? $vform->getData()['assur'][$collectionKey] : false;
$pkgNumber = array_key_exists($collectionKey, $vform->getData()['pkgNumber']) ? $vform->getData()['pkgNumber'][$collectionKey] : null;
// $pkgNumber = array_key_exists($collectionKey, $vform->getData()['pkgNumber']) ? $vform->getData()['pkgNumber'][$collectionKey] : null;
$pkgWeight = array_key_exists($collectionKey, $vform->getData()['pkgWeight']) ? $vform->getData()['pkgWeight'][$collectionKey] : null;

// Check if status has to be changed
71 changes: 22 additions & 49 deletions Controller/ExportExaprint.php
Original file line number Diff line number Diff line change
@@ -37,18 +37,13 @@
*/
class ExportExaprint extends BaseAdminController
{
public static function getJSONpath()
{
return __DIR__ . "/../Config/exportdat.json";
}

public function export()
{
if (null !== $response = $this->checkAuth(
array(AdminResources::MODULE),
array('DpdPickup'),
AccessManager::UPDATE
)) {
array(AdminResources::MODULE),
array('DpdPickup'),
AccessManager::UPDATE
)) {
return $response;
}

@@ -57,47 +52,25 @@ public function export()
try {
$vform = $this->validateForm($form);

$file_path = self::getJSONpath();

if ((file_exists($file_path) ? is_writable($file_path) : is_writable(__DIR__ . "/../Config/"))) {
$file = fopen(self::getJSONpath(), 'w');
fwrite(
$file,
json_encode(
array(
"name" => $vform->get('name')->getData(),
"addr" => $vform->get('addr')->getData(),
"addr2" => $vform->get('addr2')->getData(),
"zipcode" => $vform->get('zipcode')->getData(),
"city" => $vform->get('city')->getData(),
"tel" => $vform->get('tel')->getData(),
"mobile" => $vform->get('mobile')->getData(),
"mail" => $vform->get('mail')->getData(),
"expcode" => ($vform->get('expcode')->getData())
)
)
);

fclose($file);
DpdPickup::setConfigValue(DpdPickup::CONF_EXA_NAME, $vform->get('name')->getData());
DpdPickup::setConfigValue(DpdPickup::CONF_EXA_ADDR, $vform->get('addr')->getData());
DpdPickup::setConfigValue(DpdPickup::CONF_EXA_ADDR2, $vform->get('addr2')->getData());
DpdPickup::setConfigValue(DpdPickup::CONF_EXA_ZIPCODE, $vform->get('zipcode')->getData());
DpdPickup::setConfigValue(DpdPickup::CONF_EXA_CITY, $vform->get('city')->getData());
DpdPickup::setConfigValue(DpdPickup::CONF_EXA_TEL, $vform->get('tel')->getData());
DpdPickup::setConfigValue(DpdPickup::CONF_EXA_MOBILE, $vform->get('mobile')->getData());
DpdPickup::setConfigValue(DpdPickup::CONF_EXA_MAIL, $vform->get('mail')->getData());
DpdPickup::setConfigValue(DpdPickup::CONF_EXA_EXPCODE, $vform->get('expcode')->getData());

return $this->generateRedirectFromRoute(
"admin.module.configure",
[],
[
'module_code' => "DpdPickup",
'current_tab' => "configure_export_exaprint",
'_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction'
]
);
} else {
throw new \Exception(
Translator::getInstance()->trans(
"Can't write DpdPickup/Config/exportdat.json. Please change the rights on the file and/or the directory.",
[],
DpdPickup::DOMAIN
)
);
}
return $this->generateRedirectFromRoute(
"admin.module.configure",
[],
[
'module_code' => "DpdPickup",
'current_tab' => "configure_export_exaprint",
'_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction'
]
);
} catch (\Exception $e) {
$error_message = $e->getMessage();
}
Loading

0 comments on commit 00d164a

Please sign in to comment.