카테고리 별 Magento 사용자 정의 제품을 나열하십시오
-
29-09-2020 - |
문제
공동으로 개인화 된 제품 유형을 만드는 최상의 개인화 된 제품 모듈을 사용하고 있으며 카테고리 ID 로이 제품 목록을 표시해야합니다.이 코드를 사용하여 시도했습니다.
$cat_id = 3;
$category = Mage::getModel('catalog/category')->load($cat_id);
$collection = $category->getProductCollection()->addAttributeToSort('position');
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
.
및 IT는 개인화 된 것들을 제외하고 Magento와 함께 제공되는 모든 기본 제품 유형을 형성합니다.
해결책
새 제품 유형이면 컬렉션에서 필터링하십시오.
$collection = $category->getProductCollection()->addAttributeToSort('position')
->addAttributeToFilter('type_id', array('eq' => 'Milople Personalized Product'));
.
이것이 당신이 원하는 것입니다.
편집 :
시도 :
$category = new Mage_Catalog_Model_Category();
$category->load(3); //this is category id
$collection =
$category->getProductCollection()->addAttributeToFilter('type_id',
array('eq' => 'Milople Personalized Product'));
. 다른 팁
코드 아래에 카테고리별로 모든 제품을 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>
. 제휴하지 않습니다 magento.stackexchange