Showing posts with label k2. Show all posts
Showing posts with label k2. Show all posts

Monday, March 28, 2011

Enable HTML in joomla k2 extra fields

K2 is a wonderful CCK and content replacement for the standard joomla content. In fact I am using it with k2mart to create some awesome shopping cart goodnes. Of course the shopping cart I am converting from is a Custom CMS/E-commerce system that has tons of custom html pieces in the product buy now pages.

Specifically I needed the ability to choose several custom messages that have little html to open new windows, highlight messages etc.

There are community links for an older version of k2 here

These don't work in the latest so here is an updated working html hax for K2 v2.4.1!

Open up Administrator/components/com_k2/models/extrafield.php

//line 32 
if (!$row->bind(JRequest::get('post')))
 

//around line 53 look for 
$objects = array ();
$values = JRequest::getVar('option_value');
$names = JRequest::getVar('option_name');

Replace with the following (if you have questions see documentation)
 //line 32 - replaced
if (!$row->bind(JRequest::get('post',JREQUEST_ALLOWHTML)))


//around line 53 - replaced
$objects = array ();
$values = JRequest::getVar('option_value','','post','string',JREQUEST_ALLOWRAW);
$names = JRequest::getVar('option_name','','post','string',JREQUEST_ALLOWRAW);
 


Stumble Upon CodePyro

Tuesday, March 15, 2011

Remove modules from Virtuemart Checkout

In creating a new e-commerce site with K2 the Virtuemart checkout was showing all the homepage modules.

After reading a lot of different overly complex solutions on the forums I created this.

//add this code at the top of your template
global $option;
 
//disable modules for virtuemart checkout
 $vmpage= 0;
 if($option == 'com_virtuemart')
 {
  $vmpage= 1;
     $mainWidth = "twoL";
 }

//Then for every module position you need to turn off just add && !$vmpage
//example
if($this->countModules('right')  &&  !$vmpage ){}


Stumble Upon CodePyro

Sunday, March 13, 2011

k2mart Creating a module Product Grid

To create your product grid you will need to first setup k2mart custom listing overrides.

Once that is done create a new mod_k2_content module item and add it to your template. My grid is fairly large so it goes in the "bottom" position under the content.

Change module settings

  • Change the "Select sub-template" to your new custom override directory.
  • Select the categories or specific items, I chose categories to make it simple
  • Configure all of the things you would like to show, I turned off everything but the image; all of the items prices and names come from the k2mart plugin so we dont need any of the k2 items properties

!important: Before saving your module, make sure to enable k2 plugins under advanced in the module. Or k2mart will not load.

Now that your module is all setup we can make grid changes. Open up Template/html/mod_k2_content/CUSTOM_OVERRIDE/default.php file to alter the default list behavior. In this file you will find that the k2 items are setup in an HTML list.

Add a class of "productGrid" to the UL and "boxItem" to the LI.
//around line 20
<ul class="productGrid">
    <?php foreach ($items as $key=>$item):  
//around line 26 
<li class="<?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1) echo ' lastItem'; ?> boxItem">

Now go adjust your template style sheets to get the list items to behave as a grid. I wanted all of my k2 items in a box format to fit 4 items per row. To do this I made each list item a block with a width and padding to ensure they would fit in 980px.
.productGrid li.boxItem
{  
    color:#D76024;     
    display:block; 
    float:left; 
    font-weight:bold;
    font-size:14px !important;
    padding:5px 20px 5px 20px;
    width:200px;
}

Now we have a grid of our products but the k2 mart product boxes are ugly. Lets go fix that too.

Open up the custom override TEMPLATE/html/k2mart/module.php
Change the module.php k2mart class from class="itemVmFields" to class="itemGrid".

To get my desired look of Product Name, then Image, then Price, I copied over the image display from the mod_k2_content file. As you can see I removed the LI item for the product name and put it into an h4 tag before the image.

//K2mart STARTS HERE
<div class="itemGrid"> 

//moved product name into h4
 <?php if($this->params->get('moduleProductName') && !empty($product->name)): ?>
         <h4 >
            <span class="itemLabel"><?php echo JText::_('Name'); ?>:</span>
            <span class="itemValue"><?php echo $product->name; ?></span>
         </h4>
<?php endif; ?>

//Image code pulled from mod_k2_content/default.php        
 <?php if(isset($item)):?>
     <div class="moduleItemIntrotext">
            <a class="moduleItemImage" href="<?php echo $item->link; ?>" title="<?php echo JText::_('Continue reading'); ?> &quot;<?php echo K2HelperUtilities::cleanHtml($item->title); ?>&quot;">
              <img src="<?php echo $item->image; ?>" alt="<?php echo $item->title; ?>"/>
          </a>
       </div>
 <?php endif;?> 
    <ul> 

