Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Debusschere Alexandre committed Jun 6, 2018
0 parents commit 352dbd1
Show file tree
Hide file tree
Showing 56 changed files with 3,499 additions and 0 deletions.
42 changes: 42 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,42 @@
Contributing to La Poste Suivi
--------------------------

La Poste Suivi is an open-source module. Everyone is welcome and even encouraged to contribute with their own improvements.

To contribute to the project, you should ideally be familiar with Git, the source code management system that PrestaShop uses, with the official repository being hosted on Github:
* You can learn more about Git here: http://try.github.io/ (there are many tutorials available on the Web).
* You can get help on Github here: https://help.github.com/.
* Windows users can get a nice interface for Git by installing TortoiseGit: https://tortoisegit.org/

Contributors should follow the following process:

1. Create your Github account, if you do not have one already.
2. Fork the La Poste Suivi project to your Github account.
3. Clone your fork to your local machine.
4. Create a branch in your local clone for your changes.
5. Change the files in your branch. Be sure to follow [the coding standards][1].
6. Push your changed branch to your fork in your Github account.
7. Create a pull request for your changes on the PrestaShop project. Be sure to follow [the commit message norm][2] in your pull request. If you need help to make a pull request, read the [Github help page about creating pull requests][3].
8. Wait for one of the core developers either to include your change in the codebase, or to comment on possible improvements you should make to your code.

That's it: you have contributed to this open source project! Congratulations!

The PrestaShop documentation features a thorough explanation of the [complete process to your first pull request][4].

If you don't feel comfortable forking the project or using Git, you can also either:
* Edit a file directly within Github: browse to the target file, click the "Edit" button, make your changes in the editor then click on "Propose File Change". Github will automatically create a new fork and branch on your own Github account, then suggest to create a pull request to PrestaShop. Once the pull request is submitted, you just have to wait for a core developer to answer you.

Thank you for your help !


### About licenses

* All core files you commit in your pull request must respect/use the [MIT License][7].

[1]: http://doc.prestashop.com/display/PS16/Coding+Standards
[2]: http://doc.prestashop.com/display/PS16/How+to+write+a+commit+message
[3]: https://help.github.com/articles/using-pull-requests
[4]: http://doc.prestashop.com/display/PS16/Contributing+code+to+PrestaShop
[5]: http://forge.prestashop.com/
[6]: http://doc.prestashop.com/display/PS16/How+to+use+the+Forge+to+contribute+to+PrestaShop
[7]: https://opensource.org/licenses/MIT
175 changes: 175 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions README.md
@@ -0,0 +1,54 @@
# La Poste Suivi

## À propos

La Poste Suivi est une solution de suivie professionnelle en back-office utilisant l'API Suivi de La Poste.
**Suivre vos colis La Poste, Colissimo et Chronopost avec un seul module** devient possible, et même changer de statut automatiquement en fonction du suivi !

## Fonctionnalités

La nouvelle API La Poste vous permettra de suivre aussi bien vos colis La Poste, Colissimo et Chronopost de façon simple et automatisée grâce à une interface claire et sans fioriture.
Il est également possible de changer le statut des commandes automatiquement en fonction des statuts de suivi des colis.

Il suffit de souscrire à l'API sur [https://developer.laposte.fr/products/suivi/latest](https://developer.laposte.fr/products/suivi/latest) pour recevoir votre clé API.

Le service est fiable et pérenne, vous utilisez une API officielle La Poste ce qui vous garanti le bon fonctionnement du service.


## Les "+" pour vous

* Module de suivi simple et efficace (~2 minutes pour la configuration)
* Mise à jour automatique des suivis et statuts de vos commandes
* Le suivi est affiché au marchand dans un nouvel onglet dédié sur la fiche de commande
* Un résumé de tous les suivis est disponible dans le nouvel onglet Commandes > La Poste Suivi
* Le numéro de suivi est affiché dans la liste de vos commandes
* Le suivi est affiché au client (front-office) dans l'historique des commandes
* Ajout de la tache planifiée automatiquement dans le module "Éditeur de tâches cron" de PrestaShop
* Compatible avec les modules Colissimo et SoNice

