Keyword

Extra Fields?

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 2 weeks ago #99868 by jmcruznet
Extra Fields? was created by jmcruznet
I made an extra field of price for each item but i want that extra field to show on the back-end item table and hide it from the front-end. Is that possible?

Please Log in or Create an account to join the conversation.

  • Yiota
  • Yiota's Avatar
  • Visitor
13 years 2 weeks ago #99869 by Yiota
Replied by Yiota on topic Extra Fields?
You can modify the extrafields if statement inside the item.php of your k2 template overrides to achieve that.

Please Log in or Create an account to join the conversation.

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 2 weeks ago #99870 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
Can you list how am i gonna do that? I'm not really into php programming. Thanks..

Please Log in or Create an account to join the conversation.

  • Yiota
  • Yiota's Avatar
  • Visitor
13 years 2 weeks ago #99871 by Yiota
Replied by Yiota on topic Extra Fields?
First of all make sure that you have made K2 template overrides. Read here how to if not.

 

Then open item.php and locate the following block.

 

<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>      <!-- Item extra fields -->      <div class="itemExtraFields">          <h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>          <ul>            <?php foreach ($this->item->extra_fields as $key=>$extraField): ?>            <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 endforeach; ?>            </ul>        <div class="clr"></div>      </div>      <?php endif; ?>

 

Replace it with this one and change the bolded part with your own.

 

<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>      <!-- Item extra fields -->      <div class="itemExtraFields">          <h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>          <ul>            <?php foreach ($this->item->extra_fields as $key=>$extraField): ?>                <?php if ($extraField->id=='EXTRAFIELD_PRICE_ID'): echo ''; ?>                <?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; ?>

 

Make sure that the first block matches the one I have pasted, which is of the default K2 template. If you have made changes, make the appropriate ones to the new code as well. All you need to pay attention to is the if part.

Please Log in or Create an account to join the conversation.

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 2 weeks ago #99872 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
Which item.php? I tried looking on the administrator components side thinking that the table was on the backend and didn't find "itemExtraFields". I tried looking at the Components side but i only found this line:

function extraFields(){        $mainframe = &JFactory::getApplication();        $itemID=JRequest::getInt('cid',NULL);        JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');        $catid = JRequest::getVar('id');        $category = & JTable::getInstance('K2Category', 'Table');        $category->load($catid);        require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'models'.DS.'extrafield.php');        $extraFieldModel= new K2ModelExtraField;        $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);        $output='<table class="admintable" id="extraFields">';        $counter=0;        if (count($extraFields)){            foreach ($extraFields as $extraField){                $output.='<tr><td align="right" class="key">'.$extraField->name.'</td>';                $output.='<td>'.$extraFieldModel->renderExtraField($extraField,$itemID).'</td></tr>';                $counter++;            }        }        $output.='</table>';

Please Log in or Create an account to join the conversation.

  • Yiota
  • Yiota's Avatar
  • Visitor
13 years 2 weeks ago #99873 by Yiota
Replied by Yiota on topic Extra Fields?
In templates/YOUR_TEMPLATE/html/com_k2/default/item.php. If that does not exist, read to the link I have provided above on how to create the K2 template overrides.

Please Log in or Create an account to join the conversation.

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 2 weeks ago #99874 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
Okay i did the templating already. I'm having a little problem with the social buttons though. I'll fix that later.

So if my PRICE ID is 1, ill change the bold part to <?php if ($extraField->id=='1'): echo ''; ?> ? Because i tried already both but still the price field doesn't show-up on the table. =/

Please Log in or Create an account to join the conversation.

  • Yiota
  • Yiota's Avatar
  • Visitor
13 years 2 weeks ago #99875 by Yiota
Replied by Yiota on topic Extra Fields?
That is what you wanted, right? You do not want the price field to show in the frontend of your site with all the other extrafields and just show it in the backend list of extrafields, right?

Please Log in or Create an account to join the conversation.

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 2 weeks ago #99876 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
I want the extrafield to show on item table. Another column for price field for each products.

Please Log in or Create an account to join the conversation.

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 2 weeks ago #99877 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
Anyway if that's not possible. Can i hide K2 custom fields for a certain user group? An example: if you are a Manager or Editor user you can see all fields - if you are only visiting you can't see certain custom fields.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum