Viewed   133 times

I want to know how to make a custom admin panel page in opencart.

Requires login with the controller - the admin panel does not seem to use the same controller as the normal site. I know how to make custom pages with opencart (but this is not for the admin)

A simple Hello World example would be great

 Answers

3

OpenCart 2.x

The path names have changed in OpenCart 2 - you will want to create

admin/controller/extension/module/hello.php admin/language/en-gb/extension/module/hello.php admin/view/template/extension/module/hello.tpl Then the route becomes

admin/index.php?route=extension/module/hello

OpenCart 1.x

  • Include full MVC flow.

I found out how to do this. OpenCart uses the MVC pattern. I recommend reading about How to be an OpenCart Guru? post about learning how the system works - this Admin workflow should also suffice for customer end.

1) Create a new file in admin/controller/custom/helloworld.php

Your filename and controller name should be the same in desc order:

helloworld.php

<?

class ControllerCustomHelloWorld extends Controller{ 
    public function index(){
                // VARS
                $template="custom/hello.tpl"; // .tpl location and file
        $this->load->model('custom/hello');
        $this->template = ''.$template.'';
        $this->children = array(
            'common/header',
            'common/footer'
        );      
        $this->response->setOutput($this->render());
    }
}
?>

2) Create a new file in admin/view/template/custom/hello.tpl

Hello.tpl

<?php echo $header; ?>
<div id="content">
<h1>HelloWorld</h1>
<?php
echo 'I can also run PHP too!'; 
?>
</div> 
<?php echo $footer; ?>

3) Create a new file in admin/model/custom/hello.php

<?php
class ModelCustomHello extends Model {
    public function HellWorld() {
        $sql = "SELECT x FROM `" . DB_PREFIX . "y`)"; 
        $implode = array();
        $query = $this->db->query($sql);
        return $query->row['total'];    
    }       
}
?>

4) You then need to enable the plugin to avoid permission denied errors:

Opencart > Admin > Users > User Groups > Admin > Edit

Select and Enable the Access Permission.

To visit your page go to

www.yoursite.com/opencart/admin/index.php?route=custom/helloworld

Tuesday, November 8, 2022
3

I'm firmly in the 1 camp. Currency conversion is core business logic, and belongs in your models, not your views.

Further, although money looks like floating-point numbers, it isn't. Money changes hands in integer quantities of whatever your base unit is. In the US, for example, If gumballs are 10 cents each and I buy ten, then I'm trading 100 pennies for 10 gumballs. Even if I give a dollar bill, from a software perspective, it's best to count that as 100 pennies.

For more on this, see Martin Fowler's "Patterns of Enterprise Application Architecture" and "Analysis Patterns". He talks through all the issues in detail and gives good sample code. You can also find some of that info on the web:

  • Quantity (with some money sample code)
  • Money (mainly a pointer into his book)

If you need the accounting to work, I'd also talk to the accountant. Currency conversion is often complicated by changing rates, weird fees, and other nonsense, and you can spend a long time chasing pennies to make the books balance if you don't get it right from the get-go.

Monday, August 8, 2022
 
arbel
 
5

If You really need to have the multi-domain multi-store, You can achieve it by setting up the sub-domain multi-store first and then making the domains to be aliases to this sub-domains, e.g.

  • Default Store -> http://www.domain.com
  • Store 1 -> http://sub1.domain.com
  • Store 2 -> http://sub2.domain.com
  • Store 3 -> http://sub3.domain.com

and then

  • http://www.domain1.com -> http://sub1.domain.com
  • http://www.domain2.com -> http://sub2.domain.com
  • http://www.domain3.com -> http://sub3.domain.com

Though the Store 1 could be accessed now by both http://sub1.domain.com and http://www.domain1.com it is up to marketing to deliver only http://www.domain1.com URL. Perhaps some other .htaccess restrictions/redirect from direct access to http://sub1.domain.com may be set but this is not necessary at all. Using these aliases to sub-domains You should be able to preserve all the functionality of multi-store on sub-domains...

Sunday, December 11, 2022
 
edison
 
3

hmmm. Thanks for your help everyone. The solution I have come up ( with your help ofcourse :) is as follows:

I have two custom templates:

   my_model_list.html
   my_model_detail.html

Under views.py:

class MyModel(object):
    # ... Access other models
    # ... process / normalise data 
    # ... store data

@staff_member_required
def my_model_list_view(request) #show list of all objects
    #. . . create objects of MyModel . . .
    #. . . call their processing methods . . .
    #. . . store in context variable . . . 
    r = render_to_response('admin/myapp/my_model_list.html', context, RequestContext(request))
    return HttpResponse(r)

@staff_member_required
def my_model_detail_view(request, row_id) # Shows one row (all values in the object) in detail     
    #. . . create object of MyModel . . .
    #. . . call it's methods . . .
    #. . . store in context variable . . . 
    r = render_to_response('admin/myapp/my_model_detail.html', context, RequestContext(request))
    return HttpResponse(r)

Under the main django urls.py:

urlpatterns = patterns( 
    '',
    (r'^admin/myapp/mymodel/$', my_model_list_view),
    (r'^admin/myapp/mymodel/(d+)/$', my_model_detail_view),
    ( r'^admin/', include( admin.site.urls ) )
)
Sunday, September 25, 2022
 
zeusnet
 
1

You would want to update the api.error content definition:

<!-- This content definition is to render an error page that displays unhandled errors. -->
<ContentDefinition Id="api.error">
  <LoadUri>~/tenant/default/exception.cshtml</LoadUri>
  <RecoveryUri>~/common/default_page_error.html</RecoveryUri>
  <DataUri>urn:com:microsoft:aad:b2c:elements:globalexception:1.1.0</DataUri>
  <Metadata>
    <Item Key="DisplayName">Error page</Item>
  </Metadata>
</ContentDefinition>
Tuesday, November 15, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :