Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into dw-sprint
Browse files Browse the repository at this point in the history
# Conflicts:
#	merchant.php
  • Loading branch information
DevWael committed Dec 13, 2024
2 parents ce5a48d + 008d862 commit 71b3f8e
Show file tree
Hide file tree
Showing 42 changed files with 1,357 additions and 490 deletions.
10 changes: 0 additions & 10 deletions admin/classes/class-merchant-admin-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ public function __construct() {
'tutorial_url' => 'https://docs.athemes.com/article/merchant-recently-viewed-products/',
),

// Boost Revenue.

// Reduce Cart Abandonment.
'buy-now' => array(
'pro' => false,
Expand Down Expand Up @@ -328,14 +326,6 @@ public function __construct() {
'desc' => esc_html__( 'Help visitors instantly find the products they\'re looking for by using predictive search', 'merchant' ),
'tutorial_url' => 'https://docs.athemes.com/article/real-time-search/',
),
'code-snippets' => array(
'pro' => false,
'section' => 'improve-experience',
'icon' => Merchant_SVG_Icons::get_svg_icon( 'module-code-snippets' ),
'title' => esc_html__( 'Code Snippets', 'merchant' ),
'desc' => esc_html__( 'Add code snippets in WordPress without having to edit your theme\'s functions.php file ', 'merchant' ),
'tutorial_url' => 'https://docs.athemes.com/article/code-snippets/',
),
'scroll-to-top-button' => array(
'pro' => false,
'section' => 'improve-experience',
Expand Down
68 changes: 65 additions & 3 deletions admin/classes/class-merchant-admin-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function __construct() {
add_action( 'wp_ajax_merchant_admin_products_search', array( $this, 'products_search' ) );

add_action( 'clean_user_cache', array( $this, 'clear_customer_choices_cache' ), 10, 2 );

// Delete module data
add_action( 'admin_init', array( $this, 'delete_module_data' ) );
}

/**
Expand Down Expand Up @@ -726,9 +729,53 @@ public static function disabled_field( $settings, $value, $module_id = '') {
public static function replace_field( $settings, $value, $search, $replace, $module_id = '') {
ob_start();
self::field( $settings, $value, $module_id );
$field = ob_get_clean();
$field_html = ob_get_clean();

// Replace attributes in the field
$field = str_replace( $search, $replace, $field_html );

// Process specific field types
if ( isset( $settings['type'] ) && $settings['type'] === 'hook_select' ) {
$field = self::update_field_attributes( $field, array(
'select' => '[hook_name]',
'input' => '[hook_priority]',
) );
}

echo wp_kses( str_replace( $search, $replace, $field ), merchant_kses_allowed_tags( array( 'all' ) ) );
echo wp_kses( $field, merchant_kses_allowed_tags( array( 'all' ) ) );
}

/**
* Update attributes for specific tags in the field HTML.
*
* @param string $field_html The field's HTML.
* @param array $tag_updates An associative array where keys are tag names
* and values are strings to append to the `name` attribute.
*
* @return string Updated field HTML.
*/
private static function update_field_attributes( $field, $updates ) {
if ( ! class_exists( 'WP_HTML_Tag_Processor' ) ) {
return $field;
}

foreach ( $updates as $tag => $append ) {
$processor = new WP_HTML_Tag_Processor( $field ); // Reset processor for each tag type

while ( $processor->next_tag( $tag ) ) {
$current_name = $processor->get_attribute( 'name' );

// Append the specified string if not already present
if ( $current_name && ! str_ends_with( $current_name, $append ) ) {
$processor->set_attribute( 'name', $current_name . $append );
}
}

// Update the field with the latest processed HTML
$field = $processor->get_updated_html();
}

return $field;
}

/**
Expand Down Expand Up @@ -2241,7 +2288,7 @@ public static function fields_group( $settings, $value, $module_id = '', $inside
if ( $inside_flexible ) {
static::replace_field(
$field,
isset( $args['value'][$settings['id']][ $field['id'] ] ) ? $args['value'][$settings['id']][ $field['id'] ] : ( $field['default'] ?? '' ),
$args['value'][ $settings['id'] ][ $field['id'] ] ?? ( $field['default'] ?? '' ),
"name=\"merchant[{$field['id']}]",
"name=\"merchant[{$args['id']}][{$args['option_key']}][{$settings['id']}][{$field['id']}]\" data-name=\"merchant[{$args['id']}][0][{$settings['id']}][{$field['id']}]",
$module_id
Expand Down Expand Up @@ -2674,6 +2721,21 @@ public function clear_customer_choices_cache( $user_id, $user ) {
delete_transient( 'customers_select2_choices' );
}
}

/**
* Delete module data.
*
* @return void
*/
public function delete_module_data() {
$options = get_option( 'merchant', array() );

// Code Snippets module was removed, so delete data from DB as well.
if ( isset( $options['code-snippets'] ) ) {
unset( $options['code-snippets'] );
update_option( 'merchant', $options );
}
}
}

Merchant_Admin_Options::instance();
Expand Down
12 changes: 8 additions & 4 deletions assets/js/src/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,19 @@
if (elements.length === 0) {
return;
}
elements.each(function () {
elements.each(function ( index ) {
let input = $(this).find('input'),
options = {
locale: JSON.parse(merchant_datepicker_locale),
selectedDates: [input.val() ? new Date(input.val()) : ''],
onSelect: ({date, formattedDate, datepicker}) => {
if (typeof (formattedDate) === "undefined") {
// allow removing date
input.val('');
// input.val('');
datepicker.$el.value = '';
}
input.trigger('change.merchant');
input.trigger('change.merchant-datepicker', [ formattedDate, input ]);
input.trigger('change.merchant-datepicker', [ formattedDate, input, options, index ]);
}
},
fieldOptions = $(this).data('options');
Expand All @@ -288,8 +289,11 @@
}
options = Object.assign(options, fieldOptions);
}
new AirDatepicker(input.getPath(), options);

const datepickerObj = new AirDatepicker(input.getPath(), options);
input.attr('readonly', true);

$( document ).trigger( 'initiated.merchant-datepicker', [ datepickerObj, input, options, index ] );
});
},

