News:

Looking for documentation? Take a look on our wiki

Main Menu

Load modules inside VM product custom field

Started by dslove, July 17, 2019, 09:37:55 AM

Previous topic - Next topic

dslove

Hi,

I'm looking to create a custom field for VM products where I can insert {loadposition xxx} or {loadmoduleid xxx} to load modules.

Ideally, I'd like to use the core Textarea or Editor type custom fields.

Any suggestions on how to make these work in such a way?

Thanks  :)

Studio 42

{loadposition xxx} is to load Joomla modules inside an article.
If you need a customfield render, here a sample for the position posxxx
    if (!empty($this->product->customfieldsSorted['posxxx'])) {
      echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'posxxx'));
    } // Product Custom posxxx end
    ?>

in the category the loop use $product and not $this->product
the file used for the this loop is by default here JOOMLAROOT/components/com_virtuemart/sublayouts/products.php and you should do an override in your template
Note that "ontop" and  "addtocart" position is already rendered, if you choose to render customfields in category view. You have a setting for this in the virtuemart config, bu some template dev simply removed it

dslove

Thank you Studio 42,

There will be approximately 30 different modules, each corresponding to 5-10 different products (inside product view only).

A "fixed" module position will not work in this case

The only way to match modules to products correctly, is to make it possible for calling a module using some type of shortcode like {loadposition xxx} or ideally {loadmoduleid xxx} in a custom field.

Studio 42


dslove

Nice, thanks!

So this is something similar to another extension I have found, https://www.regularlabs.com/extensions/modulesanywhere although I understand that your offering has more options?

Studio 42

This is a different tool.
My tool render the modules in a customfield position and have to be set in each product you need it.
Modules anywhere render only in fields that can handel default Joomla content plugins.
So you have to know, what you need ? Display modules inside a customfield position or render a module inside an article, product details (the only view supporting content plugins) ....

dslove

Thank you, I 'm currently testing a solution relating articles to products (has broader usage scope across the specific website) .
I'll be sure to go for the suggested tool if I use custom HTML modules instead  :)

Have a great day!

PRO

Quote from: dslove on July 17, 2019, 11:11:03 AM

The only way to match modules to products correctly, is to make it possible for calling a module using some type of shortcode like {loadposition xxx} or ideally {loadmoduleid xxx} in a custom field.


You can create a position with the product ID in the position   dynamically.


I make a module and type in position  field   custom-position889 (where 889 is the product id)


Then in product details template

jimport('joomla.application.module.helper');
$position='custom-position'.$this->product->virtuemart_product_id;
$modules = JModuleHelper::getModules($position);
$html='';
foreach ($modules as $module) {
$html.= '<div class="mod-style">';
$html.=JModuleHelper::renderModule($module);
$html.='</div>';
}
echo $html;



dslove

#8
Quote from: PRO on July 23, 2019, 20:21:16 PM
You can create a position with the product ID in the position   dynamically.


I make a module and type in position  field   custom-position889 (where 889 is the product id)


Then in product details template

jimport('joomla.application.module.helper');
$position='custom-position'.$this->product->virtuemart_product_id;
$modules = JModuleHelper::getModules($position);
$html='';
foreach ($modules as $module) {
$html.= '<div class="mod-style">';
$html.=JModuleHelper::renderModule($module);
$html.='</div>';
}
echo $html;

This is actually a very smart idea, thank you ;)

Although I would love to add this individually to products in the form of a custom field, I could integrate your code to the productdetails/default.php file, add a check for published modules in position and get the same visual result (tabbed contents).

Kudos!

Studio 42