Author Topic: Custom Field Types (Explained)  (Read 195167 times)

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10443
  • VirtueMart Version: 3+
Custom Field Types (Explained)
« on: March 07, 2012, 18:04:25 PM »
still working

This thread will layout all types in the custom field list.

Custom Field Codes for Coders

S = String
I =Integer
P =Property (was Parent, which was a group!)
B= Bolean (True)
D = Date
T = Time
M =Image
V =Cart Variant
A =Generic Child Variant
X=Editor
Y=Textarea

For example
<?php if ($field->field_type == S){
My Special String Output
} ?>

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10443
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #1 on: March 08, 2012, 16:12:17 PM »
Using The Custom Field Type "String" for an extra field.

Warranty Display Example
1st Setup a Custom field type "string" called "warranty" like in the picture below.
Next Go Into a product, and apply the custom field "warranty" to the product.
Fill In the warranty text. 2 years, 3 years etc.

NEXT:: You need to create a position in your product details view for the warranty text.
<div id="warranty-text"><strong>This is the Warranty Div</strong>
<?php if (!empty($this->product->customfieldsSorted['warranty'])) {
   $this->position='warranty';
   echo $this->loadTemplate('customfields'); } ?></div>



[attachment cleanup by admin]

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10443
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #2 on: March 08, 2012, 17:21:22 PM »
Use the Custom field "IMAGE" to display a NON-cart Variant.

Free Shipping Icon on product page example.

1st Create a Custom field type "image" and name it "shipping icon" like the image below.
Next, upload your free shipping icon in "shop media files"
Go to edit product, and apply the custom field. Choose the image in the dropdown.

[attachment cleanup by admin]

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10443
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #3 on: March 08, 2012, 19:13:18 PM »
Using a String for external images


Create a Custom field  type "string" named "external"
In Edit Product apply the field. Paste the url to the image in the field.
This below is the code for displaying the image.

<div class="product-fields">
       <?php
       $custom_title = null;
       foreach ($this->product->customfieldsSorted[external] as $field) {
      if ($field->display) {
          ?>
          <?php if ($field->custom_title != $custom_title) { ?>
            <img src="<?php echo $field->display ?>" alt="<?php echo $this->product->product_name ?>"  />
<?php } ?>
          <?php } ?> <?php } ?>
        </div>


Using a String to Link to related articles, installation instructions etc.


Create a Custom field  type "string" with the name "Installation Instructions" or whatever you want the anchor text to be.
Assign it to the position "link"
In Edit Product apply the field. Paste the url
This below is the code for displaying the link.

<div class="product-fields">
       <?php
       $custom_title = null;
       foreach ($this->product->customfieldsSorted[link] as $field) {
      if ($field->display) {
          ?>
          <?php if ($field->custom_title != $custom_title) { ?>
             <a href="<?php echo $field->display ?>" ><?php echo JText::_($field->custom_title); ?></a>
<?php } ?>
          <?php } ?> <?php } ?>
        </div>

kg

  • Beginner
  • *
  • Posts: 26
Re: Custom Field Types (Explained)
« Reply #4 on: March 29, 2012, 17:20:18 PM »
Hi
Thank you for this post.

It seems the list is not complete:
S = String
I=Integer
P=Parent
B=Boolean
D=Date
T=Time
M=Image
V=Cart Variant
A=Generic Child Variant
G=Plugin
X=Editor
Y=Text Editor


When I look in the code, it seems there is a type "E" and that is a Plugin with VM-Custom

// kg

Da_Hobit

  • Beginner
  • *
  • Posts: 22
Re: Custom Field Types (Explained)
« Reply #5 on: April 08, 2012, 10:13:43 AM »
thnx BanquetTables.pro for this great post !

with the products i use the custom fields this script works like a charm, but when i have a product without the custom fields i get the following error:

Warning: Invalid argument supplied for foreach() 

