Forum

Thread tagged as: Question, Problem, Shop

Categories within Blocks in Shop Product

Hi,

I have a sinking feeling I have made an error with my templating, but thought I would check here. I have a product.html file which contains the following:

<perch:blocks>
<perch:block type="clock" label="Clock Specific">
    <perch:template path="blocks/clock.html" />
</perch:block>
<perch:block type="watch" label="Watch Specific">
    <perch:template path="blocks/watch.html" />
</perch:block>
</perch:blocks>

Within those templates I am selecting categories like this (example from clock.html):

<perch:categories id="clocktype" set="clock-type" label="Clock Type">
    <perch:category id="catTitle" />
</perch:categories>

<perch:categories id="clockcategory" set="clock-category" label="Clock Category">
    <perch:category id="catTitle" />
</perch:categories>

My issue is I am now trying to filter based on those categories, and I am getting no results. An example of my function with filter would be:

perch_shop_products([
    'template' => 'products/category_grid',
    'category' =>'clock-type/wall-clock',
    'count' => 24,
    'paginate' => true
]);

I am getting no results, despite that category being selected for several products. Looking at showall shows the category as selected but within a _blocks. Is this the problem? This is what I am seeing in _blocks:

Array
(
    [0] => Array
        (
            [clocktype] => Array
                (
                    [0] => 29
                )

            [clockfamily] => Array
                (
                    [0] => 37
                )

            [height] => 45
            [width] => 45
            [depth] => 9
            [case_material] => Chrome metal
            [case_finish] => 
            [case_colour] => 
            [dial_colour] => 
            [dial_style] => Marker
            [hands_material] => Metal
            [hands_style] => Baton and Teardrop
            [lens_material] => Glass Lens
            [alarm_function] => 
            [snooze_function] => 
            [silent_sweep] => 
            [main_colour] => chromesilver
            [main_case_material] => Metal
            [_block_type] => clock
            [_block_id] => ohrv3u
            [_block_index] => 0
        )

)

If this is the problem is there a way around it without me altering my product template?

Thanks for any help

Mike

Diagnostics

Perch Runway: 2.8.34, PHP: 5.6.27, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.34), assets (2.8.34), categories (2.8.34), perch_forms (1.8.3), perch_shop_orders (1.0.10), perch_shop_products (1.0.10), perch_shop (1.0.10), perch_members (1.5), perch_mailchimp (3.0.1)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_mailchimp', 'perch_members', 'perch_shop' );
PERCH_LOGINPATH: /admin
PERCH_PATH: /Volumes/Data-1/g Websites/newgatetrade/newgate-trade/admin
PERCH_CORE: /Volumes/Data-1/g Websites/newgatetrade/newgate-trade/admin/core
PERCH_RESFILEPATH: /Volumes/Data-1/g Websites/newgatetrade/newgate-trade/admin/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 6a33f95eca3667f9e0c39bf5ca2980fe
Resource folder writeable: Yes
HTTP_HOST: newgatetrade.dev
DOCUMENT_ROOT: /Volumes/Data-1/g Websites/newgatetrade/newgate-trade
REQUEST_URI: /admin/core/settings/diagnostics/
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
Mike Harrison

Mike Harrison 37 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't categorise a block, because blocks can't be sorted or filtered. Add the category to the content item itself.

Ah fair enough - so I need to add this to the main product.html template:

<perch:categories id="clocktype" set="clock-type" label="Clock Type">
<perch:category id="catTitle" />
</perch:categories>

<perch:categories id="clockcategory" set="clock-category" label="Clock Category">
<perch:category id="catTitle" />
</perch:categories>

Was trying to keep it tidy in the blocks as those categories don't apply to the watches, but if my approach doesn't work I will switch it out and re-do all the products.

Thanks for your help

Mike