Removing the placeholder images for Product Tags using WooCommerce Predictive Search - image

I am using the predictive search to look for products and using PRO it searches for product tags as well, which is great. However, it still shows the placeholder (like a broken image link box) for the tags. I am simply wanting to remove the placeholder for tags only.
Anyone have an idea of the 'IF' statement I would use and where I would apply it? Again, it would only be for the product tags, I still would like the product itself to show the thumbnail images.

In the Wordpress plugins directory open the predictive search folder then open the classes folder. In the file class-wc-predictive-search-filter.php on line 331 you will see a foreach loop
foreach ( $search_tags as $item ) {
$link_detail = get_term_link($item->slug, 'product_tag');
$avatar = WC_Predictive_Search::woops_get_product_cat_thumbnail($item->term_id,64,64);
$item_html = '<div class="ajax_search_content"><div class="result_row"><span class="rs_avatar">'.$avatar.'</span><div class="rs_content_popup"><span class="rs_name">'.stripslashes( $item->name).'</span><span class="rs_description">'.WC_Predictive_Search::woops_limit_words(strip_tags( str_replace("\n", "", $item->description) ),$text_lenght,'...').'</span></div></div></div>';
$rs_items['p_tag'] .= $item_html.'[|]'.$link_detail.'[|]'.stripslashes( $item->name)."\n";
$end_row--;
if ($end_row < 1) break;
}
}
}
you will need to remove
<span class="rs_avatar">'.$avatar.'</span>
so the foreach loop reads
foreach ( $search_tags as $item ) {
$link_detail = get_term_link($item->slug, 'product_tag');
$avatar = WC_Predictive_Search::woops_get_product_cat_thumbnail($item->term_id,64,64);
$item_html = '<div class="ajax_search_content"><div class="result_row"><div class="rs_content_popup"><span class="rs_name">'.stripslashes( $item->name).'</span><span class="rs_description">'.WC_Predictive_Search::woops_limit_words(strip_tags( str_replace("\n", "", $item->description) ),$text_lenght,'...').'</span></div></div></div>';
$rs_items['p_tag'] .= $item_html.'[|]'.$link_detail.'[|]'.stripslashes( $item->name)."\n";
$end_row--;
if ($end_row < 1) break;
}
}
}

Related

In Magento,how can i add different image for same product that was assigned to more than one category,When it is in different categories

I Have a product for example,t-shirt that is added to men's category and women's category.Now I want to display a woman's image of that t-shirt on women's category & man's t-shirt image in men's category.
Is there any possiblities for the above without creating the same product again.
If possible kindly provide idea for it.
Ok fair enough. Here's a quick solution to your problem. It's a bit scrappy, but you get the idea. In this example I assume your ladies category has an ID of 123, and the image you want to show in the ladies category is the product's second image;
$otherImage = false;
$catId = 123; // The id of the category to show a different image on
$imageNumber = 2; // The position in the gallery of the image you want to show
$currentCatId = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId();
if($currentCatId == $catId) { // This is the category you wanted
$count = 1;
$gallery = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();
foreach ($gallery as $image):
if($count == $imageNumber) {
// This is the image you want
$otherImage = $this->helper('catalog/image')->init($_product, 'image', $image->getFile())->resize(180);
}
$count++;
endforeach;
}
if($otherImage) { echo '<img src="'.$otherImage.'" />'; } else { echo '<img src="'.$this->helper('catalog/image')->init($_product, 'small_image')->resize(180).'" />'; }
There is no native way to do this in Magento. Product images can be set per store view but not per category. I can think of various ways you could achieve this, but unless your portfolio is huge, I would recommend you either use a unisex image (maybe both male and female) or create a separate product for each gender.
T

Drupal 8 images with image style

