Posts by hus_hmd

    RE the return to the page where the item/product is after exiting the edit form would be very useful to be applied across Perch, not just Perch Shop. This applies to other actions too, not just editing. Like your client stated, it is not great that deleting an item (Shop product/Collection item/etc) on page x always returns you to page 1. I wonder if these UX issues are addressed in v4, drewm ?


    Also, is there a way to edit the table view so other fields can be added to the product list? Like images, brands or categories, just like a normal content region in Perch's view mode supports?


    You can use the Pipit Catalog app for now. It provides an alternative admin listing page for products.

    There is more than one way to achieve this. Which way you use depends on how (or if) you want the editor to manage this URL and where you want the URL to be placed.


    For instance, if you always want this URL to be the last in the navigation links list, you can add it inside perch:after:


    HTML
    1. <perch:after>
    2. <!--* Add link here *-->
    3. </ul>
    4. </perch:after>


    You can hardcode it there if it makes sense in your use case. Or you can generate the URL outside the template and pass it as a variable to the template.

    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.

    Perch generates the different image sizes when you save an edit form. So in your post edit template (default is post.html), include additional tags to generate the image sizes you need. You can add the suppress attribute if you don't need to output these versions from this template:


    HTML
    1. <perch:blog id="image" type="image" label="Image">
    2. <perch:blog id="image" type="image" width="800" height="400" crop suppress>
    3. <perch:blog id="image" type="image" width="320" height="240" crop suppress>

    a region is still required for navigation.

    It's not required. What you need is a page that is registered with Perch. If a page is not registered with Perch, some of the page functions lose meaning in this context.


    If Perch encounters a perch_content() call, it automatically adds the page to the pages list on the control panel for you. However, you can add pages directly from the control panel yourself by clicking on the "+ Add page" button.

    A blog post is not a page. So on post.php you need to determine whether the slug from the URL matches a real blog post and proceed accordingly. This means your post.php page should respond with a 404 status code if the post is not found.


    See the post 404 Response which details how you can programmatically respond with a 404 on standard Perch and on Perch Runway.


    In your case, it would be something like this:


    Hi drewm


    Perch very rarely gets in my way as a developer, but it does when it doesn't allow me to add custom attributes to Perch form tags. Thanks to JS libraries like Vue and Alpine it's become common to use attributes like x-*, v-*, @click, @submit.prevent, etc.


    While I understand that some Perch-specific attributes should not be exposed on the front-end, you can perhaps have some reserved attributes like app and anitspam that Perch can always strip. And perhaps Perch can strip any perch-* attribute, so developers can still add their custom attributes and access them in an app's form handler.


    HTML
    1. <perch:form app="some_app" perch-custom-attribute="unicorn" method="post" x-show="isOpen()">
    2. <perch:input type="text" id="some_id" antispam="honeypot">
    3. </perch:form>



    Related post by Tobe : Allow passing through of custom attributes on form inputs

    There are multiple things to consider.


    (A) Use a HTML form. It is semantic. It is accessible. And the FormData API makes it easy to grab the form field values. The form does not have to be hidden. You normally display a button for the user to add an item to the cart. That button should be inside a form.




    (B) Use a Perch-templated form as Perch adds a hidden field which it needs to handle the form submission





    (C) Normally you don't just submit a form and assume things went ok. Ideally you'd get some feedback. There are 2 problems with this:

    1. Perch doesn't natively respond with a feedback for submitted forms in a way that is useful for submitting forms with Javascript
    2. The add to cart form for Perch Shop never throws an error even if it couldn't add the item to the cart

    For (1), the Pipit app has a function for sending back a response: pipit_form_response(). However, because of (2) it is probably not very helpful in this case.



    What you can do instead is submit the form via Javascript to an endpoint (or even to the same page), get the items of the cart to determine whether the item you wanted to add has been added and send back an appropriate response:




    The Pipit app v0.5 has a utility function for sending back a JSON response pipit_respond() which can be useful here:


    PHP
    1. pipit_respond($status_code, $response);