diff --git a/CHANGELOG.md b/CHANGELOG.md index f140678..cc7a51d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2022-05-29 4.6.3 +* Types of deliveries and payments are displayed only for available stores + ## 2022-05-17 4.6.2 * Modified method getting an address by history diff --git a/VERSION b/VERSION index 3208b09..7962f0f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.6.2 \ No newline at end of file +4.6.3 \ No newline at end of file diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index ee93bde..d0baafb 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -188,19 +188,30 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration ]; } - /** - * Shipping options - */ - $shipping_option_list = []; - $retailcrm_shipping_list = $this->apiClient->deliveryTypesList(); + $crmSite = $this->apiClient->getSingleSiteForKey(); - if (!empty($retailcrm_shipping_list) && $retailcrm_shipping_list->isSuccessful()) { - foreach ($retailcrm_shipping_list['deliveryTypes'] as $retailcrm_shipping_type) { - if ($retailcrm_shipping_type['active'] == false) { + /** + * Delivery options + */ + $crmDeliveryList = $this->apiClient->deliveryTypesList(); + + if ($crmDeliveryList instanceof WC_Retailcrm_Response && $crmDeliveryList->isSuccessful()) { + $shippingOptionList = []; + + foreach ($crmDeliveryList['deliveryTypes'] as $crmDelivery) { + if ($crmDelivery['active'] === false) { continue; } - $shipping_option_list[$retailcrm_shipping_type['code']] = $retailcrm_shipping_type['name']; + if ( + isset($crmDelivery['sites']) + && $crmDelivery['sites'] !== [] + && in_array($crmSite, $crmDelivery['sites']) === false + ) { + continue; + } + + $shippingOptionList[$crmDelivery['code']] = $crmDelivery['name']; } $wc_shipping_list = get_wc_shipping_methods(); @@ -220,7 +231,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration 'css' => 'min-width:350px;', 'class' => 'select', 'type' => 'select', - 'options' => $shipping_option_list, + 'options' => $shippingOptionList, 'desc_tip' => true, ]; } @@ -232,23 +243,31 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration */ $crmPaymentsList = $this->apiClient->paymentTypesList(); - if (!empty($crmPaymentsList) && $crmPaymentsList->isSuccessful()) { - $paymentsList = []; + if ($crmPaymentsList instanceof WC_Retailcrm_Response && $crmPaymentsList->isSuccessful()) { + $paymentOptionList = []; $integrationPayments = []; - foreach ($crmPaymentsList['paymentTypes'] as $crmPaymentType) { - if ($crmPaymentType['active'] == false) { + foreach ($crmPaymentsList['paymentTypes'] as $crmPayment) { + if ($crmPayment['active'] === false) { continue; } - if (isset($crmPaymentType['integrationModule'])) { - $integrationPayments['code'][] = $crmPaymentType['code']; - $integrationPayments['name'][] = $crmPaymentType['name']; - - $crmPaymentType['name'] .= ' - ' . __('Integration payment', 'retailcrm'); + if ( + isset($crmPayment['sites']) + && $crmPayment['sites'] !== [] + && in_array($crmSite, $crmPayment['sites']) === false + ) { + continue; } - $paymentsList[$crmPaymentType['code']] = $crmPaymentType['name']; + if (isset($crmPayment['integrationModule'])) { + $integrationPayments['code'][] = $crmPayment['code']; + $integrationPayments['name'][] = $crmPayment['name']; + + $crmPayment['name'] .= ' - ' . __('Integration payment', 'retailcrm'); + } + + $paymentOptionList[$crmPayment['code']] = $crmPayment['name']; } $wc_payment = WC_Payment_Gateways::instance(); @@ -282,7 +301,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration 'type' => 'select', 'title' => __($title, 'woocommerce'), 'class' => 'select', - 'options' => $paymentsList, + 'options' => $paymentOptionList, 'desc_tip' => true, 'description' => __($description, 'woocommerce'), ]; diff --git a/src/readme.txt b/src/readme.txt index c52f069..d4feff6 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla Requires PHP: 7.0 Requires at least: 5.3 Tested up to: 6.0 -Stable tag: 4.6.2 +Stable tag: 4.6.3 License: GPLv1 or later License URI: http://www.gnu.org/licenses/gpl-1.0.html @@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i == Changelog == += 4.6.3 = +* Types of deliveries and payments are displayed only for available stores + = 4.6.2 = * Modified method getting an address by history diff --git a/src/retailcrm.php b/src/retailcrm.php index 7b07f2f..2ca8f23 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -5,7 +5,7 @@ * Description: Integration plugin for WooCommerce & Simla.com * Author: RetailDriver LLC * Author URI: http://retailcrm.pro/ - * Version: 4.6.2 + * Version: 4.6.3 * Tested up to: 6.0 * WC requires at least: 5.4 * WC tested up to: 6.9 diff --git a/src/uninstall.php b/src/uninstall.php index 315290a..30aae38 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.6.2 + * @version 4.6.3 * * @package RetailCRM */ diff --git a/tests/datasets/data-base-retailcrm.php b/tests/datasets/data-base-retailcrm.php index aafe15a..f38523c 100644 --- a/tests/datasets/data-base-retailcrm.php +++ b/tests/datasets/data-base-retailcrm.php @@ -75,6 +75,18 @@ class DataBaseRetailCrm ], 'active' => true ], + [ + 'name' => 'payment4', + 'code' => 'payment4', + 'active' => true, + 'sites' => ['prestaShop'] + ], + [ + 'name' => 'payment5', + 'code' => 'payment5', + 'active' => true, + 'sites' => ['woocommerce'] + ] ] ]; } @@ -93,6 +105,18 @@ class DataBaseRetailCrm 'name' => 'delivery2', 'code' => 'delivery2', 'active' => false + ], + [ + 'name' => 'delivery3', + 'code' => 'delivery3', + 'active' => true, + 'sites' => ['prestaShop'] + ], + [ + 'name' => 'delivery4', + 'code' => 'delivery4', + 'active' => true, + 'sites' => ['woocommerce'] ] ] ]; diff --git a/tests/test-wc-retailcrm-base.php b/tests/test-wc-retailcrm-base.php index b999427..89e4173 100644 --- a/tests/test-wc-retailcrm-base.php +++ b/tests/test-wc-retailcrm-base.php @@ -36,10 +36,12 @@ class WC_Retailcrm_Base_Test extends WC_Retailcrm_Test_Case_Helper 'paymentTypesList', 'statusesList', 'customFieldsList', + 'getSingleSiteForKey', ] ) ->getMock(); + $this->setMockResponse($this->apiMock, 'getSingleSiteForKey', ['woocommerce']); $this->setMockOrderMethods(); $this->setMockDeliveryTypes(); $this->setMockPaymentTypes();