Now lets play with our style sheets for the k2mart items in our grid
.itemGrid ul { margin:0px; padding:0px;}
.itemGrid ul li{ margin:0px; padding:0px; height:auto; list-style:none;}
.itemGrid h4{ color:#AAA;}

Of course then I played with buttons and text styles, but hey its a start.

Final Results:


Stumble Upon CodePyro

Sunday, March 13, 2011

K2 override k2mart templates

In Joomla and K2 with K2 mart for virtuemart it was difficult for me to find/discover how best to customize the plugin templates. It turns out to be really simple though.

Create a folder called k2mart in your templates html overrides folder. TEMPLATE/html/k2mart

Then copy the 4 files from plugins/k2/k2mart/tmpl folder into your new overrides.


Specifically I needed to change the listing plugin to build a product grid. The listing template is actually calling the module.php file.


Stumble Upon CodePyro

Thursday, October 07, 2010

JUser::_load: Unable to load user with id

In joomla or k2 you may receive this error "JUser::_load: Unable to load user with id". Guess what, a user with that id was deleted and the error shows because some piece of content is trying to load that user account. In my case it was being thrown from k2 comments because the user had commented on the blog post had been deleted.

To resolve this create an empty user in the admin of joomla and change its ID to the missing one in phpmyadmin.

OR

You can just delete the users stuff.. i.e. comments photo etc from k2 or joomla.


Stumble Upon CodePyro

Thursday, August 26, 2010

k2 how to show comments on latestitem or category

If your here you are wondering how the heck am i able to show the comments section for a K2 item in either the latestitem or category template.

For starters you need to create a customized template override by placing a copy of
components/com_k2/templates into /templates/[YOUR TEMPLATE]/html/com_k2/.
Note: notice there will not be a templates folder in your custom html/com_k2. The template files go directly into the com_k2 folder!
More details on templates

I am using a menu item to pull k2 content, which doesn't show you the menu for selecting a sub-template. Basically this requires you to edit the template in the Default folder.

Now go ahead and edit the /templates/[YOUR TEMPLATE]/html/com_k2/latest_item.php. Find the line that says...

<?php echo $this->item->event->K2AfterDisplay; ?>

Now paste the following code just after that line.

<?php 
     //you can set the limit start by using pagination; we only needed the top 3 comments
  //look at line 143 of /components/com_k2/views/item/view.html.php
  $limitstart =0;
  $limit = 3;
  //get the comments array
  $comments = K2ModelItem::getItemComments($this->item->id, $limitstart, $limit);
   $this->item->comments = $comments; 
  ?>
  
  <?php if($this->item->params->get('itemComments') && ( ($this->item->params->get('comments') == '2' && !$this->user->guest) || ($this->item->params->get('comments') == '1'))):?>
  <!-- K2 Plugins: K2CommentsBlock -->
  <?php echo $this->item->event->K2CommentsBlock; ?>
  <?php endif;?>

 <?php if($this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2')) && empty($this->item->event->K2CommentsBlock)):?>
  <!-- Item comments -->
  <a name="itemCommentsAnchor" id="itemCommentsAnchor"></a>

  <div class="itemComments">

   <?php if($this->item->comments): ?>
  

   <ul class="itemCommentsList">
     <?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) ? " authorResponse" : ""; ?>">
 
    <span class="commentLink">
     <a href="<?php echo $this->item->link; ?>#comment<?php echo $comment->id; ?>" name="comment<?php echo $comment->id; ?>" id="comment<?php echo $comment->id; ?>">
      <?php echo JText::_('Comment Link'); ?>
     </a>
    </span>
 
     <?php if($comment->userImage):?>
     <img src="<?php echo $comment->userImage; ?>" alt="<?php echo $comment->userName; ?>" width="<?php echo $this->item->params->get('commenterImgWidth'); ?>" />
     <?php endif; ?>
 
     <span class="commentDate">
     <?php echo JHTML::_('date', $comment->commentDate, JText::_('DATE_FORMAT_LC2')); ?>
    </span>
 
    <span class="commentAuthorName">
     <?php echo JText::_("posted by"); ?>
     <?php if(!empty($comment->userLink)): ?>
     <a href="<?php echo $comment->userLink; ?>" title="<?php echo $comment->userName; ?>" target="_blank" rel="nofollow">
      <?php echo $comment->userName; ?>
     </a>
     <?php else: ?>
     <?php echo $comment->userName; ?>
     <?php endif; ?>
    </span>
 
    <p><?php echo $comment->commentText; ?></p>
 
     <div class="clr"></div>
   </li>
   <?php endforeach; ?>
    </ul>
 
  <?php endif; ?>
 

   <?php $user = &JFactory::getUser(); if ($this->item->params->get('comments') == '2' && $user->guest):?>
<!--     <div>
   <a href="<?php echo $this->item->link.'#itemCommentsAnchor'; ?>" title="<?php if(!empty($this->item->image_caption)) echo $this->item->image_caption; else echo $this->item->title; ?>">
   <?php echo JText::_('Login to post comments');?></a></div>-->
   
   <div class="s5box_login cboxelement"><a href="#"><?php echo JText::_('Login to post comments');?></a></div>
   <?php endif; ?>

  </div>
  <?php endif; ?>
 



If your interested the magic comes from the call to the K2ModelItem::getItemComments function. It actually retrieves the Comments array since it is not included in the Categories nor latest item. The Comments display code came directly from the item.php in the templates. Take a look at it if you need to add other functionality!


Stumble Upon CodePyro