Forum

Thread tagged as: Shop

Displaying/viewing an order from the url

From the list of orders in the account section for a logged in customer, to view an individual order I'm using the following code to view the order selected. Is this ok or is there a better way? It displays the correct order but maybe there is a cleaner way?

url to view an order is : /account/orders/27
url pattern in runway is: account/orders/[i:orderID]

Code on the display order page is:

function getUriSegments() {
        return explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
    }

    function getUriSegment($n) {
        $segs = getUriSegments();
        return count($segs)>0&&count($segs)>=($n-1)?$segs[$n]:'';
    }

    // View order based on order id in url
    perch_shop_order(getUriSegment(3));

I've tried this but it doesn't display the order as i guess it doesn't know where to look for the number or url?

perch_shop_order($order_id);
Mark Watts

Mark Watts 0 points

  • 4 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

Look here: https://docs.grabaperch.com/runway/routing/named-segments/

All you need is:

$order_id = perch_get('orderID');
perch_shop_order($order_id);

another perspective

perch_shop_order(perch_get('orderID')); // will echo with default template

$order_id = perch_shop_order(perch_get('orderID'), ['skip-template'=>true]); // will return

Thanks Duncan & Robert they worked a treat! thought there had to be a simpler way :o) Thanks again!