Magento return wrong media url on frontend - php

Im stuck on wired situation. The thing i do is getting magento blog data and show on specific page. The problem is magento return the wrong media URL on front end like this <img alt="" src="{{media url=" wysiwyg="" blogimg1.jpg"}}"="">. All i want it will return image src like this "mydomain.com/images/blogimg1.jpg". I try to find solution but couldnot succeed.
My code is below
<?php
$collections = Mage::getModel('blog/blog')->getCollection()
->addPresentFilter()
->addEnableFilter(AW_Blog_Model_Status::STATUS_ENABLED)
->addStoreFilter()
->joinComments()
->setOrder('created_time', 'desc');
foreach ($collections as $collection) {
echo $collection->title."<br>";
echo $collection->post_content."<br>";
echo $collection->short_content."<br>";
}
?>

Problem solve we have to use the filter , and everything gonna fine
Mage::helper('cms')->getPageTemplateProcessor()->filter($collection->short_content)

Related

Change default user profile URL - BBpress Plugin

Bbpress Wordpress Plugin have default link user profile url. The link like this: www.example.com/forum/users/(username)
The main purpose in nutshell is: I want to change the url.
Actually, I found the solution but its not perfect. The code like this:
function user_profile_link(){
$url = 'http://localhost/example.com/profile/';
$author_id = bbp_get_reply_author_id();
$user_info = get_userdata($author_id);
echo ' '. $user_info->display_name.' ';
}
add_filter('bbp_get_user_profile_url', 'user_profile_link');
Yes, the code working well. But the outcome is, the user profile URL not replaced and there is double URL like this image below:
image1
I think the problem solved if I display: none it. The code like this:
<style>
.bbp-author-link{
display: none;
}
</style>
But there is one problem. The new URL that I make appeared beside the breadcrumbs like this image:
image2
I want to remove the link that appeared beside the breadcrumbs. Is there any solution? Any help is appreciated. Thank You
In a filter hook, you normally have to override the current value by returning it. Therefore try returning the new value by using the function you already created. It may remove the duplicate.
Also, use site_url() instead of $url variable because there will be issues when you use a hardcoded URL.
function user_profile_link(){
$author_id = bbp_get_reply_author_id();
$user_info = get_userdata($author_id);
return site_url()."/profile/".$user_info->user_login;
}
add_filter('bbp_get_user_profile_url', 'user_profile_link');
For this problem, I found the solution.
The code is like this:
function user_profile_link(){
$author_id = bbp_get_reply_author_id();
$user_info = get_userdata($author_id);
$url = site_url()."/profile/".$user_info->user_login;
return $url;
}
add_filter('bbp_get_user_profile_url', 'user_profile_link');

Set Base Image Programmatically

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.
Below you can see an overview of my goal.
I am trying to sell Similar product in my magento for this i wrote some code that every thing is working fine..
But i have only one problem with images..
that is I am getting all images of current product but the base image is not selected, How can i set the very first image as base image Programmatically.
Any ideas ?
Hello You can do as follows :
$image =$imagePath."image.png";
$product->setMediaGallery(array('images'=>array (), 'values'=>array ()));
if(is_file($image))
{
$product->addImageToMediaGallery($image, array ('image', 'small_image', 'thumbnail'), false, false);
}
i.e you need to first set the media gallery, P.S This is a necessary step.
then add all images to gallery using addImageToMediaGallery where 'image' ref to 'base_image'
i.e in above example we are setting image.png to base_image, small_image and thumbnail image in a single call.
hope this helps you.
I've achieved the same result by using:
$product->setSmallImage($path)
->setThumbnail($path)
->setImage($path)
->save();
Works better for the case where your media gallery has one or more pictures in it.
I'm doing
$product->load();
$gallery = $product->getMediaGalleryImages();
$paths = array();
foreach ($gallery as $image) {
$paths[] = $image->getFile();
}
sort($paths);
$path = array_shift($paths);
try {
$product->setSmallImage($path)
->setThumbnail($path)
->setImage($path)
->save();
} catch (Exception $e) {
echo $e->getMessage();
}
Which gets all the product images, sort's them by file name and sets the first to the product primary image. As I ran a import and added all my pictures, but didn't set the primary image.
To grab a set or "broken" products I used:
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter('small_image', array('eq' => ''));

Magento: How to get thumbnail?

