Keyword

Extra Fields?

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 8 months 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 8 months 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 8 months 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 8 months 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 8 months 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 8 months 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 8 months 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 8 months 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 8 months 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 8 months 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.

More
13 years 8 months ago #99878 by william white

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

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 8 months ago #99879 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
This is the item.php from templates/html/com_k2?

William White said:
williamwhitejr.com/index.php?option=com_k2&view=item&amp...

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

More
13 years 8 months ago #99880 by william white
Replied by william white on topic Extra Fields?
Yes, best to put it in an override directory so changes wont be lost if you reinstall k2

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

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 8 months ago #99881 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
It's giving me an error. I made a few tweaks though.

 

<?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):?>            <!-- insert code to test for registared and wether or not to skip here Replace HideField2 with name of your extra field--> <?php $user =& JFactory::getUser(); ?> <strong><?php if($extraField->name == "Price" && $user->get('guest') ==1) { ?></strong> <!-- prove it works - delete the text below after testing -->            field omitted            <?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; ?>

 

The error is Parse error: syntax error, unexpected T_ENDIF

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

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 8 months ago #99882 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
I figured out the error. But the extra-field is still showing to Guest users, I'm guessing it's my extra_field name.. How do i find or know my extra_field_name if i named it Price? Thanks in advance for everything too.

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

More
13 years 8 months ago #99883 by william white
Replied by william white on topic Extra Fields?
check the spelling and capitalization of the extra field name

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

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 8 months ago #99884 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
How do i find my extra field name? I named my custom field 'Price'.

I already have tried changing the name to this:


<strong><?php if($extraField->name == "Price" && $user->get('Guest') ==1): ?></strong>
<strong><?php if($extraField->name == "itemExtraFields" && $user->get('Guest') ==1): ?></strong>
<strong><?php if($extraField->name == "itemExtraFieldsValue" && $user->get('Guest') ==1): ?></strong>

Nothing worked..

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

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 8 months ago #99885 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
any idea? anyone?

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

  • jmcruznet
  • jmcruznet's Avatar Topic Author
  • Offline
  • Junior Member
More
13 years 8 months ago #99886 by jmcruznet
Replied by jmcruznet on topic Extra Fields?
I got it! Thanks a Billion! anyway, here's the refined code for your code William White:

 

<?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 ($user->guest): ($extraField->name == "itemExtraFields")?>

<?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; ?>

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


Powered by Kunena Forum