News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Custom Field Types (Explained)

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

Previous topic - Next topic

amorino

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

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

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

amorino

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

amorino, you cannot use this in category.




amorino

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

Quote from: 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>
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

Quote from: PRO 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>

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

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

I just uploaded a pdf just like a regular image, and it works good

WITHOUT using custom field

see image

[attachment cleanup by admin]

amorino

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


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

amorino

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


amorino

#44
Thank you again Pro
I tried
<?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 :
<?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 :
<?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