Merge branch 'template-category-in-simple-product-search' into 'master'
Connected template category to product in bundle product search See merge request saburly/wiaas/new-wiaas!43
This commit was merged in pull request #43.
This commit is contained in:
@@ -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].']';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,10 +56,14 @@ class Wiaas_Admin_Template_Selection {
|
||||
<div id="wiaas_selected_template_items_container"><?php
|
||||
$template_products_data = self::show_template_products($value);
|
||||
|
||||
self::render_template_products($template_products_data['hardware']);
|
||||
self::render_template_products($template_products_data['services']);
|
||||
self::render_template_products($template_products_data['installation']);
|
||||
self::render_template_products($template_products_data['software']);
|
||||
$product = wc_get_product( $post->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);
|
||||
?></div><?php
|
||||
|
||||
}
|
||||
@@ -132,17 +136,22 @@ class Wiaas_Admin_Template_Selection {
|
||||
* Render html of template categories
|
||||
*
|
||||
* @param $template_products array containing template category information
|
||||
* @param $categories_form_bundle
|
||||
*/
|
||||
public static function render_template_products($template_products) {
|
||||
public static function render_template_products($template_products, $categories_form_bundle = array()) {
|
||||
|
||||
if (!empty($template_products)) {
|
||||
|
||||
|
||||
foreach ($template_products as $item) {
|
||||
|
||||
$connected_product = $categories_form_bundle[$item['template_category_id']] ?
|
||||
$categories_form_bundle[$item['template_category_id']]->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');
|
||||
|
||||
}
|
||||
|
||||
@@ -83,7 +83,8 @@ class Wiaas_Template_Admin_Ajax {
|
||||
|
||||
$terms = get_terms(array(
|
||||
'taxonomy' => 'template_category',
|
||||
'name__like' => $term
|
||||
'name__like' => $term,
|
||||
'hide_empty' => false
|
||||
));
|
||||
|
||||
foreach ($terms as $t) {
|
||||
|
||||
@@ -9,5 +9,6 @@ if (!defined('ABSPATH')) {
|
||||
<h3>
|
||||
<strong class="item-title"><?php echo $title; ?></strong>
|
||||
<strong class="item-title">[<?php echo $quantity; ?>]</strong>
|
||||
<strong class="item-title">[<?php echo $connected_product_name; ?>]</strong>
|
||||
</h3>
|
||||
</div><?php
|
||||
|
||||
@@ -9,11 +9,17 @@ class Wiaas_Template_Category_Object {
|
||||
|
||||
public $quantity = '';
|
||||
|
||||
public $product_id = '';
|
||||
|
||||
public function __construct($id, $title, $quant) {
|
||||
public $product_name = '';
|
||||
|
||||
|
||||
public function __construct($id, $title, $quant, $product_id = '', $product_name = '') {
|
||||
$this->template_category_id = $id;
|
||||
$this->name = $title;
|
||||
$this->quantity = $quant;
|
||||
$this->product_id = $product_id;
|
||||
$this->product_name = $product_name;
|
||||
}
|
||||
|
||||
public function get_quantity(){
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user