From 66452eee8657b7dc73a83283032bfc7ed368db34 Mon Sep 17 00:00:00 2001 From: Nedim Uka Date: Tue, 23 Oct 2018 15:48:56 +0200 Subject: [PATCH] Connected template category to product in bundle product search --- ...ss-wiaas-admin-product-additional-info.php | 19 ++++++++++++++--- .../class-wiaas-admin-template-selection.php | 21 +++++++++++++------ .../views/html-wiaas-template-selection.php | 1 + .../class-wiaas-template-category-object.php | 8 ++++++- .../class-wiaas-wc-product-template.php | 4 +++- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/backend/app/plugins/wiaas/includes/admin/simple-product/class-wiaas-admin-product-additional-info.php b/backend/app/plugins/wiaas/includes/admin/simple-product/class-wiaas-admin-product-additional-info.php index 489417e..067e2b6 100644 --- a/backend/app/plugins/wiaas/includes/admin/simple-product/class-wiaas-admin-product-additional-info.php +++ b/backend/app/plugins/wiaas/includes/admin/simple-product/class-wiaas-admin-product-additional-info.php @@ -44,6 +44,14 @@ class Wiaas_Admin_Product_Additional_Info { } } + /** + * This method filters search results by template country + * In addition it adds template category to label of every product + * + * @param $search_results array provided by filter + * @return mixed array of filtered search results + */ + public static function filter_product_by_country($search_results) { $url = wp_get_referer(); @@ -59,9 +67,14 @@ class Wiaas_Admin_Product_Additional_Info { if (!empty($search_results)) { $search_result_objects = array_map('wc_get_product', array_keys($search_results)); - foreach ($search_result_objects as $result_id => $producta) { - if (Wiaas_Countries::get_product_country_term_id($producta) !== $country_id) { - unset($search_results[$producta->get_id()]); + foreach ($search_result_objects as $result_id => $product_form_search) { + if (Wiaas_Countries::get_product_country_term_id($product_form_search) !== $country_id) { + unset($search_results[$product_form_search->get_id()]); + } else { + $template_category = wp_get_object_terms($product_form_search->get_id(), 'template_category', array('fields' => 'names')); + if(!empty($template_category)){ + $search_results[$product_form_search->get_id()] = $search_results[$product_form_search->get_id()].'-'.$template_category[0]; + } } } } diff --git a/backend/app/plugins/wiaas/includes/admin/template/class-wiaas-admin-template-selection.php b/backend/app/plugins/wiaas/includes/admin/template/class-wiaas-admin-template-selection.php index 2fca714..3135d2d 100644 --- a/backend/app/plugins/wiaas/includes/admin/template/class-wiaas-admin-template-selection.php +++ b/backend/app/plugins/wiaas/includes/admin/template/class-wiaas-admin-template-selection.php @@ -56,10 +56,14 @@ class Wiaas_Admin_Template_Selection {
ID ); + $bundled_items = $product->get_bundled_items('view'); + $categories_form_bundle = WC_Product_Template::extract_bundled_product_categories($bundled_items); + + self::render_template_products($template_products_data['hardware'], $categories_form_bundle); + self::render_template_products($template_products_data['services'], $categories_form_bundle); + self::render_template_products($template_products_data['installation'], $categories_form_bundle); + self::render_template_products($template_products_data['software'], $categories_form_bundle); ?>
product_name : ''; + $product_id = $item['template_category_id']; $title = $item['template_category_title']; $quantity = $item['quantity']; - + $connected_product_name = $connected_product; include('views/html-wiaas-template-selection.php'); } diff --git a/backend/app/plugins/wiaas/includes/admin/template/views/html-wiaas-template-selection.php b/backend/app/plugins/wiaas/includes/admin/template/views/html-wiaas-template-selection.php index 4c19b4e..7059d58 100644 --- a/backend/app/plugins/wiaas/includes/admin/template/views/html-wiaas-template-selection.php +++ b/backend/app/plugins/wiaas/includes/admin/template/views/html-wiaas-template-selection.php @@ -9,5 +9,6 @@ if (!defined('ABSPATH')) {

[] + []

template_category_id = $id; $this->name = $title; $this->quantity = $quant; + $this->product_id = $product_id; + $this->product_name = $product_name; } public function get_quantity(){ diff --git a/backend/app/plugins/wiaas/includes/templates/class-wiaas-wc-product-template.php b/backend/app/plugins/wiaas/includes/templates/class-wiaas-wc-product-template.php index e9b4198..e9f6484 100644 --- a/backend/app/plugins/wiaas/includes/templates/class-wiaas-wc-product-template.php +++ b/backend/app/plugins/wiaas/includes/templates/class-wiaas-wc-product-template.php @@ -92,7 +92,9 @@ function construct_template_products_class() { $template_category_object = new Wiaas_Template_Category_Object( $category_template_id, $cat, - $item_data['quantity_max']); + $item_data['quantity_max'], + $item->get_id(), + $item->get_title()); $template_category_objects[$category_template_id] = $template_category_object; }