Expand Down
8 changes: 7 additions & 1 deletion assets/js/src/modules/free-gifts/admin/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@
productNames.push( $(this).attr( 'title' ) )
} );
productName = productNames.length ? productNames.join( ', ' ) : 'Categories';
} else if ( rule === 'tags' ) {
const productNames = [];
layout.find( '.merchant-field-tag_slugs .select2-selection__choice' ).each( function() {
productNames.push( $(this).attr( 'title' ) )
} );
productName = productNames.length ? productNames.join( ', ' ) : 'Tags';
}

spendingText = spendingText?.replace( /{amount}|{goalAmount}/g, spendingGoal );
spendingText = spendingText?.replace( /{productName}|{categories}/g, productName );
spendingText = spendingText?.replace( /{productName}|{categories}|{tags}/g, productName );
$( '.merchant-free-gifts-widget-offer-label' ).html( spendingText );

$( document ).on( 'change', '.merchant-field-rules_to_apply select', function() {
Expand Down
14 changes: 11 additions & 3 deletions assets/js/src/modules/frequently-bought-together/admin/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
initPreview();
});

$( document ).on( 'change', '.merchant-module-page-setting-field-select select', function () {
const selectedHook = $( this ).val();

let priority = merchant?.fbt_object?.hooks[selectedHook] || 10;

$( this ).closest( '.merchant-module-page-setting-field-hook_select' ).find( '.merchant-module-page-setting-field-number input' ).val( priority );
} );

function initPreview() {
let layout = $('.merchant-flexible-content-control.frequently-bought-together-style').find('.layout.active'),
titleTextColor = layout.find('.merchant-field-title input').val(),
Expand Down Expand Up @@ -49,11 +57,11 @@
$('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-product .upsell-info p').text(cartSaveLabel.replace('{amount}', '10%'));
$('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-product .upsell-info .add-to-cart').text(cartBundleButtonText);
$('.merchant-checkout-preview .offer-title').text(checkoutTitle.replace('{offer_quantity}', '3'));
$('.merchant-checkout-preview .product-details .product-info p').text(checkoutDiscountText.replace('{discount}', '10%').replace('{fbt_products}', fbt_object.product_names));
$('.merchant-checkout-preview .product-details .product-info p').text(checkoutDiscountText.replace('{discount}', '10%').replace('{fbt_products}', merchant?.fbt_object.product_names));
$('.merchant-checkout-preview .product-details .product-info .add-to-order').text(checkoutButtonText);
$('.merchant-thank-you-preview .offer-title').text(thankYouTitle.replace('{offer_quantity}', '3').replace('{discount}', '10%'));
$('.merchant-thank-you-preview .product-details .product-info p').text(thankYouDiscountText.replace('{discount}', '10%').replace('{fbt_products}', fbt_object.product_names));
$('.merchant-thank-you-preview .merchant-tooltip .tooltip-text').html(thankYouBonusTipText.replace('{discount}', '10%').replace('{fbt_products}', fbt_object.product_names));
$('.merchant-thank-you-preview .product-details .product-info p').text(thankYouDiscountText.replace('{discount}', '10%').replace('{fbt_products}', merchant?.fbt_object.product_names));
$('.merchant-thank-you-preview .merchant-tooltip .tooltip-text').html(thankYouBonusTipText.replace('{discount}', '10%').replace('{fbt_products}', merchant?.fbt_object.product_names));
$('.merchant-thank-you-preview .product-details .product-info .add-to-order').text(thankYouButtonText);
}

Expand Down
Loading

0 comments on commit 71b3f8e

Please sign in to comment.