feat: Add product price comparison table
- Add "Load Product Comparison" button in admin - Display WooCommerce products with local price (sale/regular) - Show Google Merchant Center price for each product - Show match type (offerId vs gtin) and match status - Helps debug product matching issues - Limited to 50 in-stock products for performance Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
$('#informatiq-sp-manual-sync').on('click', this.handleManualSync);
|
||||
$('#informatiq-sp-test-connection').on('click', this.handleTestConnection);
|
||||
$('#informatiq-sp-revoke-auth').on('click', this.handleRevokeAuth);
|
||||
$('#informatiq-sp-compare-products').on('click', this.handleCompareProducts);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -179,6 +180,82 @@
|
||||
$button.prop('disabled', false).text('Revoke Authorization');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle compare products button click
|
||||
*/
|
||||
handleCompareProducts: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $button = $(this);
|
||||
var $spinner = $button.next('.spinner');
|
||||
var $results = $('#informatiq-sp-comparison-results');
|
||||
var $tbody = $('#informatiq-sp-comparison-tbody');
|
||||
|
||||
// Disable button and show spinner
|
||||
$button.prop('disabled', true);
|
||||
$spinner.addClass('is-active');
|
||||
|
||||
// Make AJAX request
|
||||
$.ajax({
|
||||
url: informatiqSP.ajaxUrl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'informatiq_sp_compare_products',
|
||||
nonce: informatiqSP.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
var data = response.data;
|
||||
var html = '';
|
||||
|
||||
if (data.products.length === 0) {
|
||||
html = '<tr><td colspan="6">No in-stock products with SKU found.</td></tr>';
|
||||
} else {
|
||||
$.each(data.products, function(i, product) {
|
||||
var localPrice = product.local_price ? data.currency + parseFloat(product.local_price).toFixed(2) : '-';
|
||||
var googlePrice = product.google_price ? data.currency + parseFloat(product.google_price).toFixed(2) : '-';
|
||||
var priceLabel = product.price_type === 'sale' ? ' <small>(sale)</small>' : ' <small>(regular)</small>';
|
||||
var matchLabel = product.match_type ? product.match_type : '-';
|
||||
var statusClass = product.found ? 'color: #00a32a;' : 'color: #d63638;';
|
||||
var statusText = product.found ? 'Found' : 'Not Found';
|
||||
|
||||
if (product.found && product.google_offer) {
|
||||
matchLabel += ' <small>(' + product.google_offer + ')</small>';
|
||||
}
|
||||
|
||||
html += '<tr>';
|
||||
html += '<td><a href="post.php?post=' + product.id + '&action=edit">' + product.name + '</a></td>';
|
||||
html += '<td><code>' + product.sku + '</code></td>';
|
||||
html += '<td>' + localPrice + priceLabel + '</td>';
|
||||
html += '<td>' + googlePrice + '</td>';
|
||||
html += '<td>' + matchLabel + '</td>';
|
||||
html += '<td style="' + statusClass + '"><strong>' + statusText + '</strong></td>';
|
||||
html += '</tr>';
|
||||
});
|
||||
}
|
||||
|
||||
$tbody.html(html);
|
||||
$results.show();
|
||||
|
||||
// Show summary
|
||||
var summary = 'Showing ' + data.products.length + ' WooCommerce products. ';
|
||||
summary += data.google_count + ' products found in Google Merchant Center.';
|
||||
$button.after('<p class="description" style="margin-top: 10px;">' + summary + '</p>');
|
||||
|
||||
} else {
|
||||
alert('Error: ' + (response.data.message || 'Unknown error'));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
alert('Error: ' + errorThrown);
|
||||
},
|
||||
complete: function() {
|
||||
$button.prop('disabled', false);
|
||||
$spinner.removeClass('is-active');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user