## Les "+" pour le client

* L'assurance de savoir à tout moment l'avancement de la livraison, la position du colis
* Une information claire et pertinente

## Limite de support

Il s’agit d’un module gratuit mis à la disposition de la communauté PrestaShop, ainsi, aucun support technique ne sera fourni de notre part.
Le module est fourni “tel quel”, sans garantie d’aucune sorte (voir LICENCE.md).

Le module étant relativement simple, en cas de support technique, votre webmaster et/ou agence web devraient avoir les connaissances techniques nécessaires à la correction et/ou adaptation du module à votre boutique.

En cas de bug avéré, vous pouvez nous soumettre un rapport de bug sur GitHub en suivant la procédure décrite dans l’entête de la configuration du module :
[https://github.com/Common-Services/lapostesuivi/issues](https://github.com/Common-Services/lapostesuivi/issues)

## Compatibilité

PrestaShop 1.6 et 1.7.

## Prérequis

* Technique :
* Librairie **cURL** installée
* Version PHP supèrieure à 5.3.0 (idéalement 5.6+)
* API :
* S'inscrire et créer un projet pour l'API Suivi sur [https://developer.laposte.fr/products/suivi/latest](https://developer.laposte.fr/products/suivi/latest)
34 changes: 34 additions & 0 deletions bootstrap/autoload.php
@@ -0,0 +1,34 @@
<?php
/**
* @author debuss-a <alexandre@common-services.com>
* @copyright Copyright (c) 2018 Common-Services
* @license CC BY-SA 4.0
*/

/**
* @param string $class_name
*/
function laPosteSuiviAutoLoader($class_name)
{
$folders_path = array(
_PS_MODULE_DIR_.'lapostesuivi/classes/',
_PS_MODULE_DIR_.'lapostesuivi/interfaces/',
);

foreach ($folders_path as $dir) {
$recursive_iterator_iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir),
RecursiveIteratorIterator::SELF_FIRST
);

foreach ($recursive_iterator_iterator as $file) {
/** @var SplFileObject $file */
if (Tools::strtolower($file->getBasename('.php')) == Tools::strtolower($class_name)) {
require_once $file->getRealPath();
break;
}
}
}
}

spl_autoload_register('laPosteSuiviAutoLoader');
35 changes: 35 additions & 0 deletions bootstrap/index.php
@@ -0,0 +1,35 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
88 changes: 88 additions & 0 deletions classes/LaPosteSuiviEmployee.php
@@ -0,0 +1,88 @@
<?php
/**
* @author debuss-a <alexandre@common-services.com>
* @copyright Copyright (c) 2018 Common-Services
* @license CC BY-SA 4.0
*/

if (!defined('_PS_VERSION_')) {
exit;
}

