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

amorino

  • Jr. Member
  • **
  • Posts: 144
    • Création sites web Tunisie
Re: Custom Field Types (Explained)
« Reply #30 on: August 09, 2012, 14:39:48 pm »
Sorry if i give a little up

but I'm blocked on how to insert the pdf in the category page
In the details page it's ok ;)
Best regards
Amorino
Création sites web Tunisie
http://www.idealconception.com

amorino

  • Jr. Member
  • **
  • Posts: 144
    • Création sites web Tunisie
Re: Custom Field Types (Explained)
« Reply #31 on: August 12, 2012, 13:58:58 pm »
Hello
could you please tell me how to make this code working with custom field type image?
I used it to upload pdf files

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


Best regrads
Amorino
Création sites web Tunisie
http://www.idealconception.com

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10272
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #32 on: August 12, 2012, 15:06:53 pm »
amorino,
The correct API is a little different, you have to check the position, to make sure it does not show up in all positions

the position name is "pdf"

If using a string for the pdf url

<?php foreach ($this->product->customfieldsSorted[$this->position] as $field) {
         if ($field->layout_pos == pdf) { ?>
<a class="pdficon" target="_blank" href="<?php echo $field->display;?>"></a><?php
         }
       }
       ?>

if just using image field
<?php foreach ($this->product->customfieldsSorted[$this->position] as $field) {
         if ($field->layout_pos == pdf) {
                               echo $field->display;
         }
       }
       ?>
I do NOT do development work for hire.

amorino

  • Jr. Member
  • **
  • Posts: 144
    • Création sites web Tunisie
Re: Custom Field Types (Explained)
« Reply #33 on: August 12, 2012, 18:11:35 pm »
Hello PRO,
thank you for your help I used the second code in Category template but it gives :
Warning: Invalid argument supplied for foreach() in /home/****/public_html/components/com_virtuemart/views/category/tmpl/default.php on line 305

In admin pannel I made the position of the field (pdf)

The code I used is :
<?php foreach ($this->product->customfieldsSorted[$this->position] as $field) {
         if ($field->layout_pos == pdf) {
                               echo $field->display;
         }
       }
       ?>

Coud you help me please
Best regards
Amorino
Création sites web Tunisie
http://www.idealconception.com

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10272
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #34 on: August 12, 2012, 18:32:45 pm »
amorino, you cannot use this in category.



I do NOT do development work for hire.

amorino

  • Jr. Member
  • **
  • Posts: 144
    • Création sites web Tunisie
Re: Custom Field Types (Explained)
« Reply #35 on: August 12, 2012, 18:37:38 pm »
Hello pro,

I tried it also in product details and it's the same :

Warning: Invalid argument supplied for foreach() in /home/****/public_html/components/com_virtuemart/views/productdetails/tmpl/default.php on line 54

Best regards
Amorino
Création sites web Tunisie
http://www.idealconception.com

techmodule

  • Beginner
  • *
  • Posts: 43
Re: Custom Field Types (Explained)
« Reply #36 on: August 13, 2012, 04:43:13 am »
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>
Dear
I use the type of custom field is image
But i dont know how to add image to this
Plz check for me
Thank you

[attachment cleanup by admin]

hiepnhung07

  • Beginner
  • *
  • Posts: 1
Re: Custom Field Types (Explained)
« Reply #37 on: August 13, 2012, 04:52:34 am »
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>

thank you for your teach but i am a new member and i dont know what's file i need add code to display image. please help me!

amorino

  • Jr. Member
  • **
  • Posts: 144
    • Création sites web Tunisie
