$rowHtml .= ''; } else { $rowHtml .= ''; } // elseif ( 'feed_product_type' == $fieldsKey && empty( $default_value ) ) { // $rowHtml .= ''; // } $rowHtml .= ''; $rowHtml .= ''; $selected_value2 = isset( $saved_value['metakey'] ) ? $saved_value['metakey'] : ''; if ( empty( $selected_value2 ) && 'yes' == $globalValue && empty( $template_id ) ) { $selected_value2 = $globalValueMetakey; } $selectDropdownHTML = ''; $rowHtml .= $selectDropdownHTML; $rowHtml .= ''; $rowHtml .= ''; return $rowHtml; } /* * * Function to create sellernext user */ public function ced_amazon_create_sellernext_user() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } $marketplace_id = isset( $_POST['marketplace_id'] ) ? sanitize_text_field( $_POST['marketplace_id'] ) : false; $reAuthorising = isset( $_POST['reAuthorising'] ) ? sanitize_text_field( $_POST['reAuthorising'] ) : false; update_option( 'ced_amazon_current_marketplace_id', $marketplace_id ); $domain = ced_get_navigation_url( 'amazon', array( 'section' => 'setup-amazon', ) ); if ( ! empty( $marketplace_id ) ) { $amzonCurlRequest = CED_AMAZON_DIRPATH . 'admin/amazon/lib/ced-amazon-curl-request.php'; if ( file_exists( $amzonCurlRequest ) ) { require_once $amzonCurlRequest; $this->amzonCurlRequestInstance = new Ced_Amazon_Curl_Request(); } $ced_amazon_regions_info = array(); $amzonRegions = CED_AMAZON_DIRPATH . 'admin/partials/amazonRegions.php'; if ( file_exists( $amzonRegions ) ) { require_once $amzonRegions; } $home_redirect_url_params = array( 'page' => 'sales_channel', 'channel' => 'amazon', 'section' => 'setup-amazon', ); $params = array( 'section' => 'setup-amazon', 'connected' => 'true', ); if ( 'true' == $reAuthorising || $reAuthorising ) { $params['reAuthorising'] = true; } $home_redirect_url = ced_get_navigation_url( 'amazon', $params ); $login_query_params = array( 'region' => $ced_amazon_regions_info[ $marketplace_id ]['region_value'], 'country' => $ced_amazon_regions_info[ $marketplace_id ]['shop-name'], 'state' => 'test', 'marketplace_id' => $marketplace_id, 'domain' => site_url(), 'marketplace' => 'amazon', 'home_redirect_url' => $home_redirect_url ); $redirect_url = CED_LIVE_VALIDATOR . 'v1/auth?' . http_build_query( $login_query_params ); wp_send_json_success( $redirect_url ); } wp_die(); } /* * *Function to fetch next level Category */ public function my_amazon_cron_schedules( $schedules ) { if ( ! isset( $schedules['ced_amazon_6min'] ) ) { $schedules['ced_amazon_6min'] = array( 'interval' => 6 * 60, 'display' => __( 'Once every 6 minutes' ), ); } if ( ! isset( $schedules['ced_amazon_8min'] ) ) { $schedules['ced_amazon_8min'] = array( 'interval' => 8 * 60, 'display' => __( 'Once every 8 minutes' ), ); } if ( ! isset( $schedules['ced_amazon_10min'] ) ) { $schedules['ced_amazon_10min'] = array( 'interval' => 10 * 60, 'display' => __( 'Once every 10 minutes' ), ); } if ( ! isset( $schedules['ced_amazon_11min'] ) ) { $schedules['ced_amazon_11min'] = array( 'interval' => 11 * 60, 'display' => __( 'Once every 11 minutes' ), ); } if ( ! isset( $schedules['ced_amazon_12min'] ) ) { $schedules['ced_amazon_12min'] = array( 'interval' => 12 * 60, 'display' => __( 'Once every 12 minutes' ), ); } if ( ! isset( $schedules['ced_amazon_15min'] ) ) { $schedules['ced_amazon_15min'] = array( 'interval' => 15 * 60, 'display' => __( 'Once every 15 minutes' ), ); } if ( ! isset( $schedules['ced_amazon_20min'] ) ) { $schedules['ced_amazon_20min'] = array( 'interval' => 20 * 60, 'display' => __( 'Once every 20 minutes' ), ); } if ( ! isset( $schedules['ced_amazon_30min'] ) ) { $schedules['ced_amazon_30min'] = array( 'interval' => 30 * 60, 'display' => __( 'Once every 30 minutes' ), ); } return $schedules; } /* * * Function to update wizard step */ public function ced_amazon_update_current_step() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } $current_step = isset( $_POST['current_step'] ) ? sanitize_text_field( $_POST['current_step'] ) : false; $user_id = isset( $_POST['user_id'] ) ? sanitize_text_field( $_POST['user_id'] ) : false; if ( ! empty( $current_step ) && ! empty( $user_id ) ) { $sellernextShopIds = get_option( 'ced_amazon_remote_shop_ids', array() ); $sellernextShopIds[ $user_id ]['ced_amz_current_step'] = $current_step; update_option( 'ced_amazon_remote_shop_ids', $sellernextShopIds ); return wp_json_encode( array( 'message' => 'updated', 'status' => '200', ) ); } else { return wp_json_encode( array( 'message' => 'failed', 'status' => '400', ) ); } } /* * * Function to get orders. */ public function ced_amazon_get_orders() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } $seller_id = isset( $_POST['seller_id'] ) ? sanitize_text_field( $_POST['seller_id'] ) : ''; $amz_order_id = isset( $_POST['amz_order_id'] ) ? sanitize_text_field( $_POST['amz_order_id'] ) : ''; $created_after = isset( $_POST['created_after'] ) ? sanitize_text_field( $_POST['created_after'] ) : ''; $created_before = isset( $_POST['created_before'] ) ? sanitize_text_field( $_POST['created_before'] ) : ''; $params = array( 'amz_order_id' => $amz_order_id, 'created_after' => $created_after, 'created_before' => $created_before, ); $mplocation = ''; if ( ! empty( $seller_id ) ) { $mplocation_arr = explode( '|', $seller_id ); $mplocation = isset( $mplocation_arr[1] ) ? $mplocation_arr[0] : ''; } $file_name = plugin_dir_path( __FILE__ ) . 'amazon/lib/class-order-manager.php'; if ( file_exists( $file_name ) ) { require_once $file_name; $class_name = 'Ced_Umb_Amazon_Order_Manager'; if ( class_exists( $class_name ) ) { $OrderInstance = Ced_Umb_Amazon_Order_Manager::get_instance(); $order_id = $OrderInstance->is_umb_order_exists( $amz_order_id ); if ( ! is_wp_error( $OrderInstance ) ) { $params['mplocation'] = $mplocation; $params['cron'] = false; $params['seller_id'] = $seller_id; $response = $OrderInstance->fetchOrders( $params ); if ( 'completed' == $response['status'] && 0 < count( $response['orders_imported'] ) ) { $message = __( 'Orders have been fetched successfully. Please reload the page to view your new orders.', 'multichannel-for-woocommerce' ); $status = 'success'; $classes = 'success is-dismissable'; } elseif ( 'completed' == $response['status'] && 0 == count( $response['orders_imported'] ) ) { $message = __( 'No orders found to import!', 'multichannel-for-woocommerce' ); $classes = 'error is-dismissable'; $status = 'success'; } else { $message = __( 'Error while importing orders', 'multichannel-for-woocommerce' ); $classes = 'error is-dismissable'; $status = 'error'; } wp_send_json_success( array( 'message' => $message, 'status' => $status, 'class' => $classes ) ); wp_die(); } else { $message = __( 'An unexpected error occurred. Please try again.', 'multichannel-for-woocommerce' ); $classes = 'error is-dismissable'; $status = 'error'; } } else { $message = __( 'Class missing to perform operation, please check if extension configured successfully!', 'multichannel-for-woocommerce' ); $classes = 'error is-dismissable'; $status = 'error'; } } else { $message = __( 'Please check if selected marketplace is active!', 'multichannel-for-woocommerce' ); $classes = 'error is-dismissable'; $status = 'error'; } wp_die(); } public function ced_amz_fetch_next_page_orders( $next_token, $mplocation, $seller_id ) { $logger = wc_get_logger(); $context = array( 'source' => 'ced_amazon_order_fetch' ); $logger->info( 'ced amzon next page order function called', $context ); $params['mplocation'] = $mplocation; $params['cron'] = false; $params['seller_id'] = $seller_id; $params['next_token'] = $next_token; $this->order_manager->fetchOrders( $params ); } public function ced_amazon_remove_account_from_integration() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( $check_ajax ) { $seller_id = isset( $_POST['seller_id'] ) ? sanitize_text_field( $_POST['seller_id'] ) : false; $sellernextShopId = isset( $_POST['sellernextShopId'] ) ? sanitize_text_field( $_POST['sellernextShopId'] ) : false; if ( ! empty( $seller_id ) && ! empty( $sellernextShopId ) ) { $ced_amazon_remote_shop_ids = get_option( 'ced_amazon_remote_shop_ids', array() ); unset( $ced_amazon_remote_shop_ids[ $sellernextShopId ] ); update_option( 'ced_amazon_remote_shop_ids', $ced_amazon_remote_shop_ids ); $ced_amazon_sellernext_shop_ids = get_option( 'ced_amazon_sellernext_shop_ids', array() ); unset( $ced_amazon_sellernext_shop_ids[ $sellernextShopId ] ); update_option( 'ced_amazon_sellernext_shop_ids', $ced_amazon_sellernext_shop_ids ); update_option( 'ced_amazon_mode_of_operation', '' ); if ( function_exists( 'as_has_scheduled_action' ) ) { if ( as_has_scheduled_action( 'ced_amazon_price_scheduler_job_' . $seller_id ) ) { as_unschedule_all_actions( 'ced_amazon_price_scheduler_job_' . $seller_id ); } if ( as_has_scheduled_action( 'ced_amazon_inventory_scheduler_job_' . $seller_id ) ) { as_unschedule_all_actions( 'ced_amazon_inventory_scheduler_job_' . $seller_id ); } if ( as_has_scheduled_action( 'ced_amazon_order_scheduler_job_' . $seller_id ) ) { as_unschedule_all_actions( 'ced_amazon_order_scheduler_job_' . $seller_id ); } if ( as_has_scheduled_action( 'ced_amazon_existing_products_sync_job_' . $seller_id ) ) { as_unschedule_all_actions( 'ced_amazon_existing_products_sync_job_' . $seller_id ); } if ( as_has_scheduled_action( 'ced_amazon_catalog_asin_sync_job_' . $seller_id ) ) { as_unschedule_all_actions( 'ced_amazon_catalog_asin_sync_job_' . $seller_id ); } } $amazon_accounts = get_option( 'ced_amzon_configuration_validated', array() ); if ( is_array( $amazon_accounts ) && isset( $amazon_accounts[ $seller_id ] ) ) { unset( $amazon_accounts[ $seller_id ] ); update_option( 'ced_amzon_configuration_validated', $amazon_accounts ); } // Delete account participation option value wp_send_json( array( 'status' => 'success', 'message' => 'Account Deleted Successfully', 'title' => 'Account Deleted', ) ); } elseif ( ! empty( $sellernextShopId ) ) { $ced_amazon_remote_shop_ids = get_option( 'ced_amazon_remote_shop_ids', array() ); unset( $ced_amazon_remote_shop_ids[ $sellernextShopId ] ); update_option( 'ced_amazon_remote_shop_ids', $ced_amazon_remote_shop_ids ); $ced_amazon_sellernext_shop_ids = get_option( 'ced_amazon_sellernext_shop_ids', array() ); unset( $ced_amazon_sellernext_shop_ids[ $sellernextShopId ] ); update_option( 'ced_amazon_sellernext_shop_ids', $ced_amazon_sellernext_shop_ids ); wp_send_json( array( 'status' => 'success', 'message' => 'Account Deleted Successfully', 'title' => 'Account Deleted', ) ); } else { wp_send_json( array( 'status' => 'error', 'message' => 'User ID not found', 'title' => 'Invalid User ID', ) ); } } } /** * Function to verify seller */ public function ced_amazon_seller_verification() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } $user_id = isset( $_POST['user_id'] ) ? sanitize_text_field( $_POST['user_id'] ) : ''; $seller_id = isset( $_POST['seller_id'] ) ? sanitize_text_field( $_POST['seller_id'] ) : ''; $sellernextShopIds = get_option( 'ced_amazon_remote_shop_ids', array() ); $config_array_key = $seller_id; if ( ! empty( $user_id ) && ! empty( $seller_id ) ) { $amzonCurlRequest = CED_AMAZON_DIRPATH . 'admin/amazon/lib/ced-amazon-curl-request.php'; if ( file_exists( $amzonCurlRequest ) ) { require_once $amzonCurlRequest; $this->amzonCurlRequestInstance = new Ced_Amazon_Curl_Request(); } else { wp_send_json( array( 'success' => false, 'message' => 'Curl Request file doesn\'t exits', ) ); } $payload = array(); $originalPayload = array(); $originalPayload = $this->amzonCurlRequestInstance->getMarketplaceParticipations( $user_id ); if ( $originalPayload['success'] ) { $payload = isset( $originalPayload['response'] ) && isset( $originalPayload['response']['payload'] ) ? $originalPayload['response']['payload'] : array(); } else { wp_send_json( $originalPayload ); } $seller_id_array = explode( '|', $seller_id ); $mp_location = isset( $seller_id_array[0] ) ? $seller_id_array[0] : ''; $merchant_id = isset( $seller_id_array[1] ) ? $seller_id_array[1] : ''; $marketplace_id = ced_get_marketplace_id_by_country( $mp_location ); $accountData = array(); $sellerParticipation = false; $participate_accounts = array(); if ( ! empty( $payload ) && is_array( $payload ) && isset( $originalPayload['success'] ) && $originalPayload['success'] ) { foreach ( $payload as $index => $accountsConnected ) { if ( $accountsConnected['marketplace']['id'] == $marketplace_id ) { $accountData = $accountsConnected; $sellerParticipation = isset( $accountsConnected['participation']['isParticipating'] ) ? $accountsConnected['participation']['isParticipating'] : false; $current_mp_participation = array( $config_array_key => $sellerParticipation ); if ( is_array( $participate_accounts ) && ! empty( $participate_accounts ) ) { $participate_accounts = array_replace( $participate_accounts, $current_mp_participation ); } else { $participate_accounts = $current_mp_participation; } $sellernextShopIds[ $user_id ]['marketplaces_participation'] = $participate_accounts; $sellernextShopIds[ $user_id ]['hasSuspendedListings'] = isset( $accountsConnected['participation']['hasSuspendedListings'] ) ? $accountsConnected['participation']['hasSuspendedListings'] : false; update_option( 'ced_amazon_remote_shop_ids', $sellernextShopIds ); wp_send_json( array( 'success' => true, 'data' => array( 'seller_id' => $seller_id, 'marketplace_id' => $marketplace_id, 'user_id' => $user_id, ), ) ); } } } else { $ced_amzon_configuration_validated = get_option( 'ced_amzon_configuration_validated', array() ); $sellernextShopIds = get_option( 'ced_amazon_remote_shop_ids', array() ); $ced_mp_seller_key = ''; if ( ! empty( $user_id ) && isset( $sellernextShopIds[ $user_id ] ) ) { $ced_mp_seller_key = isset( $sellernextShopIds[ $user_id ] ) && isset( $sellernextShopIds[ $user_id ]['ced_mp_seller_key'] ) ? $sellernextShopIds[ $user_id ]['ced_mp_seller_key'] : ''; if ( isset( $ced_mp_seller_key ) && ! empty( $ced_mp_seller_key ) ) { unset( $ced_amzon_configuration_validated[ $ced_mp_seller_key ] ); update_option( 'ced_amzon_configuration_validated', $ced_amzon_configuration_validated ); } } unset( $sellernextShopIds[ $user_id ] ); update_option( 'ced_amazon_remote_shop_ids', $sellernextShopIds ); wp_send_json( array( 'success' => false, 'message' => 'unable to verify marketplace/seller id', ) ); } die; } else { wp_send_json( array( 'success' => false, 'message' => 'User Id or Seller Id is missing', ) ); } } public function ced_amazon_add_custom_profile_rows() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } $sanitized_array = filter_input_array( INPUT_POST, FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $custom_field = isset( $sanitized_array['custom_field'] ) ? $sanitized_array['custom_field'] : array(); $category_id = isset( $_POST['primary_cat'] ) ? sanitize_text_field( $_POST['primary_cat'] ) : ''; $sub_category_id = isset( $_POST['secondary_cat'] ) ? sanitize_text_field( $_POST['secondary_cat'] ) : ''; $user_id = isset( $_POST['userid'] ) ? sanitize_text_field( $_POST['userid'] ) : ''; $seller_id = ''; $file_url = isset( $_POST['fileUrl'] ) ? sanitize_text_field( $_POST['fileUrl'] ) : ''; if ( empty( $seller_id ) ) { $ced_amazon_remote_shop_ids = get_option( 'ced_amazon_remote_shop_ids', array() ); $seller_id = isset( $ced_amazon_remote_shop_ids[ $user_id ] ) ? $ced_amazon_remote_shop_ids[ $user_id ]['ced_mp_seller_key'] : ''; } $this->ced_amazon_profile_dropdown( '', '', $sanitized_array, $custom_field, $category_id, $sub_category_id, 'yes', $user_id, $seller_id, $file_url ); wp_die(); } public function ced_amazon_profile_dropdown( $field_id = '', $required = '', $sanitized_array = array(), $custom_field = array(), $category_id = '', $sub_category_id = '', $display_hidden = 'no', $user_id = '', $seller_id = '', $file_url = '' ) { global $wpdb; $results = $wpdb->get_results( "SELECT DISTINCT meta_key FROM {$wpdb->prefix}postmeta", 'ARRAY_A' ); $query = $wpdb->get_results( $wpdb->prepare( "SELECT `meta_value` FROM {$wpdb->prefix}postmeta WHERE `meta_key` LIKE %s", '_product_attributes' ), 'ARRAY_A' ); $addedMetaKeys = get_option( 'CedUmbProfileSelectedMetaKeys', false ); $row_html = ''; $mod_custom_field = array_values( $custom_field ); foreach ( $mod_custom_field[0] as $custom_key => $custom_value ) { $index = strpos( $custom_key, '_custom_field' ); if ( $index > -1 ) { $slug = substr( $custom_key, 0, $index ); } else { $slug = $custom_key; } $optionLabel = $custom_value['label']; $row_html .= ' '; $row_html .= ''; $ced_amzon_configuration_validated = get_option( 'ced_amzon_configuration_validated', array() ); if ( empty( $seller_id ) ) { $ced_amazon_remote_shop_ids = get_option( 'ced_amazon_remote_shop_ids', array() ); $seller_id = isset( $ced_amazon_remote_shop_ids[ $user_id ] ) ? $ced_amazon_remote_shop_ids[ $user_id ]['ced_mp_seller_key'] : ''; } $userData = isset( $ced_amzon_configuration_validated[ $seller_id ] ) ? $ced_amzon_configuration_validated[ $seller_id ] : array(); $userCountry = isset( $userData['ced_mp_name'] ) ? $userData['ced_mp_name'] : ''; $upload_dir = wp_upload_dir(); $valid_values2 = array(); if ( empty( $file_url ) ) { $valid_values_file = $upload_dir['basedir'] . '/ced-amazon/templates/' . $userCountry . '/' . $category_id . '/valid_values.json'; $valid_values = file_get_contents( $valid_values_file ); $valid_values2 = json_decode( $valid_values, true ); } if ( ( isset( $valid_values2[ $custom_key ] ) && isset( $valid_values2[ $custom_key ][ $sub_category_id ] ) ) || ( isset( $valid_values2[ $optionLabel ] ) && isset( $valid_values2[ $optionLabel ][ $sub_category_id ] ) ) ) { $row_html .= ''; } elseif ( ( isset( $valid_values2[ $custom_key ] ) && isset( $valid_values2[ $custom_key ]['all_cat'] ) ) || ( isset( $valid_values2[ $optionLabel ] ) && isset( $valid_values2[ $optionLabel ]['all_cat'] ) ) ) { $row_html .= ''; } else { $row_html .= ''; if ( 'yes' == $display_hidden ) { $row_html .= ''; } else { $row_html .= ''; } $row_html .= ' '; } $row_html .= ''; $selectDropdownHTML = ''; $row_html .= $selectDropdownHTML; $row_html .= ''; echo wp_json_encode( array( 'succes' => true, 'data' => $row_html, ) ); wp_die(); } } public function ced_amazon_update_template() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } if ( ! function_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } if ( WP_Filesystem() ) { global $wp_filesystem; } $next_level = 4; $category_id = isset( $_POST['primary_cat'] ) ? sanitize_text_field( $_POST['primary_cat'] ) : ''; $sub_category_id = isset( $_POST['secondary_cat'] ) ? sanitize_text_field( $_POST['secondary_cat'] ) : ''; $browse_nodes = isset( $_POST['browse_nodes'] ) ? sanitize_text_field( $_POST['browse_nodes'] ) : ''; $seller_id = isset( $_POST['seller_id'] ) ? sanitize_text_field( $_POST['seller_id'] ) : ''; $user_id = isset( $_POST['user_id'] ) ? sanitize_text_field( $_POST['user_id'] ) : ''; $ced_amzon_configuration_validated = get_option( 'ced_amzon_configuration_validated', array() ); if ( empty( $seller_id ) ) { $ced_amazon_remote_shop_ids = get_option( 'ced_amazon_remote_shop_ids', array() ); $seller_id = isset( $ced_amazon_remote_shop_ids[ $user_id ] ) ? $ced_amazon_remote_shop_ids[ $user_id ]['ced_mp_seller_key'] : ''; } $userData = $ced_amzon_configuration_validated[ $seller_id ]; $userCountry = $userData['ced_mp_name']; $marketplace_id = $userData['marketplace_id']; $amzonCurlRequest = CED_AMAZON_DIRPATH . 'admin/amazon/lib/ced-amazon-curl-request.php'; if ( file_exists( $amzonCurlRequest ) ) { require_once $amzonCurlRequest; $this->amzonCurlRequestInstance = new Ced_Amazon_Curl_Request(); } else { return; } if ( empty( $user_id ) ) { echo wp_json_encode( array( 'success' => false, 'message' => 'Invalid Shop Id', 'status' => 'error', ) ); die; } $url_array = array( 4 => array( 'url' => 'webapi/rest/v1/category-attribute/?category_id=' . $category_id . '&sub_category_id=' . $sub_category_id . '&browse_node_id=' . $browse_nodes . '&barcode_exemption=false', 'key' => 'category_attributes', ), ); $upload_dir = wp_upload_dir(); $dirname = $upload_dir['basedir'] . '/ced-amazon/templates/' . $userCountry . '/' . $category_id . '/' . $sub_category_id; $fileName = '/products.json'; $filePath = $dirname . $fileName; $filePath = sanitize_file_name( $filePath ); if ( ! is_dir( $dirname ) ) { wp_mkdir_p( $dirname ); } $amazon_profile_data_response = $this->amzonCurlRequestInstance->ced_amazon_get_category( $url_array[ $next_level ]['url'], $user_id, $seller_id ); $decoded_amazon_profile_data_response = json_decode( $amazon_profile_data_response, true ); if ( $decoded_amazon_profile_data_response['status'] ) { $amazon_profile_data = $decoded_amazon_profile_data_response['data']; } else { echo esc_attr( wp_send_json( $decoded_amazon_profile_data_response ) ); die; } $amazon_profile_template = isset( $amazon_profile_data['response'] ) ? $amazon_profile_data['response'] : array(); // Update product flat file template stricture json file $this->amzonCurlRequestInstance->fetchProductTemplate( $category_id, $userCountry, $seller_id, $marketplace_id, $user_id ); if ( empty( $amazon_profile_template ) ) { echo wp_json_encode( array( 'success' => false, 'message' => 'Unable to fetch Data.', 'status' => 'error', ) ); die; } $amazon_profile_template_data = wp_json_encode( $amazon_profile_template ); $amazon_profile_template_data = sanitize_text_field( $amazon_profile_template_data ); if ( ! file_exists( $filePath ) && WP_Filesystem() ) { if ( $wp_filesystem ) { $wp_filesystem->put_contents( $filePath, $amazon_profile_template_data, FS_CHMOD_FILE ); } } echo wp_json_encode( array( 'success' => true, 'message' => 'Product Template has been updated', 'status' => 'success', ) ); die; } /** Get product id based on Amazon Seller SKU field of product level (if product SKU not exist) **/ public function get_amazon_seller_sku( $meta_key = '', $meta_value = '' ) { if ( empty( $meta_key ) || empty( $meta_value ) ) { return; } global $wpdb; $productId = $wpdb->get_var( $wpdb->prepare( " SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = %s AND meta_value = %s", $meta_key, $meta_value ) ); return $productId; } /** * Quick view feed response using modal in feeds table. * * @name ced_amazon_view_feed_response() * @since 1.0.0 */ public function ced_amazon_view_feed_response() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } require_once CED_AMAZON_DIRPATH . 'admin/amazon/lib/class-feed-manager.php'; $feed_id = isset( $_POST['feed_id'] ) ? sanitize_text_field( $_POST['feed_id'] ) : ''; $seller_id = isset( $_POST['seller_id'] ) ? sanitize_text_field( $_POST['seller_id'] ) : ''; if ( empty( $feed_id ) || empty( $seller_id ) ) { $html_response = '
Error: Feed id or seller id missing!
'; wp_send_json_success( $html_response ); wp_die(); } global $wpdb; $tableName = $wpdb->prefix . 'ced_amazon_feeds'; $feed_request_ids = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}ced_amazon_feeds WHERE `feed_id` = %d", $feed_id ), 'ARRAY_A' ); if ( ! is_array( $feed_request_ids ) || ! is_array( $feed_request_ids[0] ) ) { $html_response = '
Error: Feed details not found!
'; wp_send_json_success( $html_response ); wp_die(); } $feed_request_id = $feed_request_ids[0]; $main_id = $feed_request_id['id']; $feed_type = $feed_request_id['feed_action']; $location_id = $feed_request_id['feed_location']; $response = $feed_request_id['response']; $response = json_decode( $response, true ); $response_format = false; if ( ! empty( $feed_id ) ) { if ( isset( $response['status'] ) && 'DONE' == $response['status'] ) { $response_format = true; } else { $feed_manager = Ced_Umb_Amazon_Feed_Manager::get_instance( ); $response = $feed_manager->getFeedItemsStatusSpApi( $feed_id, $feed_type, $location_id, $seller_id ); if ( isset( $response['status'] ) && 'DONE' == $response['status'] ) { $response_format = true; } $response_data = wp_json_encode( $response ); $wpdb->update( $tableName, array( 'response' => $response_data ), array( 'id' => $main_id ) ); } if ( $response_format ) { if ( 'POST_FLAT_FILE_LISTINGS_DATA' == $feed_type ) { $tab_response_data = explode( "\n", $response['body'] ); $first_row_data = explode( "\t", $tab_response_data[0] ); $second_row_data = explode( "\t", $tab_response_data[1] ); $third_row_data = explode( "\t", $tab_response_data[2] ); $response_heading = isset( $first_row_data[0] ) ? $first_row_data[0] : ''; $processed_record_lable = isset( $second_row_data[1] ) ? $second_row_data[1] : ''; $processed_record_value = isset( $second_row_data[3] ) ? $second_row_data[3] : ''; $success_record_lable = isset( $third_row_data[1] ) ? $third_row_data[1] : ''; $success_record_value = isset( $third_row_data[3] ) ? $third_row_data[3] : ''; $tab_response_html = ''; $tab_error_code_arr = array(); foreach ( $tab_response_data as $tabKey => $tabValue ) { $line_data = explode( "\t", $tabValue ); if ( 'Feed Processing Summary' == $line_data[0] || 'Feed Processing Summary:' == $line_data[0] ) { continue; } elseif ( empty( $line_data[0] ) || '' == $line_data[0] ) { continue; } elseif ( 'original-record-number' == $line_data[0] ) { continue; } elseif ( in_array( $line_data[2], $tab_error_code_arr ) ) { continue; } elseif ( ! empty( $line_data[2] ) ) { $tab_error_code_arr[] = $line_data[2]; $tab_response_html .= '' . esc_attr( $line_data[2] ) . ''; $tab_response_html .= '' . esc_attr( $line_data[4] ) . ''; } } if ( isset( $tab_response_html ) && '' != $tab_response_html ) { $tableHtml = ''; $tableHtml .= $tab_response_html; $tableHtml .= '
Error code Error message
'; } else { $tableHtml = '

