Posts by tonyastley

    Hello,


    I'm trying to insert a next attribute into a form to redirect customers to different places depending on the stage in the registration process. However no method I try is inserting the next attribute dynamically:


    Set the status as a system variable depending:

    Code
    1. $status = perch_get('status'); /*Set to 'checkout' */
    2. PerchSystem::set_var('status', $status);

    Check for the value of the status:

    Code
    1. <perch:form id="register" class="customerDetails" method="post" app="perch_shop" <perch:if id="status" value="checkout" match="eq">next="/shop/checkout"</perch:if>>
    2. <h4>New Customers</h4>
    3. <perch:if id="status" value="checkout" match="eq">Redirect back to checkout</perch:if><!--This shows the code-->

    The if statement works in the body of the form, but not in the opening tag. It does not redirect back to the checkout.


    I've tried setting the redirect as a variable and passing it in:


    PHP
    1. <?php
    2. if($status == 'checkout'){ $redirect = 'next="/shop/checkout"';} else {$redirect = 'next="/shop/account"';}
    3. PerchSystem::set_var('redirect', $redirect);
    4. ?>
    Code
    1. <perch:form id="register" class="customerDetails" method="post" app="perch_shop" <perch:shop id="redirect">

    This does not work either.


    Only hard coding the next attribute into the template works, but this means I have to maintain separate templates for all of the redirect scenarios.

    Thanks Hussein, I tried your solution and it worked getting the page paths in as an array. There was a little bit more for me to work out as Perch sorts the array alphabetically if they are all passed in together, regardless of their order.


    So, I looked into array manipulation and worked out the following solution for anyone that's interested:


    Using Husseins method to get the list of matching pages into an array:

    Code
    1.  $pages = perch_pages_navigation([
    2. 'skip-template' => true,
    3. 'from-path' => '/care-units/',
    4. 'levels' => 1,
    5. 'hide-extensions' => false,
    6. ]);


    This array includes everything about each page that is available perch_pages_navigation. So the following code sorts the array by 'pageTreePosition' which puts the pages in the order they are sorted in admin.

    Code
    1. array_multisort(array_column($pages, 'pageTreePosition'), SORT_ASC, $pages);

    Note: I believe the above requires PHP7.


    As mentioned Perch will sort the array alphabetically no matter what order it receives it, so we cannot pass it in as it is, we need to loop through each value:

    PHP
    1. <ul>
    2. <?php
    3. foreach ($paths as &$path) {
    4. perch_content_custom(array('Unit Details'), array(
    5. 'page' => $path,
    6. 'template' => 'menu_lis.html',
    7. ));
    8. }
    9. ?>
    10. </ul>

    The only downside to this is that as we are essentially processing each value independently perch:before and perch:after will apply to every item, hence I have to lose the before and after markup and code it into the parent page template instead.


    Tip:

    If at any stage you want to see on your page what is being returned (you may wish to sort on a different value), you can use print_r:

    Code
    1. echo '<p>Array: '; print_r($pages); echo '</p>';

    It escapes double quotes too unfortunately.

    If I echo the variable it looks fine, the only time I see the backslashes is when I inspect the perch debug to see what has failed.

    Almost there. Excuse my coding, I'm very much a designer, not a programmer.


    I have a navigation template that looks like:


    Code
    1. <perch:if not-exists="perch_item_first">, </perch:if>'<perch:pages id="pagePath" />'

    This produces the comma separated list of pages I need, however when I save this to a variable and pass the variable into perch_content_custom, the system is escaping the single quotes with backslashes.

    Code
    1. regionPage='\'/section/page-01.php\',\'/section/page-02.php\',\'/section/page-03.php\'

    Is there a way to get rid of the backslashes?

    OK figured it out. perch_shop_order_addresses requires 'shop/' to be in the path of the template otherwise it returns a template not found in the config.


    perch_shop_order_addresses([
    'template' => 'shop/addresses/billingID.html',
    ]);


    What threw me is that perch_shop_cart does not require it, in fact it doesn't work with it.


    perch_shop_cart([
    'template'=>'cart/cart_list.html'
    ]);


    Confusing.

    Thanks Jordin,


    Looks like I've been using Perch Templates incorrectly for years. I recently replaced the shop app entirely to reset the base templates and started adding mine back into the correct place.


    The issue still persists though, logging in at that stage of the buying process changes the wording on the submit button of the perch_shop_order_address_form to 'login' rather than what the (default) template says it should be 'OK!'.

    Second half of that debug:


    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.

    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.

    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.

    Hello Hussein,


    Any ideas why re-ordering the products using pipit catalog would initially break the product category filtering.


    Following a re-order in product catalog, all the products disappear, and only show again once each product is saved?


    Even a basic category declaration does not show the products:


    Code
    1. perch_shop_products([
    2. 'category' => $fullcatPath,
    3. ]);


    Yet a unfiltered, uncategorised product call will show them.