I've been trying to find a way to add Photo to a customer profile in Magento.
They have everything but this, and I can't find anywhere how to do it.
Any help is appreciated.
I'm using Community edition.
To upload profile photo for customer in magento we need to follow few steps as below.
Add a new field for profile photo(How to create new fields for customer - Check this link it will helps you).
The above link helps you to add a new filed in DB and you need to upload that photo manually the below code will helps you to upload photos in magento.
if(isset($_FILES['logo']['name']) and (file_exists($_FILES['logo']['tmp_name'])))
{
try {
$uploader = new Varien_File_Uploader('logo');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS .'catalog/customer/logo/';
$newName = time() . $_FILES['logo']['name'];
$uploader->save($path, $newName);
$customer->setLogo($newName);
// actual path of image
$imageUrl = $path . $newName;
// path of the resized image to be saved
// here, the resized image is saved in media/resized folder
$imageResized = $path . $newName;
// resize image only if the image file exists and the resized image file doesn't exist
// the image is resized proportionally with the width/height 135px
if (!file_exists($imageResized)&&file_exists($imageUrl)) :
$imageObj = new Varien_Image($imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->resize(150, 150);
$imageObj->save($imageResized);
endif;
}catch(Exception $e) {
}
}
After upload we need to save file name in DB.
$customer->setLogo($newName);
Related
After exporting, changing some details and then importing a large number of products into Magento, I noticed all the images are no longer set. The images still exist in the media gallery for each product, but they are not set as the base image.
I've seen that in some cases, you need to copy images over to a /media/import/ folder, but is it possible to change the import file so that I can keep the images where they are?
Right now, all the images appear to be in a folder: /media/catalog/product/
Any help would be very appreciated.
Additionally, if it were possible to run a script that sets all product's base image to the first image in its gallery, that would work just as well. Thanks!
Let's say that you have load the products and you are ready to make a change and save them. With this code:
if (file_exists($imagePath)) {//New image file
//Load your media table
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
try {
//Now you have all the images available for your product
//if you previously have assign anything
$items = $mediaApi->items($product->getId());
//loop them
foreach ($items as $item) {
//With that line you can remove them if you want
echo ($mediaApi->remove($product->getId(), $item['file']));
}
} catch (Exception $exception) {
var_dump($exception);
die('Exception Thrown');
}
$cache = Mage::getSingleton('core/cache');
$cache->flush();
//You need that line
$product->setMediaGallery(array('images' => array(), 'values' => array()));
//That line assigns your new image.As base,thumbail and image.
//Use it in the loop if you want to reassign an existing image.
$product->addImageToMediaGallery($imagePath, array('thumbnail', 'small_image', 'image'), false, false);
I hope that helps you
Cheers!
I installed the plugin http://wordpress.org/plugins/automatic-featured-image-posts/ but I am having a problemm, because the plugin doesn't remove the original image from the post content after creating the featured image. (and therefore when I don't add the featured image there appear 2 images on the post)
I tried adding this to the auto-featured-image.php
add_action('publish_post', 'eliminaroriginal');
and then
function eliminaroriginal(){ //update the post without image
$post_parent_id = $post->post_parent === 0 ? $post->ID :
$post->post_parent; $contenido = preg_replace("/[caption
.+?[/caption]|\< [img][^>][.]*>/i", "", $post->post_content,
1); $mipost = array(); $mipost['ID'] = $post_parent_id;
$mipost['post_content'] = $contenido; wp_update_post( $mipost );
}
but it didn't have any result.
Please help me, I don't know what should I do.
Thank you before hand!
I want to show animated gif images for product .
Uploading gif image is posible but the same is not seen on frontend.
I saw the functionality due to cache in magento animated gif images is not seen.
How can I implement it ?
Check this link for reference.
Thanks in Advance.
You can implement it .
Though your caching functionality will not work for animated gif image.
copy file from
path : app/code/core/Mage/Catalog/Model/Product/Image.php
to
path : app/code/local/Mage/Catalog/Model/Product/Image.php
(create folders if necessary)Find the line public function getUrl() and replace the function with:
public function getUrl()
{
$baseDir = Mage::getBaseDir('media');
$file = ('gif' == strtolower(pathinfo($this->_baseFile, PATHINFO_EXTENSION))) ? $this->_baseFile : $this->_newFile;
$path = str_replace($baseDir . DS, "", $file);
return Mage::getBaseUrl('media') . str_replace(DS, '/', $path);
}
Hope this will help you.
i am trying to display product gallery images in my custom cms home page. If i use the code from media.phtml to display the gallery images, it does not work. I found this piece of code and it worked.
<div id="thumbs" class = "thumbs-home">
<?php
$obj = new Mage_Catalog_Block_Product_View_Media();
$_product1 = new Mage_Catalog_Model_Product();
// Load all product information of a particular product
$Products_one = Mage::getModel('catalog/product')->load($productId);
// Use your Product Id instead of $id
$countt = count($Products_one->getMediaGalleryImages());
if($countt>0){
foreach ($Products_one->getMediaGalleryImages() as $_image)
{
// For the Original Image
$thumb_img = "<img src=".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"",$_image->url)." alt=''width='60' height='60' />";
echo "<a href='".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"",$_image->url)."'rel='lightbox[gallery]'>".$thumb_img."</a>";
//For gallery Image
//$resizeimage = $obj->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->backgroundColor(242,242,243)->resize(400,300);
//echo "<img src=".$resizeimage."alt='' />";
}
}
?>
This gets the actual images and gets resized by the width and height attributes. But i want to resize the image through magento. The last piece of code $resizeimage is not working for some reason. How can i make this work? The problem is that i am using a lightbox to display the gallery images which displays the actual high resolution images that are too large. The light box takes in width and height of image provided and i am not able to figure out as to how i set a standard dimensions for the light box. So the only other option is the have the images resized by magento before passing them to the lightbox. Thanks.
You just need to call proper object, instead of $obj->helper you should use Mage::helper, so your call should look like this:
print Mage::helper('catalog/image')
->init($product, 'thumbnail', $image->getFile())
->backgroundColor(255,255,255)
->resize(100,100);
And that's it! :)
I am trying to add images under the cms/pages/homepage for magento version 1.5.1.0 However, when I click on content-->show/hide editor / followed by insert image -> create directory and then hit refresh the directory disappears from the list. Furthermore, the images will not upload on the front end or on the backend when I cilck on show/hide editor, after hitting insert?
If any one has an ideas that would be great?
Thanks for your time,
Teli
I've got the same problem. You can find the solution here:
http://www.magentocommerce.com/boards/viewthread/220720/P15/#t349314
Open the file:
app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php
Around line 62 comment out
FROM
$subDirectories = Mage::getModel('core/file_storage_directory_database')->getSubdirectories($path);
foreach ($subDirectories as $directory) {
$fullPath = rtrim($path, DS) . DS . $directory['name'];
if (!file_exists($fullPath)) {
mkdir($fullPath, 0777, true);
}
}
to:
/* $subDirectories = Mage::getModel('core/file_storage_directory_database')->getSubdirectories($path);
foreach ($subDirectories as $directory) {
$fullPath = rtrim($path, DS) . DS . $directory['name'];
if (!file_exists($fullPath)) {
mkdir($fullPath, 0777, true);
}
}*/
Note: To make it in the better way without edit the core of Magento, create the same file and folder structure under the local folder, so the new file with the modification must go to app/code/local/Mage/Cms/Model/Wysiwyg/Images/Storage.php