';
};
if ($aieo_lc_bands) {
rooster_admin_band_open(array('cols' => 2));
}
list($aieo_lc_open, $aieo_lc_close) = AIEO_DMM_UI::card(array(
'anchor' => 'loyalty-classes-global-stacking-recipe',
'icon' => 'layers',
'title' => __('Global stacking recipe', 'ai-eshop-optimizer'),
'description' => __('Every discount a customer can receive, and the single rule that decides how they combine. A shopper can qualify for a role price, a brand discount, a loyalty class and a gift at the same time — this screen is where you decide whether those stack, override one another, or stop at the best one, so the price on the shelf is never an accident.', 'ai-eshop-optimizer'),
'span' => 'all',
'footer' => $aieo_lc_save('loyalty-classes-global-stacking-recipe'),
));
echo $aieo_lc_open;
echo $aieo_lc_why(__('Decide how role price, brand discount, loyalty class and brand gift combine across the whole shop.', 'ai-eshop-optimizer'));
$aieo_lc_recipe_select = static function ($key, $id, $label, array $options, $class = '') use ($recipe) {
$value = isset($options[(string) $recipe[$key]]) ? (string) $recipe[$key] : (string) key($options);
return AIEO_Kit::row($label, AIEO_Kit::select('recipe[' . $key . ']', $options, $value, array('id' => $id)), '', array('id' => $id, 'class' => $class));
};
$aieo_lc_recipe_applies = static function ($key, $id, $label) use ($recipe) {
return AIEO_Kit::row($label, AIEO_Kit::select('recipe_applies[' . $key . ']', array(
'on' => __('Applied', 'ai-eshop-optimizer'),
'off' => __('Off', 'ai-eshop-optimizer'),
), 'off' === (string) $recipe[$key] ? 'off' : 'on', array('id' => $id)), '', array('id' => $id));
};
$aieo_lc_fields = AIEO_Kit::row(
__('When several discounts apply', 'ai-eshop-optimizer'),
AIEO_Kit::select('discounts_combine', array(
'best' => __('The best one applies', 'ai-eshop-optimizer'),
'cascade' => __('They are applied one after the other', 'ai-eshop-optimizer'),
), AIEO_DMM_Settings::discounts_combine($settings), array('id' => 'aieo-lc-discounts-combine')),
__('The shop\'s default. With the best one, a customer pays the lowest of the sale price, their role price, the largest discount and their class\'s price, and no discount is taken off a price that is already reduced. Each offer can have its own choice in the offers store.', 'ai-eshop-optimizer'),
array('id' => 'aieo-lc-discounts-combine')
);
$aieo_lc_fields .= $aieo_lc_recipe_select('role_pricing', 'aieo-lc-recipe-role-pricing', __('Role pricing', 'ai-eshop-optimizer'), array(
'active' => __('Active (role prices apply)', 'ai-eshop-optimizer'),
'off' => __('Off', 'ai-eshop-optimizer'),
));
$aieo_lc_fields .= $aieo_lc_recipe_applies('brand_discount', 'aieo-lc-recipe-brand-discount-applies', __('Brand discount', 'ai-eshop-optimizer'));
$aieo_lc_fields .= $aieo_lc_recipe_select('brand_discount', 'aieo-lc-recipe-brand-discount', __('How a brand discount stacks', 'ai-eshop-optimizer'), array(
'stack_multiplicative' => __('Stack × (on role-adjusted)', 'ai-eshop-optimizer'),
'stack_additive' => __('Stack additively', 'ai-eshop-optimizer'),
'replace_role' => __('Replace role price', 'ai-eshop-optimizer'),
), 'aieo-lc-when-cascade');
$aieo_lc_fields .= $aieo_lc_recipe_applies('loyalty_class', 'aieo-lc-recipe-loyalty-class-applies', __('Loyalty class', 'ai-eshop-optimizer'));
$aieo_lc_fields .= $aieo_lc_recipe_select('loyalty_class', 'aieo-lc-recipe-loyalty-class', __('How a class\'s percentage stacks', 'ai-eshop-optimizer'), array(
'stack_multiplicative' => __('Stack × (on role+brand)', 'ai-eshop-optimizer'),
'stack_additive' => __('Stack additively', 'ai-eshop-optimizer'),
'replace_all' => __('Replace all other discounts', 'ai-eshop-optimizer'),
), 'aieo-lc-when-cascade');
$aieo_lc_fields .= $aieo_lc_recipe_select('brand_gift', 'aieo-lc-recipe-brand-gift', __('Brand gift', 'ai-eshop-optimizer'), array(
'over_and_above' => __('Over and above (in addition to %)', 'ai-eshop-optimizer'),
'off' => __('Off', 'ai-eshop-optimizer'),
));
$aieo_lc_fields .= $aieo_lc_recipe_select('no_free_shipping_gate', 'aieo-lc-recipe-nfs-gate', __('No-free-shipping gate', 'ai-eshop-optimizer'), array(
'hard' => __('Hard (remove free shipping when any excluded item in cart)', 'ai-eshop-optimizer'),
'soft' => __('Soft (keep rates; UI can warn)', 'ai-eshop-optimizer'),
'off' => __('Off (no gate)', 'ai-eshop-optimizer'),
));
ob_start();
echo '
' . $aieo_lc_fields . '
';
echo $aieo_lc_form('loyalty-classes-global-stacking-recipe');
echo $aieo_lc_close;
do_action('aieo_dmm_offers_settings_cards');
list($aieo_lc_open, $aieo_lc_close) = AIEO_DMM_UI::card(array(
'anchor' => 'loyalty-classes-product-bundle-delivery',
'col' => 1,
'icon' => 'package',
'title' => __('Product-bundle delivery (performance)', 'ai-eshop-optimizer'),
'description' => __('Controls how the single-product page fetches upsells, cross-sells, need-based and related products. Both modes use the same cache table keyed by (product_id, role_hash, locale, mode) — flipping the switch does NOT require a cache flush. Prices are always pre-computed and baked into the cached HTML.', 'ai-eshop-optimizer'),
'footer' => $aieo_lc_save('loyalty-classes-product-bundle-delivery'),
));
echo $aieo_lc_open;
$bundle_mode = isset($settings['bundle_mode']) ? $settings['bundle_mode'] : 'full';
ob_start();
echo '
' . AIEO_Kit::row(
__('Bundle mode', 'ai-eshop-optimizer'),
AIEO_Kit::checks('bundle_mode', array(
'full' => __('Full', 'ai-eshop-optimizer'),
'rec_only' => __('Rec-only', 'ai-eshop-optimizer'),
), array((string) $bundle_mode), array(
'type' => 'radio',
'descriptions' => array(
'full' => __('one AJAX returns all 4 recommendation blocks PLUS variation data (feeds om-product-swatches). Fewest HTTP requests.', 'ai-eshop-optimizer'),
'rec_only' => __('one AJAX returns only the 4 recommendation blocks; om-product-swatches still fires its own variation AJAX. Cleaner separation.', 'ai-eshop-optimizer'),
),
)),
__('Recently-viewed is always handled separately with a localStorage-first strategy (zero AJAX when fresh).', 'ai-eshop-optimizer'),
array('id' => 'aieo-lc-bundle-mode', 'group' => true)
) . '
';
echo $aieo_lc_form('loyalty-classes-product-bundle-delivery');
echo $aieo_lc_close;
list($aieo_lc_open, $aieo_lc_close) = AIEO_DMM_UI::card(array(
'anchor' => 'loyalty-classes-pricing-engine',
'col' => 2,
'icon' => 'gauge',
'title' => __('Pricing engine (performance)', 'ai-eshop-optimizer'),
'description' => __('Controls how the DMM engine resolves brand/category/schedule/loyalty/NFS facts on every price request. Both modes produce identical prices — only the lookup strategy differs. Default is "Reactive" for a safe rollout. Flip to "Precomputed" on a server where you want to measure the hot-path savings. The switch takes effect on the next page load; FP rows are built lazily on first request.', 'ai-eshop-optimizer'),
'footer' => $aieo_lc_save('loyalty-classes-pricing-engine'),
));
echo $aieo_lc_open;
$pricing_mode = isset($settings['pricing_mode']) ? $settings['pricing_mode'] : 'reactive';
ob_start();
echo '
' . AIEO_Kit::row(
__('Pricing mode', 'ai-eshop-optimizer'),
AIEO_Kit::checks('pricing_mode', array(
'reactive' => __('Reactive', 'ai-eshop-optimizer'),
'precomputed' => __('Precomputed', 'ai-eshop-optimizer'),
), array((string) $pricing_mode), array(
'type' => 'radio',
'descriptions' => array(
'reactive' => __('walk active brand/category/schedule rules per request (cached via object cache). Same behaviour as Pass 1.', 'ai-eshop-optimizer'),
'precomputed' => __('read pre-stamped wp_aieo_dmm_product_fp / wp_aieo_dmm_user_fp rows. No taxonomy joins, no rule walks, no loyalty joins on the hot path. Required for future personalised / sequence-based discounts.', 'ai-eshop-optimizer'),
),
)),
__('Admin rule changes bump a single integer and never scan these tables; stale FP rows are recomputed one-at-a-time by the next reader.', 'ai-eshop-optimizer'),
array('id' => 'aieo-lc-pricing-mode', 'group' => true)
) . '
__('What comes back to the ERP?', 'ai-eshop-optimizer'), 'html' => sprintf(esc_html($aieo_lc_emit), 'aieo_dmm_loyalty_points_added')));
} else {
echo '