Successful records: ' . $success_record_value . '

'; } } elseif ( strpos( $feed_type, 'JSON_LISTINGS_FEED' ) === 0 ) { $feed_response = json_decode( $response['body'], true ); if ( isset( $feed_response ) && ! empty( $feed_response ) ) { $summary_data = isset( $feed_response['summary'] ) ? $feed_response['summary'] : array(); $success_record = ''; if ( ! empty( $summary_data ) ) { foreach ( $summary_data as $summary_label => $summary_fields ) { if ( 'messagesAccepted' == $summary_label ) { $success_record = $summary_fields; } } } $error_data = isset( $feed_response['issues'] ) ? $feed_response['issues'] : array(); $error_html = ''; $json_error_code_arr = array(); if ( ! empty( $error_data ) ) { foreach ( $error_data as $error_label => $error_fields ) { $error_code = isset( $error_fields['code'] ) ? $error_fields['code'] : ''; $message = isset( $error_fields['message'] ) ? $error_fields['message'] : ''; if ( in_array( $error_code, $json_error_code_arr ) ) { continue; } if ( isset( $error_code ) && ! empty( $error_code ) ) { $json_error_code_arr[] = $error_code; $error_html .= '' . esc_attr( $error_code ) . ''; $error_html .= '' . esc_attr( $message ) . ''; } } } if ( isset( $error_html ) && '' != $error_html ) { $tableHtml = ''; $tableHtml .= $error_html; $tableHtml .= '
Error code Error message
'; } else { $tableHtml = '

