`
kirenenko04
  • 浏览: 146397 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Import Product Images

 
阅读更多
	/**
	 * 导入某个商品图片,先清空再导入
	 * @param unknown $images 远程图片地址数组
	 * @param unknown $sku 商品sku.
	 */
	public function importProductImages($images,$sku) {
		//remove All images
		$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
		$product = Mage::getModel('catalog/product')->load($product->getId());
		//deleting
		$mediaGalleryAttribute = Mage::getModel('catalog/resource_eav_attribute')->loadByCode(4, 'media_gallery');
		$gallery = $product->getMediaGalleryImages();
		foreach ($gallery as $image)
			$mediaGalleryAttribute->getBackend()->removeImage($product, $image->getFile());
		$product->save();
		//import product images
		if (count($images)) {
			//download image from remote server
			$mediaAttribute = array (
					'thumbnail',
					'small_image',
					'image'
			);
			
			$count_i = 0;
			
			foreach ($images as $key=>$image) {
				$file_name = basename($image);
				$outPath = BP. DS .'media'.DS .'import'.DS.'images'.DS;
				if (file_exists($outPath)) {
					@unlink($outPath);
				} else {
					mkdir($outPath,0777);
				}
				if (substr(basename($this->_old_site . $image,".jpg"),-1) != 'm') {
					++$count_i;
					$this->save_image($this->_old_site . $image,$outPath . $file_name);
					//save image to magento
					if ($count_i == 1) {
						$product->addImageToMediaGallery($outPath . $file_name, $mediaAttribute, false, false);
					} else {
						$product->addImageToMediaGallery($outPath . $file_name, null, false, false);
					}
				}
			}
			$product->save();
		}
	}

 

分享到:
评论

相关推荐

    polycom宝利通视频会议软件3.9 2018

    “DEVICE” means the POLYCOM hardware product with which the SOFTWARE PRODUCT is supplied or, if this SOFTWARE PRODUCT is delivered as software only, on a device (including but not limited to minimum ...

    react-product-carousel-zoom:水龙头旋转产品旋转木马

    import ProductGallery from 'react-product-carousel-zoom'; const source = { images : [ { src: "product-image.jpg", attributes : { width: "375px", height: "375px", alt: "image 1" } }, { src:...

    3DVIA Composer V6R2014

    disassembly, maintenance and repair, a demonstration model of a product from various angles, annotations and explanatory graphics), high-quality vector images (SVG, CGM), and technical illustrations ...

    《PDF文件阅读软件专业版》(Tracker Software PDF-XChange Viewer Pro)v4.0178 And v2.048[压缩包]

    The PDF-XChange Viewer is a FREE product and may be used both for private and commercial use - provided it is not redistributed or bundled with other software - without prior consent. Please contact ...

    WordPress Top Plugins.pdf

    Product Images 139 Product Download 140 Setting up your Payment Gateway 140 Web Invoice—invoicing and billing for WordPress 141 Setting up an invoice 143 Select the client 143 Client ...

    新版Android开发教程.rar

    ----------------------------------- Android 编程基础 1 封面----------------------------------- Android 编程基础 2 开放手机联盟 --Open --Open --Open --Open Handset Handset Handset Handset Alliance ...

    FlashToSilverlight

    * SilverX Expression is Microsoft Expression Blend addin so you need to install Expression Blend 4 to use the product. SilverX products are aimed to help to migrate existing Flash movies into ...

    odoo_config:odoo 尝试性小模块

    产品多图上传展示 (参考师兄 product_images) 1. 用VUE 实现前端逻辑 2. 支持鼠标拖拉, 把图片拖动到组件向关的位置即可 3. 图片顺序变更支持鼠标拖动图片改变图片顺序,会会写入数据库 自定义导入导出,继承所写...

    Flash Sample

    The source files for these movies can be found in the Flash MX/Samples folder. Notice You may reuse these files as you want, but they are not officially supported as part of the product....

    在Amazon上按图搜索-crx插件

    For your comfort, we have removed the elements blocking access to images on Amazon. For example, on the product page, when the image is zoomed. You can search by an any image in internet, not only ...

    Agisoft Metashape Professional 1.5.3 Build 8407

    Agisoft Metashape (formerly PhotoScan) is a stand-alone software product that performs photogrammetric processing of digital images and generates 3D spatial data to be used in GIS applications, ...

    Delphi7.1 Update

    not all of the features mentioned in this file are available inall editions of the product.This update resolves the following issues:IDE* Using the up/down arrow keys to navigate and select items from...

    ICS delphixe10源码版

    in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. ...

Global site tag (gtag.js) - Google Analytics