I downloaded a script to create a CSV datafeed of my products and I would also like to include a url to the thumbnail. The code already has the following for the product image url:
$product_data['ImageURL']=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();
So I tried to adjust this to:
$product_data['ThumbnailURL']=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getThumbnail();
Which displays exactly the same image url (not the thumb). How would I fix this?
I did a var_dump($product); and the result was:
["image"]=> string(18) "/f/i/file_2_18.png" ["small_image"]=> string(18) "/f/i/file_2_18.png" ["thumbnail"]=> string(18) "/f/i/file_2_18.png"
I also need to get the subcategory for the product but I don't know how to call this. How can I see which variables are possible? E.g. $product->getPrice or $product->getName?
I recently needed to do this as well... here's how I got to it:
$_product->getMediaGalleryImages()->getItemByColumnValue('label', 'LABEL_NAME')->getUrl();
Or another example
You should use the catalog product media config model for this purpose.
<?php
//your code ...
echo Mage::getModel('catalog/product_media_config')
->getMediaUrl( $product->getImage() ); //getSmallImage(), getThumbnail()
Edit After your comment.
Update Answer
See below URL
Make all store images the base, small and thumbnail images in Magento?
Try it
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
if (!$product->hasImage()) continue;
if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
$product->save();
}
Hope that helps you!
If you want to see which data you can access you could try this:
<?php var_dump(array_keys($product->getData())); ?>
You can then use two methods to get this data:
<?php $product->getAttributeName() // Use CamcelCase ?>
or
<?php $product->getData('attribute_name') // underscores ?>

CakePHP and Lightview JQuery Plugin: Increment View Count

I am using the following plugin in my webpage:
http://www.nickstakenburg.com/projects/lightview/
The script works great in terms of displaying the photos and everything else it is supposed to do, however, I would like to accomplish the following I havent been able to:
Have the plugin increment view count everytime an image is displayed
I have created the following action in my photo.php model, but I can't figure out a way to call using the Plugin:
function incrementViewCount($id) {
$this->updateAll(
array('Photo.viewed' => 'Photo.viewed+1'),
array('Photo.id' => $id)
);
}
I have it setup per the following on my site:
<?php
foreach ($photocategory['Photo'] as $photo){
?>
<li>
<a
href="/img/uploads/photos/<?php echo photo['photocategory_id']."/".$photo['image']; ?>"
class="lightview"
data-lightview-group="shared_options"
>
<img
style="width:155px;height:113px;"
src="/img/uploads/photos/<?php echo $photo['photocategory_id']."/thumb/".$photo['image']; ?>"
alt=""
/>
</a>
</li>
<?php } ?>
If anyone knows anything about this plugin or jQuery and if you can suggest a way to accomplish this, it would be great!
If you are using CakePHP this
https://github.com/sliker/CakePHP-Counter-Plugin may help.
Has simple call methods for incrementing counter.

Grabbing a custom product image label in Magento?

I have a block on my front page that is grabbing the two newest products with a custom product image called image_feature_front_right.
I use this code as the query:
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getModel("catalog/product")->getCollection();
$_productCollection->addAttributeToSelect('*');
$_productCollection->addAttributeToFilter("image_feature_front_right", array("notnull" => 1));
$_productCollection->addAttributeToFilter("image_feature_front_right", array("neq" => 'no_selection'));
$_productCollection->addAttributeToSort('updated_at', 'DESC');
$_productCollection->setPageSize(2);
I am able to get:
the image: echo $this->helper('catalog/image')->init($_product, 'image_feature_front_right')->directResize(230,315,4)
the product url: echo $_product->getProductUrl()
the product name: $this->stripTags($_product->getName(), null, true)
The only thing I am unable to get is the custom images label. I have tried echo $this->getImageLabel($_product, 'image_feature_front_right'), but that seems to do nothing.
Can anyone point me in the right direction?
Thanks!
Tre
I imagine this is some sort of magento bug. The issue seems to be that the Magento core is not setting the custom_image_label attribute. Whereas for the default built-in images [image, small_image, thumbnail_image] it does set these attributes - so you could do something like:
$_product->getData('small_image_label');
If you look at Mage_Catalog_Block_Product_Abstract::getImageLabel() it just appends '_label' to the $mediaAttributeCode that you pass in as the 2nd param and calls $_product->getData().
If you call $_product->getData('media_gallery'); you'll see the custom image label is available. It's just nested in an array. So use this function:
function getImageLabel($_product, $key) {
$gallery = $_product->getData('media_gallery');
$file = $_product->getData($key);
if ($file && $gallery && array_key_exists('images', $gallery)) {
foreach ($gallery['images'] as $image) {
if ($image['file'] == $file)
return $image['label'];
}
}
return '';
}
It'd be prudent to extend the Magento core code (Ideally Mage_Catalog_Block_Product_Abstract, but I don't think Magento lets you override Abstract classes), but if you need a quick hack - just stick this function in your phtml file then call:
<?php echo getImageLabel($_product, 'image_feature_front_right')?>

Categories