Re: Custom Field Types (Explained)
« Reply #38 on: August 14, 2012, 18:09:01 pm »
Hello,
nothing works for me to display the pdf file uploaded :(

Any step by step help please
Best regards
Amorino
Création sites web Tunisie
http://www.idealconception.com

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10272
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #39 on: August 14, 2012, 19:07:58 pm »
I just uploaded a pdf just like a regular image, and it works good

WITHOUT using custom field

see image

[attachment cleanup by admin]
I do NOT do development work for hire.

amorino

  • Jr. Member
  • **
  • Posts: 144
    • Création sites web Tunisie
Re: Custom Field Types (Explained)
« Reply #40 on: August 14, 2012, 19:14:53 pm »
Thank you Pro
But how to put it in a specific position in the product details and category template
Thank you in advance
Amoriono
Création sites web Tunisie
http://www.idealconception.com

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10272
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #41 on: August 14, 2012, 19:58:40 pm »

default_images.php
This code will NOT display the PDF icon in the additional images div


<?php
// Showing The Additional Images
// if(!empty($this->product->images) && count($this->product->images)>1) {
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) {
       // Added By PRO
        if ($image->file_extension !=pdf) {
        // PRO Checks for PDF and does NOT Display it
      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
} // Showing The Additional Images END ?>




THEN: This code will display the PDF icon wherever you want to put it

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
}  ?>
I do NOT do development work for hire.

amorino

  • Jr. Member
  • **
  • Posts: 144
    • Création sites web Tunisie
Re: Custom Field Types (Explained)
« Reply #42 on: August 14, 2012, 22:52:11 pm »
Thank you a lot pro
I'm really near what I want to do

Now on the product page it works like a charm
I would just put it in category page
components/com_virtuemart/views/category/tmpl/default.php

But it doesn't work
Could you please help me to do it
Best regards
and thank youuuuuuuuuuuuuuuuu again
Amorino
Création sites web Tunisie
http://www.idealconception.com

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10272
  • VirtueMart Version: 3+
Re: Custom Field Types (Explained)
« Reply #43 on: August 14, 2012, 23:58:37 pm »
I do NOT do development work for hire.

amorino

  • Jr. Member
  • **
  • Posts: 144
    • Création sites web Tunisie
Re: Custom Field Types (Explained)
« Reply #44 on: August 15, 2012, 04:19:34 am »
Thank you again Pro
I tried
Code: [Select]
<?php
//Pro Hack PDF to position
if (!empty($product->images_name) and count ($product->images_name)>1) {
    
?>

    <div class="additional-images">
   <?php
   
// List all Images
   
if (count($product->images_name) > 0) {
       foreach (
$product->images_name as $image) {
       
// Displays ONLY pdf files
        
if ($image->file_extension ==pdf) {
      echo 
'<div class="floatleft"><strong> Télécharger la brochure : </strong> <br>' $image->displayMediaThumb('class="product-image"'true'class="modal"'truetrue) . '</div>'//'class="modal"'
       
}}
        
// PRO DONE, added the close tag
   
}
   
?>

        <div class="clear"></div>
    </div>
<?php
}  ?>

Also tried this :
Code: [Select]
<?php
//Pro Hack PDF to position
if (!empty($images->product_name) and count ($images->product_name)>1) {
    
?>

    <div class="additional-images">
   <?php
   
// List all Images
   
if (count($images->product_name) > 0) {
       foreach (
$images->product_name as $image) {
       
// Displays ONLY pdf files
        
if ($image->file_extension ==pdf) {
      echo 
'<div class="floatleft"><strong> Télécharger la brochure : </strong> <br>' $image->displayMediaThumb('class="product-image"'true'class="modal"'truetrue) . '</div>'//'class="modal"'
       
}}
        
// PRO DONE, added the close tag
   
}
   
?>

        <div class="clear"></div>
    </div>
<?php
}  ?>

also tried this :
Code: [Select]
<?php
//Pro Hack PDF to position
if (!empty($product->images) and count ($product->images)>1) {
    
?>

    <div class="additional-images">
   <?php
   
// List all Images
   
if (count($product->images) > 0) {
       foreach (
$product->images as $image) {
       
// Displays ONLY pdf files
        
if ($image->file_extension ==pdf) {
      echo 
'<div class="floatleft"><strong> Télécharger la brochure : </strong> <br>' $image->displayMediaThumb('class="product-image"'true'class="modal"'truetrue) . '</div>'//'class="modal"'
       
}}
        
// PRO DONE, added the close tag
   
}
   
?>
but always nothing to display
Best regards
Amorino
Création sites web Tunisie
http://www.idealconception.com