2011-10-22 4 views
0

Heyhey, 나는 하나 개의 범주에서 모든 제품을로드하고 다른 범주 (그래서, 기본적으로, 단지 추가 카테고리에 모든 제품을 연결)에 추가하는 스크립트를 만들려고 해요젠토 1.6 복사 카테고리 제품

. 내가 시도하고있는 것은 :

$category = Mage::getModel('catalog/category'); 
$category->load($id); // Preset category id 
$collection = $category->getProductCollection(); 
$collection->addAttributeToSelect('*'); 

foreach ($collection as $product) { 
    $result[] = $product->getProductId(); 
// Now get category ids and add a specific category to them and save? 
} 

$ 결과가 비어 있고 진행 방법을 모른다. 어떤 아이디어?

+0

당신이 foreach는 전에 colletion의 위해서 var_dump를 할 경우 당신은 무엇을 얻을? –

답변

2

먼저 모든 속성을 선택하지 말고 $collection->addAttributeToSelect('id')이면 충분합니다. 제품 ID는이 같은 뭔가를 시도 할 수

$product->getId(); 

이 범주를 변경하려면 사용 얻을 둘째 :

$categories = $product->getCategoryIds(); 
$categories[] = 4; // Category to add 
$product->setCategoryIds($categories); 
$product->save();