' . esc_html__('Save', 'ai-eshop-optimizer') . ' ' . \Rooster\Admin\Ui::button(__('Cancel edit', 'ai-eshop-optimizer'), array('class' => 'aieo-dmm-complementary-cancel-btn', 'attrs' => array('hidden' => true))) . ' ' . \Rooster\Admin\States::outcome('', '', array('id' => 'aieo-cx-outcome')); list($aieo_cx_open, $aieo_cx_close) = AIEO_DMM_UI::card(array( 'anchor' => 'complementary-products', 'title' => __('New complementary set', 'ai-eshop-optimizer'), 'description' => __('For each source product, choose the products shown beside it on its page, with one button that adds them to the cart. Switch "Bought together" on to give the set a better price or a gift when all of it is bought.', 'ai-eshop-optimizer'), 'footer' => $aieo_cx_footer, )); echo $aieo_cx_open; ?> $aieo_cx_id( $name ), 'label' => $label, 'control' => $control ); if ( '' !== $help ) { $field['help'] = $help; } if ( $attrs ) { $field['attrs'] = $attrs; } return \Rooster\Admin\Ui::field_row( $field ); }; $aieo_cx_search = static function ( $name, $multiple = false ) use ( $aieo_cx_id ) { return ''; }; $aieo_cx_master = $aieo_cx_id( 'together' ); $aieo_cx_results = array( 'set_price', 'percent', 'amount', 'gift' ); $aieo_cx_when = static function ( array $for ) use ( $aieo_cx_master ) { return \Rooster\Admin\States::depends_attrs( $aieo_cx_master, false, array( 'value' => $for ) ); }; $aieo_cx_count = static function ( $i ) use ( $aieo_cx_id, $aieo_cx_when, $aieo_cx_results ) { $parts = array(); foreach ( array( 'min' => __( 'How many', 'ai-eshop-optimizer' ), 'max' => __( 'up to', 'ai-eshop-optimizer' ) ) as $end => $label ) { $name = 'members[' . $i . '][' . $end . ']'; $parts[] = array( 'label' => $label, 'id' => $aieo_cx_id( $name ), 'control' => \Rooster\Admin\Ui::input( $name, 'min' === $end ? '1' : '', array( 'id' => $aieo_cx_id( $name ), 'type' => 'number', 'min' => '1', 'max' => (string) AIEO_DMM_Complementary_Sets::MAX_UNITS, 'step' => '1', 'xs' => true ) ), 'attrs' => $aieo_cx_when( 'min' === $end ? $aieo_cx_results : array( 'percent', 'amount', 'gift' ) ), ); } return $parts; }; $aieo_cx_price = static function ( $i ) { return ''; }; $aieo_cx_currency = function_exists( 'get_woocommerce_currency_symbol' ) ? html_entity_decode( get_woocommerce_currency_symbol(), ENT_QUOTES, 'UTF-8' ) : ''; $aieo_cx_shown = 3; $aieo_cx_head = $aieo_cx_row( 'label', __( 'Label (internal)', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::input( 'label', '', array( 'id' => $aieo_cx_id( 'label' ), 'medium' => true ) ) ); $aieo_cx_head .= $aieo_cx_row( 'enabled', __( 'Enabled', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::toggle( 'enabled', true, array( 'id' => $aieo_cx_id( 'enabled' ), 'hidden' => false, 'label' => __( 'On', 'ai-eshop-optimizer' ), 'label_hidden' => true ) ), __( 'One switch: it shows the set on the product\'s page and, with "Bought together", gives its price.', 'ai-eshop-optimizer' ) ); $aieo_cx_head .= $aieo_cx_row( 'source_product_id', __( 'Source product', 'ai-eshop-optimizer' ), $aieo_cx_search( 'source_product_id' ), __( 'The product whose page shows the set. It is the set\'s first product.', 'ai-eshop-optimizer' ) ); $aieo_cx_members = \Rooster\Admin\Ui::field_row( array( 'id' => $aieo_cx_id( 'members[0][min]' ), 'label' => __( 'This product', 'ai-eshop-optimizer' ), 'parts' => $aieo_cx_count( 0 ), 'help_html' => $aieo_cx_price( 0 ), 'attrs' => $aieo_cx_when( $aieo_cx_results ), ) ); for ( $aieo_cx_i = 1; $aieo_cx_i < AIEO_DMM_Complementary_Sets::MAX_MEMBERS; $aieo_cx_i++ ) { $aieo_cx_name = 'members[' . $aieo_cx_i . '][p]'; $aieo_cx_members .= \Rooster\Admin\Ui::field_row( array( 'id' => $aieo_cx_id( $aieo_cx_name ), 'label' => sprintf( __( 'Product %d', 'ai-eshop-optimizer' ), $aieo_cx_i + 1 ), 'parts' => array_merge( array( array( 'label' => __( 'Product', 'ai-eshop-optimizer' ), 'id' => $aieo_cx_id( $aieo_cx_name ), 'control' => $aieo_cx_search( $aieo_cx_name ) ) ), $aieo_cx_count( $aieo_cx_i ) ), 'help_html' => $aieo_cx_price( $aieo_cx_i ), 'attrs' => array( 'data-aieo-cx-member' => (string) $aieo_cx_i ) + ( $aieo_cx_i > $aieo_cx_shown ? array( 'hidden' => true ) : array() ), ) ); } $aieo_cx_members .= $aieo_cx_row( 'add', __( 'More products', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::button( __( 'Add a product', 'ai-eshop-optimizer' ), array( 'class' => 'aieo-dmm-complementary-add-btn', 'attrs' => array( 'id' => $aieo_cx_id( 'add' ) ) ) ), sprintf( __( 'A set holds up to %d products, the source product included.', 'ai-eshop-optimizer' ), AIEO_DMM_Complementary_Sets::MAX_MEMBERS ) ); $aieo_cx_fields = $aieo_cx_row( 'together', __( 'Bought together', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::select( 'together', array( '' => __( 'Off: a list of products to add', 'ai-eshop-optimizer' ), 'set_price' => __( 'A set price', 'ai-eshop-optimizer' ), 'percent' => __( 'A percentage off', 'ai-eshop-optimizer' ), 'amount' => __( 'An amount off', 'ai-eshop-optimizer' ), 'gift' => __( 'A gift', 'ai-eshop-optimizer' ), ), '', array( 'id' => $aieo_cx_master ) ), __( 'What the customer gets for buying the whole set: each product in the number you set, in any mix of its variations.', 'ai-eshop-optimizer' ) ); $aieo_cx_fields .= $aieo_cx_row( 'set_price', __( 'The set\'s price', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::input( 'set_price', '', array( 'id' => $aieo_cx_id( 'set_price' ), 'short' => true, 'inputmode' => 'decimal', 'unit' => $aieo_cx_currency ) ), __( 'What one complete set costs. Every product is bought in exactly its number.', 'ai-eshop-optimizer' ), $aieo_cx_when( array( 'set_price' ) ) ); $aieo_cx_fields .= $aieo_cx_row( 'percent', __( 'Percentage off', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::input( 'percent', '', array( 'id' => $aieo_cx_id( 'percent' ), 'xs' => true, 'inputmode' => 'decimal', 'unit' => '%' ) ), '', $aieo_cx_when( array( 'percent' ) ) ); $aieo_cx_fields .= $aieo_cx_row( 'amount', __( 'Amount off', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::input( 'amount', '', array( 'id' => $aieo_cx_id( 'amount' ), 'short' => true, 'inputmode' => 'decimal', 'unit' => $aieo_cx_currency ) ), __( 'Taken off each set.', 'ai-eshop-optimizer' ), $aieo_cx_when( array( 'amount' ) ) ); $aieo_cx_fields .= $aieo_cx_row( 'gift_products[]', __( 'The gift', 'ai-eshop-optimizer' ), $aieo_cx_search( 'gift_products[]', true ), __( 'The product given with the set. With more than one, the first in stock is given.', 'ai-eshop-optimizer' ), $aieo_cx_when( array( 'gift' ) ) ); $aieo_cx_fields .= $aieo_cx_row( 'per', __( 'How often', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::select( 'per', array( 'set' => __( 'For each complete set', 'ai-eshop-optimizer' ), 'once' => __( 'Once per order', 'ai-eshop-optimizer' ), ), 'set', array( 'id' => $aieo_cx_id( 'per' ) ) ), '', $aieo_cx_when( $aieo_cx_results ) ); $aieo_cx_fields .= \Rooster\Admin\Ui::field_row( array( 'id' => $aieo_cx_id( 'starts' ), 'label' => __( 'When it runs', 'ai-eshop-optimizer' ), 'parts' => array( array( 'label' => __( 'First day', 'ai-eshop-optimizer' ), 'id' => $aieo_cx_id( 'starts' ), 'control' => \Rooster\Admin\Ui::input( 'starts', '', array( 'id' => $aieo_cx_id( 'starts' ), 'type' => 'date' ) ) ), array( 'label' => __( 'Last day', 'ai-eshop-optimizer' ), 'id' => $aieo_cx_id( 'ends' ), 'control' => \Rooster\Admin\Ui::input( 'ends', '', array( 'id' => $aieo_cx_id( 'ends' ), 'type' => 'date' ) ) ), ), 'help' => __( 'Leave both empty and it always runs. Its limits and its audience are the offer\'s own settings.', 'ai-eshop-optimizer' ), 'attrs' => $aieo_cx_when( $aieo_cx_results ), ) ); $aieo_cx_fields .= \Rooster\Admin\Ui::field_row( array( 'label' => __( 'The sums', 'ai-eshop-optimizer' ), 'group' => true, 'control' => \Rooster\Admin\States::outcome( '', '', array( 'id' => 'aieo-cx-sums' ) ) . \Rooster\Admin\States::outcome( '', '', array( 'id' => 'aieo-cx-review' ) ) . \Rooster\Admin\Ui::button( __( 'More settings in the offer', 'ai-eshop-optimizer' ), array( 'href' => '#', 'size' => 'sm', 'class' => 'aieo-dmm-complementary-settings', 'attrs' => array( 'hidden' => true ) ) ), 'attrs' => $aieo_cx_when( $aieo_cx_results ), ) ); $aieo_cx_look = $aieo_cx_row( 'offer_title', __( 'Picker title (shown above the list)', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::input( 'offer_title', '', array( 'id' => $aieo_cx_id( 'offer_title' ), 'medium' => true, 'placeholder' => $module->default_offer_title() ) ) ); $aieo_cx_look .= $aieo_cx_row( 'button_text', __( 'Button text', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::input( 'button_text', '', array( 'id' => $aieo_cx_id( 'button_text' ), 'medium' => true, 'placeholder' => $module->default_button_text() ) ) ); $aieo_cx_look .= $aieo_cx_row( 'placement', __( 'Placement', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::select( 'placement', array( 'before_add_to_cart' => __( 'Before Add to cart button', 'ai-eshop-optimizer' ), 'after_add_to_cart' => __( 'After Add to cart button', 'ai-eshop-optimizer' ), 'after_summary' => __( 'After product summary', 'ai-eshop-optimizer' ), ), 'before_add_to_cart', array( 'id' => $aieo_cx_id( 'placement' ) ) ), __( 'NB — this affects future installs of the picker globally; today the renderer only honours the global default.', 'ai-eshop-optimizer' ) ); $aieo_cx_look .= $aieo_cx_row( 'checkboxes_state', __( 'Default checkbox state', 'ai-eshop-optimizer' ), \Rooster\Admin\Ui::select( 'checkboxes_state', array( 'unchecked' => __( 'Unchecked', 'ai-eshop-optimizer' ), 'checked' => __( 'Pre-checked', 'ai-eshop-optimizer' ), ), 'unchecked', array( 'id' => $aieo_cx_id( 'checkboxes_state' ) ) ) ); echo \Rooster\Admin\Ui::notice( '' . esc_html__( 'A copy, not saved yet.', 'ai-eshop-optimizer' ) . '', 'info', array( 'inline' => true, 'id' => 'aieo-cx-copy', 'attrs' => array( 'hidden' => true ) ) ); ?>
' . $aieo_cx_head . ''; echo \Rooster\Admin\Ui::fold( __( 'The products in the set', 'ai-eshop-optimizer' ), '
' . $aieo_cx_members . '
', array( 'open' => true, 'id' => 'aieo-cx-fold-members' ) ); echo '
' . $aieo_cx_fields . '
'; echo \Rooster\Admin\Ui::fold( __( 'How the list looks', 'ai-eshop-optimizer' ), '
' . $aieo_cx_look . '
', array( 'id' => 'aieo-cx-fold-look' ) ); ?>
' . esc_html__('Export CSV', 'ai-eshop-optimizer') . ' ' . \Rooster\Admin\Ui::button(__('Import CSV', 'ai-eshop-optimizer'), array('class' => 'aieo-dmm-complementary-import-btn', 'attrs' => array('id' => 'aieo-dmm-complementary-import-btn'))) . \Rooster\Admin\Ui::file( '', array( 'id' => 'aieo-dmm-complementary-csv-file', 'accept' => '.csv,text/csv', 'hidden' => true, 'labelledby' => 'aieo-dmm-complementary-import-btn' ) ); list($aieo_cx_open, $aieo_cx_close) = AIEO_DMM_UI::card(array( 'anchor' => 'complementary-current-sets', 'icon' => 'list', 'title' => __('Current sets', 'ai-eshop-optimizer'), 'description' => __('The complementary product sets you have defined; edit a set to change which products are suggested together.', 'ai-eshop-optimizer'), 'tools' => $aieo_cx_tools, 'flush' => true, )); echo $aieo_cx_open; ?> ' . esc_html(implode(', ', array_slice(AIEO_DMM_Complementary::csv_columns(2), 0, 6)) . ', …, ' . implode(', ', AIEO_DMM_Complementary::CSV_TAIL)) . '' ) . ' ' . esc_html__('A count is one number (5) or a range (3-5); empty is 1. "together" is set_price, percent, amount, gift or empty; gift_skus are separated by |; the days are year-month-day.', 'ai-eshop-optimizer'); echo \Rooster\Admin\Guidance::text('', 'guidance', array('html' => $aieo_cx_csv_note)); echo \Rooster\Admin\States::outcome('', '', array('id' => 'aieo-cx-csv-outcome')); ?> (int) $row['id'], 'label' => (string) ($row['label'] ?? ''), 'source' => (int) $row['source_product_id'] > 0 ? ('' !== (string) $row['source_product_name'] ? (string) $row['source_product_name'] : '#' . (int) $row['source_product_id']) : '', 'src_url' => (int) $row['source_product_id'] > 0 ? (string) get_permalink((int) $row['source_product_id']) : '', 'products' => implode(', ', array_map('strval', (array) $row['product_names'])), 'together' => (int) ($row['offer_id'] ?? 0) > 0, 'enabled' => ! empty($row['enabled']), 'sold' => AIEO_DMM_Offer_Reports::sold_together_html((int) $row['id'], (int) ($row['offer_id'] ?? 0)), ); } AIEO_Table::render(array( 'page_id' => 'complementary', 'row_key' => 'id', 'rows' => $aieo_cx_rows, 'id' => 'aieo-dmm-complementary-table', 'caps' => array('search' => true), 'filters' => array( array('key' => 'source', 'label' => __('Source product', 'ai-eshop-optimizer'), 'control' => 'combo', 'any' => __('Any product', 'ai-eshop-optimizer')), array('key' => 'together', 'label' => __('Bought together', 'ai-eshop-optimizer'), 'kind' => 'boolean', 'control' => 'segmented'), array('key' => 'enabled', 'label' => __('Enabled', 'ai-eshop-optimizer'), 'kind' => 'boolean', 'control' => 'segmented'), ), 'empty' => __('No complementary sets defined yet.', 'ai-eshop-optimizer'), 'columns' => array( array('key' => 'label', 'label' => __('Label', 'ai-eshop-optimizer')), array('key' => 'source', 'label' => __('Source product', 'ai-eshop-optimizer'), 'type' => 'link', 'format' => array('href' => 'src_url', 'external' => true)), array('key' => 'products', 'label' => __('With these products', 'ai-eshop-optimizer')), array('key' => 'together', 'label' => __('Bought together', 'ai-eshop-optimizer'), 'type' => 'boolean'), array('key' => 'sold', 'label' => __('Results', 'ai-eshop-optimizer'), 'type' => 'html'), array('key' => 'enabled', 'label' => __('Enabled', 'ai-eshop-optimizer'), 'type' => 'boolean'), ), 'actions' => array( array( 'id' => 'edit', 'label' => __('Edit', 'ai-eshop-optimizer'), 'class' => 'rooster-admin-button rooster-admin-button--sm aieo-dmm-edit-complementary', 'data' => array('set' => static function ($r) { return (string) (int) $r['id']; }), ), array( 'id' => 'duplicate', 'label' => __('Duplicate', 'ai-eshop-optimizer'), 'class' => 'rooster-admin-button rooster-admin-button--sm aieo-dmm-copy-complementary', 'data' => array('copy' => static function ($r) { return (string) (int) $r['id']; }), ), array( 'id' => 'aieo_dmm_complementary_delete', 'label' => __('Delete', 'ai-eshop-optimizer'), 'class' => 'rooster-admin-button rooster-admin-button--sm aieo-dmm-delete-row', ), ), )); ?> 3, 'last' => AIEO_DMM_Complementary_Sets::MAX_MEMBERS - 1, 'i18n' => array( 'notSaved' => __( 'The set was not saved.', 'ai-eshop-optimizer' ), 'notLoaded' => __( 'The set could not be opened: reload the page.', 'ai-eshop-optimizer' ), 'exportFailed' => __( 'The sets could not be exported: try again.', 'ai-eshop-optimizer' ), 'importFailed' => __( 'The file was not imported.', 'ai-eshop-optimizer' ), 'network' => __( 'The request did not reach the shop: try again.', 'ai-eshop-optimizer' ), ), ); ?>