2014-01-23 5 views
3

Magento 제품을 프로그래밍 방식으로 추가하는 프로젝트를 진행하고 있습니다. 다음 코드 세그먼트 여기프로그래밍 방식으로 Magento 제품 만들기

try{ 
    //create new product 
    $newProduct = new Mage_Catalog_Model_Product(); 
    $newProduct->setAttributeSetId(9) 
       ->setTypeId('simple') 
       ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) 
       ->setTaxClassId(2) 
       ->setCreatedAt(strtotime('now')) 
       ->setName($data[0]) 
       ->setSku($data[1]) 
       ->setWeight($data[2]) 
       ->setStatus($data[3]) 
       ->setPrice($data[4]) 
       ->setCategoryIds(explode(',',$data[5])) 
       ->setWebsiteIds(explode(',',$data[6])) 
       ->setDescription($data[7]) 
       ->setShortDescription($data[8]) 
           .... 
       ->setFreeGroundShipping($data[18]) 
       ->setMetaTitle($data[19]) 
       ->setMetaKeyword($data[20]) 
       ->setMetaDescription($data[21]) 
       ->setStockData(array(
            'manage_stock'=>0, 
            'min_sale_qty'=>$data[22], 
            'max_sale_qty'=>$data[23])) 
       ->setSetupFee($data[24]) 
       ->setsetupCost($data[25]); 
    $newProduct->save();     
}catch(Exception $e){ 
    $result['status'] = 3; 
    $result['message'] = 'There is an ERROR happened! NOT ALL products are created! Error:'.$e->getMessage(); 
    echo json_encode($result); 
    return; 
} 

이 문제가 온다 : 코드를 실행 한 후, 나는 젠토 제품을 관리 되돌아 가게되었다, 제품이 만들어졌습니다,하지만 "매장보기"속성 중 일부는 비어 있습니다! 데이터베이스에 가서 모든 속성에 값이 있음을 확인했습니다.

아무에게도 attributs를 보여줄 수있는 아이디어가 있습니까? 고마워요!

+0

속성이 기본보기에 채워져 있습니까? 또는 모든보기/웹 사이트에 속성이 비어 있습니까? –

+0

기본 저장소보기의 경우 비어 있습니다. – CharlesDou

답변

8

제품을 추가하기 전에 스토어를 관리자로 설정하십시오.

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
+0

어이, 그게 효과적이야! 그게 내 하루 종일 괴롭 혔어! 너무 고마워. – CharlesDou

+0

기꺼이 도와 드리겠습니다. –