I have a problem. I use friendly urls in MODX Revolution 2.1.5-pl. But I want product pages to be dynamic. All my products are supposed to be listed in site.com/product/ when you click on a product you will go to /product/product-name and load the product product-name in a snippet or something like that.
Now modx thinks the page is not found and sends me to the start page. What I want is to show /product and maybe send product-name by GET variable.
How do I solve this?
I am not the original author of the following, I copied it from the forums many moons ago. It looks like it will fit your purpose, although a few mods for revolution coding may be needed. Hope it helps
You can author a plugin that uses $modx->sendForward() and is registered to the OnPageNotFound event that does whatever you want. Here is an example:
Code:
/*
OnPageNotFound
*/
/*
this should be the Resource id of the page containing your view Snippet
*/
$productResourceId = 21;
$requestURI = trim($_SERVER['REQUEST_URI'], '/');
$requestParts = explode('/', $requestURI, 2);
if (count($requestParts) == 2) {
if ($requestParts[0] === 'store') {
/*
this assumes you have a product table with an alias field for specifying the relative product URL as t-shirts/v-neck.html
*/
$productId = $modx->db->getValue("SELECT `product_id` FROM `product` WHERE `alias` = '{$requestParts[1]}'");
if (intval($productId)) {
/*
set the productId into the $_GET variable for your product view Snippet to use
*/
$_GET['productId'] = $productId;
/*
now forward the request to your Resource containing the product view Snippet
(forwarding does not change the requested URL like a redirect)
*/
$modx->sendForward($productResourceId);
}
}
}