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

Layout Position for Custom Field

Started by Hawker, February 18, 2018, 15:55:22 PM

Previous topic - Next topic

Hawker

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!
VM v. 3.4.2
Joomla v. 3.9.5
PHP v. 7.2.1

jenkinhill

#1
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.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Hawker

#2
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
VM v. 3.4.2
Joomla v. 3.9.5
PHP v. 7.2.1

joomlaperth

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

Jörgen

#4
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
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

joomlaperth

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

Studio 42

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


Hesam

If the custom field is not in the addtocart position, its price does not affect the product price, how can this problem be solved?

Studio 42

The customfield need to be in the HTML form to be calculated
If you need this then modify your HTML