In drupal 7, i use function image_style_url('style', uri) to generate new image with style and return image's path. so what will be instead of it in drupal 8? thanks
Per the change records:
use Drupal\image\Entity\ImageStyle;
$path = 'public://images/image.jpg';
$url = ImageStyle::load('style_name')->buildUrl($path);
You should try to use the new Drupal functions wherever possible.
Instead, use:
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
$fid = 123;
$file = File::load($fid);
$image_uri = ImageStyle::load('your_style-name')->buildUrl($file->getFileUri());
Edited as per https://www.drupal.org/node/2050669:
$original_image = 'public://images/image.jpg';
// Load the image style configuration entity
use Drupal\image\Entity\ImageStyle;
$style = ImageStyle::load('thumbnail');
$uri = $style->buildUri($original_image);
$url = $style->buildUrl($original_image);
In your Controllers and other OOP part of Drupal you can use :
use Drupal\image\Entity\ImageStyle;
$path = 'public://images/image.jpg';
$url = ImageStyle::load('style_name')->buildUrl($path);
And in YOUR_THEME.theme file while Error: Class 'ImageStyle' not found in YOURTHEMENAME_preprocess_node you can do it with the follwing
$path = 'public://images/image.jpg';
$style = \Drupal::entityTypeManager()->getStorage('image_style')->load('thumbnail');
$url = $style->buildUrl($path);
Another method is provide a renderable array and let the drupal Render engine render it.
$render = [
'#theme' => 'image_style',
'#style_name' => 'thumbnail',
'#uri' => $path,
// optional parameters
];
I have found that I often want to preprocess the image to apply an image style to an image on a node or a paragraph type. In many cases I have created a paragraph that allows the user to choose the width of the image as a percentage. In the preprocess I would check the value of the width and apply the correct image style.
use Drupal\image\Entity\ImageStyle;
function THEME_preprocess_paragraph__basic_content(&$vars) {
//get the paragraph
$paragraph = $vars['paragraph'];
//get the image
$images = $paragraph->get('field_para_image');
//get the images value, in my case I only have one required image, but if you have unlimited image, you could loop thru $images
$uri = $images[0]->entity->uri->value;
//This is my field that determines the width the user wants for the image and is used to determine the image style
$preset = $paragraph->get('field_column_width')->value;
$properties = array();
$properties['title'] = $images[0]->getValue()['title'];
$properties['alt'] = $images[0]->getValue()['alt'];
//this is where the Image style is applied
switch($preset) {
case 'image-20':
$properties['uri'] = ImageStyle::load('width_20_percent')->buildUrl($uri);
break;
case 'image-45':
$properties['uri'] = ImageStyle::load('width_45_percent')->buildUrl($uri);
break;
case 'image-55':
$properties['uri'] = ImageStyle::load('width_55_percent')->buildUrl($uri);
break;
case 'image-100':
$properties['uri'] = ImageStyle::load('width_100_percent')->buildUrl($uri);
break;
}
//assign to a variable that the twig template can use
$vars['basic_image_display'] = $properties;
}
In this example, I am preprocessing a specific paragraph type named "basic_content" but you can do the same thing with a node preprocess. Continuing my example, I would have a twig template named paragraph--basic_content.html.twig to handle the display of that paragraph type.
Displaying the image would be something like this in the twig file.
<img class="img-responsive" src="{{basic_image_display['uri']}}" alt="{{ basic_image_display['alt'] }}" title="{{ basic_image_display['title'] }}"/>
$view_mode = $variables['content']['field_media_image']['0']['#view_mode'];
$display_content = \Drupal::service('entity_display.repository')
->getViewDisplay('media', 'image', $view_mode)->build($media_entity);
$style = ImageStyle::load($display_content['image'][0]['#image_style']); $original_image = $media_entity->get('image')->entity->getFileUri();
$destination = $style->buildUri($original_image);
This is how you get image style from a media image entity.
Works for me from a classic Drupal database Query in .module file :
$query = \Drupal::database()->select('file_managed', 'f' );
$query->addField('f', 'uri');
$pictures = $query->execute()->fetchAll();
foreach ($pictures as $key => $picture) {
$largePictureUri = entity_load('image_style', 'large')->buildUrl($picture->uri);
}
I used in Drupal 8 this code. It's working fine.
$fid = 374; //get your file id, this value just for example
$fname = db_select('file_managed', 'f')->fields('f', array('filename'))->condition('f.fid', $fid)->execute()->fetchField();
$url = entity_load('image_style', 'YOUR_STYLE_NAME')->buildUrl($fname);

