diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fbf0dc..1ea3252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v3.0.4 +* Проверка корректности генерации категорий в ICML + ## v3.0.3 * Исправлена ошибка при обновлении со старой версии для некоторых клиентов diff --git a/VERSION b/VERSION index 75a22a2..b0f2dcb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.3 +3.0.4 diff --git a/retailcrm/lib/RetailcrmCatalog.php b/retailcrm/lib/RetailcrmCatalog.php index 77d0835..3656a61 100644 --- a/retailcrm/lib/RetailcrmCatalog.php +++ b/retailcrm/lib/RetailcrmCatalog.php @@ -56,6 +56,7 @@ class RetailcrmCatalog $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $shop_url = (Configuration::get('PS_SSL_ENABLED') ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_); $protocol = (Configuration::get('PS_SSL_ENABLED')) ? "https://" : "http://"; + $homeCategory = Configuration::get('PS_HOME_CATEGORY'); $items = array(); $categories = array(); @@ -71,29 +72,41 @@ class RetailcrmCatalog $types = Category::getCategories($id_lang, true, false); foreach ($types as $category) { - if (!self::isCategoryActive(new Category($category['id_category']))) { - if (!in_array($category['id_category'], $inactiveCategories)) { - $inactiveCategories[] = $category['id_category']; + $categoryId = (empty($category['id_category']) && isset($category['id'])) + ? $category['id'] : $category['id_category']; + + if (!self::isCategoryActive(new Category($categoryId))) { + if (!in_array($categoryId, $inactiveCategories)) { + $inactiveCategories[] = $categoryId; } continue; } - $picture = $link->getCatImageLink($category['link_rewrite'], $category['id_category'], 'category_default'); + $picture = $link->getCatImageLink($category['link_rewrite'], $categoryId, 'category_default'); - $categoriesIds[] = $category['id_category']; + $categoriesIds[] = $categoryId; $categories[] = array( - 'id' => $category['id_category'], - 'parentId' => $category['id_parent'], + 'id' => $categoryId, + 'parentId' => self::getParentCategoryId($category['id_parent']), 'name' => $category['name'], 'picture' => $picture ? $protocol . $picture : '' ); } + foreach ($categories as $key => $innerCategory) { + if (isset($innerCategory['parentId']) + && !empty($innerCategory['parentId']) + && !in_array($innerCategory['parentId'], $categoriesIds) + ) { + $innerCategory['parentId'] = $homeCategory; + $categories[$key] = $innerCategory; + } + } + $products = Product::getProducts($id_lang, 0, 0, 'name', 'asc'); foreach ($products AS $product) { - $homeCategory = Configuration::get('PS_HOME_CATEGORY'); $category = $product['id_category_default']; if (!in_array($category, $categoriesIds)) { @@ -315,4 +328,33 @@ class RetailcrmCatalog return $category->active; } + + /** + * Returns active parent category + * + * @param int $parentId + * + * @return null + */ + private static function getParentCategoryId($parentId) + { + $home = Configuration::get('PS_HOME_CATEGORY'); + + if (empty($parentId)) { + return $home; + } + + if ($parentId == $home) { + return $home; + } + + /** @var \Category|\CategoryCore $category */ + $category = new Category($parentId); + + if (empty($category->id) || !$category->active) { + return $home; + } + + return $parentId; + } } diff --git a/retailcrm/lib/RetailcrmJobManager.php b/retailcrm/lib/RetailcrmJobManager.php index 813c419..d5aa2ad 100644 --- a/retailcrm/lib/RetailcrmJobManager.php +++ b/retailcrm/lib/RetailcrmJobManager.php @@ -167,13 +167,6 @@ class RetailcrmJobManager $exception->getTraceAsString(), $job ); - } catch (\Throwable $throwable) { - static::handleError( - $throwable->getFile(), - $throwable->getMessage(), - $throwable->getTraceAsString(), - $job - ); } } @@ -288,8 +281,6 @@ class RetailcrmJobManager static::execHere($fileCommandLine, $once); } catch (\Exception $exception) { throw new RetailcrmJobManagerException($exception->getMessage(), $fileCommandLine); - } catch (\Throwable $exception) { - throw new RetailcrmJobManagerException($exception->getMessage(), $fileCommandLine); } } diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 900c162..08e7128 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -116,7 +116,7 @@ class RetailCRM extends Module { $this->name = 'retailcrm'; $this->tab = 'export'; - $this->version = '3.0.3'; + $this->version = '3.0.4'; $this->author = 'DIGITAL RETAIL TECHNOLOGIES SL'; $this->displayName = $this->l('retailCRM'); $this->description = $this->l('Integration module for retailCRM'); @@ -1102,12 +1102,6 @@ class RetailCRM extends Module RetailcrmLogger::writeNoCaller($exception->getTraceAsString()); Configuration::updateValue(static::MODULE_LIST_CACHE_CHECKSUM, 'exception'); - return static::getCachedCmsModulesList(); - } catch (Throwable $throwable) { - RetailcrmLogger::writeCaller(__METHOD__, $throwable->getMessage()); - RetailcrmLogger::writeNoCaller($throwable->getTraceAsString()); - Configuration::updateValue(static::MODULE_LIST_CACHE_CHECKSUM, 'throwable'); - return static::getCachedCmsModulesList(); } }