array('label' => __('Product image', 'ai-eshop-optimizer'), 'sel' => '.wp-block-woocommerce-product-image'),
'title' => array('label' => __('Product title', 'ai-eshop-optimizer'), 'sel' => '.wp-block-post-title'),
'price' => array('label' => __('Price', 'ai-eshop-optimizer'), 'sel' => '.wp-block-woocommerce-product-price'),
'rating' => array('label' => __('Star rating', 'ai-eshop-optimizer'), 'sel' => ':is(.aieo-rating-stars--archive,.aieo-rating-aggregate)', 'pin' => true),
'quick_view' => array('label' => __('Quick-View button (“Discover it”)', 'ai-eshop-optimizer'), 'sel' => '.aieo-quick-view-trigger', 'is_quick_view' => true, 'pin' => true),
'buy' => array('label' => __('Buy button', 'ai-eshop-optimizer'), 'sel' => ':is(.wp-block-aieo-product-card-swatches,.wp-block-woocommerce-product-button,.wc-block-components-product-button)', 'is_buy' => true, 'pin' => true),
);
}
public static function default_order() {
return array('image', 'title', 'price', 'rating', 'quick_view', 'buy');
}
public function get_settings() {
$stored = get_option(self::OPTION_KEY, array());
if (!is_array($stored)) { $stored = array(); }
$catalog = self::element_catalog();
$ids = array_keys($catalog);
$order = (isset($stored['order']) && is_array($stored['order'])) ? $stored['order'] : array();
$order = array_values(array_intersect(array_map('strval', $order), $ids));
foreach (self::default_order() as $id) { if (!in_array($id, $order, true)) { $order[] = $id; } }
foreach ($ids as $id) { if (!in_array($id, $order, true)) { $order[] = $id; } }
$sv = (isset($stored['visible']) && is_array($stored['visible'])) ? $stored['visible'] : array();
$sd = (isset($stored['device']) && is_array($stored['device'])) ? $stored['device'] : array();
$qv_enabled_default = class_exists('AIEO_DMM_Settings') ? (bool) AIEO_DMM_Settings::get('side_cart_quick_view_enabled', false) : false;
$qv_label_default = class_exists('AIEO_DMM_Settings') ? (string) AIEO_DMM_Settings::get('side_cart_quick_view_label', '') : '';
$out = array(
'order' => $order,
'visible' => array(),
'device' => array(),
'pin_buy_bottom' => array_key_exists('pin_buy_bottom', $stored) ? !empty($stored['pin_buy_bottom']) : true,
'equalize_rows' => array_key_exists('equalize_rows', $stored) ? !empty($stored['equalize_rows']) : true,
'quick_view_label' => array_key_exists('quick_view_label', $stored) ? (string) $stored['quick_view_label'] : $qv_label_default,
'title_width' => array_key_exists('title_width', $stored) ? (string) $stored['title_width'] : '70%',
'title_width_m' => array_key_exists('title_width_m', $stored) ? (string) $stored['title_width_m'] : '70%',
'buy_width' => array_key_exists('buy_width', $stored) ? (string) $stored['buy_width'] : '70%',
'buy_width_m' => array_key_exists('buy_width_m', $stored) ? (string) $stored['buy_width_m'] : '70%',
'qv_width' => array_key_exists('qv_width', $stored) ? (string) $stored['qv_width'] : '70%',
'qv_width_m' => array_key_exists('qv_width_m', $stored) ? (string) $stored['qv_width_m'] : '',
'var_font' => array_key_exists('var_font', $stored) ? (string) $stored['var_font'] : '',
'var_font_m' => array_key_exists('var_font_m', $stored) ? (string) $stored['var_font_m'] : '',
);
foreach ($catalog as $id => $meta) {
if (array_key_exists($id, $sv)) {
$out['visible'][$id] = !empty($sv[$id]);
} elseif (!empty($meta['is_quick_view'])) {
$out['visible'][$id] = $qv_enabled_default;
} else {
$out['visible'][$id] = true;
}
$dev = isset($sd[$id]) ? (string) $sd[$id] : '';
if (!in_array($dev, array('all', 'desktop', 'mobile'), true)) {
$dev = !empty($meta['is_quick_view']) ? 'desktop' : 'all';
}
$out['device'][$id] = $dev;
}
return $out;
}
private function sanitize_width($v) {
$v = trim((string) $v);
if ($v === '') { return ''; }
if (is_numeric($v)) { return $v . 'px'; }
return preg_match('/^[0-9]*\.?[0-9]+\s*(%|px|rem|em|vw|vh)$/i', $v) ? $v : '';
}
private function is_product_archive() {
if (!function_exists('is_shop')) { return false; }
if (is_shop()) { return true; }
if (function_exists('is_product_taxonomy') && is_product_taxonomy()) { return true; }
if (function_exists('is_post_type_archive') && is_post_type_archive('product')) { return true; }
if (is_search() && ('product' === get_query_var('post_type') || is_post_type_archive('product'))) { return true; }
return false;
}
public function enqueue_layout_css() {
if (is_admin() || !$this->is_product_archive()) { return; }
if (class_exists('AIEO_Card', false)) { return; }
$s = $this->get_settings();
$catalog = self::element_catalog();
$scopes = array('.wc-block-product-template', '.wp-block-woocommerce-product-template');
$rules = array();
foreach ($scopes as $sc) {
$rules[] = $sc . ' > li{display:flex !important;flex-direction:column !important;height:100% !important;}';
$rules[] = $sc . ' > li > *{order:500;}';
$rules[] = $sc . ' .wc-block-components-product-image img{min-height:0;}';
}
$pinned_seen = false;
foreach ($s['order'] as $i => $id) {
if (!isset($catalog[$id])) { continue; }
$sel = (string) $catalog[$id]['sel'];
$ord = ($i + 1) * 10;
foreach ($scopes as $sc) {
$rules[] = sprintf('%s %s{order:%d !important;}', $sc, $sel, $ord);
}
if (!empty($s['pin_buy_bottom']) && !empty($catalog[$id]['pin'])) {
foreach ($scopes as $sc) {
$rules[] = $pinned_seen
? sprintf('%s %s{margin-top:10px !important;margin-bottom:0 !important;}', $sc, $sel)
: sprintf('%s %s{margin-top:auto !important;margin-bottom:0 !important;}', $sc, $sel);
}
$pinned_seen = true;
}
if (empty($s['visible'][$id])) {
foreach ($scopes as $sc) {
$rules[] = sprintf('%s %s{display:none !important;}', $sc, $sel);
}
continue;
}
$dev = isset($s['device'][$id]) ? $s['device'][$id] : 'all';
if ($dev === 'desktop') {
foreach ($scopes as $sc) {
$rules[] = sprintf('@media (max-width:767px){%s %s{display:none !important;}}', $sc, $sel);
}
} elseif ($dev === 'mobile') {
foreach ($scopes as $sc) {
$rules[] = sprintf('@media (min-width:768px){%s %s{display:none !important;}}', $sc, $sel);
}
}
}
$title_sel = '.wp-block-post-title';
$buy_box = '.wp-block-aieo-product-card-swatches';
$buy_btn = $buy_box . ' .aieo-archive-add-to-cart';
$qv_sel = '.aieo-quick-view-trigger';
$var_sel = $buy_box . ' .om-variation-item';
$tw = trim((string) $s['title_width']); $twm = trim((string) $s['title_width_m']);
$bw = trim((string) $s['buy_width']); $bwm = trim((string) $s['buy_width_m']);
$qw = trim((string) $s['qv_width']); $qwm = trim((string) $s['qv_width_m']);
$vf = trim((string) $s['var_font']); $vfm = trim((string) $s['var_font_m']);
$buy_rule = function ($sc, $w) use ($buy_btn) {
return $sc . ' ' . $buy_btn . '{display:flex !important;align-items:center !important;justify-content:center !important;width:' . $w . ' !important;margin-inline:auto !important;box-sizing:border-box !important;text-align:center !important;line-height:1 !important;padding-top:calc(var(--aieo-btn-archive-pad-t, 8px) + 0.1em) !important;}';
};
$mobile = array();
foreach ($scopes as $sc) {
if ($tw !== '') { $rules[] = $sc . ' ' . $title_sel . '{max-width:' . $tw . ' !important;margin-inline:auto !important;}'; }
if ($bw !== '' || $bwm !== '') {
$rules[] = $sc . ' ' . $buy_box . '{width:100% !important;box-sizing:border-box !important;}';
$rules[] = $sc . ' ' . $buy_box . ' .om-product-swatches--archive{width:100% !important;}';
$arc = $sc . ' ' . $buy_box . ' .om-product-swatches--archive';
$svf = ($vf !== '') ? $vf : '12px';
$rules[] = $arc . ' .om-variation-type-button{justify-content:center !important;}';
$rules[] = $arc . ' .om-variation-type-button a{font-size:' . $svf . ' !important;line-height:1.1 !important;border-radius:0 !important;padding:5px 8px !important;}';
$rules[] = $arc . ' .variations_form{margin:0 !important;padding:0 !important;}';
$rules[] = $arc . ' .single_variation_wrap{display:none !important;}';
$rules[] = $arc . ' .reset_variations_alert{display:none !important;}';
$img = $arc . ':has(.om-variation-type-image)';
$clr = $arc . ':has(.om-variation-type-color)';
$rules[] = $img . ' .variations_form,' . $clr . ' .variations_form{height:0 !important;min-height:0 !important;overflow:visible !important;}';
$rules[] = $img . ' .variations,' . $clr . ' .variations{height:0 !important;}';
$rules[] = $arc . ' .variations tr:has(.om-variation-type-button){margin-bottom:10px !important;}';
}
if ($bw !== '') { $rules[] = $buy_rule($sc, $bw); }
if ($qw !== '') { $rules[] = $sc . ' ' . $qv_sel . '{width:' . $qw . ' !important;margin-inline:auto !important;box-sizing:border-box !important;}'; }
if ($vf !== '') { $rules[] = $sc . ' ' . $var_sel . '{font-size:' . $vf . ' !important;}'; }
if ($twm !== '') { $mobile[] = $sc . ' ' . $title_sel . '{max-width:' . $twm . ' !important;margin-inline:auto !important;}'; }
if ($bwm !== '') { $mobile[] = $buy_rule($sc, $bwm); }
if ($qwm !== '') { $mobile[] = $sc . ' ' . $qv_sel . '{width:' . $qwm . ' !important;margin-inline:auto !important;box-sizing:border-box !important;}'; }
if ($vfm !== '') { $mobile[] = $sc . ' ' . $var_sel . '{font-size:' . $vfm . ' !important;}'; }
}
if (!empty($mobile)) {
$rules[] = '@media (max-width:767px){' . implode('', $mobile) . '}';
}
if (!empty($s['equalize_rows'])) {
foreach ($scopes as $sc) {
$rules[] = $sc . ' .wp-block-woocommerce-product-price{display:flex !important;flex-direction:column !important;justify-content:center !important;align-items:center !important;}';
}
}
$css = implode('', $rules);
wp_register_style('aieo-dmm-archive-card', false, array(), defined('AIEO_VERSION') ? AIEO_VERSION : '1.0');
wp_enqueue_style('aieo-dmm-archive-card');
wp_add_inline_style('aieo-dmm-archive-card', $css);
if (!empty($s['equalize_rows'])) {
wp_register_script('aieo-dmm-archive-card', false, array(), defined('AIEO_VERSION') ? AIEO_VERSION : '1.0', true);
wp_enqueue_script('aieo-dmm-archive-card');
wp_add_inline_script('aieo-dmm-archive-card', $this->equalize_js());
}
}
private function equalize_js() {
return <<<'JS'
(function(){
"use strict";
var SEL = [".wp-block-post-title", ".wp-block-woocommerce-product-price", ".aieo-rating-stars--archive"];
var GRIDS = ".wc-block-product-template, .wp-block-woocommerce-product-template";
// Anchor the absolute-positioned image-swatch column to the product image's
// actual vertical centre. The theme pins it to 25% of the CARD, which drifts
// down into the title as the card grows (longer titles) — so the "+N" tail
// spilled past the image. offsetTop/offsetHeight are both relative to the
// position:relative card
, so this re-centres it on the image regardless
// of card height.
function centerSwatchColumns(li){
var imgCol = li.querySelector(".om-product-swatches--archive .om-variation-type-image");
if (!imgCol) { return; }
var tr = imgCol.closest("tr");
var img = li.querySelector(".wp-block-woocommerce-product-image");
if (!tr || !img) { return; }
var h = img.offsetHeight;
if (h > 0) { tr.style.top = Math.round(img.offsetTop + h / 2) + "px"; }
}
function run(){
document.querySelectorAll(GRIDS).forEach(function(grid){
var cards = Array.prototype.filter.call(grid.children, function(n){ return n.tagName === "LI"; });
if (!cards.length) { return; }
cards.forEach(function(li){ SEL.forEach(function(s){ var el = li.querySelector(s); if (el) { el.style.minHeight = ""; } }); });
var rows = {};
cards.forEach(function(li){ var k = Math.round(li.offsetTop); (rows[k] = rows[k] || []).push(li); });
Object.keys(rows).forEach(function(k){
var row = rows[k];
SEL.forEach(function(s){
var max = 0;
row.forEach(function(li){ var el = li.querySelector(s); if (el) { var h = el.offsetHeight; if (h > max) { max = h; } } });
if (max > 0) { row.forEach(function(li){ var el = li.querySelector(s); if (el) { el.style.minHeight = max + "px"; } }); }
});
});
cards.forEach(centerSwatchColumns);
});
}
var t;
function schedule(){ clearTimeout(t); t = setTimeout(run, 60); }
if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", run); } else { run(); }
window.addEventListener("load", run);
window.addEventListener("resize", schedule);
if (document.fonts && document.fonts.ready && document.fonts.ready.then) { document.fonts.ready.then(run); }
if (window.MutationObserver) {
document.querySelectorAll(GRIDS).forEach(function(grid){
try { new MutationObserver(schedule).observe(grid, { childList: true }); } catch (e) {}
});
}
})();
JS;
}
public function ajax_save() {
AIEO_DMM::verify_ajax_request();
$open_terms = array();
$in_both = array();
foreach (array('list' => 'card_options_in_list', 'side_cart' => 'card_options_in_side_cart') as $where => $field) {
$ids = (isset($_POST[$field]) && is_array($_POST[$field])) ? array_map('absint', wp_unslash($_POST[$field])) : array();
foreach (array_filter($ids) as $tid) {
if (!term_exists($tid, 'product_cat')) { continue; }
if (isset($open_terms[$tid]) && $open_terms[$tid] !== $where) { $in_both[] = $tid; }
$open_terms[$tid] = $where;
}
}
if (!empty($in_both)) {
$names = array();
foreach (array_unique($in_both) as $tid) {
$term = get_term($tid, 'product_cat');
$names[] = $term instanceof WP_Term ? html_entity_decode($term->name, ENT_QUOTES, 'UTF-8') : (string) $tid;
}
wp_send_json_error(array(
'message' => sprintf(__('In both category lists: %s. Keep each category in one.', 'ai-eshop-optimizer'), implode(', ', $names)),
));
}
$catalog = self::element_catalog();
$allowed = array_keys($catalog);
$raw = isset($_POST['order']) ? wp_unslash($_POST['order']) : array();
if (!is_array($raw)) { $raw = array(); }
$order = array();
foreach ($raw as $id) {
$id = sanitize_key($id);
if (in_array($id, $allowed, true) && !in_array($id, $order, true)) { $order[] = $id; }
}
if (empty($order)) { $order = self::default_order(); }
$rawvis = (isset($_POST['visible']) && is_array($_POST['visible'])) ? wp_unslash($_POST['visible']) : array();
$rawdev = (isset($_POST['device']) && is_array($_POST['device'])) ? wp_unslash($_POST['device']) : array();
$visible = array();
$device = array();
foreach ($allowed as $id) {
$visible[$id] = !empty($rawvis[$id]);
$dev = isset($rawdev[$id]) ? sanitize_key((string) $rawdev[$id]) : 'all';
$device[$id] = in_array($dev, array('all', 'desktop', 'mobile'), true) ? $dev : 'all';
}
$open_in = isset($_POST['card_options_in']) ? sanitize_key(wp_unslash((string) $_POST['card_options_in'])) : 'list';
update_option('aieo_card_options_in', in_array($open_in, array('list', 'side_cart'), true) ? $open_in : 'list');
update_option('aieo_card_options_in_terms', $open_terms);
$under = isset($_POST['card_under_picture']) ? sanitize_key(wp_unslash((string) $_POST['card_under_picture'])) : 'stars';
update_option('aieo_card_under_picture', in_array($under, array('swatches', 'name'), true) ? $under : 'stars');
$pin = !empty($_POST['pin_buy_bottom']);
$equalize = !empty($_POST['equalize_rows']);
$qv_label = isset($_POST['quick_view_label']) ? sanitize_text_field(wp_unslash((string) $_POST['quick_view_label'])) : '';
$tw = $this->sanitize_width(isset($_POST['title_width']) ? wp_unslash((string) $_POST['title_width']) : '');
$twm = $this->sanitize_width(isset($_POST['title_width_m']) ? wp_unslash((string) $_POST['title_width_m']) : '');
$bw = $this->sanitize_width(isset($_POST['buy_width']) ? wp_unslash((string) $_POST['buy_width']) : '');
$bwm = $this->sanitize_width(isset($_POST['buy_width_m']) ? wp_unslash((string) $_POST['buy_width_m']) : '');
$qw = $this->sanitize_width(isset($_POST['qv_width']) ? wp_unslash((string) $_POST['qv_width']) : '');
$qwm = $this->sanitize_width(isset($_POST['qv_width_m']) ? wp_unslash((string) $_POST['qv_width_m']) : '');
$vf = $this->sanitize_width(isset($_POST['var_font']) ? wp_unslash((string) $_POST['var_font']) : '');
$vfm = $this->sanitize_width(isset($_POST['var_font_m']) ? wp_unslash((string) $_POST['var_font_m']) : '');
update_option(self::OPTION_KEY, array(
'order' => $order,
'visible' => $visible,
'device' => $device,
'pin_buy_bottom' => $pin,
'equalize_rows' => $equalize,
'quick_view_label' => $qv_label,
'title_width' => $tw,
'title_width_m' => $twm,
'buy_width' => $bw,
'buy_width_m' => $bwm,
'qv_width' => $qw,
'qv_width_m' => $qwm,
'var_font' => $vf,
'var_font_m' => $vfm,
), false);
if (class_exists('AIEO_DMM_Settings')) {
$patch = array('side_cart_quick_view_enabled' => !empty($visible['quick_view']));
if ($qv_label !== '') { $patch['side_cart_quick_view_label'] = $qv_label; }
AIEO_DMM_Settings::update($patch);
}
if (isset($_POST['shop_view']) && '' !== self::theme_shop_view() && current_user_can('edit_theme_options')) {
$view = 'list' === sanitize_key(wp_unslash((string) $_POST['shop_view'])) ? 'list' : 'grid';
$design = \Rooster\Core\Setup::group('design');
if ((string) ($design['shop_view'] ?? 'grid') !== $view) {
$design['shop_view'] = $view;
\Rooster\Core\Setup::save('design', $design);
}
}
wp_send_json_success(array(
'order' => $order,
'message' => __('Archive card layout saved.', 'ai-eshop-optimizer'),
));
}
private static function theme_shop_view() {
if (!class_exists('\Rooster\Core\Setup') || !method_exists('\Rooster\Core\Setup', 'save') || !method_exists('\Rooster\Core\Setup', 'group') || !function_exists('rooster_setting')) {
return '';
}
return 'list' === rooster_setting('design', 'shop_view', 'grid') ? 'list' : 'grid';
}
private function category_choices() {
$terms = get_terms(array('taxonomy' => 'product_cat', 'hide_empty' => false));
if (!is_array($terms)) { return array(); }
$by_id = array();
foreach ($terms as $term) { $by_id[$term->term_id] = $term; }
$out = array();
foreach ($terms as $term) {
$names = array(html_entity_decode($term->name, ENT_QUOTES, 'UTF-8'));
$up = (int) $term->parent;
for ($depth = 0; $up > 0 && isset($by_id[$up]) && $depth < 20; $depth++) {
array_unshift($names, html_entity_decode($by_id[$up]->name, ENT_QUOTES, 'UTF-8'));
$up = (int) $by_id[$up]->parent;
}
$out[(string) $term->term_id] = implode(' › ', $names);
}
asort($out, SORT_NATURAL | SORT_FLAG_CASE);
return $out;
}
public function render_subtab() {
$s = $this->get_settings();
$catalog = self::element_catalog();
$device_labels = array(
'all' => __('Desktop + mobile', 'ai-eshop-optimizer'),
'desktop' => __('Desktop only', 'ai-eshop-optimizer'),
'mobile' => __('Mobile only', 'ai-eshop-optimizer'),
);
$behaviour_form = 'aieo-card-product-archive-card-card-behaviour-form';
$order_form = 'aieo-card-product-archive-card-card-elements-order-visibility-device-form';
$save = static function ($form_id) {
return class_exists('\Rooster\Admin\States') ? \Rooster\Admin\States::save_button($form_id) : '';
};
rooster_admin_band_open(array('cols' => 2));
list($open, $close) = AIEO_DMM_UI::card(array(
'anchor' => 'product-archive-card-card-behaviour',
'icon' => 'activity',
'title' => __('Card behaviour', 'ai-eshop-optimizer'),
'footer' => $save($behaviour_form),
));
echo $open;
ob_start();
echo '';
if ('' !== self::theme_shop_view()) {
echo \Rooster\Admin\Ui::field_row(array(
'id' => 'aieo-arch-shop-view',
'label' => __('Shop pages open as', 'ai-eshop-optimizer'),
'control' => \Rooster\Admin\Ui::select('shop_view', array(
'grid' => __('A grid', 'ai-eshop-optimizer'),
'list' => __('A list, with a short description', 'ai-eshop-optimizer'),
), self::theme_shop_view(), array('id' => 'aieo-arch-shop-view')),
'help' => __('The shop, category, brand and search pages. Visitors can still switch with the grid and list buttons. The theme keeps this setting: it is also under Appearance, Site style, Shop.', 'ai-eshop-optimizer'),
));
}
echo \Rooster\Admin\Ui::field_row(array(
'id' => 'aieo-arch-card-options-in',
'label' => __('Product options open in', 'ai-eshop-optimizer'),
'control' => \Rooster\Admin\Ui::select('card_options_in', array(
'list' => __('The card\'s list (a sheet on phones, a window on desktop)', 'ai-eshop-optimizer'),
'side_cart' => __('The side cart\'s Quick view', 'ai-eshop-optimizer'),
), (string) get_option('aieo_card_options_in', 'list'), array('id' => 'aieo-arch-card-options-in')),
'help' => __('For products with more options than their card shows: what a swatch, +N or the button opens. The side cart\'s Quick view needs the side cart on; without it the card\'s list opens.', 'ai-eshop-optimizer'),
));
echo \Rooster\Admin\Ui::field_row(array(
'id' => 'aieo-arch-card-under-picture',
'label' => __('Under the picture', 'ai-eshop-optimizer'),
'control' => \Rooster\Admin\Ui::select('card_under_picture', array(
'stars' => __('The stars, the swatches under the title', 'ai-eshop-optimizer'),
'swatches' => __('The swatches, the stars under the title', 'ai-eshop-optimizer'),
'name' => __('The brand and the name, then the swatches or the short description, then the stars', 'ai-eshop-optimizer'),
), in_array(get_option('aieo_card_under_picture', 'stars'), array('swatches', 'name'), true) ? (string) get_option('aieo_card_under_picture') : 'stars', array('id' => 'aieo-arch-card-under-picture')),
'help' => __('What sits right under the product picture on every card. The cards of a row keep their parts on the same lines, with or without swatches.', 'ai-eshop-optimizer'),
));
$open_terms = get_option('aieo_card_options_in_terms', array());
$open_terms = is_array($open_terms) ? $open_terms : array();
$categories = $this->category_choices();
$open_rows = array(
'list' => array('aieo-arch-card-options-in-list', __('Categories that open the card\'s list', 'ai-eshop-optimizer')),
'side_cart' => array('aieo-arch-card-options-in-side-cart', __('Categories that open the side cart\'s Quick view', 'ai-eshop-optimizer')),
);
foreach ($open_rows as $where => $row) {
echo \Rooster\Admin\Ui::field_row(array(
'id' => $row[0],
'label' => $row[1],
'control' => \Rooster\Admin\Ui::combo('card_options_in_' . $where, $categories, array_map('strval', array_keys($open_terms, $where, true)), array('id' => $row[0], 'multiple' => true, 'placeholder' => __('None: the choice above', 'ai-eshop-optimizer'))),
'help' => 'list' === $where
? __('Whatever the choice above: on these categories\' pages and their subcategories\' pages (the nearest choice wins), and on other pages (shop, search, home) for the cards of products whose categories agree. A category in neither list follows the choice above.', 'ai-eshop-optimizer')
: __('The same, for the side cart\'s Quick view.', 'ai-eshop-optimizer'),
));
}
$switches = array(
array('pin_buy_bottom', 'aieo-arch-pin', !empty($s['pin_buy_bottom']), __('Pin the stars + buy button to the bottom of each card', 'ai-eshop-optimizer'), __('The star rating and the buy button drop together to the card bottom, so they line up across a row even when titles differ in length.', 'ai-eshop-optimizer')),
array('equalize_rows', 'aieo-arch-equalize', !empty($s['equalize_rows']), __('Equalize title and price heights across each row', 'ai-eshop-optimizer'), __('For the products sitting in the same row, the titles share one height (so they end together) and the prices share one band — a single price is vertically centred where a neighbour has a was/now sale price. Keeps the whole row visually level.', 'ai-eshop-optimizer')),
);
foreach ($switches as $sw) {
$row = \Rooster\Admin\Ui::field_row(array(
'id' => $sw[1],
'label' => html_entity_decode($sw[3], ENT_QUOTES, 'UTF-8'),
'control' => \Rooster\Admin\Ui::toggle($sw[0], $sw[2], array('id' => $sw[1], 'hidden' => false, 'label' => __('On', 'ai-eshop-optimizer'), 'label_hidden' => true)),
'help' => $sw[4],
));
echo $row;
}
$row = \Rooster\Admin\Ui::field_row(array(
'id' => 'aieo-arch-qv-label',
'label' => __('Quick-View button label', 'ai-eshop-optimizer'),
'control' => \Rooster\Admin\Ui::input('quick_view_label', (string) $s['quick_view_label'], array('id' => 'aieo-arch-qv-label', 'medium' => true, 'placeholder' => __('Discover it', 'ai-eshop-optimizer'))),
'help' => __('Text on the Quick-View button (leave blank for the default). Toggle the button itself on/off in the list below.', 'ai-eshop-optimizer'),
));
echo $row;
echo '
';
ob_start();
echo '' . esc_html__('Element sizes (e.g. 70%, 60%, 220px, 13px), centred where applicable. Leave blank for the natural size. The buy-button width applies to BOTH the simple “buy” and the variable “see options” button, so they harmonise — set the Quick-View to the same value for a fully matched stack.', 'ai-eshop-optimizer') . '
';
$width_rows = array(
array('id' => 'title', 'key' => 'title_width', 'label' => __('Product title (max-width)', 'ai-eshop-optimizer'), 'd' => $s['title_width'], 'm' => $s['title_width_m'], 'ph_d' => '70%', 'ph_m' => '70%'),
array('id' => 'buy', 'key' => 'buy_width', 'label' => __('Buy button (width)', 'ai-eshop-optimizer'), 'd' => $s['buy_width'], 'm' => $s['buy_width_m'], 'ph_d' => '70%', 'ph_m' => '70%'),
array('id' => 'qv', 'key' => 'qv_width', 'label' => __('Quick-View button (width)', 'ai-eshop-optimizer'), 'd' => $s['qv_width'], 'm' => $s['qv_width_m'], 'ph_d' => '70%', 'ph_m' => ''),
array('id' => 'varfont', 'key' => 'var_font', 'label' => __('Variation buttons (font size)', 'ai-eshop-optimizer'),'d' => $s['var_font'], 'm' => $s['var_font_m'], 'ph_d' => '13px', 'ph_m' => '13px'),
);
echo '';
foreach ($width_rows as $wr) {
$parts = array();
foreach (array('d' => array(__('Desktop', 'ai-eshop-optimizer'), $wr['key'], $wr['d'], $wr['ph_d']), 'm' => array(__('Mobile', 'ai-eshop-optimizer'), $wr['key'] . '_m', $wr['m'], $wr['ph_m'])) as $dev => $p) {
$pid = 'aieo-arch-w-' . $wr['id'] . '-' . $dev;
$parts[] = array(
'label' => $p[0],
'id' => $pid,
'control' => \Rooster\Admin\Ui::input($p[1], (string) $p[2], array('id' => $pid, 'xs' => true, 'placeholder' => $p[3])),
);
}
$row = \Rooster\Admin\Ui::field_row(array('id' => 'aieo-arch-w-' . $wr['id'], 'label' => $wr['label'], 'parts' => $parts));
echo $row;
}
echo '
';
echo AIEO_Kit::fold(__('Sizes', 'ai-eshop-optimizer'), (string) ob_get_clean(), array('id' => 'aieo-section-product-archive-card-sizes'));
echo AIEO_DMM_UI::card_form('aieo_dmm_archive_card_save', $this->get_id(), $behaviour_form, (string) ob_get_clean());
echo $close;
list($open, $close) = AIEO_DMM_UI::card(array(
'anchor' => 'product-archive-card-card-elements-order-visibility-device',
'icon' => 'grip-vertical',
'title' => __('Card element order and visibility', 'ai-eshop-optimizer'),
'description' => __('Drag the rows to reorder. Top of the list = top of the card.', 'ai-eshop-optimizer'),
'footer' => $save($order_form),
));
echo $open;
$rows = array();
foreach ($s['order'] as $id) {
if (!isset($catalog[$id])) { continue; }
$dev = isset($s['device'][$id]) ? $s['device'][$id] : 'all';
$devices_for = sprintf(__('Devices for %s', 'ai-eshop-optimizer'), $catalog[$id]['label']);
$rows[] = array(
'key' => $id,
'label' => $catalog[$id]['label'],
'show' => !empty($s['visible'][$id]),
'show_name' => 'visible[' . $id . ']',
'control' => \Rooster\Admin\Ui::select('device[' . $id . ']', $device_labels, (string) $dev, array('id' => 'aieo-arch-device-' . $id, 'aria-label' => $devices_for)),
);
}
$order_list = \Rooster\Admin\Fields::ordered_list($rows, array(
'id' => 'aieo-arch-order-list',
'label' => __('Card element order and visibility', 'ai-eshop-optimizer'),
'name' => 'order',
'default' => self::default_order(),
));
$order_sig = ' ';
ob_start();
echo $order_list;
echo $order_sig;
echo AIEO_DMM_UI::card_form('aieo_dmm_archive_card_save', $this->get_id(), $order_form, (string) ob_get_clean());
echo $close;
rooster_admin_band_close();
?>