Hi in some project i need to import the csv of products in that i have he values of product images is like
http://www.example.com/image.jpg
i need to import that by default there is no mechanism in magento to import external image.
for doinmg this we have to edit the import function in below file
app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php
around line 754 you will see some code like this
foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
if (isset($importData[$mediaAttributeCode])) {
$file = trim($importData[$mediaAttributeCode]);
if (!empty($file) && !$mediaGalleryBackendModel->getImage($product, $file)) {
$arrayToMassAdd[] = array('file' => trim($file), 'mediaAttribute' => $mediaAttributeCode);
}
}
}
you simply need to replace this dunction with the below one
foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
if (isset($importData[$mediaAttributeCode])) {
$file = trim($importData[$mediaAttributeCode]);
if (!empty($file) && !$mediaGalleryBackendModel->getImage($product, $file)) {
// Start Of Code To Import Images From Urls
if (preg_match('%http?://[a-z0-9\-./]+\.(?:jpe?g|png|gif)%i', $file)) {
$path_parts = pathinfo($file);
$html_filename = DS . $path_parts['basename'];
$fullpath = Mage::getBaseDir('media') . DS . 'import' . $html_filename;
if(!file_exists($fullpath)) {
file_put_contents($fullpath, file_get_contents($file));}
$arrayToMassAdd[] = array('file' => trim($html_filename), 'mediaAttribute' => $mediaAttributeCode);
}
else
{
$arrayToMassAdd[] = array('file' => trim($file), 'mediaAttribute' => $mediaAttributeCode);
}
// End Of Code To Import Images From URLs
}
}
}
Hope this will help you. thanks
http://www.example.com/image.jpg
i need to import that by default there is no mechanism in magento to import external image.
for doinmg this we have to edit the import function in below file
app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php
around line 754 you will see some code like this
foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
if (isset($importData[$mediaAttributeCode])) {
$file = trim($importData[$mediaAttributeCode]);
if (!empty($file) && !$mediaGalleryBackendModel->getImage($product, $file)) {
$arrayToMassAdd[] = array('file' => trim($file), 'mediaAttribute' => $mediaAttributeCode);
}
}
}
you simply need to replace this dunction with the below one
foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
if (isset($importData[$mediaAttributeCode])) {
$file = trim($importData[$mediaAttributeCode]);
if (!empty($file) && !$mediaGalleryBackendModel->getImage($product, $file)) {
// Start Of Code To Import Images From Urls
if (preg_match('%http?://[a-z0-9\-./]+\.(?:jpe?g|png|gif)%i', $file)) {
$path_parts = pathinfo($file);
$html_filename = DS . $path_parts['basename'];
$fullpath = Mage::getBaseDir('media') . DS . 'import' . $html_filename;
if(!file_exists($fullpath)) {
file_put_contents($fullpath, file_get_contents($file));}
$arrayToMassAdd[] = array('file' => trim($html_filename), 'mediaAttribute' => $mediaAttributeCode);
}
else
{
$arrayToMassAdd[] = array('file' => trim($file), 'mediaAttribute' => $mediaAttributeCode);
}
// End Of Code To Import Images From URLs
}
}
}
Hope this will help you. thanks
You have not specified that after doing this change which Import feature i have to use, is it System >> Dataflow Profiles >> Import/Export >> Import All Products or the System >> Import/Export ?
ReplyDeleteDataflow Profiles >> Import/Export
Deleteworked for me
it should work for both
Deletebut i will suggest you to use magmi now , it imports the image from the live url and its very fast as compare to the magento default data profile.
DeleteHere is the article how to import images from external URLs without codes (for non-technical people like me) -
ReplyDeletehttps://www.mag-manager.com/useful-articles/how-to/how-to-import-images-from-external-urls-to-magento/
HI Maria but in this we need to use the store manager to do this.
ReplyDeletethanks
not working in 1930. I have tried
ReplyDelete