Successful records: ' . $success_record . '

'; } } else { $tableHtml = $feed_response; } } else { $sxml = simplexml_load_string( $response['body'], 'SimpleXMLElement', LIBXML_NOCDATA ); $arrayResponse = wp_json_encode( $sxml ); $arrayResponse = json_decode( $arrayResponse, true ); if ( isset( $arrayResponse['Message'] ) && ! empty( $arrayResponse['Message'] ) ) { $processingSummary = isset( $arrayResponse['Message'] ) && isset( $arrayResponse['Message']['ProcessingReport'] ) && isset( $arrayResponse['Message']['ProcessingReport']['ProcessingSummary'] ) ? $arrayResponse['Message']['ProcessingReport']['ProcessingSummary'] : array(); $processingSummaryHtml = ''; $results = isset( $arrayResponse['Message']['ProcessingReport']['Result'][0] ) ? $arrayResponse['Message']['ProcessingReport']['Result'] : $arrayResponse['Message']['ProcessingReport']; $resultsHtml = ''; $success_record = ''; if ( ! empty( $processingSummary ) ) { foreach ( $processingSummary as $label => $fields ) { $processingSummaryHtml .= $label . ' : ' . $fields . '
'; if ( 'MessagesSuccessful' == $label ) { $success_record = $fields; } } } $xml_error_code_arr = array(); if ( ! empty( $results ) ) { foreach ( $results as $label => $fields ) { if ( 'Result' == $label || is_numeric( $label ) ) { if ( is_object( $fields ) ) { $fields = $this->xml2array( $fields ); } $resultMessageCode = isset( $fields['ResultMessageCode'] ) ? $fields['ResultMessageCode'] : ''; $resultDescription = isset( $fields['ResultDescription'] ) ? $fields['ResultDescription'] : ''; if ( in_array( $resultMessageCode, $xml_error_code_arr ) ) { continue; } if ( isset( $resultMessageCode ) && ! empty( $resultMessageCode ) ) { $xml_error_code_arr[] = $resultMessageCode; $resultsHtml .= '' . esc_attr( $resultMessageCode ) . ''; $resultsHtml .= '' . esc_attr( $resultDescription ) . ''; } } } } if ( isset( $resultsHtml ) && '' != $resultsHtml ) { $tableHtml = ''; $tableHtml .= $resultsHtml; $tableHtml .= '
Error code Error message
'; } else { $tableHtml = '

