VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product pricing => Topic started by: sandomatyas on June 26, 2019, 12:31:46 PM

Title: Override product price progmatically
Post by: sandomatyas on June 26, 2019, 12:31:46 PM
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?
Title: Re: Override product price progmatically
Post by: kishoreonwork on June 26, 2019, 15:11:16 PM
the function is

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

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


Thanks
Kishore
Title: Re: Override product price progmatically
Post by: sandomatyas on June 26, 2019, 15:48:44 PM
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?
Title: Re: Override product price progmatically
Post by: kishoreonwork on June 26, 2019, 15:59:56 PM
My bad that was wrong function, it was  for the cart, it will modify the price of the product in the cart.



Title: Re: Override product price progmatically
Post by: PRO on June 26, 2019, 17:02:41 PM
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;
   }