News:

Support the VirtueMart project and become a member

Main Menu

Custom Field Types (Explained)

Started by PRO, March 07, 2012, 18:04:25 PM

Previous topic - Next topic

dorex

Quote from: Mole_LR on November 15, 2012, 01:47:26 AM
What is the syntax to show THE CustomField, for example, CustomFieldX (not using foreach) into Category View. I'm using CategoryView as table and I need to show needed customfields in columns:

product_sku   customfieldX customfieldY
1111                  valueX1      valueY1
222                    valueX2       valueY2

Every product can have more customfields (also customfieldZ, customfieldA), but I need to show only these 2!

Is it possible, if yes - HOW?

Thank You!   

I've been reading almost all the posts related to custom fields. The above quoted answer is the only one I found, which is somehow related to my question. The problem is that the above mentioned question was never answered. Here is my question:

In the productdetails page, I would like to display a 2 colon table with all the details about the product ( not just the customfields !).

A table structure for the output, for example:

"Manufacturer:"         manufacturer name
"Product Title:"          title of the product
"Category:"               name of the category
"XYZ 001:"                 custom field value
"XYZ 002:"                 custom field value
"XYZ 003:"                 custom field values


NONE of the customfields are Cart Variant.

Customfield's specs are as follows:
XYZ 001   -   ID 30  - integer - one value per each product
XYZ 002   -   ID 31  - string - one value per each product
XYZ 003   -   ID 32  - string - multiple values per each product

So far, I've managed to display the first three rows.

My question is how do I echo the value of a SPECIFIC customfield (ONLY ONE customfield, without using foreach) in the productdetails page? (I want to insert that into a table cell.)

Thank you in advance for any advice on this one.

