Extrafields Visibility. K2 Extension - joomla

So i have this code changed in ../html/com_k2/template/default/item.php:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('Additional Info:'); ?></h3>
<ul>
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php $user =& JFactory::getUser(); ?>
<?php if($extraField->name == "Price" && $user->get('Guest') ==1): ?>
<?php else: ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo ($extraField->type=='date')?JHTML::_('date', $extraField->value, JText::_('K2_DATE_FORMAT_LC')):$extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<div class="clr"></div>
</div>
<?php endif; ?>
What I'm trying to achieve is to hide the extrafield on Guest Viewer on the front-page, and that extrafield will only be visible to certain User groups. I already tried changing this line three times:
name == "Price" && $user->get('Guest')==1): ?>
name == "itemExtraFields" &&$user->get('Guest')
==1): ?>
name == "itemExtraFieldsValue"
&&$user->get('Guest') ==1): ?>
(I named my custom field as Price)
So i don't know if I'm missing something on the code or i got the itemFields name wrong. Any help would be appreciated a ton. I already asked in the k2 forum and joomla forum but no one is answering.

Try this code. It is working fine.
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php if($extraField->name === "Price" && $this->user->guest){}
else{ ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?php }?>
<?php endforeach; ?>
I just added a strict comparison to the name and brackets for the if else condition. Also altered the way of checking guest user.

Related

Joomla 3.3.6 Category Blog - Subcategories before articles

I am trying to customise the category blog layout for only one category as follows:
this special category (ID 24) blog layout should display its list of
subcategories before the articles
the other categories will stick to the default layout: articles first and then
subcategories
I tried overriding blog.php:
<div class="blog<?php echo $this->pageclass_sfx; ?>" itemscope itemtype="http://schema.org/Blog">
<!-- SPECIAL CATEGORY - SUBCATEGORIES FIRST -->
<?php if ($this->category->id == 24 && !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; ?>
<?php
$introcount = (count($this->intro_items));
$counter = 0;
?>
<?php if (!empty($this->intro_items)) : ?>
<?php foreach ($this->intro_items as $key => &$item) : ?>
<?php $rowcount = ((int) $key % (int) $this->columns) + 1; ?>
<?php if ($rowcount == 1) : ?>
<?php $row = $counter / $this->columns; ?>
<div class="items-row cols-<?php echo (int) $this->columns; ?> <?php echo 'row-' . $row; ?> row-fluid clearfix">
<?php endif; ?>
<div class="span<?php echo round((12 / $this->columns)); ?>">
<div class="item column-<?php echo $rowcount; ?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?>"
itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<?php
$this->item = & $item;
echo $this->loadTemplate('item');
?>
</div>
<!-- end item -->
<?php $counter++; ?>
</div><!-- end span -->
<?php if (($rowcount == $this->columns) or ($counter == $introcount)) : ?>
</div><!-- end row -->
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!empty($this->link_items)) : ?>
<div class="items-more">
<?php echo $this->loadTemplate('links'); ?>
</div>
<?php endif; ?>
<!-- OTHER CATEGORIES - SUBCATEGORIES LAST -->
<?php if (!empty($this->children[$this->category->id]) && $this->maxLevel != 0 && $this->category->id != 24) : ?>
<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; ?>
<?php if (($this->params->def('show_pagination', 1) == 1 || ($this->params->get('show_pagination') == 2)) && ($this->pagination->get('pages.total') > 1)) : ?>
<div class="pagination">
<?php if ($this->params->def('show_pagination_results', 1)) : ?>
<p class="counter pull-right"> <?php echo $this->pagination->getPagesCounter(); ?> </p>
<?php endif; ?>
<?php echo $this->pagination->getPagesLinks(); ?> </div>
<?php endif; ?>
It displays fine for the other categories, but when trying to view the special one, I get this:
{category title}
{description}
Notice: Undefined property: ContentViewCategory::$item in {joomla}\templates\wse\html\com_content\category\blog_children.php on line 63
Notice: Undefined property: ContentViewCategory::$item in {joomla}\templates\wse\html\com_content\category\blog_children.php on line 63
Notice: Trying to get property of non-object in {joomla}\templates\wse\html\com_content\category\blog_children.php on line 63
Fatal error: Call to a member function get() on a non-object in {joomla}\layouts\joomla\content\readmore.php on line 17
Sooo I must be missing something :) Could anyone please help?
Many thanks.
Use this debug your code link It seems to me like its complaining about $item on line 63 of blog_children. Use the link provided earlier to check all the valid properties of ContentViewCategory class

