2016-03-31 13 views
0

Magento CE 1.9.1.1のxmlファイルからインポート製品スクリプトを作成しています
すべての属性は正しくインポートされますが、管理パネルでは画像のラジオボタンがチェックされていないため、製品イメージがフロントエンドに表示されません。
インポート後にこれらのラジオボタンを自動的にチェックする方法を教えてください。Magento - インポート時にベース画像、小さな画像、サムネイルを自動的に設定(管理パネル内)?

ここに私のイメージをインポートするためのコード:

$sku = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);  
$url = $image; //$image, $small_image, $thumbnail are external urls image files 
$image_type = substr(strrchr($url,"."),1); //find the image extension 
$filename = $sku.'.'.$image_type; 
$filepath = Mage::getBaseDir('media') . DS . 'import'. DS . $filename; 

file_put_contents($filepath, file_get_contents(trim($url))); 
if($is_default==true){ 
    $mediaAttribute = array (
     'image'=>$image, 
     'small_image'=>$small_image, 
     'thumbnail'=>$thumbnail, 
     ); 
}else{ 
    $mediaAttribute = null; 
} 
$prod->addImageToMediaGallery($filepath, $mediaAttribute, false, false); 
$prod->save(); 

私は85,86,87の画像、小さな画像とサムネイルのための私のIDでこれらのSQLリクエストしてみてください:

UPDATE catalog_product_entity_media_gallery AS mg, 
     catalog_product_entity_media_gallery_value AS mgv, 
     catalog_product_entity_varchar AS ev 
SET ev.value = mg.value 
WHERE mg.value_id = mgv.value_id 
AND mg.entity_id = ev.entity_id 
AND ev.attribute_id IN (85,86,87) 
AND mgv.position = 1; 

をそれ0行が変更されたことを示します。これは、手動でアップロードのために動作しますが、どのようにそれが輸入のために働くことができますMagento - Auto set base, small and thumbnail on upload

また、私は上のステップに従ってください?

おかげで、

JayD

答えて

0

は、私が問題だった、私のミスを見つけた:

if($is_default==true){ 
    $mediaAttribute = array (
     'image'=>$image, 
     'small_image'=>$small_image, 
     'thumbnail'=>$thumbnail, 
    ); 
}else{ 
    $mediaAttribute = null; 
} 

今では、と連携して動作します。

$url = $image; 

$image_type = substr(strrchr($url,"."),1); //find the image extension 
$filename = $sku.'.'.$image_type; //give a new name, you can modify as per your requirement 
$filepath = Mage::getBaseDir('media') . DS . 'import'. DS . $filename; //path for temp storage folder: ./media/import/ 

file_put_contents($filepath, file_get_contents(trim($url))); //store the image from external url to the temp storage folder 


    $mediaAttribute = array ( 'image', 
           'small_image', 
           'thumbnail', 
          ); 

$prod->addImageToMediaGallery($filepath, $mediaAttribute, true, false); 

$prod->save(); 
関連する問題