So I have been working on integrating OpenCart in to UserFrosting (http://www.userfrosting.com/). Basically I am making all the admin dashboard pages load in the UserFrosting dashboard by using .load
to inject the pages into a div
on my own html pages. I am almost finished but have one last piece to get working that isn't remaining within the UF dashboard.
I will use the Catalog / Categories page as an example to show what I am doing:
Here is my html file for categories, it's called cata-categories.html
<!DOCTYPE html>
<html lang="en">
{% include 'components/head.html' %}
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<body>
<div id="wrapper">
{% include 'components/nav-account.html' %}
<div id="page-wrapper">
{% include 'components/alerts.html' %}
<ol id="categories"></ol>
<script>
$( "#categories" ).load( "../solutions/admin/index.php?route=catalog/category" );
</script>
<br>
{% include 'components/footer.html' %}
</div>
</div></div>
</body>
</html>
This is accessed via the sidebar of UserFrosting with the following code in sidebar.html:
{% if checkAccess('uri_manage_groups') %}
<li>
<a href="{{site.uri.public}}/cata-categories/"><i class="fa fa-tags fa-fw"></i>Categories</a>
</li>
{% endif %}
The page is rendered via the following code in public/index.php for UserFrosting:
$app->get('/cata-categories/?', function () use ($app) {
$app->render('cata-categories.html', [
'page' => [
'author' => $app->site->author,
'title' => "Catagories",
'description' => "Catalogue Catagories.",
'alerts' => $app->alerts->getAndClearMessages()
]
]);
});
To keep all links clicked on the OpenCart pages I put the following script on the bottom of each main .tpl
(so for example category_list.tpl
):
<script>
$("#categories").on("click", "a", function (e) {
$("#categories").load($(this).attr("href"));
e.preventDefault();
});
</script>
Then to keep things on the same page when submitting forms I changed the redirects in the controllers (eg. category.php) to be the following:
$this->response->redirect('../../portal/cata-categories');
Everything works great, now the only issue is errors in the form submission or filtering results. For example if someone tries to add a new category but doesn't fill in any information and clicks save, it redirects to /admin/index.php?route=catalog/category/add
but not within the UserFrosting dashboard.
I want it to remain within my dashboard, and need a nudge in the right direction on what to modify within the controller to get it to do this, I'm assuming some sort of AJAX to force it not to reload the page and just show the errors. Same thing with filter buttons, it obviously needs to add filters to the URL and therefore doesn't load within the dashboard - need a way to filter without refreshing.
Any help from people with experience modifying OpenCart would be greatly appreciated and if you need any more info on what I am doing feel free to ask.