Ejemplo n.º 1
0
$open = count($productIds);
foreach ($productIds as $id) {
    $product = Mage::getModel('catalog/product')->load($id);
    $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'] = [];