VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: mark R on November 16, 2011, 23:50:10 PM

Title: Location of Custom Field
Post by: mark R on November 16, 2011, 23:50:10 PM
Hi all,

Is it possible to display a Custom field in a different place to all the other custom fields.

ie RRP at the top of the Product Details page and the rest of the Custom fields ie Size(cart variants at the bottom of the Product details page?

Many thanks once again.
Title: Re: Location of Custom Field
Post by: JtouchMobile.com on November 17, 2011, 08:31:07 AM
I think the only solution available this time is you should:
- know exactly your customer fields, I mean number of fields, fieldname
- then hack to VM 2 template (product view) to put each field to needed place

Cheers,
MobileMeWs
Title: Re: Location of Custom Field
Post by: PRO on November 17, 2011, 17:49:18 PM
which field? Is it a plugin?


Title: Re: Location of Custom Field
Post by: mark R on November 17, 2011, 23:25:28 PM
Hi all,

I want to put a custom product field called "rrp" recomended retail price....  and would like it to appear at the top of my productdetails view page..

Thanks again
Mark

Sent from my Transformer TF101 using Tapatalk
Title: Re: Location of Custom Field
Post by: PRO on November 18, 2011, 12:47:00 PM
is it in a price field? How are you inputting it?
Title: Re: Location of Custom Field
Post by: mark R on November 23, 2011, 22:03:17 PM
Hi,

Yes its just a price feld and will only be entered in the product creation /admin

Thanks

Sent from my Transformer TF101 using Tapatalk
Title: Re: Location of Custom Field
Post by: PRO on November 25, 2011, 13:16:20 PM
WHICH price field is it?
Title: Re: Location of Custom Field
Post by: mark R on December 04, 2011, 16:43:03 PM
It would just be a custom field as I would like one keep the normal price structure for later use

Sent from my Transformer TF101 using Tapatalk
Title: Re: Location of Custom Field
Post by: spacialek on December 27, 2011, 07:42:24 AM
Quote from: MobileMeWs on November 17, 2011, 08:31:07 AM
I think the only solution available this time is you should:
- know exactly your customer fields, I mean number of fields, fieldname
- then hack to VM 2 template (product view) to put each field to needed place

Cheers,
MobileMeWs


I don't get how to write the code with the custom field number and custom field name in my productdetails template..

For example, in productdetails/tmpl/default.php, there's this line of code:
<span class="product-field-display"><?php echo $field->display ?></span>

I don't know how to substitute the variable by my custom field value, as chosen in the backend..

Thanks
Title: Re: Location of Custom Field
Post by: AmStaF on December 27, 2011, 10:08:25 AM
Quote from: spacialek on December 27, 2011, 07:42:24 AM
For example, in productdetails/tmpl/default.php, there's this line of code:
<span class="product-field-display"><?php echo $field->display ?></span>

Just around that code look for

   foreach ($this->product->customfields as $field)

and change with

   foreach ($this->product->customfields as $i=>$field)

Than change

   <?php echo $field->display ?>

with (for example)

   <?php echo 'i = [' . $i . '] ' . $field->display ?>

It will show you the index of every field you need (or look at Product -> Customfields in back-end).

Than you should check $i and do what you need (by if or case statement). And of course, you can drag a piece of this code into another place of productdetails/tmpl/default.php, make the check there and than show on page what you want.
Title: Re: Location of Custom Field
Post by: spacialek on December 27, 2011, 10:55:29 AM
Thanks a lot for your answer!  :)

I did what you mentioned, and as it's the first custom field created, so the value of i gives me 0
I don't know how to write my condition though, I tried the following code, but it doesn't work:


<?php
$custom_title null ;
//foreach ($this->product->customfields as $field){
foreach ($this->product->customfields as $i=>$field) {
?>
<div class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if ($field->custom_title != $custom_title) { ?>
<span class="product-fields-title" ><?php echo JText::_($field->custom_title); ?></span>
<?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png');
?>

       
<?php if($i == 0) { ?>
<span class="product-field-display"><?php $field->display?></span>
<?php ?>
       

<span class="product-field-desc"><?php echo jText::_($field->custom_field_desc?></span>
</div>
<?php
$custom_title $field->custom_title;
?>



I'm sure it's something about the <?php if($i == 0) { ?> that I have not coded properly

Can you help me with that?

Thanks

Title: Re: Location of Custom Field
Post by: spacialek on December 27, 2011, 11:06:25 AM
ok I found my error!! I forgot the "echo"  ::)
So my final code looks like this:


<?php
$custom_title null ;
//foreach ($this->product->customfields as $field){
foreach ($this->product->customfields as $i=>$field) {
?>
<div class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if ($field->custom_title != $custom_title) { ?>
<span class="product-fields-title" ><?php echo JText::_($field->custom_title); ?></span>
<?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png');
?>

       
<?php if($i == 0) { ?>
<span class="product-field-display"> <?php echo $field->display ?></span>
<?php ?>
       

<span class="product-field-desc"><?php echo jText::_($field->custom_field_desc?></span>
</div>
<?php
$custom_title $field->custom_title;
?>



Thanks thanks thanks for your help!!
Title: Re: Location of Custom Field
Post by: AmStaF on December 27, 2011, 11:10:47 AM
You`re welcome!  :)
Title: Re: Location of Custom Field
Post by: PRO on January 09, 2012, 14:49:16 PM
Location of custom fields is in the next release

Title: Re: Location of Custom Field
Post by: spacialek on January 09, 2012, 18:23:17 PM
ok thanks! that's good news, cause it's working great the way it's described in this thread with this code foreach ($this->product->customfields as $i=>$field)
but it's not really convenient, cause the field id changes depending of the order it was added in each product.. so it needs to be really vigilant, otherwise another custom field is displayed instead.