2014-01-08 3 views
0

현재 자체 작성된 미들웨어를 사용하여 magento를 ERP 시스템에 통합하려고합니다. 나는이 메시지를 얻을 :magento 무결성 제약 제품 생성/업데이트 중 위반

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento`.`catalog_product_entity`, CONSTRAINT  `FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID` FOREIGN KEY (`attribute_set_id`) REFERENCES `eav_attribute_set` (`a) 

문제가 자리하고있는 곳 난 정말 모르겠어요. 제품 get 및 Product write의 결과 Object가 비슷합니다. 이미 웹에서 도움을 받았지만 해결 방법을 찾을 수 없었습니다. 검색 할 곳을 정말로 알지 못합니다. 맨 위에있는 메시지 만 내가 얻을 수있는 유일한 메시지이기 때문입니다.

도움이 될 것입니다. 그럼 코드 자체가 바로 속성을 사용하는 여러 섹션

하지만

$this->product = Mage::getModel('catalog/product')->loadByAttribute('sku',$this->handler['art_nr']); 
     if($this->product===false || $this->product->getId()<1){ 
      $this->product = Mage::getModel('catalog/product'); 
      $this->product->setSku($this->handler['art_nr']); 
      $this->newProduct = true; 
     } 
     $this->product->setStatus($this->shoparticle['products_status']); 
     $this->product->setName($this->handler['art_name']); 
     $categories = array(); 
     if(!$this->isNewProduct()){ 
      $categories = $this->product->getCategoryIds(); 
     } 
     $categories = $this->handler['all_categories']; 
     $this->product->setCategoryIds($categories); 
     $crosssellingSet = array(); 
     $upsellingSet  = array(); 
     $relatedSet   = array(); 
     if(is_array($this->handler['xselling']) && count($this->handler['xselling'])>0){ 
      foreach($this->handler['xselling'] as $valueSet){ 
       $product = Mage::getModel('catalog/product')->loadBySku($valueSet['art_nr']); 
       if((int)$valueSet['group']===1){ 
        $crossselling[$product->getId()] = array('position'=>$valueSet['sort_oder']); 
       }else if((int)$valueSet['group']===2){ 
        $upsellingSet[$product->getId()] = array('position'=>$valueSet['sort_oder']); 
       }else if((int)$valueSet['group']===3){ 
        $relatedSet[$product->getId()] = array('position'=>$valueSet['sort_oder']); 
       } 
      } 
     } 
     $this->product->setCrossSellProductsData($crosssellingSet); 
     $this->product->setUpsellingProductsData($upsellingSet); 
     $this->product->setRelatedProductsData($relatedSet); 
     $importDir = Mage::getBaseDir('media') . DS . 'import' . DS; 
     //check if exists and add .htaccess file for protection 
     if(!is_dir($importDir)){ 
      @mkdir($importDir,0775,true); 
      @chmod($importDir,0775); 
     } 
     if(!is_dir($importDir)){ 
      throw new Connector_Model_Exception_Error('Could not create import Directory!'); 
     } 
     if(!file_exists($importDir.'.htaccess')){ 
      file_put_contents($importDir.'.htaccess','Order deny,allow'."\n".'Deny from all'."\n"); 
     } 
     //clean direcotry 
     $dir = dir($importDir); 
     while(($e=$dir->read())!==false){ 
      if(strpos($e,'.jpg')||strpos($e,'.png')||strpos($e,'.jepg')||strpos($e,'.gif')||strpos($e,'.tif')){ 
       @unlink($importDir.$e); 
      } 
     } 
     //write images into directory 
     //and run Import 
     foreach($this->handler['images'] as $image){ 
      file_put_contents($importDir.$image['image_name'],$image['image']); 
      $this->product->addImageToMediaGallery($importDir.$image['image_name'], array('image', 'small_image', 'thumbnail'), false, false); 
     } 
     $groups = Mage::getModel('customer/group')->getCollection()->getAllIds(); 
     if((float)$this->handler['Bpreis'] > 0.00){ 
      $this->product->setPrice((float)$this->handler['Bpreis']); 
     } 
     if((float)$this->handler['art']['products_pprices'] > 0.00){ 
      $this->product->setMsrp((float)$this->handler['art']['products_pprices']); 
     } 
     //preapre the price data for ranges 
     $groupsets = array(); 
     if(count($this->handler['PGROUP'])){ 
      foreach($this->handler['PGROUP'] as $group){ 
       if(in_array(((int)$group['gruppe']-250),$groups)){ 
        $groupsets[((int)$group['gruppe']-250)][(float)$group['marge']] = (float)$group['PGPRICE']; 
       } 
      } 
     } 
     //Now run ageanst groupsets to set price range etc 
     $storeid = Mage::app()->getStore()->getWebsiteId(); 
     foreach($groupsets as $groupid=>$rangeset){ 
      if(count($rangeset)>0){ 
       foreach($rangeset as $key=>$value){ 
        if(count($rangeset)===1 && $key === (float)0){ 
         $this->product->setData(
          'group_price', 
          array(
           'website_id'=>$storeid, 
           'cust_group'=>$groupid, 
           'price'=>$value, 
          ) 
         ); 
        }else{ 
         $this->product->setData(
          'tier_price',array(
           'website_id'=>$storeid, 
           'cust_group'=>$groupid, 
           'price'=>$value, 
           'price_qty'=>$key 
          ) 
         ); 
        } 
       } 
      } 
     } 
     Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID); 
     if($this->isNewProduct()){ 
      $this->product->setCreatedAt(strtotime('now')); 
     } 
     $this->product->save(); 

답변

1

오류는 정확하게 문제가 무엇인지 알려줍니다. 잘못된 속성 세트 ID가있는 제품을 저장하려고합니다. 이것에 의해,이 경우에 설정 또는 설정되어 있지 않은 속성 세트 ID가 eav_attribute_set 테이블에없는 것을 나타냅니다. 제 생각에는 새로운 제품을 만들면 설정하지 않기 때문입니다. 기존의 것을 업데이트하는 경우 설정하지 않아도됩니다.

if($this->product===false || $this->product->getId()<1){ 
    $this->product = Mage::getModel('catalog/product'); 
    $this->product->setSku($this->handler['art_nr']); 
    // Set Attribute Set. Should be numeric for simple, bundle, configurable, grouped etc 
    $this->product->setAttributeSetId($this->handler['art_attribute_set_id']); 
    $this->newProduct = true; 
} 
+0

덕분에 많은 도움을 받았습니다. 내 자습서에서 그걸 보지 못했습니다 ^^ –

+0

probs가 없습니다. magento는 Innodb를 사용하며 데이터의 무결성을 보장하기 위해 모든 외부 키를 검증합니다. 이와 같이 더 많은 오류가 발생하면 외부 키로 사용되는 값을 검사하여 데이터베이스에 있고 유효한지 확인하십시오. – Ashley

+0

이것에 대해 자세히 살펴 보겠습니다. 고마워. –

1

확인하시기 바랍니다 가능한 한 많이 보여주기 위해 노력하겠습니다으로 분할되어


함께 ID를 설정하여 암호. 제품을 업데이트/저장하기 위해 코드를 작성한 코드를 공유하십시오.

+0

내 게시물이 도움이 되었기를 바랍니다. –