Shop Product Detail page is blank

  • Hi all,


    Wonder if anyone can help me figure out an issue I'm having - blank product detail page.

    Firstly, I'm not new to Perch, but this is the first time I'm using the Shop add-on.


    Here is my product.php page code:

    PHP
    1. <?php if (perch_get('product')) { perch_shop_product(perch_get('product'),array( 'template' => 'products/product.html' )); } else { echo "No Product Selected"; } ?>


    I'm using the default product.html template, copied to perch/templates/shop/products/ and added <perch:showall> (which is not showing anything)

    Debug: no errors


    Console: no errors

    Rewrite rule in .htacess:

    Code
    1. RewriteRule ^shop/(.+)$ shop/product.php?product=$1 [L]


    Any ideas what I've done wrong? Thanks in advance.

  • drewm

    Approved the thread.
  • Yes I get html upto where the product should show and after.


    Hardcoding this on the product.php page, works, I see the product details


    ```

    perch_shop_product('my-test-product');

    ```


    This echos: product.php


    ```

    echo perch_get('s');

    ```

  • Yes that is the corect URL structure.


    I've removed the rewrite rules for now, until I get it to work - in case that is what the issue is.


    But even without the rewrite rule and using


    /shop/product.php?s=my-test-product I still get no product details.

  • Doing that, i get the product details.


    It also shows me the output from <perch:showall> which i added to the product.html template.


    I have debug on:

    find_by_path(): "> [1] SELECT * FROM perch3_pages WHERE pagePath='/shop/product.php' LIMIT 1
    get(): "> [48] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
    get_cart_field(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=3
    get_cart_field(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=3
    get_filtered_listing_from_index(): "> [1] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_shop_index idx JOIN perch3_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch3_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='slug' AND idx.indexValue='my-test-product')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, productID ) as tbl WHERE (productDeleted IS NULL AND productStatus=1 AND parentID IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
    set(): "> [1] Using template: /templates/shop/products/product.html
    find(): "> [1] SELECT * FROM perch3_shop_brands WHERE brandID='1' AND brandDeleted IS NULL LIMIT 1
    find(): "> [1] SELECT * FROM perch3_shop_currencies WHERE currencyID=47 LIMIT 1
    find(): "> [1] SELECT * FROM perch3_shop_tax_groups WHERE groupID='1' AND groupDeleted IS NULL LIMIT 1
  • Array
    ( [s] => my-test-product/)


    Debug:

    find_by_path(): "> [1] SELECT * FROM perch3_pages WHERE pagePath='/shop/product.php' LIMIT 1
    get(): "> [48] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
    get_cart_field(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=3
    get_cart_field(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=3
  • Thanks for helping me out Drew.


    I had removed the .htaccess file completly, in the hopes it would stop using the rewrite rules, but I guess they are cached.


    Originally I was using this, which is a copy of what I used for the blog, changed for the shop:


    ```

    RewriteRule ^shop/([a-zA-Z0-9-/]+)$ /shop/product.php?s=$1 [L]

    ```


    There is a slash here '([a-zA-Z0-9-/]+)' - is that the trailing slash?


    ```

    RewriteRule ^shop/([a-zA-Z0-9-]+)$ /shop/product.php?s=$1 [L]

    ```


    I didn't want to just try it and they have it cached again.

  • The regex ^shop/([a-zA-Z0-9-/]+)$ matches:


    shop/


    followed by a group made up of any of these characters one or more times:


    • a-z
    • A-Z
    • 0-9
    • -
    • /

    So if you have a URL like shop/my-test-product/ that group is going to contain my-test-product/


    As your product slug won't contain a slash, you should take that out of the group


    ^shop/([a-zA-Z0-9-]+)$


    and then add it as an option character at the end after the group:


    ^shop/([a-zA-Z0-9-/]+)/?$

  • Hi Drew,


    Thank you for the help understanding regex.


    In that last bit of code, you added the slash back in after the 9-


    I presume that shouldn't be there?


    Should be:

    ```

    ^shop/([a-zA-Z0-9-]+)/?$

    ```


    If I understood it correctly?