News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Change product price with a plugin

Started by mesie, October 31, 2015, 13:20:11 PM

Previous topic - Next topic

mesie

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?

PRO

why a system plugin & not a customfield plugin?



mesie

not sure  ;)
I 've created a system plugin with a function function plgVmOnCheckoutAdvertise

PRO

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
      }

mesie

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

PRO

what happens when you refresh the page?

explain what your system plugin does?

mesie

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.

GJC Web Design

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?
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

mesie

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.

GJC Web Design

negative tax per bill?  haven't tried...
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

mesie

nope.
The question still remains. Why VM Cart doesn't accept the discount i apply, as soon as the discount in cart is acceptable?

PRO



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?

mesie

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.

PRO

I dont know what to tell you, I know this can be done with a product plugin