Skip to content

Commit 42225d5

Browse files
authored
Merge pull request #155 from BeAPI/issue/76158-new
Issue/76158 new
2 parents ea67c56 + 6157252 commit 42225d5

File tree

6 files changed

+74
-2
lines changed

6 files changed

+74
-2
lines changed

src/Actions/Actions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public static function register_feed_generation() {
4141
* Register new action to get orders
4242
*/
4343
public static function register_get_orders() {
44+
if ( ShoppingFeedHelper::is_order_import_disable() ) {
45+
return;
46+
}
47+
4448
$sf_accounts = ShoppingFeedHelper::get_sf_account_options();
4549
if ( empty( $sf_accounts ) ) {
4650
ShoppingFeedHelper::get_logger()->error(

src/Admin/Options.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,30 @@ function () {
15111511
);
15121512
}
15131513

1514+
add_settings_field(
1515+
'disable_orders_import_option',
1516+
__( 'Order import', 'shopping-feed' ),
1517+
function () {
1518+
?>
1519+
<label for="disable_order_import">
1520+
<input
1521+
type="checkbox"
1522+
id="disable_order_import"
1523+
name="<?php echo esc_attr( sprintf( '%s[disable_order_import]', self::SF_ORDERS_OPTIONS ) ); ?>"
1524+
value="1"
1525+
<?php checked( '1', isset( $this->sf_orders_options['disable_order_import'] ) ? $this->sf_orders_options['disable_order_import'] : '' ); ?>
1526+
>
1527+
<?php esc_html_e( 'Disable orders synchronisation', 'shopping-feed' ); ?>
1528+
</label>
1529+
<p class="description" id="tagline-description">
1530+
<?php esc_html_e( 'Disable the import of new orders to WooCommerce and stops the synchronization of existing ones with ShoppingFeed.', 'shopping-feed' ); ?>
1531+
</p>
1532+
<?php
1533+
},
1534+
self::SF_ORDERS_SETTINGS_PAGE,
1535+
'sf_orders_settings_import_options'
1536+
);
1537+
15141538
add_settings_field(
15151539
'Frequency',
15161540
__( 'Frequency', 'shopping-feed' ),

src/Admin/WoocommerceActions.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,16 @@ function ( $order_id, $message ) {
151151
add_action(
152152
$action,
153153
function ( $order_id ) use ( $sf_action ) {
154-
//if its not a sf order
154+
//if it's not a sf order
155155
if ( ! Order::is_sf_order( $order_id ) ) {
156156
return;
157157
}
158+
159+
// Don't update order is synchronisation is disabled.
160+
if ( ShoppingFeedHelper::is_order_import_disable() ) {
161+
return;
162+
}
163+
158164
try {
159165
$operations = new Operations( $order_id );
160166
if ( ! method_exists( $operations, $sf_action ) ) {

src/Orders/Operations.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ private function acknowledge( $message = '' ) {
192192
* @param string $message
193193
*/
194194
public static function acknowledge_order( $order_id, $message = '' ) {
195+
// Don't acknowledge order is synchronisation is disabled.
196+
if ( ShoppingFeedHelper::is_order_import_disable() ) {
197+
return;
198+
}
199+
195200
$ok = true;
196201
try {
197202
$operations = new self( $order_id );
@@ -247,6 +252,11 @@ public static function get_available_operations() {
247252
* @author Stéphane Gillot
248253
*/
249254
public static function acknowledge_error( OrderResource $sf_order, $error ) {
255+
// Don't acknowledge order is synchronisation is disabled.
256+
if ( ShoppingFeedHelper::is_order_import_disable() ) {
257+
return;
258+
}
259+
250260
$shop = Sdk::get_sf_account_shop( $sf_order->toArray()['storeId'] );
251261
if ( ! $shop ) {
252262
ShoppingFeedHelper::get_logger()->notice(

src/Orders/Orders.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ public function get_orders( $sf_account, $since = '' ) {
6060
'shopping-feed-orders'
6161
);
6262

63+
// Check if order import is enable
64+
if ( ShoppingFeedHelper::is_order_import_disable() ) {
65+
ShoppingFeedHelper::log(
66+
\WC_Log_Levels::INFO,
67+
'Order import is disabled',
68+
'shopping-feed-orders'
69+
);
70+
71+
return false;
72+
}
73+
6374
$shop = Sdk::get_sf_shop( $sf_account );
6475

6576
if ( ! $shop instanceof StoreResource ) {

src/ShoppingFeedHelper.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public static function get_zones_with_shipping_methods() {
427427
);
428428
}
429429

430-
$all_shipping_methods = apply_filters('sf_all_shipping_methods', $all_shipping_methods);
430+
$all_shipping_methods = apply_filters( 'sf_all_shipping_methods', $all_shipping_methods );
431431

432432
return $all_shipping_methods;
433433
}
@@ -967,4 +967,21 @@ public static function current_language() {
967967
$feed_manager = self::get_feedbuilder_manager();
968968
return $feed_manager->get_builder()->current_languages();
969969
}
970+
971+
/**
972+
* Check if order import is disable.
973+
*
974+
* @return bool
975+
*/
976+
public static function is_order_import_disable() {
977+
$orders_options = self::get_sf_orders_options();
978+
979+
if ( false === $orders_options ) {
980+
return false;
981+
}
982+
983+
$disable_order_import = (int) ( $orders_options['disable_order_import'] ?? 0 );
984+
985+
return 1 === $disable_order_import;
986+
}
970987
}

0 commit comments

Comments
 (0)