Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with WooCommerce multichannel marketing dashboard #754

Merged
merged 20 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5be052b
Add method to fetch the latest workflow of a feed
nima-karimi Mar 9, 2023
7421e7b
Update FeedIssues to use the new method to fetch latest workflow
nima-karimi Mar 9, 2023
30c70a0
Update CatalogSyncErrors to use the new method to fetch latest workflow
nima-karimi Mar 9, 2023
4ae1695
Add FeedStatusService with a method to get feed registration status
nima-karimi Mar 9, 2023
fb0ac7b
Add method to get feed sync status
nima-karimi Mar 9, 2023
1d03239
Add method to get feed overview stats
nima-karimi Mar 9, 2023
b6fd043
Add method to get global error from workflow
nima-karimi Mar 9, 2023
38a10b5
Refactor FeedState API to use methods from FeedStatusService
nima-karimi Mar 9, 2023
2921cd6
Create PinterestChannel class including basic channel details
nima-karimi Mar 9, 2023
9d1dac5
Make the PinterestChannel class a singleton
nima-karimi Mar 9, 2023
91eca30
Add is_setup_completed method
nima-karimi Mar 9, 2023
28b4d80
Implement get_setup_url method
nima-karimi Mar 9, 2023
8fa2bf6
Implement get_product_listings_status method
nima-karimi Mar 9, 2023
32b28c6
Implement get_errors_count method
nima-karimi Mar 9, 2023
343f912
Make the PinterestChannel class a singleton
nima-karimi Mar 9, 2023
ec9c3f2
Create MarketingChannelRegistrar class to register the channel
nima-karimi Mar 9, 2023
f926686
Register marketing channel if the feature exists
nima-karimi Mar 9, 2023
307aa01
Merge pull request #705 from woocommerce/feature/mcm-integration-sync…
nima-karimi Mar 17, 2023
59df331
Merge branch 'develop' into feature/mcm-integration
nima-karimi Mar 30, 2023
db7b711
Merge branch 'develop' into feature/mcm-integration
nima-karimi May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions class-pinterest-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ public function init_plugin() {
add_action( 'init', array( Pinterest\Billing::class, 'schedule_event' ) );
add_action( 'init', array( Pinterest\AdCredits::class, 'schedule_event' ) );

// Register the marketing channel if the feature is included.
if ( defined( 'WC_MCM_EXISTS' ) ) {
add_action(
'init',
array( Pinterest\MultichannelMarketing\MarketingChannelRegistrar::class, 'register' )
);
}

// Verify that the ads_campaign is active or not.
add_action( 'admin_init', array( Pinterest\AdCredits::class, 'check_if_ads_campaign_is_active' ) );

Expand Down
48 changes: 5 additions & 43 deletions src/API/FeedIssues.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct() {
/**
* Get the feed issue lines for the last workflow of the current feed.
*
* @return array|WP_Error
* @return array|WP_REST_Response|\WP_Error
*
* @param WP_REST_Request $request The request.
*
Expand All @@ -58,8 +58,9 @@ public function __construct() {
public function get_feed_issues( WP_REST_Request $request ) {

try {
$feed_id = FeedRegistration::get_locally_stored_registered_feed_id();
if ( ! Pinterest\ProductSync::is_product_sync_enabled() || ! $feed_id ) {
$merchant_id = Pinterest_For_Woocommerce()::get_data( 'merchant_id' );
$feed_id = FeedRegistration::get_locally_stored_registered_feed_id();
if ( ! Pinterest\ProductSync::is_product_sync_enabled() || ! $feed_id || ! $merchant_id ) {
return array( 'lines' => array() );
}

Expand All @@ -69,7 +70,7 @@ public function get_feed_issues( WP_REST_Request $request ) {
$per_page = $request->has_param( 'per_page' ) ? (int) $request->get_param( 'per_page' ) : 25;

if ( false === $issues_file_url ) {
$workflow = self::get_feed_workflow( $feed_id );
$workflow = Pinterest\Feeds::get_feed_latest_workflow( (string) $merchant_id, (string) $feed_id );

if ( $workflow && isset( $workflow->s3_validation_url ) ) {
$issues_file_url = $workflow->s3_validation_url;
Expand Down Expand Up @@ -269,45 +270,6 @@ private function save_feed_data_cache() {
Pinterest_For_Woocommerce()::save_data( 'feed_data_cache', $this->feed_data_files );
}

/**
* Get the latest Workflow of the
* active feed related to the last attempt to process and ingest our feed, for the Merchant saved in the settings.
*
* @param string $feed_id The ID of the feed.
*
* @return object
*
* @throws Exception PHP Exception.
*/
public static function get_feed_workflow( $feed_id ) {
if ( ! $feed_id ) {
throw new Exception( esc_html__( 'No feed ID provided.', 'pinterest-for-woocommerce' ) );
}

$merchant_id = Pinterest_For_Woocommerce()::get_data( 'merchant_id' );
$feed_report = $merchant_id ? Base::get_merchant_feed_report( $merchant_id, $feed_id ) : false;

if ( ! $feed_report || 'success' !== $feed_report['status'] ) {
throw new Exception( esc_html__( 'Could not get feed report from Pinterest.', 'pinterest-for-woocommerce' ), 400 );
}

if ( ! property_exists( $feed_report['data'], 'workflows' ) || ! is_array( $feed_report['data']->workflows ) || empty( $feed_report['data']->workflows ) ) {
return false;
}

// Get latest workflow.
usort(
$feed_report['data']->workflows,
function ( $a, $b ) {
return $b->created_at - $a->created_at;
}
);

$workflow = reset( $feed_report['data']->workflows );

return $workflow;
}

/**
* Cleanup feed cached data.
*/
Expand Down
Loading