2011-12-10 28 views
19

Ürünler ve resimler oluşturmayı/güncellemeyi farz eden basit bir Magento 1.6.x ithalat aracı oluşturmam gerekiyor. Birisi bana magento API'sini kullanmadan ürün resmini nasıl ekleyeceğimi önerebilir?Magento programatik olarak ürün resmi ekle

api performansı çok kötü olduğu ortaya çıktı ve biraz sinirli olmaya başladım .. :-(

bu sorun ile ilgili diğer bazı sorular bulduk, ancak bunların hiçbiri görüntüleri ekleyerek ilgilidir .?

$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')); 

birisi API olmadan doğrudan görüntüleri ekleyerek bana yardımcı olabilir

: ürün

Bu benim birlikte gelen budurTeşekkür

Lukas

+0

Hangi sürümü Magento'da? – benmarks

+0

Magento 1.6 - Orijinal yorumumda bulamadığım için üzgünüm .. – Bery

+0

Magento 2 için: http://magento.stackexchange.com/questions/140612/magento-2-save-all-product-data-outside-magento-with -images –

cevap

38

Ben Magento 1.6.1 yılında yaptı. Sadece resim dizininizin yollarını ilk diziye koyun ve gitmekte fayda var.

Ayrıca, addImageToMediaGallery() yöntemine aşina olmak için Mage_Catalog_Model_Product'a ve gelecekte de bilmeniz gereken diğer yöntemlere aşina olun.

// 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

Resimleri magento ile oluşturmanın bir yolu var mı? Resmin sadece bir boyutuna sahip oldum. – Bery

+0

İlk olarak, ayrı görüntülere mi ihtiyacınız var? Magento, ihtiyacınız varsa küçük resim, küçük resim ve görüntü boyutu olarak tek bir görüntü ayarlamanıza izin verir. –

+0

Tamam. Bir veya daha fazla görüntü (her ürün için en fazla hree görüntü) kullanmam ve sonra temel resim, sonra small_image ve küçük resim olarak bir tane kullanmam gerekiyor. Görüntü her zaman aynıdır (ör. Image1.jpg taban, small_image ve küçük resimdir). – 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); 

} 

Bu temel görüntü oluşturacaktır.

İlgili konular