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.
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?
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> <?php echo $loc['location']; ?> <span>(<?php echo $loc['count']; ?>)</span> </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
Related
I am currently working on an ecommerce website using opencart, trying to show the weight of each product, in product details template it works, however, when I do the same thing to the product block, it shows undefined variable. This is the site KCityMart
So what I did to show the weight in product details page is this
in file catalog/controller/product/product.php I added this
$data['weight'] = $this->weight->format($product_info['weight'],$product_info['weight_class_id']);
and in /catalog/view/theme/theme/template/product/product.tpl I added this
<ul class="volume">
<?php if ($weight > 0) { ?>
<li><?php echo $weight; ?></li>
<?php } ?>
</ul>
and it works. But, when I tried to add this to /catalog/view/theme/theme/template/common/product/default.tpl it shows "undefined variable" error.
What could be the problem? Which part did I miss?
Any input from you all will be very much appreciated. Thanks!
What is default.tpl file ? If it's new file then you need to create controller file for it and then do the same thing which you are performed in product controller.
Assigned weight varible in catalog/controller/product/default.php (Note: If you did not created default.php controller then you need to create) then add following code
> $data['weight'] = $this->weight->format($product_info['weight'],$product_info['weight_class_id']);
and in /catalog/view/theme/*/template/product/default.tpl
add following code in above file.
<ul class="volume">
<?php if ($weight > 0) { ?>
<li><?php echo $weight; ?></li>
<?php } ?>
</ul>
We are setting up a custom blog layout override for a Joomla site. I am trying to display the sub categories articles under their category headings.
For example the following structure:
Main Cat
- Sub Cat
-- Article 1
-- Article 2
- Sub Cat
-- Article 3
This layout is how the articles should display on the main blog override. For example going to Main Cat would display the above layout.
The subcategories are included in the default way with the following:
<?php if (!empty($this->children[$this->category->id]) && $this->maxLevel != 0) : ?>
<div class="cat-children">
<?php if ($this->params->get('show_category_heading_title_text', 1) == 1) : ?>
<h3> <?php echo JText::_('JGLOBAL_SUBCATEGORIES'); ?></h3>
<?php endif; ?>
<?php echo $this->loadTemplate('children'); ?> </div>
<?php endif; ?>
In the child override the title is included then we would like to display the articles from that child category.
I have tried multiple different versions of getting a for each to work for the sub articles but cannot get it to work.
For example:
<?php foreach ($this->child->children[$child->id] as $key => $item) : ?>
1
<?php echo $item->title; ?>
<?php endforeach; ?>
I have added a custom block that shows the sub categories of a parent category. as follows.
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
echo $_helper->categoryAttribute($_category, $_category->getName(), 'name');
$categoriess = $_category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($_category->getChildren())
?>
<ul class="subcategories">
<?php foreach ($categoriess as $categoryy): ?>
<li>
<a href="<?php echo $categoryy->getUrl() ?>"><img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $categoryy->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($categoryy->getName()) ?>" />
<span><?php echo $categoryy->getName() ?></span></a>
</li>
<?php endforeach; ?>
</ul>
This code correctly shows a list of the sub categories within the parent category. However when I navigate to one of these subcategories something weird happens.
The Problem
Parent category = CAR MAKES
sub categories = AUDI, FORD, VAUXHALL
Using the above code I correctly receive a list of the sub categories above. After flushing the cache, if I were to navigate to AUDI, the url will correctly generate for example:
mysite.com/CAR MAKES/Audi.html
This is fine, however if i then go back and navigate to FORD the url at the top of the page DOES display as
mysite.com/CAR MAKES/Ford.html
BUT
if I echo the url on the genrated page with this code:
<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl(); echo $currentUrl; ?>
it will always display
mysite.com/CAR MAKES/Audi.html
Even if I navigate to FORD, or VAUXHALL the url that is echo'd is /Audi.html, despite the url at the top of the page displaying correctly.
I am completely lost as to why this is happening. I am trying to produce a product list for each car make and model, but once you have navigated to one make and model, it will always display those results when navigating to another make and model. Unless I flush the cache, in which case the first time I navigate to a make and model it shows correctly, and after that the error repeats.
Add this code in your layout update.
<block type="core/template" template="your-template-path.phtml" name="template-name" ><action method="setCacheLifetime"><s>null</s></action></block>
So in a nutshell, you have two options for displaying Contacts in Joomla:
Show all Joomla Contact Categories.
Show all Joomla Contacts in a single Category.
I want to use the first option, but merge a list underneath each Category showing the list of contacts within that category, and a link to their profile.
The simplest way I thought of this was to edit a template override of the file com_contact/categories/default_items.php
I found a point where I want the list to appear, and then copied and pasted the code from the Category view (that generates the list of contacts).
<ul>
<?php // Add list of contacts for each category
foreach ($this->items as $i => $item) : ?>
<li>
<a href="<?php echo JRoute::_(ContactHelperRoute::getContactRoute($item->slug, $item->catid)); ?>">
<?php echo $item->name; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
But I am assuming I can't just copy and paste, as there needs to be an extra node added to $this->items.
At the moment, no list is being generated, just the <ul> outside the foreach loop.. but also interestingly, the <li> and the <a> IS being generated.. but linking to the current page I'm on (Probably because $item->slug is still being seen as the category).
So can anyone point me in the right direction as to how to reference the contacts within a category? All I'm after is the name and the slug/URL.
UPDATE:
I saw this in the same file (default_items.php) and although I realise it's referring to child categories... would this be a place to start for the actual contacts within the categories?
<?php if (count($item->getChildren()) > 0) :?>
<div class="collapse fade" id="category-<?php echo $item->id;?>">
<?php
$this->items[$item->id] = $item->getChildren();
$this->parent = $item;
$this->maxLevelcat--;
echo $this->loadTemplate('items');
$this->parent = $item->getParent();
$this->maxLevelcat++;
?>
</div>
<?php endif; ?>
BUMP - Does anyone have any experience with this? Or being able to call individual contacts when viewing a category? How are they linked?
For Category view in file default_children.php after tag <li... add code:
<?php
// Get Category Model data
$categoryModel = JModelLegacy::getInstance('Category', 'ContactModel', array('ignore_request' => true));
$categoryModel->setState('category.id', $child->id);
$categoryModel->setState('list.ordering', 'a.name');
$categoryModel->setState('list.direction', 'asc');
$categoryModel->setState('filter.published', 1);
$contacts = $categoryModel->getItems();
?>
For Custom Fields add this after previus code:
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
foreach($contacts as $contactItem) {
$currentContFields[] = FieldsHelper::getFields('com_contact.contact', $contactItem, true);
}
I want to make a menu that will dynamically show the active static pages from CMS; for example if in my CMS I have these pages:
About Us (enabled)
Shipping & Refund (disabled)
Terms and Conditions (enabled)
Contacts (enabled)
then the menu would look like:
About US | Terms and Conditions | Contacts
I need just a few tips on how to get started; maybe somebody has already done this before?
Dougle
thanks a lot, that was really helpful!
Fede
in Magento CMS you can make static pages that you can only access using its IDENTIFIER; what I wanted is somehow make a menu that will automatically display the ACTIVE (enabled) static pages; and if you set status to Disable it should not be in the menu;
here is the code i used, note there is IF $PageData['identifier']!='no-route'; no-rute is the 404 page, so i don't need it in the menu, but it must be enabled so Magento redirects 404 errors to this page;
<div>
<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php $collection->getSelect()
->where('is_active = 1'); ?>
<ul>
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php if($PageData['identifier']!='no-route') { ?>
<li>
<?php echo $PageData['title'] ?>
</li>
<?php } ?>
<?php endforeach; ?>
</div>
To exclude more than just the no-route I added a new field to the CMS pages to specify if the page should have a menu item or not using true or false. I followed Add a new CMS Field and used the following in main.php
$fieldset->addField('menu', 'text', array(
'name' => 'menu',
'label' => Mage::helper('cms')->__('On Menu'),
'title' => Mage::helper('cms')->__('On Menu'),
'required' => true,
'disabled' => $isElementDisabled
));
Then changed this line:
<?php if($PageData['identifier']!='no-route') { ?>
to
<?php if($PageData['menu']!= 'false') { ?>
Here is another way to put static links to Magento catalog menu.
First, create static page, assign some url key to it, for example, "my-test-page".
Go to /app/code/core/Mage/Catalog/Block, copy file Navigation.php to /app/code/local/Mage/Catalog/Block, now you able to edit it without any worries about the possibility of loosing your changes with Magento upgrade.
Open file Navigation.php at line 265 (magento 1.4) function _renderCategoryMenuItemHtml(...), change code:
$htmlLi .= '>';
$html[] = $htmlLi;
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
to that:
$htmlLi .= '>';
$html[] = $htmlLi;
if(preg_match('/\/static-/', $this->getCategoryUrl($category))) {
$link_url = str_replace("static-", "", $this->getCategoryUrl($category));
} else {
$link_url = $this->getCategoryUrl($category);
}
$html[] = '<a href="'.$link_url.'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
Now go to Categories management, edit category, change URL key to that: "static-my-test-page" and uncheck "Create Permanent Redirect for old URL" check-box. After saving category you will have link to my-test-page at top categories menu in Magento.
So after all that changes you can convert category link to static page link by adding prefix "static-" to category URL key.
In your page/html block create a method containing:
$collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());
$collection->getSelect()
->where('is_active = 1')
->order('main_table.sort_order ASC');
return $collection;
Which you can call in your template and foreach() through creating your LIs
Might need some tweaking mind, depending on your setup.
From memory though i think this is built in, have a look in design/frontend/../../templates/page/ i seem to remember striping out some similar functionality in one of the phtml files in there.
where, order and other select stuff can be found in /lib/Zend/Db/Select.php(FYI)