Coroico / AdvSearch

Dynamic content search add-on for MODx Revolution that supports results highlighting, faceted search and search in custom packages
21 stars 14 forks source link

Chunk not rendering results after upgrade to 2.0.0-beta2 #91

Open crimsonpixel opened 4 years ago

crimsonpixel commented 4 years ago

Recently upgraded this extra and now I am not getting any results in my output.

Site is running on MODX 2.7.3, PHP 7.3 and Zend libraries included

I am using the following call on my results page:

[[!AdvSearch? &queryHook=`propertyQHook` &showExtract=`1:price` &containerTpl=`propertyAdvSearchResults` &tpl=`SearchResultTpl` &perPage=`5` ]]

And whilst the page returns results, none of the placeholders in the chunk are returned. I have prefixed all the placeholders with advsearch. but still nothing comes back.

Below is an extract from my chunk:

``

Property Type: [[+advsearch.property_type:ucwords]]

    <div class="bed-highlight"><p>[[+advsearch.bedrooms:is=`1`:then=`1 bedroom`:else=`[[+advsearch.bedrooms]] bedrooms`]]</p></div>
</div>

[[+advsearch.heating]]

[[+advsearch.furnish]]

Availability: [[+advsearch.availability:strtotime:date=`%e %b %Y`]]

`` There is nothing in the error log to suggest the issue. My snippet is: `` * * Query hook * */ /* Main class: package - The name of the schema Package to add. e.g: dvd packagePath - The path to the model/ directory where the package is located. Use {core_path} as generic variable. class - The class name of the table you want to search. e.g: dvd and optionally (these parameters could be passed thru the snippet call): withFields - A comma-separated list of column names where to search. fields - A comma-separated list of column names to display. ids - A comma-separated list of primary keys to filter where the search should occurs. where - criteria or Array of criteria. e.g: "studio IN ('20th Century Fox','DreamWorks Home Ent.','Warner Bros') " sortby - csv list of couple 'columnName (ASC| DESC)'. */ $main = array( 'package' => 'lettings', 'packagePath' => '{core_path}components/lettings/model/', 'class' => 'Lettings', 'fields' => 'feature_image , street , town , county , price , bedrooms , property_type , heating , furnish , availability , status', // displayed 'withFields' => 'property_name , town , bedrooms , property_type , generic_property_type , bedrooms , price', // where we do the search 'where' => '(`Lettings`.`published` = 1)', 'sortby' => 'Lettings.price DESC', 'tablePrefix' => 'tls_' ); $andConditions = array( 'Lettings.town:=' => 'town:request:all', 'Lettings.generic_property_type:=' => 'generic_property_type:request:all', 'Lettings.price:>=' => 'min-price:request:none', 'Lettings.price:<=' => 'max-price:request:none', 'Lettings.bedrooms:=' => 'bedrooms:request:all' ); //$main['tablePrefix'] = 'modx_'; // set the query hook declaration $qhDeclaration = array( 'qhVersion' => '1.2', // version of queryHook - to manage futures changes 'main' => $main, 'andConditions' => $andConditions ); $hook->setQueryHook($qhDeclaration); return true;`` Please could you suggest a resolution.
BenceSzalai commented 4 years ago

Can you please wrap your code blocks in double or triple backtick, so they are readable?

So to display this: [[!AdvSearch? &queryHook=`propertyQHook`... type this: ``` [[!AdvSearch? &queryHook=`propertyQHook`... ```.

It'd be easier to help if decoding of your code was not an issue. ;)

crimsonpixel commented 4 years ago

OK - I've updated it. Does that work? Or I can add a file instead

BenceSzalai commented 4 years ago

Could benefit the other two code sections too, since those are hard to read as well right now.

crimsonpixel commented 4 years ago
BenceSzalai commented 4 years ago

Well, I was just trying to help so you can submit readable ModX code segments in markdown, which in turn would help you to get meaningful answers.

Regarding your issue: I've had lot of problems with v2.0.0-beta2 around not handling extracts properly. I have lot of fixes in my local repo, but haven't got the time yet to make PRs for them. I'll take a look at some point and I may be able to help or at least to explain why is it not working.

Will keep an eye out for this ticket.

For reference: Your snippet:

<?php
/**
 * AdvSearch
 *
 * Copyright 2012 by Coroico <coroico@wangba.fr>
 *
 * Query hook 
 *
 */

/*
  Main class:

    package - The name of the schema Package to add. e.g: dvd
    packagePath - The path to the model/ directory where the package is located. Use {core_path} as generic variable.
    class - The class name of the table you want to search. e.g: dvd

    and optionally (these parameters could be passed thru the snippet call):

    withFields - A comma-separated list of column names where to search.
    fields - A comma-separated list of column names to display. 
    ids - A comma-separated list of primary keys to filter where the search should occurs.
    where - criteria or Array of criteria. e.g: "studio IN ('20th Century Fox','DreamWorks Home Ent.','Warner Bros') "
    sortby - csv list of couple 'columnName (ASC| DESC)'.
*/

$main = array(
    'package' => 'lettings',
    'packagePath' => '{core_path}components/lettings/model/', 
    'class' => 'Lettings', 
    'fields' => 'feature_image , street , town , county , price , bedrooms , property_type , heating , furnish , availability , status', // displayed 
    'withFields' => 'property_name , town , bedrooms , property_type , generic_property_type , bedrooms , price', // where we do the search
    'where' => '(`Lettings`.`published` = 1)',
    'sortby' => 'Lettings.price DESC',
    'tablePrefix' => 'tls_'
);

$andConditions = array(
    'Lettings.town:=' => 'town:request:all',
    'Lettings.generic_property_type:=' => 'generic_property_type:request:all',
    'Lettings.price:>=' => 'min-price:request:none',
    'Lettings.price:<=' => 'max-price:request:none',
    'Lettings.bedrooms:=' => 'bedrooms:request:all'
);

//$main['tablePrefix'] = 'modx_';

// set the query hook declaration
$qhDeclaration = array(
    'qhVersion' => '1.2',       // version of queryHook - to manage futures changes
    'main' => $main,
    'andConditions' => $andConditions
);

$hook->setQueryHook($qhDeclaration);
return true;

And the extract from the chunk:

<div class="property-highlight">
    <div class="sq-highlight"><p>Property Type: [[+advsearch.property_type:ucwords]]</p></div>
    <div class="bed-highlight"><p>[[+advsearch.bedrooms:is=`1`:then=`1 bedroom`:else=`[[+advsearch.bedrooms]] bedrooms`]]</p></div>

</div>
<div class="property-highlight">
    <div class="heating-highlight"><p>[[+advsearch.heating]]</p></div>
    <div class="furnished-highlight"><p>[[+advsearch.furnish]]</p></div>
</div>
<div class="property-highlight">
    <div class="availablity-highlight"><p><span>Availability</span>: [[+advsearch.availability:strtotime:date=`%e %b %Y`]]</p></div>
</div>

By the way, which chunk is it from?

crimsonpixel commented 4 years ago

The &tpl chunk

crimsonpixel commented 4 years ago

Ended up rolling back to version 1.0.1 as I need the chunk to render the results.