News:

Support the VirtueMart project and become a member

Main Menu

Override product price progmatically

Started by sandomatyas, June 26, 2019, 12:31:46 PM

Previous topic - Next topic

sandomatyas

Hi
I need to write a custom script which can override some product's price based under special conditions. It could be a vmcustom plugin where the site owner could add a custom price to the product and the plugin uses it instead the core price, when the script allows it.
I can create the plugin, I have the price but the question that with which method can I override the price?

kishoreonwork

the function is

   function plgVmPrepareCartProduct(&$product, &$customfield,$selected,&$modificatorSum)

I do lot of override with this function, See the variable - $modificatorSum


Thanks
Kishore
I am available for paid joomla and virtuemart consulting.
http://www.kishoreweblabs.com/
skype kishore2607

sandomatyas

Hm. I created the vmcustom plugin, added the customfield, set as cart attribute, added to the product, but plgVmPrepareCartProduct is not triggered. Did I miss something?

kishoreonwork

My bad that was wrong function, it was  for the cart, it will modify the price of the product in the cart.



I am available for paid joomla and virtuemart consulting.
http://www.kishoreweblabs.com/
skype kishore2607

PRO

You need a hidden field

what do you have for this? function plgVmOnDisplayProductFEVM3



// Product Page Display
// is hidden field ONLY in the form and not the custom Params
   function plgVmOnDisplayProductFEVM3(&$product,&$group) {

      if ($group->custom_element != $this->_name) return '';
      $group->display = '<input type="hidden" name="customProductData['.$product->virtuemart_product_id.']['.$group->virtuemart_custom_id.']['.$group->virtuemart_customfield_id.'][hidden]" value="1" />';
return true;
   }