Perch Shop: Changing Categories Breaks Links to Products

  • I'm currently testing Perch Shop and have encountered a strange bug whereby changing the category structure the products set causes the product .


    Example: I have products assigned to a category in the product set doors:


    Products > Doors


    These are shown front end using:


    PHP
    1. <?php perch_shop_products([
    2.     'category' => 'products/doors/',
    3. ]);
    4. ?>

    Then say I need to recategorise doors into a sub category:


    Products > Domestic > Doors


    I to get the new products I make a similar call:


    PHP
    1. <?php perch_shop_products([
    2. 'category' => 'products/domestic/doors/',
    3. ]);
    4. ?>

    This shows nothing. And in fact the old call still works showing the products as if the category has not been moved.


    I go into edit the product and the categories are correctly showing as reorganised in the category field. When I save the product it behaves as expected and shows for the new call correctly.


    Obviously saving every affected product after a category reshuffle isn't workable. Has anyone got any ideas what may be causing the issue.


    I'll post some debug information here shortly.

  • Here is the debug from the product edit screen:



    Note: As of this stage the product.html template is an unedited copy of the one from the app folder.

  • Here is the debug information from the category page showing the product list:



    Again the template: /templates/shop/products/list.html is an unedited copy from the app folder.

  • Second half of that debug:


  • The ID doesn't change even if you rename the category. Category filtering require you to use category paths.


    The problem is that the Shop app's index does not get updated when a category is updated. I may be able to add something to Pipit Catalog to help with this in the meantime, but ideally this should not need the help of a third-party app.

  • Pipit Catalog v1.4 is now available and you can use it to republish/reindex all the products. So if you make changes that affect your existing category paths, you can (manually) republish the products to solve the issue you described.


    Perch fires an event when a category is updated, so a future update may automatically handles the reindexing for you. For now, v1.4 should save you the trouble of going to all the affected products and resaving them one by one.