$websites = $product->getWebsiteIds(); if (!inMainStore($websites)) { $websites = implode(",", $websites); echo "[wrong website] skip {$id}, websites: {$websites}\n"; $skippedProducts++; continue; } $data = []; $categoryData = []; $configProduct = new ConfigurableProduct($product); $categories = $configProduct->getCategoryIds(); $hasActiveCategories = false; echo sprintf("(%s) %s %s\n", --$open, str_pad($configProduct->getId(), 5), str_pad($configProduct->getName(), 30)); foreach ($categories as $categoryId) { $category = new Category($categoryId); if ($category->isVisible() && strlen($category->getName()) > 0 && !$category->isExcluded()) { if ($hasActiveCategories) { $categoryData['alternateCategoryId'][] = $categoryId; $categoryData['alternateCategoryName'][] = $category->getName(); $categoryData['alternateCategoryTree'][] = $category->getCategoryTree(); } else { $categoryData['defaultCategoryId'] = $categoryId; $categoryData['defaultCategoryName'] = $category->getName(); $categoryData['defaultCategoryTree'] = $category->getCategoryTree(); $categoryData['productType'] = $category->getName(); $categoryData['alternateCategoryId'] = []; $categoryData['alternateCategoryName'] = []; $categoryData['alternateCategoryTree'] = []; } $hasActiveCategories = true; }