Repalced virtual product with template category
This commit is contained in:
@@ -47,6 +47,7 @@ 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['service']);
|
||||
self::render_template_products($template_products_data['installation']);
|
||||
@@ -92,13 +93,13 @@ class Wiaas_Admin_Template_Selection {
|
||||
}
|
||||
|
||||
public static function render_template_products($template_products) {
|
||||
|
||||
if (!empty($template_products)) {
|
||||
|
||||
|
||||
foreach ($template_products as $item) {
|
||||
|
||||
$product_id = $item['product_id'];
|
||||
$title = $item['product_title'];
|
||||
$product_id = $item['template_category_id'];
|
||||
$title = $item['template_category_title'];
|
||||
$quantity = $item['quantity'];
|
||||
|
||||
include('views/html-wiaas-template-selection.php');
|
||||
@@ -107,65 +108,60 @@ class Wiaas_Admin_Template_Selection {
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_product_categories($products) {
|
||||
$category_ids = array();
|
||||
public static function get_product_categories($category_meta) {
|
||||
$category_objects = array();
|
||||
|
||||
if (empty($products)) {
|
||||
return $category_ids;
|
||||
|
||||
if (empty($category_meta)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($products as $product) {
|
||||
foreach ($category_meta as $meta) {
|
||||
|
||||
$product_id = $product['product_id'];
|
||||
|
||||
$post_terms = wp_get_object_terms($product_id, 'product_cat', array('fields' => 'id=>name'));
|
||||
|
||||
if (!empty($post_terms) && !is_wp_error($post_terms)) {
|
||||
|
||||
$cat = '';
|
||||
|
||||
foreach ($post_terms as $term) {
|
||||
if ($term != "Uncategorized") {
|
||||
$cat = $term;
|
||||
}
|
||||
}
|
||||
|
||||
$product_with_cat = array(
|
||||
'quantity' => $product['quantity'],
|
||||
'category_term' => $cat
|
||||
);
|
||||
|
||||
$category_ids[$product_id] = $product_with_cat;
|
||||
if (!empty($meta)) {
|
||||
|
||||
|
||||
$category_template_id = $meta['template_category_id'];
|
||||
|
||||
$template_category_object = new Wiaas_Template_Category_Object(
|
||||
$category_template_id,
|
||||
$meta['template_category_title'],
|
||||
$meta['quantity']);
|
||||
|
||||
$category_objects[$category_template_id] = $template_category_object;
|
||||
}
|
||||
|
||||
}
|
||||
return $category_ids;
|
||||
return empty($category_objects) ? null : $category_objects;
|
||||
}
|
||||
|
||||
public static function get_bundled_product_categories($bundled_items) {
|
||||
|
||||
$category_ids = array();
|
||||
$template_category_objects = array();
|
||||
foreach ($bundled_items as $item_id => $item) {
|
||||
$item_data = $item->get_data();
|
||||
$post_terms = wp_get_object_terms($item->get_product_id(), 'product_cat', array('fields' => 'id=>name'));
|
||||
$post_terms = wp_get_object_terms($item->get_product_id(), 'template_category', array('fields' => 'id=>name'));
|
||||
|
||||
if (!empty($post_terms) && !is_wp_error($post_terms)) {
|
||||
|
||||
$cat = '';
|
||||
$category_template_id = '';
|
||||
|
||||
foreach ($post_terms as $term) {
|
||||
if ($term != "Uncategorized") {
|
||||
$cat = $term;
|
||||
}
|
||||
foreach ($post_terms as $id => $term) {
|
||||
$cat = $term;
|
||||
$category_template_id = $id;
|
||||
}
|
||||
|
||||
$category_ids[$cat] = $item_data['quantity_max'];
|
||||
$template_category_object = new Wiaas_Template_Category_Object(
|
||||
$category_template_id,
|
||||
$cat,
|
||||
$item_data['quantity_max']);
|
||||
$template_category_objects[$category_template_id] = $template_category_object;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $category_ids;
|
||||
return $template_category_objects;
|
||||
}
|
||||
|
||||
|
||||
@@ -199,28 +195,30 @@ class Wiaas_Admin_Template_Selection {
|
||||
if (!empty($categories_form_template)) {
|
||||
|
||||
foreach ($categories_form_template as $category) {
|
||||
$template_cat_id = $category->template_category_id;
|
||||
|
||||
if (!in_array($category['category_term'], $bundle_category_keys)) {
|
||||
|
||||
array_push($missing_categories, $category['category_term']);
|
||||
if (!in_array($template_cat_id, $bundle_category_keys)) {
|
||||
|
||||
array_push($missing_categories, $category->name);
|
||||
|
||||
} else {
|
||||
|
||||
$product_from_bundle_quantity = $categories_form_bundle[$category['category_term']];
|
||||
$product_from_bundle_quantity = $categories_form_bundle[$template_cat_id]->quantity;
|
||||
$quantity_from_template = $category->quantity;
|
||||
|
||||
if ($category['quantity'] != $product_from_bundle_quantity) {
|
||||
array_push($insufficient_product_quantities, $category['category_term']);
|
||||
if ((int)($quantity_from_template) !== $product_from_bundle_quantity) {
|
||||
array_push($insufficient_product_quantities, $category->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$categories_meesage = implode(',', $missing_categories);
|
||||
$categories_message = implode(',', $missing_categories);
|
||||
$quantity_message = implode(',', $insufficient_product_quantities);
|
||||
|
||||
|
||||
if (!empty($missing_categories)) {
|
||||
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories missing: ' . $categories_meesage, 'woocommerce-product-bundles'));
|
||||
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories missing: ' . $categories_message, 'woocommerce-product-bundles'));
|
||||
}
|
||||
|
||||
if (!empty($insufficient_product_quantities)) {
|
||||
@@ -230,8 +228,7 @@ class Wiaas_Admin_Template_Selection {
|
||||
|
||||
}
|
||||
|
||||
public
|
||||
static function get_category_ids_form_bundle($product) {
|
||||
public static function get_category_ids_form_bundle($product) {
|
||||
$products_form_budnle = $product->get_bundled_data_items();
|
||||
$product_ids = array();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user