Skip to content

Commit ea67c56

Browse files
authored
Merge pull request #140 from BeAPI/issue/70275-2
add support for multilingual products feeds
2 parents b2dba02 + 792db98 commit ea67c56

18 files changed

+1265
-791
lines changed

shoppingfeed.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
* Plugin bootstrap function.shopping-feed/src/ShoppingFeed.php
4545
*/
4646
function init() {
47-
load_plugin_textdomain( 'shopping-feed', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
48-
4947
ShoppingFeed::get_instance();
5048

5149
if ( ! defined( 'WP_CLI' ) ) {
@@ -58,6 +56,16 @@ function init() {
5856

5957
\add_action( 'plugins_loaded', __NAMESPACE__ . '\\init', 100 );
6058

59+
/**
60+
* Load plugin translations.
61+
*
62+
* @return void
63+
*/
64+
function load_translations(): void {
65+
load_plugin_textdomain( 'shopping-feed', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
66+
}
67+
\add_action( 'init', __NAMESPACE__ . '\\load_translations' );
68+
6169
// Declare the plugin compatibility with High Performance Order Storage
6270
\add_action(
6371
'before_woocommerce_init',

src/Actions/Actions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class Actions {
2424
* Register new action to generate feed
2525
*/
2626
public static function register_feed_generation() {
27+
if ( as_has_scheduled_action( 'sf_generate_feed_action', array(), self::FEED_GROUP ) ) {
28+
as_unschedule_action( 'sf_generate_feed_action', array(), self::FEED_GROUP );
29+
}
30+
2731
as_schedule_recurring_action(
2832
time() + 60,
2933
ShoppingFeedHelper::get_sf_feed_generation_frequency(),

src/Admin/Options.php

Lines changed: 162 additions & 78 deletions
Large diffs are not rendered by default.

src/Admin/WoocommerceActions.php

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use ShoppingFeed\ShoppingFeedWC\Dependencies\ShoppingFeed\Sdk\Api\Store\StoreResource;
1111
use ShoppingFeed\ShoppingFeedWC\Dependencies\ShoppingFeed\Sdk\Client;
1212
use ShoppingFeed\ShoppingFeedWC\Dependencies\ShoppingFeed\Sdk\Credential;
13-
use ShoppingFeed\ShoppingFeedWC\Feed\AsyncGenerator;
1413
use ShoppingFeed\ShoppingFeedWC\Orders\Operations;
1514
use ShoppingFeed\ShoppingFeedWC\Orders\Order;
1615
use ShoppingFeed\ShoppingFeedWC\Orders\Orders;
@@ -37,37 +36,6 @@ class WoocommerceActions {
3736

3837

3938
public function __construct() {
40-
41-
//Generate async feed
42-
add_action(
43-
'sf_feed_generation_process',
44-
[
45-
AsyncGenerator::get_instance(),
46-
'launch',
47-
]
48-
);
49-
50-
//Generate feed part
51-
add_action(
52-
'sf_feed_generation_part',
53-
[
54-
AsyncGenerator::get_instance(),
55-
56-
'generate_feed_part',
57-
],
58-
10,
59-
3
60-
);
61-
62-
//Combine feed's parts
63-
add_action(
64-
'sf_feed_generation_combine_feed_parts',
65-
array(
66-
AsyncGenerator::get_instance(),
67-
'combine_feed_parts',
68-
)
69-
);
70-
7139
//Product Update
7240
add_action( 'woocommerce_update_product', [ $this, 'schedule_product_update' ] );
7341
add_action( 'sf_update_product_data', [ $this, 'update_product_data_callback' ] );
@@ -93,7 +61,8 @@ function () {
9361
return true;
9462
}
9563

96-
AsyncGenerator::get_instance()->launch();
64+
$part_size = ShoppingFeedHelper::get_sf_part_size();
65+
ShoppingFeedHelper::get_feedbuilder_manager()->launch_feed_generation( $part_size );
9766

9867
return true;
9968
}
@@ -315,8 +284,8 @@ public function update_stock( $product_id ) {
315284
*/
316285
public function update_product( $product_id, $only_stock = false ) {
317286
$sf_feed_options = ShoppingFeedHelper::get_sf_feed_options();
318-
$sync_stock = $sf_feed_options['synchro_stock'] ?? 'yes';
319-
$sync_price = $sf_feed_options['synchro_price'] ?? 'yes';
287+
$sync_stock = $sf_feed_options['synchro_stock'] ?? 'yes';
288+
$sync_price = $sf_feed_options['synchro_price'] ?? 'yes';
320289

321290
/**
322291
* If both stock and price synchronization are disable, bail out.

src/Cli/FeedGeneration.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,30 @@
66
defined( 'ABSPATH' ) || exit;
77

88
use ShoppingFeed\ShoppingFeedWC\Feed\Generator;
9+
use ShoppingFeed\ShoppingFeedWC\ShoppingFeedHelper;
10+
use function WP_CLI\Utils\get_flag_value;
911

1012
/**
1113
* Class to add CLI command for feed generation
1214
* @example wp shopping-feed feed-generation
1315
*/
1416
class FeedGeneration {
1517

16-
public function __invoke() {
17-
$generator = Generator::get_instance();
18-
$return = $generator->generate();
18+
/**
19+
* Generate products' feeds.
20+
*
21+
* ## OPTIONS
22+
*
23+
* [--lang=<lang>]
24+
* : Generate feed for a specific language.
25+
*
26+
* ## EXAMPLES
27+
*
28+
* wp example hello Newman
29+
*/
30+
public function __invoke( $args, $assoc_args ) {
31+
$lang = get_flag_value( $assoc_args, 'lang' );
32+
$return = ShoppingFeedHelper::get_feedbuilder_manager()->generate_feed( $lang );
1933
if ( is_wp_error( $return ) ) {
2034
\WP_CLI::error(
2135
sprintf(

src/Feed/AsyncGenerator.php

Lines changed: 0 additions & 220 deletions
This file was deleted.

0 commit comments

Comments
 (0)