i guess i need to alter the code with a check if that custom field exists or not... but don't know it , can you help ?
maybe with :  if ($field != null) { 

thnx !  - my appologies when this reply is in the wrong topic -


 to 'open the link' in a new tab, just add "target="_blank" to a href code:
<a href="<?php echo $field->display ?>"target="_blank"><?php echo JText::_($field->custom_title); ?></a>


PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10443
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #6 on: April 08, 2012, 20:56:47 PM »
is the foreach error in

default_customfields

or 

default.php

Da_Hobit

  • Beginner
  • *
  • Posts: 22
Re: Custom Field Types (Explained)
« Reply #7 on: April 08, 2012, 23:23:34 PM »
default.php

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10443
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #8 on: April 09, 2012, 11:45:11 AM »
This is how the ontop is done

<?php  if (!empty($this->product->customfieldsSorted['ontop'])) {
   $this->position = 'ontop';
   echo $this->loadTemplate('customfields');
    } // Product Custom ontop end
    ?>

totallnet

  • Beginner
  • *
  • Posts: 3
Re: Custom Field Types (Explained)
« Reply #9 on: May 19, 2012, 20:41:49 PM »
Hi all

Is it possible to create Top Ten and Most Sales in custom fields too ??
I dont need to show in products page but only in my custom search ...

Thanks in advance

Kazuo

gldproducts

  • Beginner
  • *
  • Posts: 40
Re: Custom Field Types (Explained)
« Reply #10 on: June 05, 2012, 16:33:42 PM »
Using The Custom Field Type "String" for an extra field.

Warranty Display Example
1st Setup a Custom field type "string" called "warranty" like in the picture below.
Next Go Into a product, and apply the custom field "warranty" to the product.
Fill In the warranty text. 2 years, 3 years etc.

NEXT:: You need to create a position in your product details view for the warranty text.
<div id="warranty-text"><strong>This is the Warranty Div</strong>
<?php if (!empty($this->product->customfieldsSorted['warranty'])) {
   $this->position='warranty';
   echo $this->loadTemplate('customfields'); } ?></div>

Pardon me, but what page do you add the code to?

lipes

  • Full Member
  • ***
  • Posts: 720
Re: Custom Field Types (Explained)
« Reply #11 on: June 06, 2012, 16:23:01 PM »
one question. In the Category i got this php code inserted in
<div class="product floatleft ... >
Code: [Select]
<div class="spacer">
<?php $custom_title null; foreach ($product->customfields as $field) {
if ($field->is_hidden //OSP http://forum.virtuemart.net/index.php?topic=99320.0
continue;
if ($field->display) { ?>

<span class="product-field-display"><?php echo $field->display ?></span>
<?php ?>
<?php }  ?>

When the products (In Category browsing) got any Custom Field image works good... but when the product doesnt have any custom field image gives me this msg:
Warning: Invalid argument supplied for foreach() in D:\Ampps\www\Teste2\templates\teste2\html\com_virtuemart\category\default.php on line 197
VM V. online: J2.5.14 | VM 2.0.20a | SQL 5.1.70 | PHP 5.3.25

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10443
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #12 on: June 06, 2012, 18:04:31 PM »


if (!empty($product->customfields)) {


}

lipes

  • Full Member
  • ***
  • Posts: 720
Re: Custom Field Types (Explained)
« Reply #13 on: June 06, 2012, 18:17:55 PM »
yep now its showing the image CF in the Category with products... it's working with:
Code: [Select]
<?php $custom_title null
if (!empty(
$product->customfields)) {
foreach (
$product->customfields as $field) {
if (
$field->is_hidden //OSP http://forum.virtuemart.net/index.php?topic=99320.0
continue;
if (
$field->display) { ?>

<span class="product-field-display"><?php echo $field->display ?></span>
<?php ?> <?php ?> <?php }  ?>
VM V. online: J2.5.14 | VM 2.0.20a | SQL 5.1.70 | PHP 5.3.25

jbmd

  • Beginner
  • *
  • Posts: 13
Re: Custom Field Types (Explained)
« Reply #14 on: June 07, 2012, 15:28:23 PM »
Please, is there any way how to make plugin "custom text input" obligatory (required)?