1
0
mirror of synced 2025-01-18 17:01:41 +03:00

New customization system with fallback to old one

This commit is contained in:
Pavel 2020-07-22 15:01:10 +03:00 committed by GitHub
parent 804cbfac37
commit b25e9e4a2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 73 deletions

View File

@ -56,14 +56,6 @@ if (!class_exists('WC_Retailcrm_Base')) {
$this->init_settings_fields();
}
if (!class_exists('WC_Retailcrm_Orders')) {
include_once(static::checkCustomFile('orders'));
}
if (!class_exists('WC_Retailcrm_Customers')) {
include_once(static::checkCustomFile('customers'));
}
$this->customers = new WC_Retailcrm_Customers(
$this->apiClient,
$this->settings,
@ -160,26 +152,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
return $settings;
}
/**
* Check custom file
*
* @param string $file
*
* @return string
*/
public static function checkCustomFile($file) {
if (file_exists( WP_CONTENT_DIR . '/retailcrm-custom/class-wc-retailcrm-' . $file . '.php' )) {
return WP_CONTENT_DIR . '/retailcrm-custom/class-wc-retailcrm-' . $file . '.php';
}
return WP_PLUGIN_DIR . '/woo-retailcrm/include/class-wc-retailcrm-' . $file . '.php';
}
public function generate_icml() {
if (!class_exists('WC_Retailcrm_Icml')) {
require_once (static::checkCustomFile('icml'));
}
$retailcrm_icml = new WC_Retailcrm_Icml();
$retailcrm_icml->generate();
}
@ -188,10 +161,6 @@ if (!class_exists('WC_Retailcrm_Base')) {
* Get history
*/
public function retailcrm_history_get() {
if (!class_exists('WC_Retailcrm_History')) {
include_once(static::checkCustomFile('history'));
}
$retailcrm_history = new WC_Retailcrm_History($this->apiClient);
$retailcrm_history->getHistory();
}
@ -207,10 +176,6 @@ if (!class_exists('WC_Retailcrm_Base')) {
* Load stock from retailCRM
*/
public function load_stocks() {
if (!class_exists('WC_Retailcrm_Inventories')) {
include_once(static::checkCustomFile('inventories'));
}
$inventories = new WC_Retailcrm_Inventories($this->apiClient);
$inventories->updateQuantity();
}
@ -376,10 +341,6 @@ if (!class_exists('WC_Retailcrm_Base')) {
*/
public function initialize_analytics()
{
if (!class_exists('WC_Retailcrm_Google_Analytics')) {
include_once(static::checkCustomFile('ga'));
}
if ($this->get_option('ua') && $this->get_option('ua_code')) {
$retailcrm_analytics = WC_Retailcrm_Google_Analytics::getInstance($this->settings);
echo $retailcrm_analytics->initialize_analytics();
@ -393,10 +354,6 @@ if (!class_exists('WC_Retailcrm_Base')) {
*/
public function send_analytics()
{
if (!class_exists('WC_Retailcrm_Google_Analytics')) {
include_once(static::checkCustomFile('ga'));
}
if ($this->get_option('ua') == static::YES && $this->get_option('ua_code') && is_checkout()) {
$retailcrm_analytics = WC_Retailcrm_Google_Analytics::getInstance($this->settings);
echo $retailcrm_analytics->send_analytics();
@ -410,10 +367,6 @@ if (!class_exists('WC_Retailcrm_Base')) {
*/
public function initialize_daemon_collector()
{
if (!class_exists('WC_Retailcrm_Daemon_Collector')) {
include_once(static::checkCustomFile('daemon-collector'));
}
if ($this->get_option('daemon_collector') == static::YES && $this->get_option('daemon_collector_key')) {
$retailcrm_daemon_collector = WC_Retailcrm_Daemon_Collector::getInstance($this->settings);
echo $retailcrm_daemon_collector->initialize_daemon_collector();

View File

@ -96,26 +96,56 @@ if (!class_exists( 'WC_Integration_Retailcrm')) :
*/
public static function load_module()
{
require_once(dirname(__FILE__) . '/include/interfaces/class-wc-retailcrm-builder-interface.php');
require_once(dirname(__FILE__) . '/include/models/class-wc-retailcrm-customer-switcher-state.php');
require_once(dirname(__FILE__) . '/include/models/class-wc-retailcrm-customer-switcher-result.php');
require_once(dirname(__FILE__ ) . '/include/components/class-wc-retailcrm-logger.php');
require_once(dirname(__FILE__ ) . '/include/components/class-wc-retailcrm-history-assembler.php');
require_once(dirname(__FILE__ ) . '/include/components/class-wc-retailcrm-paginated-request.php');
require_once(dirname(__FILE__) . '/include/components/class-wc-retailcrm-customer-switcher.php');
require_once(dirname(__FILE__ ) . '/include/abstracts/class-wc-retailcrm-abstract-builder.php');
require_once(dirname(__FILE__ ) . '/include/abstracts/class-wc-retailcrm-abstracts-settings.php');
require_once(dirname(__FILE__ ) . '/include/abstracts/class-wc-retailcrm-abstracts-data.php');
require_once(dirname(__FILE__ ) . '/include/abstracts/class-wc-retailcrm-abstracts-address.php');
require_once(dirname(__FILE__ ) . '/include/customer/woocommerce/class-wc-retailcrm-wc-customer-builder.php');
require_once(dirname(__FILE__ ) . '/include/order/class-wc-retailcrm-order.php');
require_once(dirname(__FILE__ ) . '/include/order/class-wc-retailcrm-order-payment.php');
require_once(dirname(__FILE__ ) . '/include/order/class-wc-retailcrm-order-item.php');
require_once(dirname(__FILE__ ) . '/include/order/class-wc-retailcrm-order-address.php');
require_once(dirname(__FILE__ ) . '/include/customer/class-wc-retailcrm-customer-address.php');
require_once(dirname(__FILE__ ) . '/include/customer/class-wc-retailcrm-customer-corporate-address.php');
require_once(dirname(__FILE__ ) . '/include/class-wc-retailcrm-base.php');
require_once(dirname(__FILE__ ) . '/include/functions.php');
require_once(self::checkCustomFile('include/interfaces/class-wc-retailcrm-builder-interface.php'));
require_once(self::checkCustomFile('include/models/class-wc-retailcrm-customer-switcher-state.php'));
require_once(self::checkCustomFile('include/models/class-wc-retailcrm-customer-switcher-result.php'));
require_once(self::checkCustomFile('include/components/class-wc-retailcrm-logger.php'));
require_once(self::checkCustomFile('include/components/class-wc-retailcrm-history-assembler.php'));
require_once(self::checkCustomFile('include/components/class-wc-retailcrm-paginated-request.php'));
require_once(self::checkCustomFile('include/components/class-wc-retailcrm-customer-switcher.php'));
require_once(self::checkCustomFile('include/abstracts/class-wc-retailcrm-abstract-builder.php'));
require_once(self::checkCustomFile('include/abstracts/class-wc-retailcrm-abstracts-settings.php'));
require_once(self::checkCustomFile('include/abstracts/class-wc-retailcrm-abstracts-data.php'));
require_once(self::checkCustomFile('include/abstracts/class-wc-retailcrm-abstracts-address.php'));
require_once(self::checkCustomFile('include/customer/woocommerce/class-wc-retailcrm-wc-customer-builder.php'));
require_once(self::checkCustomFile('include/order/class-wc-retailcrm-order.php'));
require_once(self::checkCustomFile('include/order/class-wc-retailcrm-order-payment.php'));
require_once(self::checkCustomFile('include/order/class-wc-retailcrm-order-item.php'));
require_once(self::checkCustomFile('include/order/class-wc-retailcrm-order-address.php'));
require_once(self::checkCustomFile('include/customer/class-wc-retailcrm-customer-address.php'));
require_once(self::checkCustomFile('include/customer/class-wc-retailcrm-customer-corporate-address.php'));
require_once(self::checkCustomFile('include/class-wc-retailcrm-icml.php'));
require_once(self::checkCustomFile('include/class-wc-retailcrm-orders.php'));
require_once(self::checkCustomFile('include/class-wc-retailcrm-customers.php'));
require_once(self::checkCustomFile('include/class-wc-retailcrm-inventories.php'));
require_once(self::checkCustomFile('include/class-wc-retailcrm-history.php'));
require_once(self::checkCustomFile('include/class-wc-retailcrm-ga.php'));
require_once(self::checkCustomFile('include/class-wc-retailcrm-daemon-collector.php'));
require_once(self::checkCustomFile('include/class-wc-retailcrm-base.php'));
require_once(self::checkCustomFile('include/functions.php'));
}
/**
* Check custom file
*
* @param string $file
*
* @return string
*/
public static function checkCustomFile($file)
{
$wooPath = WP_PLUGIN_DIR . '/woo-retailcrm/' . $file;
$withoutInclude = WP_CONTENT_DIR . '/retailcrm-custom/' . str_replace('include/', '', $file);
if (file_exists($withoutInclude)) {
return $withoutInclude;
}
if (file_exists($wooPath)) {
return $wooPath;
}
return dirname(__FILE__) . '/' . $file;
}
/**

View File

@ -34,12 +34,6 @@ class WC_Retailcrm_Base_Test extends WC_Retailcrm_Test_Case_Helper
$this->unit = new \WC_Retailcrm_Base($this->apiMock);
}
public function test_retailcrm_check_custom_file()
{
$file = \WC_Retailcrm_Base::checkCustomFile('ga');
$this->assertInternalType('string', $file);
}
public function test_retailcrm_form_fields()
{
$this->assertInternalType('array', $this->unit->form_fields);