mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
Added custom classes loading in bootstrap.php, fixed discount upload
* Added custom classes loading in bootstrap.php. Fixed discount uploading in case when payment type not configured * Add customization info to README
This commit is contained in:
parent
fb0c45bfd0
commit
114ae5efd1
11
README.md
11
README.md
@ -23,3 +23,14 @@ Module allows integrate CMS Prestashop with [retailCRM](https://www.retailcrm.pr
|
||||
|
||||
* This release contains an experimental feature "corporate customers". Use at your own risk.
|
||||
* This release only supports retailCRM API v5.
|
||||
|
||||
#### Customization
|
||||
|
||||
If you want to change the default behavior of a module classes and be sure that these changes won't be overwritten during the module upgrade process, you should **copy the original classes** that you are going to customize to the `prestashop-root/modules/retailcrm_custom/classes` directory.
|
||||
|
||||
From here you can modify the methods of the classes for your own purposes, and they will not be affected during the module upgrade process.
|
||||
|
||||
Keep in mind that:
|
||||
|
||||
* If the logic and classes of the module have changed a lot after an upgrade, your customized logic may cause the module to malfunction. **You should always check for changes after an upgrade and update your customized classes if needed.**
|
||||
* This feature does not allow to customize the base class (file `retailcrm.php`). For this you can use the standard Prestashop override feature.
|
||||
|
@ -60,6 +60,12 @@ class RetailcrmAutoloader
|
||||
*/
|
||||
protected static $pathTop;
|
||||
|
||||
/**
|
||||
* The top level directory where recursion for custom classes will begin.
|
||||
*
|
||||
*/
|
||||
protected static $pathTopCustom;
|
||||
|
||||
/**
|
||||
* Autoload function for registration with spl_autoload_register
|
||||
*
|
||||
@ -70,6 +76,21 @@ class RetailcrmAutoloader
|
||||
*/
|
||||
public static function loader($className)
|
||||
{
|
||||
if (file_exists(self::$pathTopCustom) && is_dir(self::$pathTopCustom)) {
|
||||
$directory = new RecursiveDirectoryIterator(self::$pathTopCustom);
|
||||
$fileIterator = new RecursiveIteratorIterator($directory);
|
||||
$filename = $className . self::$fileExt;
|
||||
|
||||
foreach ($fileIterator as $file) {
|
||||
if (Tools::strtolower($file->getFilename()) === Tools::strtolower($filename)
|
||||
&& $file->isReadable()
|
||||
&& !class_exists($className)
|
||||
) {
|
||||
include_once $file->getPathname();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$directory = new RecursiveDirectoryIterator(self::$pathTop);
|
||||
$fileIterator = new RecursiveIteratorIterator($directory);
|
||||
$filename = $className . self::$fileExt;
|
||||
@ -104,8 +125,20 @@ class RetailcrmAutoloader
|
||||
{
|
||||
self::$pathTop = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the $pathTopCustom property
|
||||
*
|
||||
* @param string $path The path representing the top level where recursion for custom
|
||||
* classes should begin. Defaults to 'modules/retailcrm_custom/classes'.
|
||||
*/
|
||||
public static function setPathCustom($path)
|
||||
{
|
||||
self::$pathTopCustom = $path;
|
||||
}
|
||||
}
|
||||
|
||||
RetailcrmAutoloader::setPath(realpath(dirname(__FILE__)));
|
||||
RetailcrmAutoloader::setPathCustom(realpath(_PS_MODULE_DIR_ . '/retailcrm_custom/classes'));
|
||||
RetailcrmAutoloader::setFileExt('.php');
|
||||
spl_autoload_register('RetailcrmAutoloader::loader');
|
||||
|
@ -894,6 +894,8 @@ class RetailcrmOrderBuilder
|
||||
}
|
||||
}
|
||||
|
||||
$crmOrder['discountManualAmount'] = round($order->total_discounts, 2);
|
||||
|
||||
if (isset($payment[$paymentType]) && !empty($payment[$paymentType])) {
|
||||
$order_payment = array(
|
||||
'externalId' => $order->id . '#' . $order->reference,
|
||||
@ -901,8 +903,6 @@ class RetailcrmOrderBuilder
|
||||
'type' => $payment[$paymentType]
|
||||
);
|
||||
|
||||
$crmOrder['discountManualAmount'] = round($order->total_discounts, 2);
|
||||
|
||||
if (((float) $crmOrder['discountManualAmount']) > ((float) $order_payment['amount'])) {
|
||||
$crmOrder['discountManualAmount'] = $order_payment['amount'];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user