2013-11-14 2 views
0

내 보낸 후 일부 정보를 변경 한 다음 많은 수의 제품을 Magento로 가져 오면 모든 이미지가 더 이상 설정되지 않은 것으로 나타났습니다. 이미지는 여전히 각 제품의 미디어 갤러리에 있지만 기본 이미지로 설정되어 있지 않습니다.Magento로 제품을 가져 오면 기존 제품의 이미지가 깨집니다.

어떤 경우에는 이미지를/media/import/폴더로 복사해야하지만 이미지를 그대로 둘 수 있도록 가져 오기 파일을 변경할 수 있습니까?

는 지금, 모든 이미지 폴더에있는 것으로 나타납니다 어떤 도움을 매우 극명하게 될 것이다

/미디어/카탈로그/제품 /.

또한 모든 제품의 기본 이미지를 갤러리의 첫 번째 이미지로 설정하는 스크립트를 실행할 수 있다면 제대로 작동 할 것입니다. 감사!

답변

1

제품을로드 했으므로 변경하고 저장할 준비가되었다고 가정 해 봅시다. 다음 코드를 사용하십시오 :

if (file_exists($imagePath)) {//New image file 
//Load your media table 
$mediaApi = Mage::getModel("catalog/product_attribute_media_api"); 
try { 
//Now you have all the images available for your product 
//if you previously have assign anything 
    $items = $mediaApi->items($product->getId()); 
//loop them 
     foreach ($items as $item) { 
//With that line you can remove them if you want 
echo ($mediaApi->remove($product->getId(), $item['file'])); 
      } 
    } catch (Exception $exception) { 
      var_dump($exception); 
    die('Exception Thrown'); 
    } 

$cache = Mage::getSingleton('core/cache'); 
$cache->flush(); 
//You need that line 
$product->setMediaGallery(array('images' => array(), 'values' => array())); 
//That line assigns your new image.As base,thumbail and image. 
//Use it in the loop if you want to reassign an existing image. 
$product->addImageToMediaGallery($imagePath, array('thumbnail', 'small_image', 'image'), false, false); 

건배!

관련 문제