久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Magento 以編程方式添加產品圖片

Magento programmatically add product image(Magento 以編程方式添加產品圖片)
本文介紹了Magento 以編程方式添加產品圖片的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我必須創建一個簡單的 Magento 1.6.x 導入代理,用于創建/更新產品及其圖像.有人可以告訴我如何在不使用 magento API 的情況下添加產品圖片嗎?

I have to create a simple Magento 1.6.x import agent that suppose to create/update products and their images. Could someone advise me how to add product image without having to use the magento API?

結果證明 api 性能很差,我開始有點沮喪.. :-(

The api performance turned out to be very poor and I am starting to be a little frustrated.. :-(

我發現了一些關于此問題的其他問題,但沒有一個與向產品添加圖像有關.

I have found some other questions regarding this problem, but none of them concerns with adding images to the product.

這是我帶來的:

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

有人可以幫我在沒有 API 的情況下直接添加圖片嗎?

Can someone help me with adding images directly without the API?

謝謝

盧卡斯

推薦答案

我在 Magento 1.6.1 中做到了這一點.只需將您的圖片 URL 路徑放在第一個數組中即可.

I did this in Magento 1.6.1. Just put your image URL paths in the first array and you are good to go.

另請參閱 Mage_Catalog_Model_Product 以熟悉 addImageToMediaGallery() 和您無疑需要熟悉的其他方法將來知道.

Also look at Mage_Catalog_Model_Product to become familiar with addImageToMediaGallery() and other methods you'll undoubtedly need to be aware of in the future.

// 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/>";
    }
}

這篇關于Magento 以編程方式添加產品圖片的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Override Magento Config(覆蓋 Magento 配置)
What would cause a print_r and/or a var_dump to fail debugging a variable?(什么會導致 print_r 和/或 var_dump 調試變量失敗?)
How to update custom options programatically in magento?(如何在 magento 中以編程方式更新自定義選項?)
Magento 404 on Admin Page(管理頁面上的 Magento 404)
Magento - get price rules from order(Magento - 從訂單中獲取價格規則)
Magento Change Product Page Titles to Include Attributes(Magento 更改產品頁面標題以包含屬性)
主站蜘蛛池模板: 国产伦精品一区二区三区四区视频 | 夜夜爽99久久国产综合精品女不卡 | 中文字幕av在线播放 | 国产人成精品一区二区三 | 黄色免费在线观看网址 | 最新免费黄色网址 | 午夜精品影院 | 久久久久久久一区 | 久久久久久国产精品 | 自拍偷拍亚洲欧美 | 日韩欧美一区二区三区免费观看 | 色婷婷影院 | 日韩欧美在线不卡 | 日本三级电影免费观看 | 亚洲一区二区久久 | 一区二区视频在线观看 | 91精品国产91久久久久久丝袜 | 美女视频三区 | 日韩在线视频观看 | 亚洲第一在线 | 亚洲精品2区 | 久久爆操 | 精品国产青草久久久久福利 | 久久成人精品视频 | 国产成人精品网站 | 毛片高清 | 欧美三级在线 | 精品成人在线 | 人人做人人澡人人爽欧美 | 久久精品亚洲 | 成人福利网站 | 欧美激情一区二区三区 | 欧美中文字幕在线观看 | 一区二区三区 在线 | 国产视频精品视频 | 2019天天操| 国产不卡视频在线 | 亚洲成人精品视频 | 亚洲色图第一页 | 天天看天天爽 | 午夜久久久 |