【发布时间】:2014-03-28 14:56:56
【问题描述】:
我在图像更新方面遇到了一个重大问题。
我正在使用此代码:
public function __construct(){
...
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$this->product = Mage::getModel('catalog/product')->loadByAttribute('sku',$this->artnr);
}
/**
* Update Images
*/
protected function updateImages(){
//Remove Existing Images to Reupload them
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
try{
$items = $mediaApi->items($this->product->getId());
foreach($items as $item){
$mediaApi->remove($this->product->getId(),$item['file']);
$unlinkImage = Mage::getBaseDir('media').DS.'catalog'.DS.'product'.$item['file'];
@unlink($unlinkImage);
}
}catch(Exception $e){
Mage::log($e->getMessage());
}
if(count($this->import['shop']['images'])>0){
//write images into directory
//and run Import
$currentimage = 0;
$mediaAttribute = array(
'thumbnail',
'small_image',
'image'
);
if(count($this->import['shop']['images'])>0){
foreach($this->import['shop']['images'] as $image){
$file = $this->importDir.$image['image_name'];
file_put_contents($file,$image['image']);
if($currentimage===0){
$this->product->addImageToMediaGallery($file,$mediaAttribute,false,false);
}else{
$this->product->addImageToMediaGallery($file,null,false,false);
}
$currentimage++;
}
}
}
}
当我输出媒体库时
Mage::log($this->product->getMediaGallery());
我得到这个输出:
[images] => Array
(
[0] => Array
(
[file] => /5/d/5de102a28622997e5eba689689878570_5.jpg
[position] => 1
[label] =>
[disabled] => 0
)
[1] => Array
(
[file] => /C/o/Cookie_4_1.png
[position] => 2
[label] =>
[disabled] => 0
)
[2] => Array
(
[file] => /p/o/post2_16_1.jpg
[position] => 3
[label] =>
[disabled] => 0
)
)
到目前为止一切顺利。 但如果我查看媒体库数据库,我会得到:
784|703|244|/5/d/5de102a28622997e5eba689689878570_5.jpg|
785|703|244|/C/o/Cookie.png
786|703|244|/p/o/post2.jpg
787|703|244|/5/d/5de102a28622997e5eba689689878570_5_1.jpg
788|703|244|/C/o/Cookie_1.png
789|703|244|/p/o/post2_1.jpg
所以它们以双精度存储。 文件只存储一次。 如果我查看后端,我会看到一个存在,一个不存在......
我不知道我在哪里弄错了,希望有人能帮助我。
【问题讨论】:
-
没人吗?嗯,我真的可以在这方面使用帮助。
标签: php mysql image magento e-commerce