diff --git a/backend/app/plugins/wiaas/assets/css/package.css b/backend/app/plugins/wiaas/assets/css/package.css index 08fe4cc..3cb3f82 100644 --- a/backend/app/plugins/wiaas/assets/css/package.css +++ b/backend/app/plugins/wiaas/assets/css/package.css @@ -128,4 +128,9 @@ #your-profile label[for="role"], #your-profile label[for="url"],#your-profile #role, #your-profile #url{ display: none; +} + +#adminmenu #toplevel_page_wiaas-cl-packages div.wp-menu-image::before { + font-family: WooCommerce!important; + content: '\e006'; } \ No newline at end of file diff --git a/backend/app/plugins/wiaas/assets/css/wiaas-admin-cl.css b/backend/app/plugins/wiaas/assets/css/wiaas-admin-cl.css new file mode 100644 index 0000000..50e9ff3 --- /dev/null +++ b/backend/app/plugins/wiaas/assets/css/wiaas-admin-cl.css @@ -0,0 +1,7 @@ +#posts-filter .tablenav .actions { + display: none; +} + +#menu-posts-product .wp-submenu li:last-child { + display: none; +} \ No newline at end of file diff --git a/backend/app/plugins/wiaas/assets/js/wiaas-admin-cl-packages.js b/backend/app/plugins/wiaas/assets/js/wiaas-admin-cl-packages.js new file mode 100644 index 0000000..55332cb --- /dev/null +++ b/backend/app/plugins/wiaas/assets/js/wiaas-admin-cl-packages.js @@ -0,0 +1,71 @@ +jQuery(document).ready(function ($) { + + $('#tabs').each(function() { + var disabled = $( this ).data('disabled') || ''; + + $( this ).tabs({ + disabled: [ disabled ] + }); + }); + + $('#wiaas_add_cl_customer_extras').click(function(e) { + e.preventDefault(); + + var customer_id = $('#wiaas_cl_customers').val(); + + if (!customer_id || customer_id === '0') { + return; + } + + $.post(window.ajaxurl, { + action: 'wiaas_create_cl_customer_extras', + _ajax_nonce: $('#wiaas_create_cl_customer_extras_nonce').val(), + customer_id: customer_id, + package_id: $('#wiaas_cl_package_id').val() + }).done( function (result) { + $('#tabs-2').append(result); + + $('#wiaas_cl_customer_' + customer_id).prop( 'disabled', true ); + }); + + $('#wiaas_cl_customers').val('0'); + }); + + $('#wiaas_package_extras').delegate('.wiaas_remove_cl_extras', 'click', function(e) { + e.preventDefault(); + + var customer_id = $( this ).data('customer_id'); + + $('#extras_customer_' + customer_id).remove(); + + $('#wiaas_cl_customer_' + customer_id).prop( 'disabled', false ); + + $('#wiaas_cl_customers').val('0'); + }); + + $('#wiaas_package_extras').delegate('.wiaas-cl-extra-input', 'change', function(e) { + e.preventDefault(); + + var val = parseFloat($( this ).val()); + var target = '#' + $( this).data('target'); + + if (isNaN(val)) { + + $(target).val('Invalid!'); + + return; + } + + var type = $( this).data('type'); + + if (type === 'fixed') { + $(target).text( $(target).data('base') + val); + } + + if (type === 'recurrent' || type === 'services') { + $(target).data(type, val); + + $(target).text( $(target).data('base') + $(target).data('recurrent') + $(target).data('services')); + } + }); +}); \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/admin/admin-cl/class-wiaas-admin-cl-packages.php b/backend/app/plugins/wiaas/includes/admin/admin-cl/class-wiaas-admin-cl-packages.php new file mode 100644 index 0000000..9176ce2 --- /dev/null +++ b/backend/app/plugins/wiaas/includes/admin/admin-cl/class-wiaas-admin-cl-packages.php @@ -0,0 +1,260 @@ +id === 'admin_page_wiaas-cl-product') { + + error_log('set parent'); + + $parent_file = 'edit.php?post_type=product'; + } + } + + public static function output_package() { + wp_enqueue_script( 'jquery-ui-tabs' ); + + $package_id = absint( $_GET['cl_package_id'] ); + + $package = wc_get_product($package_id); + + if (!$package) { + return; + } + + if (! empty($_POST['wiaas_save_cl_extras_nonce']) && ! empty($_POST['cl_extras'])) { + if (wp_verify_nonce($_POST['wiaas_save_cl_extras_nonce'], 'wiaas_save_cl_extras')) { + self::_handle_cl_extras_update($package_id); + } + } + + $bundled_items = $package->get_bundled_items(); + + $bundled_items_per_category = array(); + foreach ($bundled_items as $bundled_item) { + $category = Wiaas_Product_Category::get_category($bundled_item->product); + if (isset($category)) { + if ($category ==='hardware' || $category === 'software') { + $category = 'products'; + } + $bundled_items_per_category[$category] ?: array(); + $bundled_items_per_category[$category][] = $bundled_item; + } + } + + $configured_prices = Wiaas_Package_Pricing::get_package_prices($package); + + $cl_id = wiaas_get_current_user_organization_id(); + + $cl_extras = Wiaas_Package_CL_Pricing::get_extras($cl_id, $package_id); + + $has_default_cl_extras = ! empty($cl_extras); + + // default values for catalogue package + if (! $has_default_cl_extras) { + $cl_extras = array(); + + foreach ($configured_prices as $type => $configured_price) { + $cl_extras[$type.'_default'] = array( + 'visible' => true, + 'fixed' => 0, + 'services' => 0, + 'recurrent' => 0 + ); + } + } + + $package_cl_extra_types = array_keys($cl_extras); + + $customer_ids_with_extras = array(); + foreach ($package_cl_extra_types as $package_cl_extra_type) { + $customer_id_with_extras = explode('_customer_', $package_cl_extra_type)[1]; + + if (isset($customer_id_with_extras) && ($customer_id_with_extras = absint($customer_id_with_extras)) > 0) { + $customer_ids_with_extras[] = $customer_id_with_extras; + } + } + $customer_ids_with_extras = array_unique($customer_ids_with_extras); + + require 'views/html-cl-package-details.php'; + } + + + /** + * @section Customize display of list table products for commercial lead + */ + + /** + * Define columns for commercial lead view + * @param array $columns + * + * @return array + */ + public static function define_list_table_products_columns($columns) { + $cl_columns = array(); + + $cl_columns['thumb'] = $columns['thumb']; + $cl_columns['wiaas_cl_name'] = $columns['name']; + $cl_columns['taxonomy-package_type'] = __('Type', 'wiaas'); + $cl_columns['taxonomy-package_status'] = __('Status', 'wiaas'); + $cl_columns['taxonomy-product_country'] = $columns['taxonomy-product_country']; + $cl_columns['date'] = $columns['date']; + + return $cl_columns; + } + + /** + * Hide list table products bulk actions for commercial lead view + * + * @return array + */ + public static function define_list_table_products_bulk_actions() { + return array(); + } + + /** + * Hide list table products views for commercial lead view + * + * @return array + */ + public static function define_list_table_products_views() { + return array(); + } + + /** + * Show only ID in table products views for commercial lead view + * + * @return array + */ + public static function define_list_table_products_row_actions($actions, $post) { + if ($post->post_type === 'product') { + return array( 'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $post->ID ) ); + } + + return $actions; + } + + /** + * Define custom primary column in list table products for commercial lead view + * + * @param $default + * @param $screen_id + * + * @return string + */ + public static function define_list_table_products_primary_column($default, $screen_id) { + if ( 'edit-product' === $screen_id ) { + return 'wiaas_cl_name'; + } + return $default; + } + + public static function render_list_table_products_columns($column, $post_id) { + if ($column === 'wiaas_cl_name') { + + $package = wc_get_product($post_id); + + $edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-cl-package&cl_package_id=' . absint( $package->get_id() ) ); + + echo '' . esc_html( $package->get_title() ) . ''; + } + } + + + + + // PRIVATE HANDLERS + + private static function _handle_cl_extras_update($package_id) { + $cl_extras = wp_unslash($_POST['cl_extras']); + + $pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types()); + + $posted_cl_extras = array(); + + foreach ($cl_extras as $cl_extra) { + + $customer_id = isset($cl_extra['customer']) ? absint($cl_extra['customer']) : 0; + $type = sanitize_key($cl_extra['type']); + + $fixed_extra = isset($cl_extra['fixed']) ? floatval($cl_extra['fixed']) : 0; + $services_extra = isset($cl_extra['services']) ? floatval($cl_extra['services']) : 0; + $recurrent_extra = isset($cl_extra['recurrent']) ? floatval($cl_extra['recurrent']) : 0; + + $extra_type = $customer_id > 0 ? $type.'_customer_'.$customer_id : $type.'_default'; + + if (in_array($type, $pay_types)) { + $posted_cl_extras[$extra_type] = array( + 'type' => $type, + 'visible' => $cl_extra['visible'] === 'on', + 'fixed' => $fixed_extra, + 'services' => $services_extra, + 'recurrent' => $recurrent_extra, + ); + } + } + + Wiaas_Package_CL_Pricing::set_extras( + wiaas_get_current_user_organization_id(), + $package_id, + $posted_cl_extras + ); + } +} + +Wiaas_Admin_CL_Packages::init(); diff --git a/backend/app/plugins/wiaas/includes/admin/admin-cl/views/html-cl-package-details.php b/backend/app/plugins/wiaas/includes/admin/admin-cl/views/html-cl-package-details.php new file mode 100644 index 0000000..d2b95b5 --- /dev/null +++ b/backend/app/plugins/wiaas/includes/admin/admin-cl/views/html-cl-package-details.php @@ -0,0 +1,237 @@ + + + + + + +
| + '. esc_html(wiaas_get_organization_name($customer_id)). ''; + } + ?> + | ++ | + | + | + + + + | +
| + + | +
+
+
+
+
+
+
+
+ 0) {
+ echo sprintf( '(%s for services)', esc_attr( $configured_price['minimal_services_price'] ) );
+ }
+ ?>
+
+
+ |
+
+
+
+
+
+ 0) {
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+ =
+
+
+
+
+ =
+
+
+
+ |
+ + + type="checkbox" + > + | +