Skip to content

Commit

Permalink
Merge pull request #305 from Ecwid/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
meteor-ec authored Nov 7, 2024
2 parents 71ed1ed + 3b4191e commit 767a146
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 36 deletions.
4 changes: 4 additions & 0 deletions css/popup-deactivate.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
font-size: 1em;
}

.reasons-list-item .message textarea.more-details {
min-height: 100px;
}

.reasons-list-item.selected .message {
display: block;
}
Expand Down
8 changes: 8 additions & 0 deletions css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ body.ecwid-popup-open {
top: 0;
z-index: 100000;
display: none;
left: 0;
top: 0;
right: 0;
bottom: 0;
}

.ecwid-popup.open {
Expand All @@ -22,6 +26,10 @@ body.ecwid-popup-open {
position: absolute;
}

.ecwid-popup .success-message {
display: none;
}

.ecwid-popup-header,
.ecwid-popup-footer,
.ecwid-popup-body {
Expand Down
8 changes: 8 additions & 0 deletions css/themes/twentytwentyfive.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#dynamic-ec-store-container,
#static-ec-store-container {
max-width: var(--wp--style--global--wide-size);
}
.wp-block-post-title {
max-width: var(--wp--style--global--wide-size) !important;
padding: 0 10px 0;
}
11 changes: 11 additions & 0 deletions ecwid-shopping-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,17 @@ function ecwid_ajax_deactivate_feedback() {
$popup->ajax_deactivate_feedback();
}

add_action( 'wp_ajax_ecwid_send_feedback', 'ecwid_ajax_woo_import_feedback' );
function ecwid_ajax_woo_import_feedback() {
if ( ! current_user_can( 'manage_options' ) ) {
die();
}

require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-popup-woo-import-feedback.php';
$popup = new Ecwid_Popup_Woo_Import_Feedback();
$popup->ajax_send_feedback();
}

function ecwid_ajax_hide_message( $params ) {
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
return;
Expand Down
Binary file removed fonts/welcome-page/Gotham-Thin_Web (1).woff2
Binary file not shown.
144 changes: 144 additions & 0 deletions includes/class-ecwid-popup-woo-import-feedback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-popup.php';

class Ecwid_Popup_Woo_Import_Feedback extends Ecwid_Popup {

protected $_class = 'ecwid-popup-woo-import-feedback';

const OPTION_DISABLE_POPUP = 'ecwid_disable_deactivate_popup';

public function __construct() {
add_action( 'wp_ajax_ecwid_send_feedback', array( $this, 'ajax_send_feedback' ) );
}

public function enqueue_scripts() {
parent::enqueue_scripts();
wp_enqueue_script( 'ecwid-popup-deactivate', ECWID_PLUGIN_URL . '/js/popup-deactivate.js', array( 'jquery' ), get_option( 'ecwid_plugin_version' ) );
wp_enqueue_style( 'ecwid-popup-deactivate', ECWID_PLUGIN_URL . '/css/popup-deactivate.css', array(), get_option( 'ecwid_plugin_version' ) );
}

public function ajax_send_feedback() {

if ( ! current_user_can( 'manage_options' ) ) {
header( '403 Access Denied' );

die();
}

$to = '[email protected]';

$body_lines = array();
if ( ! ecwid_is_demo_store() ) {
$body_lines[] = 'Store ID: ' . get_ecwid_store_id();
}

$reasons = $this->_get_reasons();

if ( isset( $_GET['reason'] ) ) {
$reason = $reasons[ sanitize_text_field( wp_unslash( $_GET['reason'] ) ) ];
} else {
$reason = end( $reasons );
}

if ( isset( $reason['is_disable_message'] ) ) {
update_option( self::OPTION_DISABLE_POPUP, true );
}

$body_lines[] = 'Store URL: ' . Ecwid_Store_Page::get_store_url();
$body_lines[] = 'Plugin installed: ' . date_i18n( 'd M Y', get_option( 'ecwid_installation_date' ) );
$body_lines[] = 'Plugin version: ' . get_option( 'ecwid_plugin_version' );
$body_lines[] = 'Reason:' . $reason['text'] . "\n" . ( ! empty( $_GET['message'] ) ? sanitize_text_field( wp_unslash( $_GET['message'] ) ) : '[no message]' );

$api = new Ecwid_Api_V3();

$profile = $api->get_store_profile();
if ( $profile && @$profile->account && @$profile->account->accountEmail ) {
$reply_to = $profile->account->accountEmail;
} else {
global $current_user;
$reply_to = $current_user->user_email;
}

$subject_template = __( '[%1$s] WordPress plugin: Woo import feedback (store ID: %2$s)', 'ecwid-shopping-cart' );

$prefix = $reason['code'];
if ( ! empty( $_GET['message'] ) ) {
$prefix .= ', commented';
}

$subject = sprintf( $subject_template, $prefix, get_ecwid_store_id() );

$result = wp_mail(
$to,
$subject,
implode( PHP_EOL, $body_lines ),
'Reply-To:' . $reply_to
);

if ( $result ) {
header( 'HTTP/1.1 200 OK' );
die();
} else {
header( '500 Send mail failed' );
die();
}
}

public function is_disabled() {
$disabled = get_option( self::OPTION_DISABLE_POPUP, false );

if ( $disabled ) {
return true;
}

if ( Ecwid_Config::is_wl() ) {
return true;
}

if ( strpos( ecwid_get_current_user_locale(), 'en' ) !== 0 ) {
return true;
}

return false;
}

protected function _get_footer_buttons() {
return array(
(object) array(
'class' => 'button-primary float-left btn-send-feedback',
'title' => __( 'Send', 'ecwid-shopping-cart' ),
),
(object) array(
'class' => 'button-link btn-close',
'title' => __( 'Cancel', 'ecwid-shopping-cart' ),
),
(object) array(
'class' => 'button-link btn-close success-message',
'title' => __( 'Close', 'ecwid-shopping-cart' ),
),
);
}

protected function _get_header() {
return __( 'Help Us Improve', 'ecwid-shopping-cart' );
}

protected function _render_body() {
$reasons = $this->_get_reasons();
require ECWID_POPUP_TEMPLATES_DIR . 'woo-import-feedback.php';
}

protected function _get_reasons() {
$options = array(
array(
'text' => '',
'has_message' => true,
'code' => 'feedback',
'message_hint' => __( 'Please share your experience with us. What was positive? What can we improve?', 'ecwid-shopping-cart' ),
),
);

return $options;
}
}
29 changes: 29 additions & 0 deletions includes/importer/class-ecwid-import-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ class Ecwid_Import_Page {
const AJAX_ACTION_CHECK_IMPORT = 'ec-store-check-import';
const AJAX_ACTION_DO_WOO_IMPORT = 'ec-store-do-woo-import';
const ACTION_GET_WOO_IMPORT_LOG = 'ec-store-get-woo-import-log';
const AJAX_ACTION_SEND_ERROR_TO_LOGS = 'ec-store-send-error-to-logs';

const PARAM_FROM_IMPORT_ONBOARDING = 'from-woo-import-message';

public function init_actions() {
add_action( 'admin_menu', array( $this, 'build_menu' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'current_screen', array( $this, 'process_woo_onboarding_redirect' ) );
add_action( 'current_screen', array( $this, 'add_feedback_popup' ) );
add_action( 'wp_ajax_' . self::AJAX_ACTION_CHECK_IMPORT, array( $this, 'check_import' ) );
add_action( 'wp_ajax_' . self::AJAX_ACTION_DO_WOO_IMPORT, array( $this, 'do_woo_import' ) );
add_action( 'current_screen', array( $this, 'do_reconnect' ) );
add_action( 'admin_post_' . self::ACTION_GET_WOO_IMPORT_LOG, array( $this, 'get_woo_import_log' ) );

add_action( 'wp_ajax_' . self::AJAX_ACTION_SEND_ERROR_TO_LOGS, array( $this, 'send_error_to_logs' ) );
}

public function process_woo_onboarding_redirect() {
Expand Down Expand Up @@ -64,6 +68,7 @@ public function enqueue_scripts() {
array(
'check_token_action' => self::AJAX_ACTION_CHECK_IMPORT,
'do_woo_import_action' => self::AJAX_ACTION_DO_WOO_IMPORT,
'send_error_to_logs' => self::AJAX_ACTION_SEND_ERROR_TO_LOGS,
'_ajax_nonce' => wp_create_nonce( self::AJAX_ACTION_DO_WOO_IMPORT ),
)
);
Expand Down Expand Up @@ -120,6 +125,21 @@ public function do_woo_import() {
die();
}

public function send_error_to_logs() {
check_ajax_referer( self::AJAX_ACTION_DO_WOO_IMPORT );

if ( ! current_user_can( 'manage_options' ) ) {
die();
}

$importer = new Ecwid_Importer();
$result = $importer->send_import_error_to_logs();

echo json_encode( $result );

die();
}

protected function _get_billing_page_url() {
return 'admin.php?page=' . Ecwid_Admin::ADMIN_SLUG . '&ec-page=billing';
}
Expand Down Expand Up @@ -187,6 +207,15 @@ protected function _get_products_categories_message( $products, $categories ) {
}
}

public function add_feedback_popup() {
if ( get_current_screen()->id == 'admin_page_ec-store-import-woocommerce' ) {
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-popup-woo-import-feedback.php';

$popup = new Ecwid_Popup_Woo_Import_Feedback();
Ecwid_Popup::add_popup( $popup );
}
}

public function get_woo_import_log() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
Expand Down
8 changes: 7 additions & 1 deletion includes/importer/class-ecwid-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public function tick() {
return $progress;
}


public function append_batch( $batch_item ) {
$this->_batch[] = $batch_item;

Expand Down Expand Up @@ -299,6 +298,13 @@ public function send_import_mark_to_log() {
return $api->get_store_update_stats( $params );
}

public function send_import_error_to_logs() {
$api = new Ecwid_Api_V3();
$params = array( 'wp_import_woo_fail' => get_ecwid_store_id() );

return $api->get_store_update_stats( $params );
}

public static function is_localhost() {

if ( get_option( self::OPTIONS_SEPARATE_IMAGE_LOADING, false ) ) {
Expand Down
10 changes: 5 additions & 5 deletions includes/importer/task/class-ecwid-importer-task-main.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php

class Ecwid_Importer_Task_Main extends Ecwid_Importer_Task {

public static $type = 'main';

public function execute( Ecwid_Importer $importer, array $data ) {

$importer->send_import_mark_to_log();

if ( $importer->get_setting( Ecwid_Importer::SETTING_DELETE_DEMO ) && Ecwid_Importer::count_ecwid_demo_products() ) {
$importer->append_task(
$importer->append_task(
Ecwid_Importer_Task_Delete_Products::build( Ecwid_Importer::get_ecwid_demo_products() )
);
}

$importer->append_task( Ecwid_Importer_Task_Import_Woo_Categories::build( array() ) );
$importer->append_task( Ecwid_Importer_Task_Import_Woo_Products::build( array() ) );
}
}
}
1 change: 1 addition & 0 deletions includes/themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function ecwid_apply_theme( $theme_name = null ) {
'twentytwentytwo' => array( 'css-no-parent', 'title' ),
'twentytwentythree' => array( 'css-no-parent', 'title' ),
'twentytwentyfour' => array( 'css-no-parent', 'title' ),
'twentytwentyfive' => array( 'css-no-parent', 'title' ),
);
$generic_themes = apply_filters( 'ecwid_generic_themes', $generic_themes );

Expand Down
2 changes: 1 addition & 1 deletion js/dynamic-title.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jQuery(document).ready(function() {
if ( jQuery( '.entry-title' ).length > 0 && typeof Ecwid !== 'undefined' ) {
if ( jQuery( '.entry-title, .wp-block-post-title' ).length > 0 && typeof Ecwid !== 'undefined' ) {
Ecwid.OnPageLoaded.add(function(page) {

var alreadyFoundEl = jQuery('h1[data-ecwid-found-title]');
Expand Down
15 changes: 15 additions & 0 deletions js/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,29 @@ jQuery(document).ready(function () {

if (status.planLimitHit) {
showWooImportAlert('limit');
send_mark_to_logs('limit');
} else if (Object.keys(status.error).length > 0 || Object.keys(status.errorMessages).length > 0) {
showWooImportAlert('warning');
send_mark_to_logs();
} else {
showWooImportAlert('success');
}

switchWooImportState('complete');
}

send_mark_to_logs = function (reason = null) {
var data = {
'action': ecwid_importer.send_error_to_logs,
'_ajax_nonce': ecwid_importer._ajax_nonce,
settings: settings
};

jQuery.ajax({
'url': ajaxurl,
'data': data
});
};
};

jQuery('#ec-importer-woo-go').on('click', function () {
Expand Down
Loading

0 comments on commit 767a146

Please sign in to comment.