How to dynamically change product price before adding to cart? (no variants)

Started by aerdna, September 24, 2016, 09:28:41 AM

Previous topic - Next topic

aerdna

I'm running joomla 3.6.2 and VM 3.0.16, php5.6.

I just need to know where in a vmcustom plugin like textinput can I get access to the price that is being used for the final product price and at what point could I change the value so it would take effect in the cart? 

Here's the details: 
I have jewelry made from precious metals and I'd like my product prices to update dynamically based on the current market prices for the metals.  I currently have a plugin that is built off of the vmcustom/textinput plugin (I'm an extreme beginner here so this was the easiest way I could figure out how to do this) that I use to dynamically update the price based on the customer's selected ring size and selected gemstones, engraving, etc.  (I query for compatible gemstone inventory dynamically from the manufacturer's RESTful endpoint and so I couldn't use a variant for these things.)  The front end uses javascript to configure the product and the backend uses the plugin. It uses the plgVmPrepareCartProduct() function to add on the additional cost for the configured items like ring sizing, gemstones, etc.  I know I should have probably used a plugin for the FE too but I didn't know how.

The way I'm doing it now assumes that the product price is correct and just adds on to it additional costs using the "modificatorSum".  Unfortunately, the product price will fluctuate with the market. I don't want to set up a cron job to update all the prices in my store every night based on the market, I'd rather just update the price on the fly for the products that are configurable and will be manufactured based on the customer's specifications.  The customer expects to see the price change for those items.

So...having said all that...I don't want to change the price in the database, just the final price that would go into the cart. 

It would also be nice if I knew where I could plug in something to check a person's cart to see if a price has changed (like if they keep something in their cart for a long time then decide to checkout). I don't know how to get access to cart contents but it would be nice to be able to do that when they navigate to the cart. (Maybe I should post a separate question for this?)

Could someone point me in the right direction for these?  I realize I'm asking a lot of specifics here but even hints help me :-) 

Thanks,
Andrea

kishoreonwork


You can do this with product override.
in the function do it like that
$product->allPrices[0]['override']=1;
$product->allPrices[0]['product_override_price']={new_override_price};

Let say the price is increased by 10% then do it
$discount=10;
$product->allPrices[0]['override']=1;
$product->allPrices[0]['product_override_price']=($product->allPrices[0]['product_price'] )*(100+$discount)/100;


Let say the price is decrease by 5% then do it
$discount=5;
$product->allPrices[0]['override']=1;
$product->allPrices[0]['product_override_price']=($product->allPrices[0]['product_price'] )*(100-$discount)/100;

Let say the you want to set price to $200
$product->allPrices[0]['override']=1;
$product->allPrices[0]['product_override_price']=200;


So there are endless possibilities

Thanks
Kishore

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

Studio 42

If you hacked the plgVmPrepareCartProduct core function , it's hard to help you.
And you should update VIrtuemart and Joomla.
What i dont understand, is why you dont use modificatorSum in your plugin to update the price ?

jenkinhill

Patrick the original post is from 2 years ago, hence the old versions. Don't know why it should get a reply now, the OP has not visted the forum since that time.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Studio 42