Magento Importer Images - image

I'm trying to import images in the magento importer but nothings appearing. I've gone through all the threads and I'm sure I've done everything I'm supposed to do and now I'm at a complete loss for what the problem could be.
I've created a folder called "import" in my "media" folder and placed the image 'blog-1.jpg' in it and my data is saved in a .csv and it looks similar to this: (i've copied the entries manually for readability)
sku - test1
name - test1
description - Test
short_description - Test
status - 1
visibility - 4
tax_class - 2
qty - 1
price - 1
weight - 1
image - /blog-1.jpg
image_label - Hello
small_image - /blog-1.jpg
small_image_label - Hello
thumbnail - /blog-1.jpg
thumbnail_label - Hello
When I "check" my data it says the data is fine and its found a field. Everything else gets imported correctly but when I click on "images" it has no images in there.

First of all your image are store in media>import folder.
Then in your csv file just write in image column /imagename.jpg
It will find same imagename in import folder if image exist then it will upload the image.
I'm sorry to say, but there is more going on behind the scenes with magento images that it simply putting a filename in the database and linking to your image. The cache generation alone is pretty complex. I believe you are going to have a hard time doing it the way you are attempting.
That being said, I do have a suggestion. Since your images are already on the server, I suggest you write a simple php script to tell magento to attach them to the product image. This could be automated, but i'll give you a small example below...
To attach an image, you would simply navigate to the url like this http://yoursite.com/imageattacher.php?sku=YOURSKU&image=yourimagefilename.jpg
The script would be like this... create a file in your magento ROOT and call it imageattacher.php. Upload your images to the magento media import directory. I have not tested this but it should work.
<?php
// Initialize magento for use outside of core
umask(0);
require_once 'app/Mage.php';
Mage::app('admin');
// Get the variables from the URL
$sku = $_GET["sku"];
$imageName = $_GET["image"];
// get the image from the import dir
$import = Mage::getBaseDir('media') . DS . 'import/' . $imageName;
// Load the product by sku
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
// if the product exists, attempt to add the image to it for all three items
if ($product->getId() > 0)
{
// Add the images and set them for their respective usage (the radio button in admin)
$product->addImageToMediaGallery($import,array('image', 'small_image', 'thumbnail'),false,false);
// Make the changes stick
$product->save();
}
?>

Related

Displaying multiple images from scene7 image set on category image

I have taken over a site and am looking for some assistance.
The site currently detects if a product has a scene7 image set associated to it, and then adds IS to the code to display the image set.
I am trying to do this for category image as well, if I hardcode _IS (product sku + _ID) the image set is loaded nicely, but obviously any product sku with no image set, the image doesn't load.
This is the code with the _IS hardcoded:
flyoutViewer.setAsset("/${catalogEntryDetails.partNumber}_IS");
This snippet of code detects whether there is a set or not:
var asset = '/' + wc.render.getContextById('ItemDetailsContext').properties.partNumber;
if (data['catalogRecord.exists'] == 1) {
asset += 'IS';
}
Am I missing something major? My guess I am, I can dig out more code if necessary.
Help would be appreciated?!

Showing a default Image in a CakePHP application

I am working in a CakePHP application, where I am using HTML helper's image() function to show images. What I want, if it gets the image in the given path, then it will show the image, otherwise, it'll show a default image. I have that "default" image, but I don't understand where/how to define it.
Thanks
Extend the HTML helper and add the logic to the image method and override the called image with your default image if the originally requested image does not exist.
index.ctp file code
<?php
$MyImage = $post['Post']['image0']; // image0 is my db field
if (file_exists("img/uploads/posts/".$MyImage))
$MyImage1 ="/img/uploads/posts/".$MyImage;
else
$MyImage1 = "/img/uploads/posts/no-image.jpg";
echo $this->Html->image($MyImage1);
?>
Note : My post's images are stored in app/webroot/img/posts folder(default image is also in this folder.)

Magento 1.7 - Product Import - Images do not load