Magento home page popular products

Hi All I want to show 4 popular products on the home page of my magento 1.7.1 install. (The I can select by putting them into a category).
I've set this up by creating a hidden category called popularhome and added 4 products into it.
I've included this in a static block into my home page template by using:
{{block type="catalog/product_list" column_count="4" category_id="17" template="catalog/product/listhome.phtml"}}
My listhome.phtml template looks like this:
<div class="row popularproducts">
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<div class="alert fade in">
<a class="close" data-dismiss="alert">×</a>
<?php echo $this->__('There are no products matching the selection.') ?>
</div>
<?php else: ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<?php else: ?>
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<?php endif ?>
<div class="c3">
<?php if(($i-1)%$_columnCount==0): ?><?php elseif($i%$_columnCount==0): ?><?php endif; ?>
<div class="thumbnail">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(225); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<div class="caption">
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</div>
</div>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
<?php endif ?>
<?php endforeach ?>
<?php endif; ?>
<?php endif; ?>
</div>
However this is only showing 2 of the 4 products yet I cannot figure out why? Does anyone see anything I am missing?
Thanks!
First you need to check ,the products that you want to be appear in category page,
Is they really belong to that categories.
After that make sure Backend > Manage Categories > Edit categories > Display settings >
is Anchor = yes Then re-index your catalog.
To verify you need to cross check catalog_category_product and catalog_category_product_index.
If the category id and product id is mapped properly in these tables you should be good to go.
hope this will sure help you!

Display specific category products on no results search page

When we search for a wrong keyword like "sdfsdf" in magento site, it displays that "your search returns no results". Here I want to display any category products like "similar products" category as we display "best sellers" on home page. I have tried by calling the block in the catalogsearch.xml. BUt catalogsearch.xml doent contain any block for no results. So how can I display any category products on no results page.
I have an idea like can we display a specific category products on .phtml page? If we can display specific category of products then we can call that category from "result.phtml". Any help?
my result.phtml
<?php if($this->getResultCount()): ?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-title category-title">
<?php if ($this->helper('rss/catalog')->getTagFeedUrl()): ?>
<?php echo $this->__('Subscribe to Feed') ?>
<?php endif; ?>
<h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
<?php if ($messages = $this->getNoteMessages()):?>
<p class="note-msg">
<?php foreach ($messages as $message):?>
<?php echo $message?><br />
<?php endforeach;?>
</p>
<?php endif; ?>
<?php echo $this->getProductListHtml() ?>
<?php else: ?>
<div class="page-title category-title">
<h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
<p class="note-msg">
<?php echo ($this->getNoResultText()) ? $this->getNoResultText() : $this->__('Your search returns no results.') ?>
<?php if ($messages = $this->getNoteMessages()):?>
<?php foreach ($messages as $message):?>
<br /><?php echo $message?>
<?php endforeach;?>
<?php endif; ?>
</p>
<div class="search-noresults">
<h1>Meanwhile, You may go through our featured categories:</h1>
</div>
<?php echo $this->getLayout()->CreateBlock('catalog/product_list')->setCategoryId(18)->setTemplate('catalog/product/list.phtml')->toHtml();?>
<?php endif; ?>
A simple solution is within catalogsearch/result.phtml template you would need to setup what happens when there are no results
<?php if($this->getResultCount()): ?>
SHOW RESULTS
LEAVE DEFAULT
<?php else: ?>
NO RESULTS
<?php echo $this->getLayout()->createBlock('catalog/product_list')->setCategoryId(4)->setTemplate('catalog/product/list.phtml')->toHtml() ?>
<?php endif; ?>

Magento: getAttributeText('manufacturer') doesn't work

