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

How to call spesific costume fields?

Started by belsaas, April 11, 2015, 15:11:46 PM

Previous topic - Next topic

belsaas

Hi!

I am trying to find how I can call a specific, or specifics custom fields.
I have red some in the forum but didn't got som solutions.

It is seven custom fields I want to call (been shown). They have their ID 13, 15, 17, 18, 20, 21, 22.

I used this code in an earlier version of VM (Now I use VM3.0.6.4), and it work proper, but not with the new version of VM.


                                 <?php $theseones = array(13,15,17,18,20,21,22);
                                            foreach(
$product->customfields as $field) {
                                                if(
in_array ($product->virtuemart_custom_id,$theseones)) {
                                                    
?>

                                                    <div class="customfields">
                                                        <?php if($field->virtuemart_custom_id == '13') {  ?>
                                                            <span class="vm-custom-title"><?php echo JText::_($field->custom_title); ?></span>
                                                            <span class="vm-display"><?php echo JText::_($field->custom_value); ?></span>
                                                        <?php } elseif($field->virtuemart_custom_id == '15') {  ?>
                                                            <span class="vm-custom-title"><?php echo JText::_($field->custom_title); ?></span>
                                                            <span class="vm-display"><?php echo JText::_($field->custom_value); ?></span>
                                                        <?php } elseif($field->virtuemart_custom_id == '17') {  ?>
                                                            <span class="vm-custom-title"><?php echo JText::_($field->custom_title); ?></span>
                                                            <span class="vm-display"><?php echo JText::_($field->custom_value); ?></span>
                                                        <?php } elseif($field->virtuemart_custom_id == '18') {  ?>
                                                            <span class="vm-custom-title"><?php echo JText::_($field->custom_title); ?></span>
                                                            <span class="vm-display"><?php echo JText::_($field->custom_value); ?></span>
                                                        <?php } elseif($field->virtuemart_custom_id == '20') {  ?>
                                                            <span class="vm-custom-title"><?php echo JText::_($field->custom_title); ?></span>
                                                            <span class="vm-display"><?php echo JText::_($field->custom_value); ?></span>
                                                        <?php } elseif($field->virtuemart_custom_id == '21') {  ?>
                                                            <span class="vm-custom-title"><?php echo JText::_($field->custom_title); ?></span>
                                                            <span class="vm-display"><?php echo JText::_($field->custom_value); ?></span>
                                                        <?php } elseif($field->virtuemart_custom_id == '22') {  ?>
                                                            <span class="vm-custom-title"><?php echo JText::_($field->custom_title); ?></span>
                                                            <span class="vm-display"><?php echo JText::_($field->custom_value); ?></span>
                                                        <?php ?>
                                                    </div>
                                                <?php 
                                                
?>

                                            <?php 
                                            
?>




So my question is how can I code this to work with VM 3.0.6.4.

Regards
Ketil


-------------------------------
Joomla 3.8.1
Virtuemart 3.2.4
PHP 7.1
-------------------------------

belsaas

Can some help me with this code?
It is over one moth since I post this.

Regards
Ketil
-------------------------------
Joomla 3.8.1
Virtuemart 3.2.4
PHP 7.1
-------------------------------

GJC Web Design

I use something like this

if($product->customfieldsSorted['normal']){
foreach($product->customfieldsSorted['normal'] as $cfield){

if($cfield->custom_value =='Natural Colours'){
echo '<span class="dotty"></span><span class="dotty noshow"></span>';
}
if($cfield->custom_value =='Medium and dark colours'){
echo '<span class="dotty"></span><span class="dotty"></span>';
}
if($cfield->custom_value =='Special Colours'){
echo '<span class="dotty"></span><span class="dotty"></span><span class="dotty"></span>';
}
//caribe
if($cfield->virtuemart_custom_id =='10'){
echo ' <span class="stockservice"><strong>S</strong></span>';
}
}
}
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

PRO


belsaas

Thanks! I solved it.

I did this:
In the file "products_korpedagogen.php" (in the map template/yoo_avenue/html/com_virtuemart/sublayouts/) wrote this code:


<!-- Start of costums fields -->
            <div>
<?php echo shopFunctionsF::renderVmSubLayout('customfields_title', array('product'=>$product,'position'=>'normal')); ?>
            </div>
<!-- End of costums fields -->


This code get the codes inside the file "customfields_title.php" in the same map (template/yoo_avenue/html/com_virtuemart/sublayouts/)

defined('_JEXEC') or die('Restricted access');

$product = $viewData['product'];
$position = $viewData['position'];

$customTitle = ''; //Ketil added 11.05.2015
$field = ''; //Ketil added 11.05.2015
$custom_title = ''; //Ketil added 11.05.2015

if (!empty($product->customfieldsSorted[$position])) { //1
?>
<div>
<?php
foreach ($product->customfieldsSorted[$position] as $field) { //2
if ( $field->is_hidden //OSP http://forum.virtuemart.net/index.php?topic=99320.0
continue;
        ?>

        <div>
<?php if (!$customTitle and $field->custom_title != $custom_title and $field->show_title) { //3 ?>
<span class="product-fields-title-wrapper">
                    <span class="product-fields-title">
<?php echo vmText::($field->custom_title?>
                      </span>
<span class="product-field-display">
                        <?php echo $field->display ?>
                        </span>
                  </span>
<?php 
//3 ?>

</div>
<?php
//2 ?>

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



This is nice and good. But how can I get only one specific custom filed to display?
If I want to display only one custom filed?

Ex. I have a custom filed with this ID:

virtuemart_custom_ID: 13
custom_title: Composer
customfield_value: Felix Mendelssohn Bartholdy

Output should be like this:
Composer: Felix Mendelssohn Bartholdy

-------------------------------
Joomla 3.8.1
Virtuemart 3.2.4
PHP 7.1
-------------------------------

belsaas

I solved also this coding!


defined('_JEXEC') or die('Restricted access');

$product = $viewData['product'];
$position = $viewData['position'];

$customTitle = ''; //Ketil added 11.05.2015
$field = ''; //Ketil added 11.05.2015
$custom_title = ''; //Ketil added 11.05.2015

// Varialber for icons, added Ketil 12.05.2015
$img_norskkors = '<img src="images/stories/norskkorsenter-rod-hvit-fx-small.jpg" alt="norskkorsenter-rod-hvit-fx-small" height="25" width="35" />';
$img_spotify = '<img src="images/stories/spotify-logo.png" alt="logo" height="35" width="35" />';
$img_itunes = '<img src="images/stories/iTunes-icon.png" alt="itunes" height="35" width="35" />';
$img_wiki = '<img src="images/stories/wikipedia-logo.png" alt="wikipedia-logo1" height="35" width="35" />';


if (!empty($product->customfieldsSorted[$position])) { //1
?>
<div>
<?php $theseones = array(26,27,28,29);
foreach ($product->customfieldsSorted[$position] as $field) { //2
if(in_array($field->virtuemart_custom_id,$theseones)) { //3 // Deleted 12.05.2015 - Ketil: if ( $field->is_hidden ) //OSP http://forum.virtuemart.net/index.php?topic=99320.0
if($field->virtuemart_custom_id == '26') {
?>

<span class="icon"><?php echo "<a target='_blank' href='".$field->customfield_value."'>".$img_norskkors."</a>"?></span>
<?php }elseif($field->virtuemart_custom_id == '27') {
                        
?>

                    <span class="icon"><?php echo "<a target='_blank' href='".$field->customfield_value."'>".$img_spotify."</a>"?></span>
                    <?php }elseif($field->virtuemart_custom_id == '28') {
                        
?>

                    <span class="icon"><?php echo "<a target='_blank' href='".$field->customfield_value."'>".$img_itunes."</a>"?></span>
                        <?php }elseif($field->virtuemart_custom_id == '29') { 
                        
?>

                    <span class="icon"><?php echo "<a target='_blank' href='".$field->customfield_value."'>".$img_wiki."</a>"?></span>
                        <?php }
                    
?>

                <?php //3
                    
?>

<?php
//2 ?>

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

-------------------------------
Joomla 3.8.1
Virtuemart 3.2.4
PHP 7.1
-------------------------------

Studio 42

Why not using a customfield plugin ?
All this hooks, you have to redo when you have new ids.