Joomla pagination across different components

Because pagination is using getUserStateFromRequest method to get the limit and limitstart variable, I'm having a problem where as I navigate from one component to another, I'm shown a no items found message.
To clarify, I have a products component that has 3 pages worth of products listed. Then I have a branches component with 2 pages worth of branch information. So if I navigate to the third page in the products list, and then go to the branches component, nothing is displayed.
Has anyone any idea how to stop this from happening? Any way to maybe clear the session data?
What I ended up doing was this,
in line 624 in libraries/joomla/application/application.php file I added the following lines
$this->setUserState('option','default');
$curr_comp = JRequest::getCmd( 'option' );;
if($this->getUserState('option') != $curr_comp)
{
$this->setUserState($option . 'limitstart',0);
$this->setUserState('option',$curr_comp);
}
so the whole function reads this,
public function getUserStateFromRequest($key, $request, $default = null, $type = 'none')
{
$this->setUserState('option','default');
$curr_comp = JRequest::getCmd( 'option' );
if($this->getUserState('option') != $curr_comp)
{
$this->setUserState($option . 'limitstart',0);
$this->setUserState('option',$curr_comp);
}
$cur_state = $this->getUserState($key, $default);
$new_state = JRequest::getVar($request, null, 'default', $type);
// Save the new value only if it was set in this request.
if ($new_state !== null)
{
$this->setUserState($key, $new_state);
}
else
{
$new_state = $cur_state;
}
return $new_state;
}
This seems to be working fine at the moment. But please test before implementing on a live site
To prevent editing the core files, but with the effect limited to your extension (so other extensions could load at the wrong page, but not yours), and if your model extends modellist, override the getStart() method:
public function getStart()
{
$store = $this->getStoreId('getstart');
$input = JFactory::getApplication()->input;
$start = $limitstart = $input->getInt('limitstart', 0);
$this->setState('list.start', $limitstart); // maybe redundant
$limit = $this->getState('list.limit');
$total = $this->getTotal();
if ($start > $total - $limit)
{
$start = max(0, (int) (ceil($total / $limit) - 1) * $limit);
}
// Add the total to the internal cache.
$this->cache[$store] = $start;
return $this->cache[$store];
}
If you want a solution that works system-wide and for all extensions, you should be able to override modellist with your implementation in a plugin. Start here.
This is an old question, but I just had the same issue as the OP, but in my case with Joomla 3.4.3.
After a lot of digging and testing, I discovered a solution for this that doesn't involve any plugin or core change:
If you put limitstart=0 in the URL, the pagination will restart for that page, and this solves the problem between menus.
The way to implement this could be either with javascript, or by overriding the menu module, I chose the override:
I just need this in some menus, so I placed a CSS class into the
menu link (edit the menu, and in the "Link Type" tab, place the CSS
class in the "Link CSS Style" field), in my case it was "
video-area" (without the quotes).
Add override (add the module to the html folder of your template,
in my case it was the menu module, so it was a matter of adding the
mod_menu folder: templatefolder/html/mod_menu)
In the override of the component part of the module
(default_component.php), check to see if we have the CSS class, if
so, add the extra query to the URL (I edited case 0):
case 0: $paginationLinks = ""; if(isset($class) && strpos($class, '
video-area') !== false){ $paginationLinks =
"?limitstart=0&limit=12"; } ?><a <?php echo $class; ?>href="<?php
echo $item->flink; ?><?php echo $paginationLinks;?>" <?php echo
$title; ?>><span><?php echo $linktype; ?></span></a><?php break;
That's it! it solved my problem, and even the pagination links have the extra query :)
BONUS: notice that I have &limit=12, this changes the limit for the pagination into 12 per page, without any extra code!, (before, I had a lot of code to implement this, and by adding this to the menu it calculates the correct page number and totals, and filters the query, nice one Joomla!)

Determining which section is being viewed

Folks, I am trying to implement a rudimentary feature in Joomla but having no luck getting my head around it.
My client has setup Joomla with several sections; each section having its own categories and eventually content underneath.
I need each section to have a slightly different color component (e.g. Section A and its all subsequent child pages red, Section B - blue, etc); certain borders and backgrounds need to be unique according to each section.
I have one theme which is used by all sections. Somewhere in the theme file, I need to detect which section I am on, and based on that set a css variable accordingly:
<html>
<body class="cars-section">
</body>
</html>
All I need is to set my body's class to the right section, and all my coloring has been setup to work magically.
Any ideas how this can be done in the Joomla world? Is there another way of doing such a thing.
You need to pick the section ID up from the request.
Use this to get the relevant request variables:
<?php
$option = JRequest::getWord('option', null);
$view = JRequest::getWord('view', null);
$idalias = JRequest::getVar('id', null);
if (strpos($idalias, ":") != false) {
$idandalias = explode(":", $idalias);
$id = $idandalias[0];
} else {
$id = JRequest::getInt ('id' , 0);
}
Then use something like this to see what section you are in, if you are on a section page:
if ( $option=="com_content" && $view=="section" ) {
$sectid = $id;
}
In section pages you can just use the request, but in other pages you need to do a database query as well:
else {
$database =& JFactory::getDBO();
if ( $option=="com_content" && $view=="category" ) {
$query = "SELECT section FROM jos_categories WHERE id=$id";
}
if ( $option=="com_content" && $view=="article" } {
$query = "SELECT sectionid FROM jos_content WHERE id=$id";
}
$database->setQuery($query);
$sectid = $database->loadResult();
}
When you have the section ID you can use it to set and insert the right class.
if ( $sectid == '3' ) {
$my_cars_section_class = 'three';
}
?>
<body class="<?php echo $my_cars_section_class; ?>">
Something like that should do it.
There are a couple of ways to achieve body css-classing:
Utilize Joomla's menu page class suffix system.
Output the class based on the selected menu link from within the template. Of course, if you plan to do this, you'll need to modify your template a bit.
$menu = &JSite::getMenu();
$active = $menu->getActive();
<body <?php if($active->alias) echo 'class="' .$active->alias .'"' ?>>

WordPress plugin: finding the <!--more--> in the_content

I'm writing a WordPress plugin that filters the_content, and I'd like to make use of the <!--more--> tag, but it appears that it has been stripped out by the time it reaches me. This appears to be not a filter, but a function of the way WordPress works.
I could of course resort to reloading the already-loaded content from the database, but that sounds like it might cause other troubles. Is there any good way for me to get the raw content without the <!--more--> removed?
Chances are, by the time your plugin runs, <!--more--> has been converted to <span id="more-1"></span>
This is what I use in my plugin, which injects some markup immediately after the <!--more--> tag:
add_filter('the_content', 'inject_content_filter', 999);
function inject_content_filter($content) {
$myMarkup = "my markup here<br>";
$content = preg_replace('/<span id\=\"(more\-\d+)"><\/span>/', '<span id="\1"></span>'."\n\n". $myMarkup ."\n\n", $content);
return $content;
}
You can use the follow code:
The !is_single() will avoid display the more link in the View Post page.
add_filter('the_content', 'filter_post_content');
function filter_post_content($content,$post_id='') {
if ($post_id=='') {
global $post;
$post_id = $post->ID;
}
// Check for the "more" tags
$more_pos = strpos($filtered_content, '<!--more-->');
if ($more_pos && !is_single()) {
$filtered_content = substr($filtered_content, 0, $more_pos);
$replace_by = '<a href="' . get_permalink($post_id) . '#more-' . $post_id
. '" class="more-link">Read More <span class="meta-nav">→</span></a>';
$filtered_content = $filtered_content . $replace_by;
}
return $filtered_content;
}
Based on Frank Farmer's answer I solved to add thumbnail photo after the generated more tag (<span id="more-...) in single.php file with this:
// change more tag to post's thumbnail in single.php
add_filter('the_content', function($content)
{
if(has_post_thumbnail())
{
$post_thumbnail = get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('class'=>'img img-responsive img-thumbnail', 'style'=>'margin-top:5px;'));
$content = preg_replace('/<span id\=\"(more\-\d+)"><\/span>/', '<span id="\1"></span>'.$post_thumbnail, $content);
}
return $content;
}, 999);

Resources