VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Hawker on February 18, 2018, 15:55:22 PM

Title: Layout Position for Custom Field
Post by: Hawker on February 18, 2018, 15:55:22 PM
When making a new Custom Field, there is a box asking for its Layout position:

Custom Fields>Custom Field>Layout position

I learned from a YouTube video that this (for my case) had to be set to <addtocart> (no spaces)

Usually in Joomla, 'Layout position' fields offer a drop-down menu to select from a list of available possibilities. My forum account here does not permit me to post to the 'Requested Features' board, but:

(i) Why is there no drop-down menu here?
(ii) Where can one find the list of available 'Layout position' options for VM3, showing the correct format of wording (e.g. <addtocart>) to type into the Layout position box?

Many thanks in advance guys!
Title: Re: Layout Position for Custom Field
Post by: jenkinhill on February 18, 2018, 18:31:14 PM
The position required by the vast majority of custom field users will be 'addtocart' - ie the custom field is within the add to cart form so the value is available there to be shown when that product is added to cart.

In the file components/com_virtuemart/views/category/tmpl/default.php you can see alternative positions added by default, such as 'ontop' which is just above the vm-product-container div, or 'normal' just after the product full description. There is also 'onbot' and postions for 'related-products'.  The first three are rarely used, but the developer can add additional field positions should they be required in different positions simply by adding a code snippet to the default.php and using that file as a template override. eg: to add 'mynewposition'

<?php
   echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'mynewposition'));
?>

I suppose a selector could be used to display the positions but it would require addtocart to be the default and would rarely be used.
Title: Re: Layout Position for Custom Field
Post by: Hawker on February 18, 2018, 21:35:56 PM
Thank you jenkinhill, this solves things!  ;D

 
ontop- Just above the VM product container <div>
normal- Just after the product full description
onbot- Just below the VM product container <div>
addtocart- Within the 'Add to cart' form
Title: Re: Layout Position for Custom Field
Post by: joomlaperth on April 14, 2019, 15:40:53 PM
hi, can a custom field have two different positions (is this even possible with defining two separate CSS classes?

1) in category layout
2) product details page?

thanks in advance
Title: Re: Layout Position for Custom Field
Post by: Jörgen on April 14, 2019, 17:50:10 PM
You can display a customfield at two different positions. But this needs some extra code in your category and productdetail template.
Jörgen @ Kreativ Fotografi
Title: Re: Layout Position for Custom Field
Post by: joomlaperth on April 15, 2019, 05:03:31 AM
Hi mate, thanks for the reply, i am using latest version of joomla and virtuemart.


Joomla! 3.9.5
VirtueMart 3.4.2

what files exactly do i need to change and can you shed some light on it please? thanks
Title: Re: Layout Position for Custom Field
Post by: Studio 42 on April 15, 2019, 14:18:14 PM
A customfield position is rendered in product with code
   echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'ontop'));
This render the customfiled in position 'ontop' using sublayouts/customfields.php
The defualt file isf YOURJOOMLA/components/com_virtuemart/sublayouts/customfields.php
and template override
YOURJOOMLA/templates/YOURTEMPLATE/html/com_virtuemart/sublayouts/customfields.php
If you want anohter render you can use for eg.
   echo shopFunctionsF::renderVmSubLayout('mycustomfieldrender',array('product'=>$this->product,'position'=>'ontop'));
and add a copy of default in the template
YOURJOOMLA/templates/YOURTEMPLATE/html/com_virtuemart/sublayouts/mycustomfieldrender.php
and modify the code in this file

Title: Re: Layout Position for Custom Field
Post by: Hesam on September 12, 2023, 13:30:42 PM
If the custom field is not in the addtocart position, its price does not affect the product price, how can this problem be solved?
Title: Re: Layout Position for Custom Field
Post by: Studio 42 on September 19, 2023, 23:46:51 PM
The customfield need to be in the HTML form to be calculated
If you need this then modify your HTML