Posts by hus_hmd

    Hi Stephen,


    This is an array of strings:


    PHP
    1. $array = ['Listen Up', 'Case Studies', 'Publications', 'Resources'];


    This is a single string:


    PHP
    1. $string = "'Listen Up', 'Case Studies', 'Publications', 'Resources'";


    You need to use an array:


    PHP
    1. $collectionKeys = ['Listen Up', 'Case Studies', 'Publications', 'Resources'];
    2. perch_collection($collectionKeys, [
    3.     'count' => 10,
    4. ]);

    I realise it is not what you're looking for; it wasn't meant to be the solution. I'm hinting quite badly for you to test every step so you'd figure out what is not working. As things stand, it sounds like the filtering on perch_blog_custom() is not working as expected.


    If you do get a URL from perch_layout_var('url'), copy one and hardcode it:


    PHP
    1. perch_blog_custom([
    2. 'template' => 'post_search_result',
    3. 'filter' => 'postURL',
    4. 'value' => '/newsroom/unicorn',
    5. ]);


    This is just to confirm that the filtering works.

    If you don't have too many products, you can fetch all products and their variants, then render them using pipit_template() (from the Pipit app) - which works in a similar way to perch_template(), but supports pagination.


    If you have a large number of products, the above approach won't be great as you'd be fetching all the products for all pages (even though you're only displaying 12 per page).

    Try removing the spaces between the values:


    PHP
    1. $searchResultsIDs = '36,29,21,16,5';


    You are also missing a comma after the first filter array:


    Code
    1. [
    2. 'filter' => 'isPublished',
    3. 'value' => true,
    4. ],

    I don't think that's possible with perch_shop_products(); its primary use is to fetch/output parent products. Enabling the variants option only includes them per product so they are not taken into account in pagination.


    If you are only listing the variants for a single product, you should be able to output a paginated list with perch_shop_product_variants()

    Mxkert is probably the easiest option. However, filtering inside the template may lead to some issues. If you need pagination, the number of results per page may be inconsistent (and some pages may not show any results). The other issue is you can't easily tell when you get no results.


    An alternative would be to skip the templating, disable pagination and handle the rest in PHP:


    PHP
    1. $search_items = perch_content_search(perch_get('q'), [
    2. 'skip-template' => true,
    3. 'count' => null,
    4. ]);


    You may find these blog posts relevant:

    I meant to output it on its own like so:


    PHP
    1. perch_layout_var('url');
    2. perch_blog_custom([
    3. 'template' => 'post_search_result',
    4. 'filter' => 'postURL',
    5. 'value' => perch_layout_var('url', true),
    6. ]);


    If you have debug mode turned on, you can output it to the debug message instead:


    PHP
    1. PerchUtil::mark('Layout var');
    2. PerchUtil::debug(perch_layout_var('url', true));


    Ultimately, you need the variable to hold the correct postURL value.

    UPDATE: it's working, but because I hidden a variable in testing on the 'blog_search_result.php" page to this:

    If you remove the filtering, you probably won't get the expected result. If things are working fine up to the layout stage, the next step would be looking into whether the layout variable is holding the expected value. Try outputting it:


    PHP
    1. perch_layout_var('url');


    Do you get the result URL as expected?

    Hi Grant,


    It looks like you do not need to skip the templating. You can have the rendered template to be returned instead of output like so:


    PHP
    1. $sitename = perch_content_custom('Site Name', [], true);


    If you don't need the template to re-evaluated at runtime, you can use perch_content() instead:


    PHP
    1. $sitename = perch_content('Site Name', true);

    I'd check things one by one until you find where it is not working.


    (1) Turn on debug mode and check for errors


    (2) Your search template is only set up to show results from the Blog app. If you get a result from another source it will output an empty <li></li>. Does the term test return any Blog results? You can restrict the search to the Blog app:


    PHP
    1. perch_content_search(perch_get('q'), [
    2. 'apps' => ['PerchBlog'],
    3. ]);



    (3) Check what you're getting what expect. Output the result_url and/or showall the available variables. Is it a blog post URL like you expect?


    HTML
    1. <perch:if id="result_source" value="PerchBlog">
    2. <perch:search id="result_url">
    3. <perch:showall>
    4. </perch:if>

    If you are only dealing with a small number of values, the replace attribute is also an option. You can flip the order of the values in the options attribute:


    HTML
    1. <perch:content id="fruits" type="select" options="Big Apple|apple,Round Orange|orange,Green Pear|pear" replace="apple|Big Apple,orange|Round Orange,pear|Green Pear" >

    If you use Apple and Round Orange as the value, you can use the urlify attribute to output URL friendly versions apple and round-orange. Alternatively, you can use the format attribute to convert the text to all lowercase or all uppercase.


    And there's also the CSS route:


    As far as I know Perch Shop doesn't let you set a default address for customers at the moment. So you'd need to set the address for each order.


    Perhaps you can set up a template for the order address form that has a hidden field with the address value and just displays a button (which can say "Next" or something like that). Visually to the user it would look like a button to go to the next step, but clicking it would also set the order address.

    As far as I know there is no runtime function to do this.


    You could use the Tags class directly, just be careful when updating the app in the future. Note that your template may need to use the perch:content namespace here. And this won't get you the quantity value qty like perch_blog_tags():





    If you also need the quantity, an option would be to set up your template to render the list in JSON:



    And in PHP you can convert the JSON to an array, randomise the order of the array items, slice the array to the size you want and render the list with perch_template()

    PHP
    1. // get the rendered JSON and convert it into an array
    2. $tags = json_decode( perch_blog_tags('tag_json', true), true );
    3. if($tags !== NULL) {
    4. // randomise the order of the array items
    5. shuffle($tags);
    6. // render a template with a slice of the array (0 - 10)
    7. perch_template( 'blog/tag_link', array_slice($tags, 0, 10) );
    8. }