Here is what I tried (found some code in this post: http://forum.virtuemart.net/index.php?topic=100191.0 , but doesn't work) :





<table class="table_d_021">

<tr>
<th>Characteristics</th>
</tr>


<tr class="td02row_01">
<td>Manufacturer:</td>
<td><?php echo $this->product->mf_name ?></td>
</tr>


<tr class="td02row_02">
<td>Model:</td>
<td><?php echo $this->product->product_name ?></td>
</tr>


<tr class="td02row_01">
<td>Category:</td>
<td><?php echo $this->category->category_name?></td>
</tr>


<tr class="td02row_02">
<td>XYZ 001:</td>
<td>

<?php
     $db JFactory::getDBO();
  $query $db->getQuery(true);
  $query->select('custom_value');
  $query->from('#__fra_virtuemart_product_customfields');
  $query->where('virtuemart_product_id="' . (int) $db->escape($product->virtuemart_product_id) . '"');
  $query->where('virtuemart_custom_id="30"');
  $db->setQuery($query);
  $result $db->loadResult();
  echo "<span class=\"YourClass\">".$result."</span>";
?>


</td>
</tr>


<tr class="td02row_01">
<td>XYZ 002:</td>
<td>
                                  <div>
                 <?php if ($field->custom_title != "xyz-002") { ?>
                                 <?php echo JText::_($field->custom_title); ?>
                                 <?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png');
         } 
?>

                                  <span class="product-field-display"><?php echo $field->display ?></span>
                                  <span class="product-field-desc"><?php echo jText::_($field->custom_field_desc?></span>
                 </div>

</td>
</tr>


<tr class="td02row_02">
<td>XYZ 003:</td>
<td> ...........  </td>
</tr>

   
</table>




PHP 5.2.17 - Joomla 2.5.8 - Virtuemart 2.0.16

PRO

why not just use the custom field "specification" ??


dorex

Quote from: PRO on February 28, 2013, 17:07:40 PM
why not just use the custom field "specification" ??



Hi! Banquet, I don't really understand what you mean by custom field "specification".

I need to display in the same table the product title, the manufacturer, the category and some of the custom fields. Due to the fact that the custom fields output comes from default_customfields.php and not from default.php, it makes it very complicated for me. I took a look in default_customfields.php and even there the custom fields are called using "foreach". This is what puts them together and makes me helpless :( ... can't them be called separately ... by their ID, for example ?

Can you help me to display the value of a custom field (specified by it's ID or by it's name) in the product details page?

Thank you.
PHP 5.2.17 - Joomla 2.5.8 - Virtuemart 2.0.16

dorex

#78
Let me know if this is what you suggested by custom field "specification":

Create only one custom field, name it "Specification" and insert all the data in it, so that the "foreach" only displays one custom field?

This is not possible in my case, because even if they are not cart variants, all those custom fields are used with the "Custom Filter Pro"(from breakdesigns) in order to  filter the results in category-view.
Putting all the data in only one custom filter would make the results filtration useless and annoying for the visitor.

Thank you.
PHP 5.2.17 - Joomla 2.5.8 - Virtuemart 2.0.16

PRO

I am talking about the custom field "type"  "specification"


Hard Drive: Good
Monitor: Bad

etc.

Thats what its for

[attachment cleanup by admin]

dorex

Quote from: PRO on February 28, 2013, 21:56:57 PM
I am talking about the custom field "type"  "specification"


Hard Drive: Good
Monitor: Bad

etc.

Thats what its for

Thank you for your answer, Banquet.  I followed your advice and I've just tested custom field type "specification".  [ off topic: I think it has a bug you should check: Change the value "ABC" to "XYZ" in "Default info" field and click "save"; now you go to a product where this custom field was previously added, remove the custom field from there, save the product, then add the same custom field to the same product. It is now added with the old default info ("ABC"), instead of the new one ("XYZ"). ]

It doesn't answer to my question and it doesn't solve the problem, either. It is not what I need, because:

-- it only has two "Characteristic Label" & "Default info" fields. This means I should have a parent and create more children (custom field type specification) for it.
-- One should duplicate all the data from the other custom fields (the ones used for filtering results). This is NOT acceptable by the person who will administrate the shop. It's just about the same automation as pasting a table with specifications in the product description. And this process also can generate discrepancies between the data sets.

So, my question is still the same:

Can you help me to display the value of a custom field (specified by it's ID or by it's name) in the product details page?

Thank you.


PHP 5.2.17 - Joomla 2.5.8 - Virtuemart 2.0.16

PRO



I use this in default.php

<?php
if (!empty($this->product->customfieldsSorted['discount10'])) {
   $this->position='discount10';
   echo '<li class="redtext">';
   echo $this->loadTemplate('customfields');
   echo '</li>';}
?>

Its inside of a UL right under price


I do the same with warranty etc.

THEN:


YOU change default_customfields.php

to have specifics


here is my default_customfields.php

<?php defined ( '_JEXEC' ) or die ( 'Restricted access' );
?>

<?php foreach ($this->product->customfieldsSorted[$this->position] as $field) {
// this is a very simple 1 separated by warranty position
         if ($field->layout_pos == warranty) {
         echo $field->display;
         }
       }
       ?>
      
      <?php foreach ($this->product->customfieldsSorted[$this->position] as $field) {
// this is a very simple 1 seperated by warranty position
         if ($field->layout_pos == discount10) {
         echo $field->display;
         }
       }
       ?>
      
        <?php
       if (!empty($this->product->customfieldsSorted[$this->position])) {
if ($this->product->product_weight == 0){ $bwidth = "width49";}
else {$bwidth= "width90";}

       foreach ($this->product->customfieldsSorted[$this->position] as $field ) {
      if ($field->layout_pos == banners) {
          ?><div class="wrap"></div><div class="font15 left10 red shadow top10 center width90" id="saleBanner"><div class="<?php echo $bwidth ?>"><?php echo $field->display ?></div><?php if ($this->product->product_weight == 0) { ?>
                  <div class="width49"><?php echo JText::_('COM_VIRTUEMART_FREE_SHIP'); ?> <?php if ($this->product->min_order_level >1){ echo JText::_('COM_VIRTUEMART_FREE_SHIP_QUAN') .$this->product->min_order_level ;} ?></div><div class="wrap"></div>
               <?php    }?>   </div><div class="wrap"></div>
          <?php
      }
       } }
       ?>
      



as you can see I have different layouts foreach() position

sankalptech

Good explanation about custom field types.

realistix

Quote from: PRO on August 14, 2012, 19:58:40 PM

THEN: This code will display the PDF icon wherever you want to put it [/b]
This code can go in

productsdetails/tmpl/default.php

<?php
//Pro Hack PDF to position
if (!empty($this->product->images) and count ($this->product->images)>1) {
    ?>
    <div class="additional-images">
   <?php
   // List all Images
   if (count($this->product->images) > 0) {
       foreach ($this->product->images as $image) {
       // Displays ONLY pdf files
        if ($image->file_extension ==pdf) {
      echo '<div class="floatleft">' . $image->displayMediaThumb('class="product-image"', true, 'class="modal"', true, true) . '</div>'; //'class="modal"'
       }}
        // PRO DONE, added the close tag
   }
   ?>
        <div class="clear"></div>
    </div>
<?php
}  ?>

Hi Pro, just a quick question about the above code, got it working fine to display pdf with thumbnail on thep roduct description page but I would like it to display the "Displayed image subtitle" underneath. I have filled in the field for the pdf but it doesn't show on the product page. I'm assming it's just going to need one line of code?

Thanks in advance

patben

I want to display multiple custom fields in one place on product page, I have custom fields for books,  like pages, ISBN, publisher, etc and i want to display them together  like specification.
how can I do that??

jjk

Quote from: patben on May 16, 2013, 12:38:58 PM
I have custom fields for books,  like pages, ISBN, publisher, etc and i want to display them together  like specification.
how can I do that??

You can define a custom field named i.e. "Product Details" and then group all the other custom fields like Publisher, ISBN, Language, Format, etc. by selecting "Product Details" as the parent in the custom field settings. Thereafter you can select "Product Details" in your 'Product Edit' > 'Custom Fields' setting and all of them will display.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

patben

Quote from: jjk on May 16, 2013, 20:24:56 PM

You can define a custom field named i.e. "Product Details" and then group all the other custom fields like Publisher, ISBN, Language, Format, etc. by selecting "Product Details" as the parent in the custom field settings. Thereafter you can select "Product Details" in your 'Product Edit' > 'Custom Fields' setting and all of them will display.

i have groop all in a parent but when i put this parent to a product each custom field is in a new tab and not all in one

jjk

Quote from: patben on May 17, 2013, 12:20:29 PM
... each custom field is in a new tab and not all in one
That sounds like a problem with your template. You may switch temporarily to a standard Joomla template to see if it makes a difference.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

George Guebelli

Hello,
I am using Joomla 2.5.11 and VM 2.0.20b
I'm having problems setting up a textarea in my product. I go to Custom fields and set up as per instructions and save.
When I go to apply to a product, I select the text area and it places a huge textarea in the product area of the admin. I save it.
I go to product on Front end and there is nothing there.

I just need a simple textarea where the user can input special instructions for a product. Some products need this others don't.

Can someone please help me?

my site is www.guebelli.com/tshirts

Thanks,

George
George Guebelli

AH

You will need to change the dimensions of the text area using CSS
Regards
A

Joomla 4.4.5
php 8.1