/**
* Class LaPosteSuiviEmployee
*/
class LaPosteSuiviEmployee extends Employee implements LaPosteSuiviConstantInterface
{

/**
* Create the cron task employee and return its ID, or false on error.
*
* @return bool|int
*/
public static function create()
{
$id_employee = (int)Configuration::get('LPS_EMPLOYEE_ID');
if (self::existsInDatabase($id_employee, self::$definition['table'])) {
return $id_employee;
}

try {
$cron_employee = new self();
$cron_employee->id_profile = 1;
$cron_employee->id_lang = Configuration::get('PS_LANG_DEFAULT');
$cron_employee->lastname = 'Suivi';
$cron_employee->firstname = 'LaPoste';
$cron_employee->email = 'no-reply-'.(int)rand(1000, 9999).'@lapostesuivi.fr';
$cron_employee->passwd = LaPosteSuiviTools::generateRandomPassword();
$cron_employee->add();
} catch (Exception $exception) {
Tools::dieOrLog($exception->getMessage(), false);
return false;
}

Configuration::updateValue('LPS_EMPLOYEE_ID', $cron_employee->id);

return $cron_employee->id;
}

/**
* @return bool
*/
public static function remove()
{
$id_employee = (int)Configuration::get('LPS_EMPLOYEE_ID');
if (!self::existsInDatabase($id_employee, self::$definition['table'])) {
return true;
}

try {
$cron_employee = new self($id_employee);
if (Validate::isLoadedObject($cron_employee)) {
return $cron_employee->delete();
}
} catch (Exception $exception) {
Tools::dieOrLog($exception->getMessage(), false);
}

return false;
}

/**
* Keep only 1 LaPoste Suivi employee in Db.
*
* @param bool $autodate
* @param bool $null_values
* @return bool
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function add($autodate = true, $null_values = true)
{
if (self::existsInDatabase((int)Configuration::get('LPS_EMPLOYEE_ID'), self::$definition['table'])) {
return true;
}

return parent::add($autodate, $null_values);
}
}
80 changes: 80 additions & 0 deletions classes/LaPosteSuiviOrder.php
@@ -0,0 +1,80 @@
<?php
/**
* @author debuss-a <alexandre@common-services.com>
* @copyright Copyright (c) 2018 Common-Services
* @license CC BY-SA 4.0
*/

if (!defined('_PS_VERSION_')) {
exit;
}

/**
* Class LaPosteSuiviOrder
*/
class LaPosteSuiviOrder extends Order
{

/**
* Exactly the same as Order::setCurrentState() except that we return the
* result of OrderHistory::addWithemail().
*
* @param int $id_order_state
* @param int $id_employee
* @return bool
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function setCurrentState($id_order_state, $id_employee = 0)
{
if (empty($id_order_state)) {
return false;
}

$history = new OrderHistory();
$history->id_order = (int)$this->id;
$history->id_employee = (int)$id_employee;
$history->changeIdOrderState((int)$id_order_state, $this);

$res = Db::getInstance()->getRow(
'SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int)$this->id
);

$this->invoice_date = $res['invoice_date'];
$this->invoice_number = $res['invoice_number'];
$this->delivery_date = $res['delivery_date'];
$this->delivery_number = $res['delivery_number'];

$this->update();

return $history->addWithemail();
}

/**
* @return string|null
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function getOrderTrackingNumber()
{
if (isset($this->shipping_number) && !empty($this->shipping_number)) {
return $this->shipping_number;
}

$id_order_carrier = (int)Db::getInstance()->getValue(
'SELECT `id_order_carrier`
FROM `'._DB_PREFIX_.'order_carrier`
WHERE `id_order` = '.(int)$this->id.'
ORDER BY `id_order_carrier` DESC'
);

$order_carrier = new OrderCarrier($id_order_carrier);
if (Validate::isLoadedObject($order_carrier) && $order_carrier->tracking_number) {
return $order_carrier->tracking_number;
}

return null;
}
}
36 changes: 36 additions & 0 deletions classes/LaPosteSuiviOrderState.php
@@ -0,0 +1,36 @@
<?php
/**
* @author debuss-a <alexandre@common-services.com>
* @copyright Copyright (c) 2018 Common-Services
* @license CC BY-SA 4.0
*/

if (!defined('_PS_VERSION_')) {
exit;
}

/**
* Class LaPosteSuiviOrderState
*/
class LaPosteSuiviOrderState extends OrderState
{

/**
* Only returns order states marked as "shipped", suitable for tracking.
*
* @param int $id_lang
* @return array
*/
public static function getOrderStatesShipped($id_lang)
{
$order_states = array();

foreach (OrderState::getOrderStates($id_lang) as $order_state) {
if ($order_state['paid'] == 1 && $order_state['shipped'] == 1 && $order_state['template'] != 'refund') {
$order_states[] = $order_state;
}
}

return $order_states;
}
}

0 comments on commit 352dbd1

Please sign in to comment.