How can i add custom class="featured" into html\com_content\category\blog_item.php if that rendered article is featured too?
Is there a line of code that can determines if the article is featured?
Thanks!
Ok i`ve got it!
Into html\com_content\category\blog.php
Paste this lines on line 79
<?php
$featuredclass = '';
$item = &$item;
if ($item->featured == 1) {
$featuredclass = 'featured';
}
?>
And add
<?php echo $featuredclass;?>
on line 86
<div class="items-row cols-<?php echo (int) $this->columns;?> <?php echo 'row-'.$row ; ?>">
So it looks like this:
<?php
$featuredclass = '';
$item = &$item;
if ($item->featured == 1) {
$featuredclass = 'featured';
}
?>
<div class=" <?php echo $featuredclass;?> items-row cols-<?php echo (int) $this->columns;?>
<?php echo 'row-'.$row ; ?>">
Special thanks to Bojcheski
Related
I am using opencart version 2.0.2.0 and now i am trying to get image or image url in manufacturer page.
I have added the code in catalog/controller/product/manufacturer.php
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
if($manufacturer_image){
$this->data['manufacturers_img'] = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$this->data['manufacturers_img'] = false;
}
and call it in catalog/view/theme/default/template/product/manufacturer_list.tpl
<div class="row">
<?php foreach ($manufacturers as $manufacturer) { ?>
<div class="col-sm-3"><?php echo $manufacturer['name']; ?>
<?php echo ($manufacturers_img) ? '<img src="'.$manufacturers_img.'" alt="'.$manufacturers.'" />' : $manufacturers ;?><br />
</div>
<?php } ?>
</div>
But it's getting error in my /index.php?route=product/manufacturer page
Notice: Undefined variable: manufacturers_img in
/data1/opencart-2.0.2.0/catalog/view/theme/default/template/product/manufacturer_list.tpl
on line 32Array
lets be clear ControllerProductManufacturer index() shows list and info() shows detail of the mfg,
//catalog/controller/product/manufacturer.php:46
Replace
$data['categories'][$key]['manufacturer'][] = array(
with
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($result['manufacturer_id']);
if($manufacturer_image){
$mfg_img = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$mfg_img = false;
}
$data['categories'][$key]['manufacturer'][] = array(
'image'=>$mfg_img,
And in catalog/view/theme/default/template/product/manufacturer_list.tpl:30
inside loop
<?php if($manufacturer['image']):?>
<img src="<?php echo $manufacturer['image']; ?>" alt="<?php echo $manufacturer['name'];?>">
<?php endif;?>
Trying to build sidebar category structure in Magento so that all children for an active category show when clicked. Using below as sample, when you go into main catalog only Main Cats appear. Then when clicking any Sub Cat the children for that respective category appear and so on.
For example
Main Cat 1
Sub Cat 1
Sub/Sub 1
Sub/Sub 1
Sub/Sub 1
Sub Cat 1
Sub Cat 1
Main Cat 2
Main Cat 3
Here's the current code I have, but once you get to the last category, only the Main Cats show (in other words, if you click on Sub/Sub, the menu closes and shows only the Main Cats).
<aside id="sidebar">
<div class="sidebar-nav">
<h2><?php echo $this->__('Products') ?></h2>
<ul>
<?php foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li>'.$cat->getName()."<ul>";
foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>'.$subcat->getName()."</li>";
}
echo "</ul></li>";
} else {
echo '<li>'.$cat->getName()."</li>";
}
} ?>
</ul>
</div>
<div class="sidebar-nav">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('holiday-nav-links')->toHtml() ?>
</div>
<div class="sidebar-nav">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('about-us-nav-links')->toHtml() ?>
</div>
</aside>
Any help is much appreciated. Thank you in advance for the help!
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Please check this link http://fishpig.co.uk/magento/tutorials/display-categories-and-subcategories-in-magento/
hope this help you
Had to do this very thing a few days back . get my whole function, may include some unnecessary html parts though. Shows 2nd level categories level onwards (for 3rd level category view as well)
public function getCatTree()
{
$treeHtml = '';
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
$category = Mage::registry('current_category');
$level = $category->getLevel();
switch($level)
{
case 4 :
$level3Cat = $category->getParentCategory();
$level2Cat = $level3Cat->getParentCategory();
break;
case 3 :
$level2Cat = $category->getParentCategory();
break;
case 2 :
$level2Cat = $category;
break;
default :
$level2Cat = null;
break;
}
//get the level 2 category ID
$categoryId = $level2Cat->getId();
if (count($_categories) > 0)
{
foreach ($_categories as $_category)
{
//match with the level 2 category, then list all its children
if ($_category->getId() == $categoryId)
{
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_catChildrens = $_category->getAllChildren();
foreach(explode(',',$_catChildrens) as $index=>$child)
{
$cat = Mage::getModel('catalog/category')->load($child);
if($cat->getLevel() == 3 && $cat->getIsActive())
{
$isParent = ($cat->hasChildren()) ? 'parent' : '';
$treeHtml .= '<li class="level1 nav'.$cat->getLevel().' '.$isParent.'">'.
'<a href="'.$cat->getUrl().'">'.
$cat->getName().
'</a>';
if($cat->hasChildren())
{
$treeHtml .= '<div class="sub-menu-wrap"><ul class="level1">';
foreach($cat->getChildrenCategories() as $indx=>$_subcategory)
{
if($_subcategory->getIsActive())
{
$cat4 = Mage::getModel('catalog/category')->load($indx);
$treeHtml .= '<li class="level2 nav'.$cat4->getLevel().'">'.
'<a href="'.$cat4->getUrl().'">'.
$cat4->getName().
'</a></li>';
}
}
$treeHtml .= '</ul></div>';
}
$treeHtml .= '</li>';
}
}
return $treeHtml;
}
}
}
}
For some reason, only on view-mode icons on the product list, the "?" of the urls are replaced to "#21". Ex.: "#%21mode=list"
Somebody can help me?
Some code:
app/design/frontend/default/themename/template/catalog/product/list/toolbar.phtml
<?php if( $this->isEnabledViewSwitcher() ): ?>
<p class="view-mode">
<?php $_modes = $this->getModes(); ?>
<?php if($_modes && count($_modes)>1): ?>
<label><?php echo $this->__('View as') ?>:</label>
<?php foreach ($this->getModes() as $_code=>$_label): ?>
<?php if($this->isModeActive($_code)): ?>
<strong title="<?php echo $_label ?>" class="<?php echo strtolower($_code); ?>"><?php echo $_label ?></strong>
<?php else: ?>
<?php echo $_label ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</p>
<?php endif; ?>
app/code//core/Mage/Catalog/Block/Product/List/Toolbar.php
public function getModeUrl($mode)
{
return $this->getPagerUrl( array($this->getModeVarName()=>$mode, $this->getPageVarName() => null) );
}
and...
public function getPagerUrl($params=array())
{
$urlParams = array();
$urlParams['_current'] = true;
$urlParams['_escape'] = true; // I already tried set false, but didn't helps
$urlParams['_use_rewrite'] = true;
$urlParams['_query'] = $params;
return $this->getUrl('*/*/*', $urlParams); // I also tried not use the getUrl and concat the querystring, strangely the replace still happends...
}
I couldn't find the problem, but I make a dirt solution:
<?php echo str_replace('#%21', '&', $this->getModeUrl($_code)); ?>
I wish somebody find a better solution :)
I'm having some troubles figuring out how to change the order of the totals in the transactional email templates (In Magento).
Basicly I want the 'Tax' row to be at the very bottom - below 'Grand total incl. tax'.
I know that this is the code, that prints the rows. But I can't seem to figure out how to change the order of the rows.
<?php foreach ($this->getTotals() as $_code => $_total): ?>
<?php if ($_total->getBlockName()): ?>
<?php echo $this->getChildHtml($_total->getBlockName(), false); ?>
<?php else:?>
<tr class="<?php echo $_code?>">
<td <?php echo $this->getLabelProperties()?>>
<?php if ($_total->getStrong()):?>
<?php echo $this->escapeHtml($_total->getLabel());?>
<?php else:?>
<?php echo $this->escapeHtml($_total->getLabel());?>
<?php endif?>
</td>
<td <?php echo $this->getValueProperties()?>>
<?php if ($_total->getStrong()):?>
<?php echo $this->formatValue($_total) ?>
<?php else:?>
<?php echo $this->formatValue($_total) ?>
<?php endif?>
</td>
</tr>
<?php endif?>
Could anyone be of help with this problem?
Thanks and have a wonderful day!
Method 1: Modifying the theme template file.
Copy app/design/frontend/base/sales/order/totals.phtml to your theme file and open it.
Add the following to the top of it.
if($tax = $this->getTotal('tax'))
{
$this->removeTotal('tax');
$this->addTotal($tax, 'grand_total');
}
This code will remove the tax from the totals list, then re-add it below the Grand Total. You should move the totals.phtml file into your custom theme folder so upgrades won't override it.
Method 2: Overriding the core block file.
You can do the same patch by overriding the core Totals block by doing the following:
Copy app/code/core/Mage/Sales/Block/Order/Totals.php to app/code/local/Mage/Sales/Block/Order/Totals.php
Open app/code/local/Mage/Sales/Block/Order/Totals.php and change the getTotals() function to the following:
public function getTotals($area=null)
{
//Move tax below grand_total
if($tax = $this->getTotal('tax'))
{
$this->removeTotal('tax');
$this->addTotal($tax, 'grand_total');
}
$totals = array();
if ($area === null) {
$totals = $this->_totals;
} else {
$area = (string)$area;
foreach ($this->_totals as $total) {
$totalArea = (string) $total->getArea();
if ($totalArea == $area) {
$totals[] = $total;
}
}
}
return $totals;
}
I’m using a custom template I created, and I’m trying to display “Only X left Threshold” set at 1 on the category list(grid) page.
Magento ver. 1.4.1 -
Can anyone help me out?
EDIT
Thanks Alan, solved.
To those who need this for configurable products, here is the code for 'Less than 4 products remaining"
<?php if($_product->getTypeId() == "configurable"):
$total = 0;
$ids = $_product->getTypeInstance()->getUsedProductIds(); ?>
<ul>
<?php foreach ($ids as $id) :
$simpleproduct = Mage::getModel('catalog/product')->load($id); ?>
<li><?php $simpleproduct->getName()." - ".(int)Mage::getModel('cataloginventory/stock_item')
->loadByProduct($simpleproduct)->getQty(); ?>
</li>
<?php $total = $total + (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty(); ?>
<?php endforeach; ?>
<li><?php if ($total < 4) {
echo ("Only ".$total." Left!");
}?></li>
</ul>
<?php endif; ?>
if($product->getQty() < $some_num)
{
echo 'Only' . $product->getQty() . ' left';
}
$qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if($qtyStock < 10) {
echo 'Only' . $qtyStock . ' left';
}