4

I want to add a sub menu item "Locations" to "Catalog" menu item in opencart administration. On selecting locations, I want to see my own location management view page which inetracts with my own locations table in the opencart database.

Please let me know where and what mvc's to create to achieve this functionality in open cart. Thank you.

tereško
  • 58,060
  • 25
  • 98
  • 150
exception
  • 955
  • 2
  • 11
  • 23

2 Answers2

6

How to create a opencart admin module??

You can simply do this by adjusting:

Admin > controller > view > template > common > header.tpl

You can simply make adjustments to the menu on this page (static changes). To actually create modules for you and your staff etc. Then follow the tutorial of MVC posted on this page:

How to create a custom Admin Page in Opencart?

Community
  • 1
  • 1
TheBlackBenzKid
  • 26,324
  • 41
  • 139
  • 209
  • 1
    Thank you verry much. 1 note: `view` isn't in controller anymore, but 1 level higher ( child of `Admin` ) – Mathlight May 14 '13 at 16:28
2

I have already implemented your concept in my opencart project.

Notes:

1) by default in product adding dashboard page have a field to enter product location you fill product location there and follow my points

2) open catalog > model > category.php add this code

function getCategoryLoction($category_id) {
    $sql = "select p.location,count(p.location) as locCount from " . DB_PREFIX . "product p inner join " . DB_PREFIX . "product_to_category p2c on(p.product_id=p2c.product_id) where p2c.category_id=$category_id group by p.location";
    $query = $this->db->query($sql);
    return $query->rows;
}

3) open catalog > controller>module > category.php add this code

/* location based search starts here */
$incomingCatId  = ($this->data['category_id']!= '')?$this->data['category_id']:'0';
$locations  =   $this->model_catalog_category->getCategoryLoction($incomingCatId); 

foreach($locations as $loc):
    $this->data['locations'][] = array(
        'location' => $loc['location'],
        'count' =>  $loc['locCount'],
        'href' => $this->url->link('product/category', 'path=' . $incomingCatId.'&loc='.$loc['location'].'')
);
endforeach;    
/* location based search ends here */

4) open catalog > view >theme >default >template>module > category.tpl category add this code

<div class="l_nav_box">
    <div class="l_nav_title">
        <h6>Location</h6>
    </div>
    <ul class="cat_ul">
         <?php if(!empty($locations)): ?>
         <?php foreach ($locations as $loc) : ?>
         <?php if($loc['location']!= ''): ?>
         <li> <a href="<?php echo $loc['href']; ?>"><?php echo $loc['location']; ?> <span>(<?php echo $loc['count']; ?>)</span> </a> </li>

         <?php endif; ?>
         <?php endforeach; ?>
         <?php else: ?>
         No Locations mentioned
         <?php endif; ?>    
    </ul>       
</div>

5) important in admin side activate category module and save it choose

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Ishak Ali
  • 340
  • 4
  • 10
  • sorry dude I think it is not suit for you..This code is used to display locations and if you click it it redirects to appropriate product – Ishak Ali Oct 04 '12 at 09:44