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

PRO

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

#1
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

#2
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

#3
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

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

#5
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

is the foreach error in

default_customfields

or 

default.php


PRO

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

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

Quote from: BanquetTables.pro 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>

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

lipes

one question. In the Category i got this php code inserted in
<div class="product floatleft ... >
<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



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


}

lipes

#13
yep now its showing the image CF in the Category with products... it's working with:
<?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

Please, is there any way how to make plugin "custom text input" obligatory (required)?