Hi! I have augmented Search to include blog posts. But there is a glitch: If search keyword does not return 1 or more products then it will not return any blog posts even if there is a blog post(s) with the keyword. It's like the code is saying "no matching products so quit". I think this is happening in the file:
catalog/controller/product/search.php
added code:
Line 23
// Load the Journal2 Blog Model
$this->load->model('journal2/blog');
$data['blog_posts'] = array(); // Initialize the blog_posts array
Line 988
// Fetch blog posts based on the search term
$blog_results = $this->model_journal2_blog->getBlogPostsByKeyword($search);
foreach ($blog_results as &$blog_post) {
// Check if 'journal_blog_post_id' is set to avoid undefined index notice
if (isset($blog_post['post_id'])) {
$blog_post['href'] = $this->url->link('journal2/blog/post', 'journal_blog_post_id=' . $blog_post['post_id']);
} else {
// Handle the case where 'journal_blog_post_id' is not set, if necessary
$blog_post['href'] = '#'; // or some default value
}
}
// Pass blog results to the view
$data['blog_results'] = $blog_results;
A couple other files have been modded to get this augmentation but I don't think the problem is with them.
OC 2.3.0.2 and Journal2 theme
Any ideas will be appreciated.
catalog/controller/product/search.php
added code:
Line 23
// Load the Journal2 Blog Model
$this->load->model('journal2/blog');
$data['blog_posts'] = array(); // Initialize the blog_posts array
Line 988
// Fetch blog posts based on the search term
$blog_results = $this->model_journal2_blog->getBlogPostsByKeyword($search);
foreach ($blog_results as &$blog_post) {
// Check if 'journal_blog_post_id' is set to avoid undefined index notice
if (isset($blog_post['post_id'])) {
$blog_post['href'] = $this->url->link('journal2/blog/post', 'journal_blog_post_id=' . $blog_post['post_id']);
} else {
// Handle the case where 'journal_blog_post_id' is not set, if necessary
$blog_post['href'] = '#'; // or some default value
}
}
// Pass blog results to the view
$data['blog_results'] = $blog_results;
A couple other files have been modded to get this augmentation but I don't think the problem is with them.
OC 2.3.0.2 and Journal2 theme
Any ideas will be appreciated.
Last edited by rh001 on Wed Jul 03, 2024 12:17 am, edited 1 time in total.
OpenCart 2 does not include a blog feature. The Journal2 framework is not the same as OpenCart, hence you have to contact the Journal support, or find a professional developer from the commercial support section to do the needed changes for the search.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Hi and thank for the reply.
My question is about the Opencart search function and is general, not about Journal2 theme specifically. I posted here just to ask and don't appreciate the effort you took to scold me. You're a scold. Any future harrassment from you will be reported.
My question is about the Opencart search function and is general, not about Journal2 theme specifically. I posted here just to ask and don't appreciate the effort you took to scold me. You're a scold. Any future harrassment from you will be reported.
Hi!
Try to look at template file. It can have something like this:
I think your code in template file for output founded posts is in this block. Try to move it down.
Try to look at template file. It can have something like this:
Code: Select all
{% if products %}
My FREE extensions in marketplace. [ security | flexibility | speedup ]
If that solves the issue please add [SOLVED] to the start of this topic title.
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
You're welcome. Happy to help.
My FREE extensions in marketplace. [ security | flexibility | speedup ]
Who is online
Users browsing this forum: No registered users and 13 guests