Ajout et config du module Chronopost

This commit is contained in:
2021-09-22 23:03:39 +02:00
parent 7287fb7959
commit 08f1af5f96
60 changed files with 13945 additions and 18 deletions

View File

@@ -0,0 +1,107 @@
<?php
namespace ChronopostHomeDelivery\Config;
use ChronopostHomeDelivery\ChronopostHomeDelivery;
use Symfony\Component\Filesystem\Filesystem;
use Thelia\Model\ConfigQuery;
class ChronopostHomeDeliveryConst
{
/** Delivery types Name => Code */
const CHRONOPOST_HOME_DELIVERY_DELIVERY_CODES = [
"Chrono13" => "1",
"Chrono18" => "16",
"ChronoExpress" => "17",
"ChronoClassic" => "44",
"Fresh13" => "2R",
"Chrono10" => "2"
];
/** @TODO Add other delivery types */
/** Chronopost shipper identifiers */
const CHRONOPOST_HOME_DELIVERY_CODE_CLIENT = "chronopost_home_delivery_code";
const CHRONOPOST_HOME_DELIVERY_PASSWORD = "chronopost_home_delivery_password";
/** WSDL for the Chronopost Shipping Service */
const CHRONOPOST_HOME_DELIVERY_SHIPPING_SERVICE_WSDL = "https://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl";
//const CHRONOPOST_HOME_DELIVERY_RELAY_SEARCH_SERVICE_WSDL = "https://ws.chronopost.fr/recherchebt-ws-cxf/PointRelaisServiceWS?wsdl";
const CHRONOPOST_HOME_DELIVERY_COORDINATES_SERVICE_WSDL = "https://ws.chronopost.fr/rdv-cxf/services/CreneauServiceWS?wsdl";
/** @TODO Add other WSDL config key */
/** @Unused */
const CHRONOPOST_HOME_DELIVERY_TRACKING_URL = "https://ws.chronopost.fr/tracking-cxf/TrackingServiceWS/trackSkybillV2";
/** @Unused */
public function getTrackingURL()
{
$URL = self::CHRONOPOST_HOME_DELIVERY_TRACKING_URL;
$URL .= "language=" . "fr_FR"; //todo Make locale a variable
$URL .= "&skybillNumber=" . "XXX"; //todo Use real skybill Number -> getTrackingURL(variable)
return $URL;
}
/** Local static config value, used to limit the number of calls to the DB */
protected static $config = null;
/**
* Set the local static config value
*/
public static function setConfig()
{
$config = [
/** Chronopost basic informations */
self::CHRONOPOST_HOME_DELIVERY_CODE_CLIENT => ChronopostHomeDelivery::getConfigValue(self::CHRONOPOST_HOME_DELIVERY_CODE_CLIENT),
self::CHRONOPOST_HOME_DELIVERY_PASSWORD => ChronopostHomeDelivery::getConfigValue(self::CHRONOPOST_HOME_DELIVERY_PASSWORD),
/** END */
];
/** Delivery types */
foreach (self::getDeliveryTypesStatusKeys() as $statusKey) {
$config[$statusKey] = ChronopostHomeDelivery::getConfigValue($statusKey);
}
/** Set the local static config value */
self::$config = $config;
}
/**
* Return the local static config value or the value of a given parameter
*
* @param null $parameter
* @return array|mixed|null
*/
public static function getConfig($parameter = null)
{
/** Check if the local config value is set, and set it if it's not */
if (null === self::$config) {
self::setConfig();
}
/** Return the value of the config parameter given, or null if it wasn't set */
if (null !== $parameter) {
return (isset(self::$config[$parameter])) ? self::$config[$parameter] : null;
}
/** Return the local static config value */
return self::$config;
}
/** Status keys of the delivery types.
* @return array
*/
public static function getDeliveryTypesStatusKeys()
{
$statusKeys = [];
foreach (self::CHRONOPOST_HOME_DELIVERY_DELIVERY_CODES as $name => $code) {
$statusKeys[$name] = 'chronopost_home_delivery_delivery_' . strtolower($name) . '_status';
}
return $statusKeys;
}
}

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<loops>
<loop class="ChronopostHomeDelivery\Loop\ChronopostHomeDeliveryLoop" name="chronopost.home.delivery" />
<loop class="ChronopostHomeDelivery\Loop\ChronopostHomeDeliveryDeliveryMode" name="chronopost.home.delivery.delivery.mode" />
<loop class="ChronopostHomeDelivery\Loop\ChronopostHomeDeliveryAreaFreeshipping" name="chronopost.home.delivery.area.freeshipping" />
</loops>
<forms>
<form name="chronopost_home_delivery_configuration_form" class="ChronopostHomeDelivery\Form\ChronopostHomeDeliveryConfigurationForm" />
<form name="chronopost.home.delivery.freeshipping.form" class="ChronopostHomeDelivery\Form\ChronopostHomeDeliveryFreeShippingForm" />
<form name="chronopost.home.delivery.add.price.form" class="ChronopostHomeDelivery\Form\ChronopostHomeDeliveryAddPriceForm" />
<form name="chronopost.home.delivery.update.price.form" class="ChronopostHomeDelivery\Form\ChronopostHomeDeliveryUpdatePriceForm" />
</forms>
<services>
<service id="hook.order.module.chronopost.home.delivery" class="ChronopostHomeDelivery\EventListeners\SetDeliveryType" scope="request">
<argument type="service" id="request"/>
<tag name="kernel.event_subscriber"/>
</service>
<service id="chronopost.home.delivery.deliverytype.smarty.plugin" class="ChronopostHomeDelivery\Smarty\Plugins\ChronopostHomeDeliveryDeliveryType" scope="request">
<argument type="service" id="request" />
<argument type="service" id="event_dispatcher"/>
<tag name="thelia.parser.register_plugin" />
</service>
<service id="api.chronopost.home.delivery" class="ChronopostHomeDelivery\EventListeners\APIListener" scope="request">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
<service id="chronopost.home.delivery.notification.mail" class="ChronopostHomeDelivery\EventListeners\ShippingNotificationSender">
<argument type="service" id="thelia.parser" />
<argument type="service" id="mailer"/>
<tag name="kernel.event_subscriber"/>
</service>
</services>
<hooks>
<hook id="chronopost.home.delivery.hook.back" class="ChronopostHomeDelivery\Hook\BackHook">
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfiguration" />
<tag name="hook.event_listener" event="module.config-js" type="back" method="onModuleConfigJs" />
</hook>
<hook id="chronopost.home.delivery.hook.front" class="ChronopostHomeDelivery\Hook\FrontHook" scope="request">
<tag name="hook.event_listener" event="order-delivery.extra" />
</hook>
</hooks>
</config>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="http://thelia.net/schema/dic/module"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
<fullnamespace>ChronopostHomeDelivery\ChronopostHomeDelivery</fullnamespace>
<descriptive locale="en_US">
<title>ChronopostHomeDelivery</title>
<subtitle>Chronopost home delivery module</subtitle>
</descriptive>
<descriptive locale="fr_FR">
<title>ChronopostHomeDelivery</title>
<subtitle>Module de livraison à domicile Chronopost</subtitle>
</descriptive>
<languages>
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.0.4</version>
<authors>
<author>
<name>Thelia</name>
<email>info@thelia.net</email>
</author>
</authors>
<type>classic</type>
<thelia>2.3.4</thelia>
<stability>other</stability>
<mandatory>0</mandatory>
<hidden>0</hidden>
</module>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="chronopost.home.delivery.config.save" path="/admin/module/ChronopostHomeDelivery/config" methods="post">
<default key="_controller">ChronopostHomeDelivery\Controller\ChronopostHomeDeliveryBackOfficeController::saveAction</default>
</route>
<route id="chronopost.home.delivery.configShipper.save" path="/admin/module/ChronopostHomeDelivery/configShipper" methods="post">
<default key="_controller">ChronopostHomeDelivery\Controller\ChronopostHomeDeliveryBackOfficeController::saveActionShipper</default>
</route>
<route id="chronopost.home.delivery.save.label" path="/admin/module/ChronopostHomeDelivery/saveLabel">
<default key="_controller">ChronopostHomeDelivery\Controller\ChronopostHomeDeliveryBackOfficeController::saveLabel</default>
</route>
<route id="chronopost.home.delivery.toggle.freeshipping" path="/admin/module/chronopost-home-delivery/freeshipping" methods="post">
<default key="_controller">ChronopostHomeDelivery\Controller\ChronopostHomeDeliveryFreeShippingController::toggleFreeShippingActivation</default>
</route>
<route id="chronopost.home.delivery.edit.freeshippingfrom" path="/admin/module/chronopost-home-delivery/freeshipping_from" methods="post">
<default key="_controller">ChronopostHomeDelivery\Controller\ChronopostHomeDeliveryFreeShippingController::setFreeShippingFrom</default>
</route>
<route id="chronopost.home.delivery.edit.areafreeshipping" path="/admin/module/chronopost-home-delivery/area_freeshipping" methods="post">
<default key="_controller">ChronopostHomeDelivery\Controller\ChronopostHomeDeliveryFreeShippingController::setAreaFreeShipping</default>
</route>
<route id="chronopost.home.delivery.add.price" path="/admin/module/chronopost-home-delivery/slice/save" methods="post">
<default key="_controller">ChronopostHomeDelivery\Controller\ChronopostHomeDeliverySliceController::saveSliceAction</default>
</route>
<route id="chronopost.home.delivery.update.price" path="/admin/module/chronopost-home-delivery/slice/delete" methods="post">
<default key="_controller">ChronopostHomeDelivery\Controller\ChronopostHomeDeliverySliceController::deleteSliceAction</default>
</route>
<route id="chronopost.home.delivery.get.coordinates" path="/admin/module/chronopost-home-delivery/coordinates">
<default key="_controller">ChronopostHomeDelivery\Controller\ChronopostHomeDeliveryRelayController::findByAddress</default>
</route>
</routes>

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia" namespace="ChronopostHomeDelivery\Model"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../vendor/propel/propel/resources/xsd/database.xsd" >
<table name="chronopost_home_delivery_order">
<column name="id" autoIncrement="true" primaryKey="true" required="true" type="INTEGER" />
<column name="order_id" required="true" type="INTEGER" />
<column name="delivery_type" type="LONGVARCHAR" />
<column name="delivery_code" type="LONGVARCHAR" />
<column name="label_directory" type="LONGVARCHAR" />
<column name="label_number" type="LONGVARCHAR" />
<foreign-key foreignTable="order" name="fk_chronopost_home_delivery_order_order_id" onDelete="CASCADE" onUpdate="RESTRICT">
<reference foreign="id" local="order_id" />
</foreign-key>
</table>
<table name="chronopost_home_delivery_delivery_mode">
<column name="id" primaryKey="true" autoIncrement="true" required="true" type="INTEGER" />
<column name="title" size="255" type="VARCHAR"/>
<column name="code" size="55" type="VARCHAR" required="true"/>
<column name="freeshipping_active" type="BOOLEAN"/>
<column name="freeshipping_from" type="FLOAT"/>
</table>
<table name="chronopost_home_delivery_price">
<column name="id" primaryKey="true" autoIncrement="true" required="true" type="INTEGER" />
<column name="area_id" required="true" type="INTEGER" />
<column name="delivery_mode_id" required="true" type="INTEGER" />
<column name="weight_max" type="FLOAT" />
<column name="price_max" type="FLOAT" />
<column name="franco_min_price" type="FLOAT" />
<column name="price" required="true" type="FLOAT" />
<foreign-key foreignTable="area" name="fk_chronopost_home_delivery_price_area_id" onDelete="RESTRICT" onUpdate="RESTRICT">
<reference foreign="id" local="area_id" />
</foreign-key>
<foreign-key foreignTable="chronopost_home_delivery_delivery_mode" name="fk_chronopost_home_delivery_price_delivery_mode_id" onDelete="RESTRICT" onUpdate="RESTRICT">
<reference foreign="id" local="delivery_mode_id" />
</foreign-key>
</table>
<table name="chronopost_home_delivery_area_freeshipping">
<column name="id" primaryKey="true" autoIncrement="true" required="true" type="INTEGER" />
<column name="area_id" required="true" type="INTEGER" />
<column name="delivery_mode_id" required="true" type="INTEGER" />
<column name="cart_amount" defaultValue="0.000000" scale="6" size="16" type="DECIMAL" />
<foreign-key foreignTable="area" name="fk_chronopost_home_delivery_area_freeshipping_area_id" onDelete="RESTRICT" onUpdate="RESTRICT">
<reference foreign="id" local="area_id" />
</foreign-key>
<foreign-key foreignTable="chronopost_home_delivery_delivery_mode" name="fk_chronopost_home_delivery_area_freeshipping_delivery_mode_id" onDelete="RESTRICT" onUpdate="RESTRICT">
<reference foreign="id" local="delivery_mode_id" />
</foreign-key>
</table>
<external-schema filename="local/config/schema.xml" referenceOnly="true" />
</database>

