add ERP mock objects for testing orders without real ERP
This commit is contained in:
parent
71db3fc055
commit
68f8e1eb51
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,6 +6,7 @@
|
||||
*.tar.gz
|
||||
download/*
|
||||
log/*
|
||||
!log/index.php
|
||||
modules/gamification/
|
||||
upload/*
|
||||
*sitemap.xml
|
||||
@ -86,4 +87,4 @@ modules/*/mails/*
|
||||
config.codekit
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
.zfs/
|
||||
.zfs/
|
||||
|
35
log/index.php
Normal file
35
log/index.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2015 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-2015 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;
|
8
modules/erporder/Mocks/ErpTools.php
Normal file
8
modules/erporder/Mocks/ErpTools.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
class ErpTools
|
||||
{
|
||||
public static function logError($param, $text)
|
||||
{
|
||||
file_put_contents(_PS_ROOT_DIR_.'/log/erptools_error_erp_fake_order_id' , print_r(array('params'=>$param, 'text'=>$text), true), FILE_APPEND);
|
||||
}
|
||||
}
|
14
modules/erporder/Mocks/MockRipcord.php
Normal file
14
modules/erporder/Mocks/MockRipcord.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
class MockRipcord
|
||||
{
|
||||
/**
|
||||
* This method returns a new MockRipcord client.
|
||||
* @param string $url The url of the RPC server to connect with
|
||||
*/
|
||||
public static function client($url)
|
||||
{
|
||||
return new StdClass();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
255
modules/erporder/Mocks/newOrder.php
Normal file
255
modules/erporder/Mocks/newOrder.php
Normal file
@ -0,0 +1,255 @@
|
||||
<?php
|
||||
|
||||
class NewOrder
|
||||
{
|
||||
const TYPE_INVOICE = 'invoice';
|
||||
const TYPE_DELIVERY = 'delivery';
|
||||
const ORDER_DRAFT = 'draft';
|
||||
const ORDER_SALE = 'progress';
|
||||
|
||||
private $model = false;
|
||||
private $uid = false;
|
||||
|
||||
public $order = array(
|
||||
'order_policy' => 'manual',
|
||||
'picking_policy' => 'direct',
|
||||
'pricelist_id' => 1, // Euro
|
||||
'warehouse_id' => 7, // Roykin
|
||||
'origin' => 'Roykin Prestashop',
|
||||
);
|
||||
|
||||
private $line = array(
|
||||
'delay' => 0,
|
||||
'product_uom' => 1,
|
||||
'state' => 'confirmed'
|
||||
);
|
||||
|
||||
public $lines = array();
|
||||
|
||||
private $id_fake = 0;
|
||||
private $data_collected = array();
|
||||
|
||||
public function __construct($model, $uid)
|
||||
{
|
||||
$this->model = $model;
|
||||
$this->uid = $uid;
|
||||
}
|
||||
|
||||
public function create($table, $params)
|
||||
{
|
||||
$this->data_collected[] = array(
|
||||
'method' => 'create',
|
||||
'table' => $table,
|
||||
'params' => $params
|
||||
);
|
||||
|
||||
$d = new DateTime();
|
||||
$id_fake = $d->format('His');
|
||||
return $id_fake;
|
||||
}
|
||||
|
||||
public function exec_workflow($order_id)
|
||||
{
|
||||
file_put_contents(_PS_ROOT_DIR_.'/log/erp_fake_order_id_'.$order_id , print_r(
|
||||
array(
|
||||
'data_collected' => $this->data_collected,
|
||||
'order' => $this->order,
|
||||
'lines' => $this->lines
|
||||
),
|
||||
true));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function search($table, $cond)
|
||||
{
|
||||
$this->data_collected[] = array(
|
||||
'method' => 'search',
|
||||
'table' => $table,
|
||||
'params' => $cond
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
public function read($table, $params, $key = false)
|
||||
{
|
||||
$this->data_collected[] = array(
|
||||
'method' => 'read',
|
||||
'table' => $table,
|
||||
'params' => $params,
|
||||
'key' => $key
|
||||
);
|
||||
return array(rand(0, 100));
|
||||
}
|
||||
|
||||
public function assignWaitValidation($bool)
|
||||
{
|
||||
$this->order['wait_validation'] = $bool;
|
||||
}
|
||||
|
||||
public function assignPositionFiscal($id)
|
||||
{
|
||||
$this->order['fiscal_position'] = $id;
|
||||
}
|
||||
|
||||
public function assignCurrency($id)
|
||||
{
|
||||
$this->order['currency_id'] = $id;
|
||||
}
|
||||
|
||||
public function assignDate($date)
|
||||
{
|
||||
$this->order['date_order'] = $date;
|
||||
}
|
||||
|
||||
public function assignReference($ref)
|
||||
{
|
||||
$this->order['name'] = $ref;
|
||||
}
|
||||
|
||||
public function assignCustomer(Customer $customer)
|
||||
{
|
||||
$this->order['partner_id'] = (int)$customer->id_erp;
|
||||
}
|
||||
|
||||
public function assignState($state)
|
||||
{
|
||||
$this->order['state'] = $state;
|
||||
}
|
||||
|
||||
public function assignPayment($payment)
|
||||
{
|
||||
$this->order['payment_term'] = $payment;
|
||||
}
|
||||
|
||||
public function assignInvoiceCustomer(Address $address)
|
||||
{
|
||||
$id = $this->getAddressInErp($address, NewOrder::TYPE_INVOICE);
|
||||
$this->order['partner_invoice_id'] = (int)$id;
|
||||
}
|
||||
|
||||
public function assignShippingCustomer(Address $address)
|
||||
{
|
||||
$id = $this->getAddressInErp($address, NewOrder::TYPE_DELIVERY);
|
||||
$this->order['partner_shipping_id'] = (int)$id;
|
||||
}
|
||||
|
||||
public function assignCarrier($id)
|
||||
{
|
||||
$this->order['carrier_id'] = $id;
|
||||
}
|
||||
|
||||
public function assignNote($note)
|
||||
{
|
||||
$this->order['note'] = $note;
|
||||
}
|
||||
|
||||
public function checkShippingId($id)
|
||||
{
|
||||
return ($this->order->id_carrier == $id);
|
||||
}
|
||||
|
||||
private function newLine($key)
|
||||
{
|
||||
$this->lines[$key] = $this->line;
|
||||
}
|
||||
|
||||
public function assignLineProduct($key, $value)
|
||||
{
|
||||
if (empty($this->lines[$key])) {
|
||||
$this->newLine($key);
|
||||
}
|
||||
$this->lines[$key]['product_id'] = $value;
|
||||
}
|
||||
|
||||
public function assignLineName($key, $value)
|
||||
{
|
||||
if (empty($this->lines[$key])) {
|
||||
$this->newLine($key);
|
||||
}
|
||||
$this->lines[$key]['name'] = $value;
|
||||
}
|
||||
|
||||
public function assignLineOrder($key, $value)
|
||||
{
|
||||
if (empty($this->lines[$key])) {
|
||||
$this->newLine($key);
|
||||
}
|
||||
$this->lines[$key]['order_id'] = $value;
|
||||
}
|
||||
|
||||
public function assignLineUnitPrice($key, $value)
|
||||
{
|
||||
if (empty($this->lines[$key])) {
|
||||
$this->newLine($key);
|
||||
}
|
||||
$this->lines[$key]['price_unit'] = $value;
|
||||
}
|
||||
|
||||
public function assignLineQuantity($key, $value)
|
||||
{
|
||||
if (empty($this->lines[$key])) {
|
||||
$this->newLine($key);
|
||||
}
|
||||
$this->lines[$key]['product_uom_qty'] = $value;
|
||||
}
|
||||
|
||||
public function assignLineTaxes($key, $value)
|
||||
{
|
||||
if (empty($this->lines[$key])) {
|
||||
$this->newLine($key);
|
||||
}
|
||||
$this->lines[$key]['tax_id'] = $value;
|
||||
}
|
||||
|
||||
public function assignLineProductTemplate($key, $value)
|
||||
{
|
||||
if (empty($this->lines[$key])) {
|
||||
$this->newLine($key);
|
||||
}
|
||||
$this->lines[$key]['product_tmpl_id'] = $value;
|
||||
}
|
||||
|
||||
private function getAddressInErp(Address $address, $type)
|
||||
{
|
||||
return NewOrder::TYPE_INVOICE?1:2;
|
||||
/*
|
||||
// $handle = fopen(dirname(__FILE__).'/log.txt', 'a+');
|
||||
// fwrite($handle, 'heure : '.date('Y-m-d H:i:s').PHP_EOL);
|
||||
// fwrite($handle, 'is_erp : '.$address->is_erp.PHP_EOL);
|
||||
// fwrite($handle, 'id_erp : '.$address->id_erp.PHP_EOL);
|
||||
// if ($address->is_erp == 0) {
|
||||
// return $this->createAddressInErp($address, $type);
|
||||
// }
|
||||
|
||||
|
||||
$country = $this->search('res.country', array(
|
||||
array('name', '=', $address->country)
|
||||
));
|
||||
$country = $this->read('res.country', $country)[0];
|
||||
|
||||
$addr = array(
|
||||
array('id', '=', $address->id_erp),
|
||||
// array('street', '=', $address->address1),
|
||||
// array('zip', '=', $address->postcode),
|
||||
// array('country_id', '=', $country['id']),
|
||||
// array('type', '=', $type)
|
||||
);
|
||||
|
||||
$addrs = $this->search('res.partner', $addr);
|
||||
// foreach ($addrs as $addr) {
|
||||
// fwrite($handle, 'resultat recherche : '.$addr.PHP_EOL);
|
||||
// }
|
||||
if (count($addrs) == 0) {
|
||||
return $this->createAddressInErp($address, $type);
|
||||
}
|
||||
|
||||
return $addrs[0];
|
||||
*/
|
||||
}
|
||||
|
||||
public static function logError($record, $type = 'unknown')
|
||||
{
|
||||
file_put_contents(_PS_ROOT_DIR_.'/log/error_erp_fake_order_id_'.$order_id , print_r(array('record'=>$record, 'type'=>$type), true));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -27,9 +27,16 @@
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
require 'newOrder.php';
|
||||
require_once _PS_ROOT_DIR_.'/erp/ripcord/ripcord.php';
|
||||
require_once _PS_ROOT_DIR_.'/erp/ErpTools.php';
|
||||
if (defined('TEST_DISABLE_ERP') && TEST_DISABLE_ERP) {
|
||||
require_once __DIR__.'/Mocks/newOrder.php';
|
||||
require_once __DIR__.'/Mocks/MockRipcord.php';
|
||||
require_once __DIR__.'/Mocks/ErpTools.php';
|
||||
}
|
||||
else {
|
||||
require 'newOrder.php';
|
||||
require_once _PS_ROOT_DIR_.'/erp/ripcord/ripcord.php';
|
||||
require_once _PS_ROOT_DIR_.'/erp/ErpTools.php';
|
||||
}
|
||||
|
||||
class Erporder extends Module
|
||||
{
|
||||
@ -45,7 +52,11 @@ class Erporder extends Module
|
||||
$this->displayName = $this->l('Erp order');
|
||||
$this->description = $this->l('Sync order in Odoo');
|
||||
|
||||
if (defined('TEST_DISABLE_ERP') && !TEST_DISABLE_ERP) {
|
||||
if (defined('TEST_DISABLE_ERP') && TEST_DISABLE_ERP) {
|
||||
$this->uid = '0';
|
||||
$this->model = MockRipcord::client('');
|
||||
}
|
||||
else {
|
||||
$this->common = ripcord::client(ERP_URL.'/xmlrpc/2/common');
|
||||
$this->common->version();
|
||||
$this->uid = $this->common->authenticate(ERP_DB, ERP_USERNAME, ERP_PASSWORD, array());
|
||||
@ -65,10 +76,6 @@ class Erporder extends Module
|
||||
|
||||
public function hookActionOrderStatusPostUpdate($params)
|
||||
{
|
||||
if (defined('TEST_DISABLE_ERP') && TEST_DISABLE_ERP) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order = new Order($params['id_order']);
|
||||
|
||||
// if ($_SERVER['REMOTE_ADDR'] != '88.163.22.99') {
|
||||
@ -245,6 +252,13 @@ class Erporder extends Module
|
||||
}
|
||||
}
|
||||
|
||||
if (defined('TEST_DISABLE_ERP') && TEST_DISABLE_ERP) {
|
||||
if ($order_id) {
|
||||
$res = $newOrder->exec_workflow((int)$order_id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($isCB && $order_id) {
|
||||
|
||||
$res = $newOrder->exec_workflow((int)$order_id);
|
||||
@ -273,9 +287,9 @@ class Erporder extends Module
|
||||
|
||||
public function hookActionPDFInvoiceRender($params)
|
||||
{
|
||||
if (defined('TEST_DISABLE_ERP') && TEST_DISABLE_ERP) {
|
||||
return;
|
||||
}
|
||||
if (defined('TEST_DISABLE_ERP') && TEST_DISABLE_ERP) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Tools::getValue('id_order')) {
|
||||
die(Tools::displayError('Order was not found.'));
|
||||
|
Loading…
Reference in New Issue
Block a user