I would very much appreciate your help. I am new to Magento and exploring it's possibilities. I have this piece of code, which loads products from category and their attributes:
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $_iterator = 0; ?>
<ul class="products-grid">
<?php $i=0; foreach ($_productCollection as $_product): ?>
<li class="item">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(252); ?>" width="252" height="252" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<h3 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h3>
<h4 class="product-name"><?php echo $_product->getAttributeText('manufacturer') ?></h4>
<?php echo $this->getPriceHtml($_product, true) ?>
</li>
<?php endforeach ?>
</ul>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
</div>
<?php endif; ?>
My question is: why "echo $_product->getAttributeText('manufacturer')" is not working here? I have tried countless variants with different code, but the manufacturer parameter just doesn't show up. Do you know why?
I have tried what Adam Moss has suggested and it worked:
'Show in Product Listing' needed to be set to yes in the attribute editor in admin. Then echo $_product->getAttributeText('manufacturer') worked without any problems.
so I got this working using #Shawn_Northrop suggestion;
<?php
echo $_product->getData('my_custom_attribute');
?>
Happy Coding...

Jooma K2 show user description in comments

I really need help this time - Joomla 2.5 and latest K2.
I'm using the default K2 comment system and I want to show the "Description" field for every commenter on that page.
So far I have this code:
$thisUserdata =& JFactory::getUser($comment->userID);
echo $thisUserdata->profile->description;
But this shows the description for the author of the page only.
If I log in with another account, it'll also show my own Description as long as I'm logged in.
All the coding I'm doing is in /components/com_k2/templates/default/item.php
The whole code for comments looks like this:
<?php if($this->item->numOfComments>0 && $this->item->params->get('itemComments') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2'))): ?>
<!-- Item user comments -->
<ul>
<?php foreach ($this->item->comments as $key=>$comment): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; echo (!$this->item->created_by_alias && $comment->userID==$this->item->created_by) ? " author-comment" : ""; echo($comment->published) ? '':' unpublishedComment'; ?>">
<div class="avatar">
<?php if($comment->userImage): ?>
<a href="<?php echo JFilterOutput::cleanText($comment->userLink); ?>" target="_blank" rel="nofollow">
<img src="<?php echo $comment->userImage; ?>" alt="<?php echo JFilterOutput::cleanText($comment->userName); ?>" width="<?php echo $this->item->params->get('commenterImgWidth'); ?>" />
</a>
<?php endif; ?>
</div>
<div class="inner">
<div class="author">
<?php if(!empty($comment->userLink)): ?>
<a href="<?php echo $comment->userLink; ?>" title="View <?php echo $comment->userName; ?> profile" target="_blank" rel="nofollow">
<?php echo $comment->userName; ?>
</a>
<?php else: ?>
<a rel="nofollow"><?php echo $comment->userName; ?></a>
<?php endif; ?>
</div>
<div class="date">
 <?php echo JHTML::_('date', $comment->commentDate, JText::_('K2_DATE_FORMAT_COM_MARIO')); ?>
</div>
<p><?php echo $comment->commentText; ?>
<?php
// USER DESCRIPTION
$thisUserdata =& JFactory::getUser($comment->userID);
echo $thisUserdata->profile->description;
?>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<div class="itemCommentsPagination">
<?php echo $this->pagination->getPagesLinks(); ?>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php if($this->item->params->get('commentsFormPosition')=='below' && $this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($this->item->catid)))): ?>
<!-- Item comments form -->
<div class="itemCommentsForm">
<?php echo $this->loadTemplate('comments_form'); ?>
</div>
<?php endif; ?>
With Joomla 2.5 you can use that to get basic user information, but you want to use the following to get the "description" or "about me" content of the commenting user..
$commentUser = JUserHelper::getProfile($comment->userID);
print_r($commentUser);
$about_me = $commentUser->profile['aboutme'];
echo $about_me;
Here is the link as well, this might help if you would like to do other things with the JUserHelper..
http://api.joomla.org/Joomla-Platform/User/JUserHelper.html#getProfile
EDIT: Make sure the plugin "User - Profile" is enabled or this will not work.

Resources