Skip to content

Commit 4000ce4

Browse files
ecoricapetitphp
authored andcommitted
Add a checkbox to disable order import. Default is to enable for new customers.
1 parent ea67c56 commit 4000ce4

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

src/Actions/Actions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ 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_disable_order_import() ) {
45+
return;
46+
}
4447
$sf_accounts = ShoppingFeedHelper::get_sf_account_options();
4548
if ( empty( $sf_accounts ) ) {
4649
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+
__( 'Disable 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="yes"
1525+
<?php checked( 1, isset( $this->sf_orders_options['disable_order_import'] ) ? $this->sf_orders_options['disable_order_import'] : 0 ); ?>
1526+
>
1527+
<?php esc_html_e( 'Would you like to deactivate order import ?', 'shopping-feed' ); ?>
1528+
</label>
1529+
<p class="description" id="tagline-description">
1530+
<?php esc_html_e( 'If the box is checked, item import will be disabled.', '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/Orders/Operations.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class Operations {
5353
* @throws Exception
5454
*/
5555
public function __construct( $order_id ) {
56+
// Check if import is enable
57+
if ( ShoppingFeedHelper::is_disable_order_import() ) {
58+
return;
59+
}
5660
//Check if the order from SF and return it with metas data
5761
$order_sf_metas = Order::get_order_sf_metas( $order_id );
5862
if (

src/Orders/Orders.php

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

63+
// Check if import is enable
64+
if ( ShoppingFeedHelper::is_disable_order_import() ) {
65+
return false;
66+
}
67+
6368
$shop = Sdk::get_sf_shop( $sf_account );
6469

6570
if ( ! $shop instanceof StoreResource ) {

src/ShoppingFeed.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public function plugin_action_links( $links = array() ) {
222222
public static function activate() {
223223
if ( defined( 'WC_VERSION' ) ) {
224224
self::add_sf_directory();
225+
ShoppingFeedHelper::set_default_orders_option();
225226
Actions::register_feed_generation();
226227
Actions::register_get_orders();
227228
}

src/ShoppingFeedHelper.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,4 +967,36 @@ public static function current_language() {
967967
$feed_manager = self::get_feedbuilder_manager();
968968
return $feed_manager->get_builder()->current_languages();
969969
}
970+
971+
/**
972+
* Return SF disable order import
973+
* @return bool
974+
*/
975+
public static function is_disable_order_import() {
976+
$orders_options = self::get_sf_orders_options();
977+
978+
if ( false === $orders_options ) {
979+
return false;
980+
}
981+
982+
return (bool) ( $orders_options['disable_order_import'] ?? 0 ); // True if the value does not exist. For existing customers
983+
}
984+
985+
/**
986+
* Set default orders options
987+
* @return void
988+
*/
989+
public static function set_default_orders_option() {
990+
// Skip if option has already set
991+
if ( false !== get_option( options::SF_ORDERS_OPTIONS ) ) {
992+
return;
993+
}
994+
995+
update_option(
996+
options::SF_ORDERS_OPTIONS,
997+
[
998+
'disable_order_import' => 1,
999+
]
1000+
);
1001+
}
9701002
}

0 commit comments

Comments
 (0)