Successful records: ' . $success_record . '

'; } } } } elseif ( isset( $response['feed_id'] ) && ! empty( $response['feed_id'] ) ) { $tableHtml = '
Feed Id Feed Type Feed Status
' . esc_attr( $response['feed_id'] ) . ' ' . esc_attr( $response['feed_action'] ) . ' ' . esc_attr( $response['status'] ) . '
'; } else { $message = isset( $response['body'] ) ? $response['body'] : $response['message']; $tableHtml = '

' . esc_attr( $message ) . '

'; } } // Final html response preparation $html_response = $tableHtml; wp_send_json_success( $html_response ); wp_die(); } // Function for XML feed response format public function xml2array( $xmlObject, $out = array() ) { foreach ( (array) $xmlObject as $index => $node ) { $out[ $index ] = ( is_object( $node ) ) ? $this->xml2array( $node ) : $node; } return $out; } /** * Add filter in order * * @since 1.0.0 */ public function ced_amazon_add_woo_order_views( $views ) { if ( ! current_user_can( 'edit_others_pages' ) ) { return $views; } $class = ( isset( $_REQUEST['order_from_amazon'] ) && 'yes' == sanitize_text_field( $_REQUEST['order_from_amazon'] ) ) ? 'current' : ''; $query_string = esc_url_raw( remove_query_arg( array( 'order_from_amazon' ) ) ); $query_string = add_query_arg( 'order_from_amazon', urlencode( 'yes' ), $query_string ); $views['amazon_order'] = '' . __( 'Amazon order', 'multichannel-for-woocommerce' ) . ''; return $views; } /** * Add filter in order * * @since 1.0.0 */ public function ced_amazon_woo_admin_order_filter_query( $query ) { global $typenow, $wp_query, $wpdb; if ( 'shop_order' == $typenow ) { if ( ! empty( $_GET['order_from_amazon'] ) ) { if ( 'yes' == $_GET['order_from_amazon'] ) { $query->query_vars['meta_query'][] = array( 'key' => 'ced_umb_order_sales_channel', 'compare' => 'EXISTS', ); } } } } /** * Change Amazon Region * * @since 1.0.0 */ public function ced_amazon_change_region() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } $params = array(); $params['user_id'] = isset( $_POST['user_id'] ) ? sanitize_text_field( $_POST['user_id'] ) : ''; $params['seller_id'] = isset( $_POST['seller_id'] ) ? sanitize_text_field( $_POST['seller_id'] ) : ''; update_option( 'ced_amz_active_marketplace', $params ); echo wp_json_encode( array( 'success' => true ) ); die; } public function ced_amazon_clone_template_modal() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } $user_id = isset( $_POST['user_id'] ) ? sanitize_text_field( $_POST['user_id'] ) : ''; $seller_id = isset( $_POST['seller_id'] ) ? sanitize_text_field( $_POST['seller_id'] ) : ''; $template_id = isset( $_POST['template_id'] ) ? trim( sanitize_text_field( $_POST['template_id'] ) ) : ''; $sanitized_array = filter_input_array( INPUT_POST, FILTER_UNSAFE_RAW ); $woo_cat = isset( $sanitized_array['woo_cat'] ) ? ( $sanitized_array['woo_cat'] ) : array(); global $wpdb; $tableName = $wpdb->prefix . 'ced_amazon_profiles'; $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}ced_amazon_profiles WHERE `id` = %s ", $template_id ), 'ARRAY_A' ); $current_amazon_profile = isset( $result[0] ) ? $result[0] : array(); if ( empty( $current_amazon_profile ) ) { wp_send_json_error( 'Unable to fetch selected template . Please try again later.' ); wp_die(); } $wpdb->insert( $tableName, array( 'primary_category' => isset( $current_amazon_profile['primary_category'] ) ? $current_amazon_profile['primary_category'] : '', 'secondary_category' => isset( $current_amazon_profile['secondary_category'] ) ? $current_amazon_profile['secondary_category'] : '', 'category_attributes_response' => '', 'wocoommerce_category' => isset( $woo_cat ) ? wp_json_encode( $woo_cat ) : '[]', 'category_attributes_structure' => isset( $current_amazon_profile['category_attributes_structure'] ) ? $current_amazon_profile['category_attributes_structure'] : '', 'browse_nodes' => isset( $current_amazon_profile['browse_nodes'] ) ? $current_amazon_profile['browse_nodes'] : '', 'browse_nodes_name' => isset( $current_amazon_profile['browse_nodes_name'] ) ? $current_amazon_profile['browse_nodes_name'] : '', 'amazon_categories_name' => isset( $current_amazon_profile['amazon_categories_name'] ) ? $current_amazon_profile['amazon_categories_name'] : '', 'category_attributes_data' => isset( $current_amazon_profile['category_attributes_data'] ) ? $current_amazon_profile['category_attributes_data'] : '', 'seller_id' => $seller_id, ), array( '%s' ) ); $clone_template_id = $wpdb->insert_id; if ( $clone_template_id ) { $href = ced_get_navigation_url( 'amazon', array( 'section' => 'add-new-template', 'template_id' => $clone_template_id, 'user_id' => $user_id, 'seller_id' => $seller_id, ) ); $ced_woo_amazon_mapping = get_option( 'ced_woo_amazon_mapping', array() ); $ced_woo_amazon_mapping[ $seller_id ][ $clone_template_id ] = $woo_cat; update_option( 'ced_woo_amazon_mapping', $ced_woo_amazon_mapping ); $ced_amz_cloned_templates = get_option( 'ced_amz_cloned_templates', array() ); $ced_amz_cloned_templates[ $seller_id ][] = $clone_template_id; update_option( 'ced_amz_cloned_templates', $ced_amz_cloned_templates ); wp_send_json_success( "Template cloned successfully View/Edit Template ." ); } else { wp_send_json_error( 'Unable to clone template . Please try again later.' ); } wp_die(); } public function ced_search_amz_categories() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } $user_id = isset( $_POST['user_id'] ) ? sanitize_text_field( $_POST['user_id'] ) : ''; $seller_id = isset( $_POST['seller_id'] ) ? sanitize_text_field( $_POST['seller_id'] ) : ''; $cat_value = isset( $_POST['cat_value'] ) ? sanitize_text_field( $_POST['cat_value'] ) : ''; require_once CED_AMAZON_DIRPATH . 'admin/amazon/lib/ced-amazon-curl-request.php'; $this->amzonCurlRequestInstance = new Ced_Amazon_Curl_Request(); $categories_array = $this->amzonCurlRequestInstance->ced_search_amz_cat( $user_id, $seller_id, $cat_value ); $html = ''; $html .= '
'; $list = ''; $second_category = ''; $primary_category = ''; if ( ! empty( $categories_array ) ) { foreach ( $categories_array as $category_array ) { $parent_ids = isset( $category_array['parent_id'] ) ? $category_array['parent_id'] : array(); if ( isset( $parent_ids ) && is_array( $parent_ids ) ) { $parent_ids = implode( ',', $parent_ids ); } $full_path = isset( $category_array['full_path'] ) && is_array( $category_array['full_path'] ) ? implode( ' > ', $category_array['full_path'] ) : ''; $second_category = isset( $category_array['category'] ) && isset( $category_array['category']['sub-category'] ) ? $category_array['category']['sub-category'] : ''; $primary_category = isset( $category_array['category'] ) && isset( $category_array['category']['primary-category'] ) ? $category_array['category']['primary-category'] : ''; $hasChildren = isset( $category_array['hasChildren'] ) ? $category_array['hasChildren'] : false; $list .= '
  • ' . esc_attr( $full_path ) . '
  • '; } } $html .= ''; $html .= '' . __( 'Browse and Select a Category', 'multichannel-for-woocommerce' ) . ''; $html .= '
      '; $html .= $list; $html .= '
    '; $html .= '
    '; // $html .= ''; wp_send_json_success( $html ); } public function ced_amz_email_restriction( $enable = '', $order = array() ) { if ( ! is_object( $order ) ) { return $enable; } $seller_id = $order->get_meta( 'ced_amazon_order_seller_id' ); $renderDataOnGlobalSettings = get_option( 'ced_amazon_global_settings', array() ); $ced_amz_email_nfc = isset( $renderDataOnGlobalSettings[ $seller_id ] ) && isset( $renderDataOnGlobalSettings[ $seller_id ]['ced_amz_email_nfc'] ) ? $renderDataOnGlobalSettings[ $seller_id ]['ced_amz_email_nfc'] : ''; $marketplace = $order->get_meta( '_umb_marketplace' ); if ( empty( $ced_amz_email_nfc ) && 'Amazon' == $marketplace ) { $enable = false; } return $enable; } public function ced_amazon_woocommerce_duplicate_product_exclude_meta_filter( $exclude_meta, $existing_meta_keys ) { $get_location = get_option( 'ced_amzon_configuration_validated', array() ); $location_keys = array_keys( $get_location ); if ( is_array( $location_keys ) && ! empty( $location_keys ) ) { foreach ( $location_keys as $key => $value ) { $mplocation_arr = explode( '|', $value ); $mplocation = isset( $mplocation_arr[1] ) ? $mplocation_arr[0] : ''; $exclude_meta[] = 'ced_amazon_already_uploaded_' . $mplocation; $exclude_meta[] = 'ced_amazon_product_asin_' . $mplocation; $exclude_meta[] = 'ced_amazon_catalog_asin_' . $mplocation; } } return $exclude_meta; } public function ced_amazon_get_selected_categories() { $check_ajax = check_ajax_referer( 'ced-amazon-ajax-seurity-string', 'ajax_nonce' ); if ( ! $check_ajax ) { return; } $user_id = isset( $_POST['user_id'] ) ? sanitize_text_field( $_POST['user_id'] ) : ''; $seller_id = isset( $_POST['seller_id'] ) ? sanitize_text_field( $_POST['seller_id'] ) : ''; $option = isset( $_POST['option'] ) ? sanitize_text_field( $_POST['option'] ) : ''; $amzonCurlRequest = CED_AMAZON_DIRPATH . 'admin/amazon/lib/ced-amazon-curl-request.php'; if ( file_exists( $amzonCurlRequest ) ) { require_once $amzonCurlRequest; $this->amzonCurlRequestInstance = new Ced_Amazon_Curl_Request(); } $cat_topic = 'category-all?&selected=' . $option; $cat_data = array( 'remote_shop_id' => $user_id, ); $response = $this->amzonCurlRequestInstance->ced_amazon_serverless_process( $cat_topic, $cat_data, 'GET' ); if ( isset( $response['body'] ) ) { $response = json_decode( $response['body'], true ); $response = isset( $response['response'] ) ? $response['response'] : array(); wp_send_json_success( $response ); } else { // No response from the API wp_send_json_error( 'No response from the API' ); } } public function ced_amazon_shipment_method( $params = array() ) { $logger = wc_get_logger(); $context = array( 'source' => 'ced_amazon_shipment_tracking' ); $seller_id = $params['seller_id'] ?? ''; if ( empty( $seller_id ) ) { $logger->info( wc_print_r( 'seller Id is empty', true ), $context ); return; } if ( CedAmazonHOPS::custom_orders_table_usage_is_enabled() ) { $this->create_amz_order_hops = true; $after_date = gmdate('Y-m-d H:i:s', strtotime('-480 hours')); $args = array( 'status' => 'completed', 'limit' => -1, 'return' => 'ids', 'meta_query' => array( 'relation' => 'AND', array( 'key' => '_amazon_umb_order_status', 'value' => 'Created', 'compare' => '=', ), array( 'key' => 'ced_amazon_order_seller_id', 'value' => $seller_id, 'compare' => '=', ), ), 'date_created' => '>=' . $after_date, ); $orders = wc_get_orders($args); } else { $args = array( 'post_type' => 'shop_order', 'fields' => 'ids', 'post_status' => array('completed'), 'numberposts' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'key' => '_amazon_umb_order_status', 'value' => 'Created', 'compare' => '=', ), array( 'key' => 'ced_amazon_order_seller_id', 'value' => $seller_id, 'compare' => '=' ) ), 'date_query' => array( array( 'after' => '120 hours ago', ), ) ); $orders = get_posts($args); } if ( empty( $orders ) ) { $logger->info( "Empty Completed Orders \n\n\n", $context ); return; } $logger->info( 'Orders found for shipment: ', $context ); $logger->info( wc_print_r( $orders, true ), $context ); if ( isset( $orders ) && ! empty( $orders ) ) { /** Acknowledgement Orders starts */ do_action( 'ced_amazon_acknowledge_order', $orders, $seller_id ); /** Acknowledgement Orders ends */ /** Order Fulfillment starts */ $this->ced_amazon_order_submit_tracking( $orders, $seller_id ); /** Order Fulfillment ends */ } } public function ced_amazon_order_submit_tracking( $orders = array(), $seller_id = '' ) { $logger = wc_get_logger(); $context = array( 'source' => 'ced_amazon_shipment_tracking' ); $logger->info( wc_print_r( ced_woo_timestamp() . ' ' . __FUNCTION__, true ), $context ); $carriers = array(); require CED_AMAZON_DIRPATH . 'admin/amazon/lib/ced-shipment-carrier-codes.php'; require_once CED_AMAZON_DIRPATH . 'admin/amazon/lib/ced-amazon-shipment-manager.php'; $shipment_instance = new Ced_Amazon_Shipment_Manager(); $global_setting_data = get_option( 'ced_amazon_global_settings', array() ); $seller_data = isset( $global_setting_data[$seller_id] ) ? $global_setting_data[$seller_id] : array(); $ced_amazon_shipment_tracking_plugin = isset( $seller_data['ced_amazon_shipment_tracking_plugin'] ) ? $seller_data['ced_amazon_shipment_tracking_plugin'] : ''; $remote_shop_id = ''; $saved_amazon_details = get_option( 'ced_amzon_configuration_validated', false ); if ( isset( $saved_amazon_details[$seller_id] ) && !empty( $saved_amazon_details[ $seller_id ] ) && is_array( $saved_amazon_details[$seller_id] ) ) { $shop_data = $saved_amazon_details[$seller_id]; $remote_shop_id = isset( $shop_data['seller_next_shop_id'] ) ? $shop_data['seller_next_shop_id'] : ''; } else { $logger->info( 'Remote shop ID not found ', $context ); return; } $count = 0; $ordershipmainarray = array(); $ordershipmainarray['@attributes'] = array( 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:noNamespaceSchemaLocation' => 'amzn-envelope.xsd', ); $ordershipmainarray['Header']['DocumentVersion'] = '1.01'; $ordershipmainarray['Header']['MerchantIdentifier'] = 'M_SELLER_XXXXXX'; $ordershipmainarray['MessageType'] = 'OrderFulfillment'; $ordershipmainarray['PurgeAndReplace'] = 'false'; $counter = 0; $shipped_orders = array(); $logger->info( 'Going to loop orders.', $context ); foreach ( $orders as $key => $orderID ) { if ( empty( $orderID ) ) { continue; } ++$count; $order = wc_get_order( $orderID ); // order_item_detail $marketplaceOrder = 'Amazon'; $isUmbOrder = $order->get_meta( 'amazon_order_id' ); $order_detail = $order->get_meta( 'order_detail' ); $order_details = $order->get_meta( 'order_item_detail' ); if ( empty( $isUmbOrder ) || 'Amazon' !== $marketplaceOrder ) { continue; } /** Fetch tracking details */ $logger->info( 'Going tracking details for order ' . $orderID , $context ); $ced_tracking_details = $shipment_instance->getTrackingDetails( $ced_amazon_shipment_tracking_plugin, $orderID ); if ( empty( $ced_tracking_details ) || ! isset( $ced_tracking_details['tracking_number'] ) || empty( $ced_tracking_details['tracking_number'] ) ) { $logger->info( 'Empty tracking details or tracking number found for WooCOmmerce order ID ' . $orderID, $context ); continue; } $custom_plgn_carrier_code = isset( $ced_tracking_details['tracking_provider_code'] ) ? $ced_tracking_details['tracking_provider_code'] : ''; $tracking_number = isset( $ced_tracking_details['tracking_number'] ) ? $ced_tracking_details['tracking_number'] : ''; $custom_plgn_carrier_name = isset( $ced_tracking_details['tracking_provider_name'] ) ? $ced_tracking_details['tracking_provider_name'] : ''; if ( empty( $tracking_number ) ) { $logger->info( "Tracking no is empty \n", $context ); continue; } if ( empty( $custom_plgn_carrier_name ) && !empty( $custom_plgn_carrier_code ) ) { $custom_plgn_carrier_name = $custom_plgn_carrier_code; } if ( empty( $custom_plgn_carrier_name ) ) { $logger->info( "custom_plgn_carrier_name no is empty \n", $context ); continue; } $mod_custom_plgn_carrier_code = strtolower( $custom_plgn_carrier_name ); /** Get amazon shipment carrier name w.r.t woocommerce shiipment carrier */ $carrier_code = isset( $carriers[ $mod_custom_plgn_carrier_code ] ) ? $carriers[ $mod_custom_plgn_carrier_code ] : ''; $logger->info( wc_print_r( 'carrier code' . $carrier_code , true ), $context ); /** Prepare shipment data as per amazon */ if ( empty( $carrier_code ) ) { /** Handling the condition when we dont have carrier name as per amazon */ $ordershipfulfildata['CarrierCode'] = 'Other'; // CarrierName $ordershipfulfildata['CarrierName'] = ucfirst( $custom_plgn_carrier_name ); $ordershipfulfildata['ShippingMethod'] = 'Standard'; if ( !empty( $tracking_number ) ) { $ordershipfulfildata['ShipperTrackingNumber'] = trim($tracking_number); } } else { $ordershipfulfildata['CarrierCode'] = trim($carrier_code); // Amazon carrier name $ordershipfulfildata['ShippingMethod'] = 'Standard'; $ordershipfulfildata['ShipperTrackingNumber'] = trim($tracking_number); } $logger->info( wc_print_r( $ordershipfulfildata , true ), $context ); $offset = '.0000000-00:00'; $FulfillmentDate = ced_woo_timestamp( 'Y-m-d\Th:i:s' ) . $offset; $ordershiparray['AmazonOrderID'] = $order_detail['AmazonOrderId']; $ordershiparray['FulfillmentDate'] = $FulfillmentDate; $ordershiparray['FulfillmentData'] = $ordershipfulfildata; $itemarray = array(); foreach ( $order_details as $key => $order_item ) { $amznitem['AmazonOrderItemCode'] = $order_item['OrderItemId']; // $amznitem['MerchantFulfillmentItemID'] = $order_item['id']; $amznitem['Quantity'] = $order_item['QuantityOrdered']; $itemarray[] = $amznitem; unset( $order_details[ $key ] ); } ++$counter; $ordershiparray['Item'] = $itemarray; $ordershipmainarray['Message'][$count]['MessageID'] = $counter; $ordershipmainarray['Message'][$count]['OperationType'] = 'Update'; $ordershipmainarray['Message'][$count]['OrderFulfillment'] = $ordershiparray; $shipped_orders[ $order_detail['AmazonOrderId'] ] = $orderID; } if ( isset( $ordershipmainarray['Message'] ) ) { require_once CED_AMAZON_DIRPATH . 'marketplaces/amazon/lib/array2xml.php'; $xml = Array2XML::createXML( 'AmazonEnvelope', $ordershipmainarray ); $xmlString = $xml->saveXML(); $xmlFileName = 'shipment_data' . $seller_id . '.xml'; $this->amazon_feed_manager->writeStringToFile( $xmlString, $xmlFileName ); $logger->info( wc_print_r( $xmlString, true ), $context ); $order_topic = 'create-feed'; $order_keys = array( 'feed_action' => 'POST_ORDER_FULFILLMENT_DATA', 'feed_content' => $xmlString, 'remote_shop_id' => $remote_shop_id, ); $file = CED_AMAZON_DIRPATH . 'admin/amazon/lib/ced-amazon-curl-request.php'; if ( file_exists( $file ) ) { require_once $file; $this->amzonCurlRequestInstance = new Ced_Amazon_Curl_Request(); $ordershipmentreponse = $this->amzonCurlRequestInstance->ced_amazon_serverless_process( $order_topic, $order_keys, 'POST' ); $ordershipmentreponse = isset( $ordershipmentreponse['body'] ) ? json_decode( $ordershipmentreponse['body'], true ) : array(); if ( $ordershipmentreponse['success'] && isset( $ordershipmentreponse['data'] ) && isset( $ordershipmentreponse['data']['feed_id'] ) ) { $feedId = $ordershipmentreponse['data']['feed_id']; require_once CED_AMAZON_DIRPATH . 'admin/amazon/lib/class-feed-manager.php'; $feed_manager = Ced_Umb_Amazon_Feed_Manager::get_instance(); $mplocation_arr = explode( '|', $seller_id ); $mplocation = isset( $mplocation_arr[0] ) ? $mplocation_arr[0] : ''; $feed_manager->insertFeedInfoToDatabase( $feedId, 'POST_ORDER_FULFILLMENT_DATA', $mplocation, $shipped_orders, 'Automatic' ); } else { $logger->info( 'Unable to create feed for shipment tracking', $context ); } } } } public function ced_amazon_check_required_details_for_cron( $params ) { $logger = wc_get_logger(); $context = $params['context'] ?? array(); $scheduler_name = $params['scheduler_name'] ?? ''; $process_name = $params['process_name'] ?? ''; $region = $params['region'] ?? ''; $seller_id = $params['seller_id'] ?? ''; $merchant_id = $params['merchant_id'] ?? ''; $transient_name = $params['transient_name'] ?? ''; $action = strtolower($process_name); $amazon_feed_manager = CED_AMAZON_DIRPATH . 'admin/amazon/lib/class-feed-manager.php'; if ( file_exists( $amazon_feed_manager ) ) { require_once $amazon_feed_manager; $this->amazon_feed_manager = new Ced_Umb_Amazon_Feed_Manager(); } if ( is_null( $this->amazon_feed_manager ) ) { $logger->info( "Unable to find feed manager file \n", $context ); return false; } if ( empty( $region ) ) { $logger->info( 'Region is missing during ' . $process_name . " ! \n", $context ); return false; } $amzonCurlRequest = CED_AMAZON_DIRPATH . 'admin/amazon/lib/ced-amazon-curl-request.php'; if ( file_exists( $amzonCurlRequest ) ) {