VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product pricing => Topic started by: mesie on October 31, 2015, 13:20:11 PM

Title: Change product price with a plugin
Post by: mesie on October 31, 2015, 13:20:11 PM
Hi,

i'm trying to change the price of a product in the cart with the help of a system plugin that i have created.
I've managed to change the the total and the the total discount of the cart but not the product's discount and price.

i set for example $cart->pricesUnformatted[$key]['discountAmount']=2; where $key is the product id.
At the end of the function i add $calculator->setCartPrices($cart->pricesUnformatted);

The issue is that the total cart prices change, but the product's no.

Any suggestions?
Title: Re: Change product price with a plugin
Post by: PRO on October 31, 2015, 14:44:51 PM
why a system plugin & not a customfield plugin?


Title: Re: Change product price with a plugin
Post by: mesie on October 31, 2015, 21:24:42 PM
not sure  ;)
I 've created a system plugin with a function function plgVmOnCheckoutAdvertise
Title: Re: Change product price with a plugin
Post by: PRO on October 31, 2015, 21:48:21 PM
maybe you need to


$cart->product

or something similar, if you are changing the total

- probably spam -ample in a shipping plugin you do

foreach ($cart->products as $product) {
         modify here
      }
Title: Re: Change product price with a plugin
Post by: mesie on October 31, 2015, 21:53:30 PM
On this foreach loop i change the discountAmount of the product. If i var_dump the cart i see the changed discount but it is not added on cart
Title: Re: Change product price with a plugin
Post by: PRO on November 01, 2015, 03:01:58 AM
what happens when you refresh the page?

explain what your system plugin does?
Title: Re: Change product price with a plugin
Post by: mesie on November 02, 2015, 08:22:57 AM
It checks if a user belongs to a specific user group and if yes it applies a discount.
The issue is that i want to exclude some products from this discount.

The discount is applied on cart without any issue. But the discount on product doesn't.
Title: Re: Change product price with a plugin
Post by: GJC Web Design on November 02, 2015, 11:41:20 AM
QuoteIt checks if a user belongs to a specific user group and if yes it applies a discount.
The issue is that i want to exclude some products from this discount.

surely a standard discount (tax & calc rule)  applied to a shoppergroup and certain categories will do this?
Title: Re: Change product price with a plugin
Post by: mesie on November 03, 2015, 08:40:59 AM
The extra thing is that the plugin checks the total and then it applies the discount. This is something that the standard virtuemart rules cannot do.
Title: Re: Change product price with a plugin
Post by: GJC Web Design on November 03, 2015, 11:11:58 AM
negative tax per bill?  haven't tried...
Title: Re: Change product price with a plugin
Post by: mesie on November 04, 2015, 08:41:28 AM
nope.
The question still remains. Why VM Cart doesn't accept the discount i apply, as soon as the discount in cart is acceptable?
Title: Re: Change product price with a plugin
Post by: PRO on November 04, 2015, 10:14:14 AM


in my quantity discount plugin
I change the price of a product like this

   if ($product->quantity >=$qdisc[0] && $product->quantity<=$qdisc[1])
{$product->allPrices[$product->selectedPrice]["product_price"]=$product->allPrices[$product->selectedPrice]["product_price"]-$customfield->pdisc;}


But, it is in a product custom plugin,
in function    plgVmPrepareCartProduct


can you modify anything about the product ? change the sku? , name etc?

How are you trying to modify it?
Title: Re: Change product price with a plugin
Post by: mesie on November 04, 2015, 10:52:47 AM
Well i have this code $cart->pricesUnformatted[$key]['discountAmount']=2;
for example to add the discount to the current product where $key is the product key.

I can see the new discount amount if i dump the $cart but it's not applied on cart.

I cannot change anything on cart. Everything i change this way, i see it in the dump but is not applied.
Title: Re: Change product price with a plugin
Post by: PRO on November 04, 2015, 22:51:48 PM
I dont know what to tell you, I know this can be done with a product plugin