VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: vmfyelloq19 on July 22, 2019, 09:04:55 AM

Title: Pre-set shopper field on checkout programmatically
Post by: vmfyelloq19 on July 22, 2019, 09:04:55 AM
Hi folks,

I need so set the value of a shopper field on particular conditions (weekday is saturday or sunday, in this case).
I've made a joomla system plugin hooking to the plgVmDisplayLogin() event as this looked the best matching event.

As far I found out that I can get all shopper fields, including custom ones with $cart=VirtueMartCart::getCart(false)
Both $cart->BTaddress and $cart->STaddress contain all fields, while $cart->BT, $cart->ST and $cart->cartfields only custom shopper fields plus tos and customer_note.
Checking joomla's virtuemart session namespace, I see ->BT, ->ST and ->cartfields as well.

Still, no matter what data I try to modify, it does not show up in the checkout form.

I tried to set values directly into joomla's session and $cart->getCart() afterwards, also tried $cart->loadCart($session_data_jsondecoded) as well as  $session->set(...) to virtuemart session namespace.

Any hints?

TIA!

Title: Re: Pre-set shopper field on checkout programmatically
Post by: Studio 42 on July 22, 2019, 11:39:39 AM
You can create a vmuserfield.
It's not the best sample but you have 1 in core : realex_hpp_api
Title: Re: Pre-set shopper field on checkout programmatically
Post by: vmfyelloq19 on July 22, 2019, 14:57:44 PM
Hi Studio 42,

thank you for your reply. Had a quick look at realex_hpp_api. Just to be sure I'm not mixing up general plugin requirements with realex_hpp_api specific stuff: I'm I right I need my own tables to store my particular single value?

Also, will the field, if required, be checked via javascript like virtuemart's own fields?

TIA!
Title: Re: Pre-set shopper field on checkout programmatically
Post by: Studio 42 on July 22, 2019, 15:13:03 PM
See http://forum.virtuemart.net/index.php?topic=141335.0 (http://forum.virtuemart.net/index.php?topic=141335.0), you can use parameters, but it's not directly set/get in the core
I know that doc is missing(since 7 year), i think that this type of plugin is not many used(and can be so powerful)
Most plugin triggers are in JOOMLAROOT/administrator/components/com_virtuemart/models/userfields.php
Search for $dispatcher->trigger in this file to find the function name and parameters
Title: Re: Pre-set shopper field on checkout programmatically
Post by: vmfyelloq19 on July 24, 2019, 08:35:45 AM
Hi Studio 42,

thanks for hinting to the forum entry. I'll check it out.