Skip to content

Instantly share code, notes, and snippets.

@incrize
Created September 14, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incrize/0111bf3671049578ea70 to your computer and use it in GitHub Desktop.
Save incrize/0111bf3671049578ea70 to your computer and use it in GitHub Desktop.
diff --git a/app/functions/fn.multivendor.php b/app/functions/fn.multivendor.php
index 08cfc1e..968e135 100644
--- a/app/functions/fn.multivendor.php
+++ b/app/functions/fn.multivendor.php
@@ -197,9 +197,6 @@ function fn_mve_import_get_primary_object_id(&$pattern, &$_alt_keys, &$v, &$skip
function fn_mve_import_check_product_data(&$v, $primary_object_id, &$options, &$processed_data, &$skip_record)
{
- static $company_categories = null;
- static $company_categories_ids = null;
-
if (Registry::get('runtime.company_id')) {
$v['company_id'] = Registry::get('runtime.company_id');
}
@@ -212,40 +209,82 @@ function fn_mve_import_check_product_data(&$v, $primary_object_id, &$options, &$
// Check the category name
if (!empty($v['Category'])) {
- if (strpos($v['Category'], $options['category_delimiter']) !== false) {
- $paths = explode($options['category_delimiter'], $v['Category']);
- array_walk($paths, 'fn_trim_helper');
- } else {
- $paths[] = $v['Category'];
+ if (!fn_mve_import_check_exist_category($v['Category'], $options['category_delimiter'], $v['lang_code'])) {
+ $processed_data['S']++;
+ $skip_record = true;
}
+ }
- if (!empty($paths)) {
- $parent_id = 0;
- foreach ($paths as $category) {
- $category_id = db_get_field("SELECT ?:categories.category_id FROM ?:category_descriptions INNER JOIN ?:categories ON ?:categories.category_id = ?:category_descriptions.category_id WHERE ?:category_descriptions.category = ?s AND lang_code = ?s AND parent_id = ?i", $category, $v['lang_code'], $parent_id);
- if (empty($category_id)) {
- $processed_data['S']++;
- $skip_record = true;
+ if (!empty($v['Secondary categories']) && !$skip_record) {
+ $delimiter = ';';
+ $categories = explode($delimiter, $v['Secondary categories']);
+ array_walk($categories, 'fn_trim_helper');
- return false;
- }
- $parent_id = $category_id;
+ foreach ($categories as $key => $category) {
+ if (!fn_mve_import_check_exist_category($category, $options['category_delimiter'], $v['lang_code'])) {
+ unset($categories[$key]);
}
- if ($company_categories === null) {
- $company_categories_ids = Registry::get('runtime.company_data.category_ids');
- }
- $allow = empty($company_categories_ids) || in_array($parent_id, $company_categories_ids);
+ }
+
+ $v['Secondary categories'] = implode($delimiter . ' ', $categories);
+ }
+
+ return true;
+}
+
+
+/**
+ * Check on exists import category in database
+ *
+ * @param array $category
+ * @param string $delimiter
+ * @param string $lang
+ * @return bool
+ */
+function fn_mve_import_check_exist_category($category, $delimiter, $lang)
+{
+ if (empty($category)) {
+ return false;
+ }
+
+ static $company_categories_ids = null;
+
+ if ($company_categories_ids === null) {
+ $company_categories_ids = Registry::get('runtime.company_data.category_ids');
+ }
+
+ if (strpos($category, $delimiter) !== false) {
+ $paths = explode($delimiter, $category);
+ array_walk($paths, 'fn_trim_helper');
+ } else {
+ $paths = array($category);
+ }
+
+ if (!empty($paths)) {
+ $parent_id = 0;
- if (!$allow) {
- $processed_data['S']++;
- $skip_record = true;
+ foreach ($paths as $name) {
+ $sql = "SELECT ?:categories.category_id FROM ?:category_descriptions"
+ . " INNER JOIN ?:categories ON ?:categories.category_id = ?:category_descriptions.category_id"
+ . " WHERE ?:category_descriptions.category = ?s AND lang_code = ?s AND parent_id = ?i";
+ $category_id = db_get_field($sql, $name, $lang, $parent_id);
+
+ if (empty($category_id)) {
return false;
}
+
+ $parent_id = $category_id;
}
+
+ if (!empty($company_category_ids) && !in_array($parent_id, $company_category_ids)) {
+ return false;
+ }
+
+ return true;
}
- return true;
+ return false;
}
function fn_mve_import_check_object_id(&$primary_object_id, &$processed_data, &$skip_record, $object = 'products')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment