Forum

Thread tagged as: Problem, Runway

Categories not updating inside Collection items

Hi

I've got a page that displays products on a page by looping through categories. The user can then filter by category.

All is working great. Drew helped me streamline it last week.

The client has been now tinkering, adding content and has unearthed an issue. I wondered if this is an issue in Perch or, as usual, there's a better way to do this.

If the client changes the name of a category the Collection items in that category disappear from the page. The category slug is being set from the Category title.

If you open a Collection item that has been assigned that updated category and re-save it, the product appears on the page again. Perch is updating the category in the product but the unsaved Collection items seem to be cached and are therefore not updating.

Many thanks in advance,

Jon

Here's my template for the page:

<?php perch_layout('global.head'); ?>

<body class="products p-product-details hk">
<div class="wrapper">

    <?php perch_layout('global.header'); ?> 

    <div class="wrapper-inner">

        <section class="l-product-intro intro block">

                    <h1><?php perch_content('Products title')?></h1>

        </section>  

        <section class="l-tech-strip">

            <div class="l-tech-title">Powered by</div><!-- l-tech-title -->             

            <div class="l-tech-brand-strip">

                <?php 

                    if (perch_get('cat')) {
                        PerchSystem::set_var('current_page', perch_page_url([], true));
                        PerchSystem::set_var('activeCat', perch_get('cat'));                    
                    };

                    perch_categories( array(

                    'set' => 'technologies',
                    'template' => 'category-nav.html'
                )); ?>


            </div><!-- l-tech-brand-strip -->

            <h2>Choose a technology above or <a href="/products/">click here</a> to view all our products.</h2>

        </section><!-- l-product-desc -->

        <?php

            // Put all the categories into a variable

            $categories = perch_categories(array(
            'set'=>'technologies',
            'skip-template' => true,

            ));       

            // Is there a category in the url?

            if (perch_get('cat')) {

                    // Make the full category path from the set and cat slurrrgs

                    $catpath = perch_get('set').'/'.perch_get('cat');

                    // Loop through the categories and grab the category info to display

                    $category = perch_category($catpath, array(
                    'skip-template' => true,

                    ));

                    foreach($category as $singlecategory) {

                    PerchSystem::set_vars($singlecategory);

                    // Display the products in that category

                    perch_collection('Products', [
                        'template' => 'products/product_list.html',
                        'category' => $singlecategory['catPath'],
                    ]);
                    }

                } else {

                   foreach($categories as $category) {

                    // Pass the category into the template
                    PerchSystem::set_vars($category);

                    // Display the products in that category

                    perch_collection('Products', [
                        'template' => 'products/product_list.html',
                        'category' => $category['catPath'],
                    ]);

                }

            }
            ?>
    </div><!-- /wrapper-inner -->
<?php perch_layout('global.footer'); ?>
<?php perch_layout('global.scripts'); ?>    
</body>
</html> 

And here's the details page template:


<div class="l-breadcrumb block"> <a href="/">Home</a> / <a href="/products/">Products</a> / <perch:categories id="product_cat" label="Technology category" set="Technologies" required="true"/><a href="/products/technologies/<perch:category id="catSlug" type="slug" for="catTitle"/>"><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></a></perch:categories> / <a href="/products/<perch:content id="product_slug" for="product_title product_sku" type="slug" />"><perch:content id="product_title" label="Product title" title="true" type="text" required="true" order="2"/></a> </div><!-- l-breadcrumb --> <section class="l-product-desc hk"> <div class="l-product-details-container"> <div class="l-product-details"> <div class="l-product-header"> <div class="l-product-sku btn btn-large">Product <perch:content id="product_sku" label="Product code (SKU)" type="text" title="true" required="true" order="1"/></div> <perch:categories id="product_cat" label="Technology category" set="Technologies" required="true"/> <div class="l-product-technology"> <img srcset="<perch:category id="cat_image" label="Technology image" type="image" height="116" density="2" bucket="technologies" help="Please upload image sized to 232px high or larger."/> 2x" src="<perch:category id="cat_image" label="Technology image" type="image" height="116" density="2" bucket="technologies" help="Please upload image sized to 232px high or larger."/>" alt="<perch:category id="cat_image_alt" label="Alt description" type="text" help="Please add a description of the image."/>"> </div> </perch:categories> </div><!-- l-product-header --> <div class="l-product-copy"> <h1><perch:content id="product_title" label="Product title" title="true" type="text" required="true" order="2"/></h1> <perch:content id="product_new" label="New product button" type="checkbox" value="checked" help="Adds a New button to the product image" suppress="true"/> <perch:content id="product_description" label="Product description" type="textarea" markdown="true" editor="markitup" size="m" /> </div><!-- l-product-copy --> </div><!-- l-product-details --> <perch:template path="product_gallery.html" label="Product images" /> </section><!-- l-product-desc --> <perch:related id="rel_products" collection="Products" label="Related products"> <perch:content id="Product_title" /> </perch:related> <perch:template path="related_products.html" label="Related products"/> <perch:content id="product_slug" for="product_title product_sku" type="slug" suppress="true" /> <perch:content id="product_hero_image" label="Product image" type="image" width="190" height="190" crop="true" density="2" bucket="products" suppress="true"/> <perch:content id="product_hero_image" label="Product image" type="image" width="190" height="190" crop="true" density="1" bucket="products" suppress="true"/>

Here's the category template


<perch:before><ul></perch:before> <li><h4><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></h4> <perch:category id="catSlug" type="slug" for="catTitle" suppress="true"/> <perch:category id="cat_desc" type="textarea" label="Description" markdown="false" size="s" /><img srcset="<perch:category id="cat_image" label="Technology image" type="image" height="116" density="2" bucket="technologies" help="Please upload image sized to 232px high or larger."/> 2x" src="<perch:category id="cat_image" label="Technology image" type="image" height="116" density="1" bucket="technologies" help="Please upload image sized to 232px high or larger."/>" alt="<perch:category id="cat_image_alt" label="Alt description" type="text" help="Please add a description of the image."/>"></li> <perch:after></ul></perch:after> <perch:category id="page_url" type="pagelist" label="Choose a page to link to" suppress="true"/> <perch:category id="cat_image_nav" label="Technology image for navigation" type="image" height="40" density="1" bucket="technologies" help="Please upload image sized to 80px high or larger." suppress="true"/> <perch:category id="cat_image_nav" label="Technology image for navigation" type="image" height="40" density="2" bucket="technologies" help="Please upload image sized to 80px high or larger." suppress="true"/>

And here's my diagnostics bits:


Perch Runway: 2.8.31, PHP: 5.6.10, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO Server OS: Darwin, apache2handler Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_blog (5.0), perch_forms (1.8.3), perch_mailchimp (2.0.1), collection_1 (2.8.31), perch_backup (1.2) App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_mailchimp', 'perch_blog', ); PERCH_LOGINPATH: /perch PERCH_PATH: /Users/ellimondo/Dropbox/Sites/techniche-intl/www.techniche-intl.com/perch PERCH_CORE: /Users/ellimondo/Dropbox/Sites/techniche-intl/www.techniche-intl.com/perch/core PERCH_RESFILEPATH: /Users/ellimondo/Dropbox/Sites/techniche-intl/www.techniche-intl.com/perch/resources Image manipulation: GD PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M F1: 2edba60ed1f613d6dd804feb202456a2 Resource folder writeable: Yes HTTP_HOST: dev2.techniche-intl.com DOCUMENT_ROOT: /Users/ellimondo/Dropbox/Sites/techniche-intl/www.techniche-intl.com REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Jonathan Elliman

Jonathan Elliman 27 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I think we probably need to rebuild the collection index if a major category change occurs. For now, does republish handle that?

Hi Drew

Thanks for replying. No, rebuilding doesn't work - I thought that too and tried it yesterday.

A rebuild button/trigger would be really useful because on another site I'm building the Collection index is still growing - in a week the SQL file jumped from 6mb to 26mb by test users just saving collections with relationships. The relationships are one way now :)

I've also seen this if a collection is referenced on a page. If the collection content changes, the page needs resaving before the change is updated.

Kind regards

Jon

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you mean by 'referenced on a page'?

Obviously we do a lot of caching, but we may be caching things a bit too strongly.

Hi Drew

I think it might be an edge case!…

I have a gallery region on the homepage that uses a mixture of blocks and related projects (which is the Collection item). The client can add a block, pick a project and arrange it in a grid on the homepage. The template brings in the related Collection item's title and image.

When a project is updated the title or image won't update until you resave the homepage. The client is happy republishing but it does seem a trifle zealous.

As an aside if you add a related item into a page as part of a block the cool little JavaScript picker doesn't activate until you save the region. Which confused the end user a little bit.

I'm off for a beer and BBQ. Way too hot in here!

Jon