Page 1 of 2
Product Specs Filter
Posted: Wed Aug 17, 2022 9:01 am
by LeeFoster
Earlier this year I made a hook to allow filtering by Product Specification for my 1.0.8.5 store and it works perfectly, I am now trying to migrate it to a 1.0.8.16 store and it is not working.
The filter box appears however the price slider does not and it doesn't actually filter anything.
I have attached the hook and relevant files
Spec Filter.rar
If anyone can identify why this might not work on the later version and maybe even improve the hook it would be much appreciated.
Re: Product Specs Filter
Posted: Wed Aug 17, 2022 10:07 am
by ecartz
Is the slider the slider from jQuery UI? Phoenix doesn't load that by default in catalog. It looks like you have code to load the main jQuery that you don't need. But you don't have jQuery UI:
Code: Select all
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js" integrity="sha512-57oZ/vW8ANMjR/KQ6Be9v/+/h6bq9/l3f0Oc7vn6qMqyhvPd1cvKBRWWpzu0QoneImqr2SkmO4MSqU+RpHom3Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Re: Product Specs Filter
Posted: Wed Aug 17, 2022 10:51 am
by LeeFoster
ecartz wrote: ↑Wed Aug 17, 2022 10:07 am
Is the slider the slider from jQuery UI? Phoenix doesn't load that by default in catalog. It looks like you have code to load the main jQuery that you don't need. But you don't have jQuery UI:
Code: Select all
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js" integrity="sha512-57oZ/vW8ANMjR/KQ6Be9v/+/h6bq9/l3f0Oc7vn6qMqyhvPd1cvKBRWWpzu0QoneImqr2SkmO4MSqU+RpHom3Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Yes it's the JQuery UI slider, adding the code mentioned allows it to add the class to the field but does not style it. I'm assuming this is because I'm not calling the stylesheet so I added the below, however, it doesn't appear to be including the css file.
Code: Select all
public function listen_injectSiteStart() {
$this->sitestart .= '<!-- Filter stylesheets hooked -->' . PHP_EOL;
$this->sitestart .= '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/base/jquery-ui.min.css" integrity="sha512-ELV+xyi8IhEApPS/pSj66+Jiw+sOT1Mqkzlh8ExXihe4zfqbWkxPRi8wptXIO9g73FSlhmquFlUOuMSoXz5IRw==" crossorigin="anonymous" referrerpolicy="no-referrer" />' . PHP_EOL;
return $this->sitestart;
}
Re: Product Specs Filter
Posted: Wed Aug 17, 2022 10:59 am
by LeeFoster
LeeFoster wrote: ↑Wed Aug 17, 2022 10:51 am
ecartz wrote: ↑Wed Aug 17, 2022 10:07 am
Is the slider the slider from jQuery UI? Phoenix doesn't load that by default in catalog. It looks like you have code to load the main jQuery that you don't need. But you don't have jQuery UI:
Code: Select all
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js" integrity="sha512-57oZ/vW8ANMjR/KQ6Be9v/+/h6bq9/l3f0Oc7vn6qMqyhvPd1cvKBRWWpzu0QoneImqr2SkmO4MSqU+RpHom3Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Yes it's the JQuery UI slider, adding the code mentioned allows it to add the class to the field but does not style it. I'm assuming this is because I'm not calling the stylesheet so I added the below, however, it doesn't appear to be including the css file.
Code: Select all
public function listen_injectSiteStart() {
$this->sitestart .= '<!-- Filter stylesheets hooked -->' . PHP_EOL;
$this->sitestart .= '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/base/jquery-ui.min.css" integrity="sha512-ELV+xyi8IhEApPS/pSj66+Jiw+sOT1Mqkzlh8ExXihe4zfqbWkxPRi8wptXIO9g73FSlhmquFlUOuMSoXz5IRw==" crossorigin="anonymous" referrerpolicy="no-referrer" />' . PHP_EOL;
return $this->sitestart;
}
Creating a new hook and adding it in the template hooks folder allows the CSS to show now and the slider is styled as it should. Now to get the actual filtering to work.
Re: Product Specs Filter
Posted: Wed Aug 17, 2022 5:47 pm
by LeeFoster
Managed to get it working to show the filter and actually filter the products. Next steps are to integrate the sort by into the same filter and to restrict the available filters to only those relevant to the category.
So here is version 1 for you all to use.
Re: Product Specs Filter
Posted: Thu Aug 18, 2022 8:39 am
by LeeFoster
I now have it working to only show the specifications used in the current category, meaning the only thing left to do is either add a sort by option or get the built in sort by to work with it.
I've added the below code into my filter and it shows the following error
Notice: Undefined variable: column_list
Code: Select all
$filter_html .= '<ul class="nav">';
$filter_html .= '<li class="nav-item dropdown">';
$filter_html .= '<a href="#" class="nav-link text-dark dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?= TEXT_SORT_BY ?><span class="caret"></span></a>';
$filter_html .= '<div class="dropdown-menu">';
foreach ($column_list as $i => $column) {
if ($column_specifications[$column]['sortable']) {
echo splitPageResults::create_sort_heading($_GET['sort'], $i+1, $column_specifications[$column]['heading']);
}
}
$filter_html .= '</div>';
$filter_html .= '</li>';
$filter_html .= '</ul>';
I suspect this is because it cannot find system/segments/sortable_product_columns.php, what I don't know is how to help it find the file.
Re: Product Specs Filter
Posted: Thu Aug 18, 2022 9:29 am
by ecartz
LeeFoster wrote: ↑Thu Aug 18, 2022 8:39 am
Notice: Undefined variable: column_list
Is this in a hook? Please show the class name (if a file hook) or the insert (for a database hook) along with the entire function. In particular, I want to see what arguments the function is taking and the listener name.
If not a hook, how are you invoking that code? Where is it? You could try changing to $GLOBALS['column_list'] and seeing if that works.
In a hook, I would expect something like
Code: Select all
class hook_shop_filter_whatever {
public function listen_filterStart($parameters) {
foreach ($parameters['column_list'] as $i => $column) {
Re: Product Specs Filter
Posted: Thu Aug 18, 2022 9:37 am
by LeeFoster
ecartz wrote: ↑Thu Aug 18, 2022 9:29 am
LeeFoster wrote: ↑Thu Aug 18, 2022 8:39 am
Notice: Undefined variable: column_list
Is this in a hook? Please show the class name (if a file hook) or the insert (for a database hook) along with the entire function. In particular, I want to see what arguments the function is taking and the listener name.
If not a hook, how are you invoking that code? Where is it? You could try changing to $GLOBALS['column_list'] and seeing if that works.
In a hook, I would expect something like
Code: Select all
class hook_shop_filter_whatever {
public function listen_filterStart($parameters) {
foreach ($parameters['column_list'] as $i => $column) {
Code: Select all
class hook_shop_filter_filter {
var $version = '1.0.0';
var $siteend = null;
public $sitestart = null;
function listen_drawForm() {
global $current_category_id;
Re: Product Specs Filter
Posted: Thu Aug 18, 2022 9:45 am
by ecartz
Try adding
Code: Select all
protected $column_specifications;
public function listen_filterStart($parameters) {
$this->column_specifications =& $parameters['column_specifications'];
}
If you already have a listen_filterStart, just add the assignment to that function (and add the property declaration outside of any function). So five lines (one blank) if you don't have listen_filterStart; two lines (the first and fourth) if you do. Then change $column_list to
Code: Select all
array_keys($this->column_specifications)
in your previous code.
Re: Product Specs Filter
Posted: Thu Aug 18, 2022 9:56 am
by LeeFoster
Ok I now have this as the start of my hook file
Code: Select all
class hook_shop_filter_filter {
var $version = '1.0.0';
var $siteend = null;
public $sitestart = null;
protected $column_list;
public function listen_filterStart($parameters) {
$this->column_list =& $parameters['column_list'];
}
and the drop down section of my form is
Code: Select all
$filter_html .= '<ul class="nav">';
$filter_html .= '<li class="nav-item dropdown">';
$filter_html .= '<a href="#" class="nav-link text-dark dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?= TEXT_SORT_BY ?><span class="caret"></span></a>';
$filter_html .= '<div class="dropdown-menu">';
foreach ($this->column_list as $i => $column) {
if ($column_specifications[$column]['sortable']) {
echo splitPageResults::create_sort_heading($_GET['sort'], $i+1, $column_specifications[$column]['heading']);
}
}
$filter_html .= '</div>';
$filter_html .= '</li>';
$filter_html .= '</ul>';
and I am getting
Warning: Invalid argument supplied for foreach() in filter.php on line 53
Line 53 is
Code: Select all
foreach ($this->column_list as $i => $column) {