Author Topic: Override product price progmatically  (Read 931 times)

sandomatyas

  • Jr. Member
  • **
  • Posts: 298
Override product price progmatically
« 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?

kishoreonwork

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 63
  • Free Virtuemart Consulting For Non Profits
    • virtuemart expert
  • Skype Name: kishore2607
  • VirtueMart Version: 3
Re: Override product price progmatically
« Reply #1 on: June 26, 2019, 15:11:16 pm »
the function is

   
Code: [Select]
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

  • Jr. Member
  • **
  • Posts: 298
Re: Override product price progmatically
« Reply #2 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?

kishoreonwork

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 63
  • Free Virtuemart Consulting For Non Profits
    • virtuemart expert
  • Skype Name: kishore2607
  • VirtueMart Version: 3
Re: Override product price progmatically
« Reply #3 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.



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

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10412
  • VirtueMart Version: 3+
Re: Override product price progmatically
« Reply #4 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;
   }
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)