Question

J'utilise les modules de produits personnalisés de Milople qui crée un type de produit personnalisé appelé "Milillet Personnalisé Produit" et j'ai besoin d'afficher une liste de ces produits sous une pièce d'identité de catégorie.J'ai essayé d'utiliser ce code:

$cat_id = 3;
$category = Mage::getModel('catalog/category')->load($cat_id);
$collection = $category->getProductCollection()->addAttributeToSort('position');
Mage::getModel('catalog/layer')->prepareProductCollection($collection);

et cela fonctionne de tous les types de produits par défaut qui viennent avec Magento, à l'exception des personnalisés.

Était-ce utile?

La solution

Si c'est un nouveau type de produit, essayez de le filtrer dans la collection:

   $collection = $category->getProductCollection()->addAttributeToSort('position')
->addAttributeToFilter('type_id', array('eq' => 'Milople Personalized Product'));

J'espère que c'est ce que vous voulez.

EDIT:

Essayez ceci:

$category = new Mage_Catalog_Model_Category(); 
$category->load(3); //this is category id 
$collection =
$category->getProductCollection()->addAttributeToFilter('type_id',
array('eq' => 'Milople Personalized Product'));

Autres conseils

ci-dessous le code est exporté à tous les produits par catégorie en CSV.

<?php 
set_time_limit(0);
ini_set("memory_limit",-1);
ini_set('max_execution_time','1800000000');

require_once '../app/Mage.php';
Mage::app(); 

$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();

$ids = $tree->getCollection()->getAllIds();
$fp = fopen('category-product-export.csv', 'w');
$field = array('Product SKU','Category Name'); 
fputcsv($fp, $field);

$_productCollection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('*')
                        ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
                        ->load();

foreach ($_productCollection as $_product){
   $cats = $_product->getCategoryIds();
   $cnt = 0;
   $catName = '';
    foreach($cats as $id) {
        $category->load($id);
        $root = 'Root Catalog';
            $isRoot = strtolower($root);
            $categoryName = strtolower($category->getName());
            if($categoryName == $isRoot){
                continue;
            }
        $categories[$id]['name'] = $category->getName();
        $categories[$id]['path'] = $category->getPath();

        $path = explode('/', $categories[$id]['path']);
        $len = count($path);
        $string = '';
        if($id > 2){
            foreach ($path as $k=>$pathId)
            {
                $separator = '';
                if($pathId > 2){
                    $category->load($pathId);
                    if($k != $len-1){ $separator = ' || ';}
                    $string.= $category->getName() . $separator;
                }

            }
            if($cnt > 0) {
                $catName.= ','.$string;
            } else {
                $catName = $string;
            }

            $cnt++;
        }
    }
    //echo $catName;
    $field = array($_product->getSku(),$catName); 
    fputcsv($fp, $field);   

} 

?>
<a href="category-product-export.csv">Download</a>

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top