2011-12-10 4 views
19

商品とその画像を作成/更新するためのシンプルなMagento 1.6.xインポートエージェントを作成する必要があります。誰かがMagento APIを使用せずに製品イメージを追加する方法を教えてもらえますか?Magentoはプログラムによって商品画像を追加します

は、APIのパフォーマンスが非常に悪いことが判明し、私は少しイライラされ始めています。.. :-(

私はこの問題に関するいくつかの他の質問を発見した、それらのどれもに画像を追加することと関係していません。誰かがAPIせずに直接画像を追加することで私を助けることができる

$product->setIsMassupdate(true) 
    ->setExcludeUrlRewrite(true) 
    ->setManufacturer($this->addManufacturers(utf8_encode($record[4]))) 
    ->setSku($record[3]) 
    ->setAttributeSetId($this->attribute_set)# 9 is for default 
    ->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) 
    ->setName(utf8_encode($record[5])) 
    ->setCategoryIds($this->getCategories(array($record[0], $record[1], $record[2]))) # some cat id's, 
    ->setWebsiteIDs(array(1)) # Website id, 1 is default 
    ->setDescription(utf8_encode($record[6])) 
    ->setShortDescription($this->shortText(utf8_encode($record[6]), 150)) 
    ->setPrice($price) # Set some price 
    ->setSpecialPrice($special_price) 
    ->setWeight($record[12]) 
    ->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED) 
    ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) 
    ->setTaxClassId(2)  // default tax class 
    ->setPixmaniaimg($record[10]) 
    ->setStockData(array('is_in_stock' => $inStock, 'qty' => $qty)) 
    ->setCreatedAt(strtotime('now')); 

:?製品

これは私がして来たものですありがとう

ルーカス

+0

Magentoのどのバージョンですか? – benmarks

+0

Magento 1.6 - 私の元のコメントにはごめんなさい。 – Bery

+0

Magento 2の場合:http://magento.stackexchange.com/questions/140612/magento-2-save-all-product-data-outside-magento-withwith -images –

答えて

38

私はMagento 1.6.1でこれを行いました。最初の配列にイメージのURLパスを入れて、あなたは良いです。

さらに、を参照して、addImageToMediaGallery()や他の方法についても理解してください。これは間違いなく将来認識する必要があります。

// Add three image sizes to media gallery 
$mediaArray = array(
    'thumbnail' => $putPathHere, 
    'small_image' => $putPathHere, 
    'image'  => $putPathHere, 
); 

// Remove unset images, add image to gallery if exists 
$importDir = Mage::getBaseDir('media') . DS . 'import/'; 

foreach($mediaArray as $imageType => $fileName) { 
    $filePath = $importDir.$fileName; 
    if (file_exists($filePath)) { 
     try { 
      $product->addImageToMediaGallery($filePath, $imageType, false); 
     } catch (Exception $e) { 
      echo $e->getMessage(); 
     } 
    } else { 
     echo "Product does not have an image or the path is incorrect. Path was: {$filePath}<br/>"; 
    } 
} 
+0

マゼンタで画像を作成する方法はありますか?私はイメージの1つのサイズだけ提供されています。 – Bery

+0

まず、別々の画像が必要ですか? Magentoでは、必要に応じて、単一の画像をサムネイル、small_image、および画像サイズとして設定できます。 –

+0

私は、1つ以上のイメージ(製品ごとに最大hreeイメージ)を使用し、最初にベースイメージ、次にsmall_imageおよびthumbnailを使用する必要があります。イメージは常に同じです(例:image1.jpgはbase、small_image、およびthumbnailです)。 – Bery

0
set_time_limit(0); 

ini_set('memory_limit', '4095M'); 

error_reporting(E_ALL); 

ini_set('display_errors', 1); 

require_once '../app/Mage.php'; 

umask(0); 

Mage::setIsDeveloperMode(true); 

$storeID = Mage_Core_Model_App::ADMIN_STORE_ID; 

Mage::app()->setCurrentStore($storeID); 



$destination = Mage::getBaseDir() . '/import/images/' . $image; 

$product->addImageToMediaGallery($destination, array('image', 'thumbnail', 'small_image'), false, false); 

} 

これは、ベース画像を設定します。

関連する問題