View File

@@ -0,0 +1,2 @@
# Sqlfile -> Database map
thelia.sql=thelia

View File

@@ -0,0 +1,103 @@
# 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;
-- ---------------------------------------------------------------------
-- chronopost_home_delivery_order
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `chronopost_home_delivery_order`;
CREATE TABLE `chronopost_home_delivery_order`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`order_id` INTEGER NOT NULL,
`delivery_type` TEXT,
`delivery_code` TEXT,
`label_directory` TEXT,
`label_number` TEXT,
PRIMARY KEY (`id`),
INDEX `FI_chronopost_home_delivery_order_order_id` (`order_id`),
CONSTRAINT `fk_chronopost_home_delivery_order_order_id`
FOREIGN KEY (`order_id`)
REFERENCES `order` (`id`)
ON UPDATE RESTRICT
ON DELETE CASCADE
) ENGINE=InnoDB;
-- ---------------------------------------------------------------------
-- chronopost_home_delivery_delivery_mode
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `chronopost_home_delivery_delivery_mode`;
CREATE TABLE `chronopost_home_delivery_delivery_mode`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255),
`code` VARCHAR(55) NOT NULL,
`freeshipping_active` TINYINT(1),
`freeshipping_from` FLOAT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
-- ---------------------------------------------------------------------
-- chronopost_home_delivery_price
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `chronopost_home_delivery_price`;
CREATE TABLE `chronopost_home_delivery_price`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`area_id` INTEGER NOT NULL,
`delivery_mode_id` INTEGER NOT NULL,
`weight_max` FLOAT,
`price_max` FLOAT,
`franco_min_price` FLOAT,
`price` FLOAT NOT NULL,
PRIMARY KEY (`id`),
INDEX `FI_chronopost_home_delivery_price_area_id` (`area_id`),
INDEX `FI_chronopost_home_delivery_price_delivery_mode_id` (`delivery_mode_id`),
CONSTRAINT `fk_chronopost_home_delivery_price_area_id`
FOREIGN KEY (`area_id`)
REFERENCES `area` (`id`)
ON UPDATE RESTRICT
ON DELETE RESTRICT,
CONSTRAINT `fk_chronopost_home_delivery_price_delivery_mode_id`
FOREIGN KEY (`delivery_mode_id`)
REFERENCES `chronopost_home_delivery_delivery_mode` (`id`)
ON UPDATE RESTRICT
ON DELETE RESTRICT
) ENGINE=InnoDB;
-- ---------------------------------------------------------------------
-- chronopost_home_delivery_area_freeshipping
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `chronopost_home_delivery_area_freeshipping`;
CREATE TABLE `chronopost_home_delivery_area_freeshipping`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`area_id` INTEGER NOT NULL,
`delivery_mode_id` INTEGER NOT NULL,
`cart_amount` DECIMAL(16,6) DEFAULT 0.000000,
PRIMARY KEY (`id`),
INDEX `FI_chronopost_home_delivery_area_freeshipping_area_id` (`area_id`),
INDEX `FI_chronopost_home_delivery_area_freeshipping_delivery_mode_id` (`delivery_mode_id`),
CONSTRAINT `fk_chronopost_home_delivery_area_freeshipping_area_id`
FOREIGN KEY (`area_id`)
REFERENCES `area` (`id`)
ON UPDATE RESTRICT
ON DELETE RESTRICT,
CONSTRAINT `fk_chronopost_home_delivery_area_freeshipping_delivery_mode_id`
FOREIGN KEY (`delivery_mode_id`)
REFERENCES `chronopost_home_delivery_delivery_mode` (`id`)
ON UPDATE RESTRICT
ON DELETE RESTRICT
) ENGINE=InnoDB;
# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;