I have been trying to import products into Magento and images. The products are being imported and created properly but the images to not get imported.
I am aware of the basics of importing as I have done it in the past but cannot figure out what the issue is and what to do next.
some notes how and what I did:
I am aware to add a "/" before the image name
image name is case sensitive
upload images in media/import folder
media folder to be 777
Tried different folders like var/import or
media/catalog/product/import
Removed the .htcaccess file in media
Flushed cache
when i upload manually an image on a product it does show up properly
i tried specifying the _media_attribute_id in a column as 88 maybe
that should help but it didn't
If you have a Mage_Catalog_Model_Product, all you need to do is this:
$fn = '/absolute/path/to/image.jpg';
$types = array('thumbnail', 'small_image', 'image'); // or null if you already have the product's thumbnail, small image, and image set
$move = true; // move the source file, don't leave it sitting around
$exclude = false; // enabled in product view
$label = 'Turquoise';
$product->addImageToMediaGallery($fn, $types, $move, $exclude); // Strictly speaking, only the first parameter is required
if(!empty($label)) {
$gallery = $product->getData('media_gallery');
$gallery_img = array_pop($gallery);
$gallery_img['label'] = $label;
array_push($gallery['images'], $gallery_img);
$product->setData('media_gallery', $gallery);
}
$product->save();
I have faced the same problem while uploading product image. And i tested many methods to figure that out. But nothing helped me. At last in one of the tutorial I have seen that the image name and the sku name has to be same. with the extension of file extension. So i followed it and by God's grace it worked. You may try that also. It worked for me. I had spent almost one full day to figure that out.

Magento Order PDF logo function

I'm using an add Print order button to print a customer's order (not invoice) and I can't figure out how to get the logo to show up on the pdf. The following is the code that is in the extension but I can't find the function to manipulate it and I don't understand why it's not pulling the logo that I have in configuration. Please advise. :)
$this->insertLogo($page, $order->getStore());
You probably don't have store logo for PDF set. In admin you should go to
System -> Configuration -> Sales -> Sales -> Invoice and Packing Slip Design
and set your logo there.
Now for the logn explanation in case the above won't work :)
insertLogo function is located in class Mage_Sales_Model_Order_Pdf_Abstract (I asume that your class derives from it).
The rows that you should note are $image = Mage::getStoreConfig('sales/identity/logo', $store); and $image = Mage::getBaseDir('media') . '/sales/store/logo/' . $image;
getStoreConfig function is looking for the name of logo image in core_config_data table. You can check if the value is set with
SELECT * FROM core_config_data WHERE path = 'sales/identity/logo'
If the query won't return anything or will return value that is not an image name then you'll have to set that value first.
If that value is set you should have a look in
/your_store_root_dir/media/sales/store/logo/value_that_is_in_the_database
to see if the store logo image realy exists and if it doesn't add it there.
Did you check code in that class ($this) and/or its parent class? You'll see function inserLogo there.

Image issue inside PDF loop

I'm using DOMPDF to generate PDF's that can contain images and I'm having a weird issue with that.
The PDF is generated inside a loop and the amount of PDF's that needs to be generated varies. When there is only 1 PDF generated everything goes well. The image (or logo in this case) is getting inserted beautifully.
But when there are 2 or more PDF's that have to be generated for some reason the image is replaced with a red cross. But: the image in the first PDF generated in that batch works perfectly. So: the image in PDF #1 loads perfectly, the image in PDF #2 and up is getting replaced with a red cross.
I'm using the latest stable release of DOMPDF (v0.5.2). I've also tested with v0.5.1 but that had the same behaviour.
The server I'm testing this on runs on Linux, with PHP 5.3.8. No errors in the error-log about this (and I do have error logging enabled).
--- edit:
The "path" to the image is an absolute URL, not an absolute or relative (PHP) path and with outputting the contents of the loop to the browser (or a normal HTML email, without the PDF attachment) it displays the image (in all mails) perfectly.
--- edit2:
Using a function to flush all buffers at the end of the loop (which, unfortunately, doesn't change anything to my issue):
function flush_buffers()
{
ob_end_flush();
ob_flush();
flush();
ob_start();
}
An example of the loop I'm using:
for ( $i = 0; $i < count($cert); ++$i )
{
// load the email-template
ob_start();
include($template);
$content = ob_get_contents();
ob_end_clean();
// require dompdf
include_once('dompdf/dompdf_config.inc.php');
// set PDF path - inside temp dir
$newpdf = trailingslashit(realpath(sys_get_temp_dir())).$cert[$i]['coupon'].'.pdf';
// replace shortcodes with wanted content
$certificate = preg_replace($shortcodes, $replacements, $certificate);
$certificate = '<html><body>'.$certificate.'</body></html>'."\n";
$dompdf = new DOMPDF();
$dompdf->load_html($certificate);
$dompdf->set_paper($pageformat, $orientation);
$dompdf->render();
save_pdf($newpdf, $dompdf->output()); // save PDF
#flush_buffers();
}
One of the shortcodes is [logo] and that's getting replaced with an img-tag. As I previously mentioned: that image works fine in the first PDF, but not in the other PDF's.
Upgrading to dompdf 0.6beta2 fixed this issue. Thanks Fabien!

Resources