VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product pricing => Topic started by: vmfyelloq19 on June 25, 2020, 20:51:16 PM

Title: Custom plugin & product discount price not working
Post by: vmfyelloq19 on June 25, 2020, 20:51:16 PM
Hi folks,

I'm currently using a custom plugin*.
Everything works fine for basic products, for example:
product_price =10
plugin sets modificatorSum = 100
final price = 110

But if the product has a discounted price,
product_discounted_price = 9
the plugin's price modificator is still applied to product_price
the final price is 9, completely ignoring modificatorSum

Is this a known bug? Any way to work around it?

TIA!

*) basically like this:
class plgVmCustomMyplugin extends vmCustomPlugin {
    public function plgVmPrepareCartProduct(&$product, &$customfield, $selected, &$modificatorSum){
        // [some rocket science logic here]
        $modificatorSum=100;
        retrun true;
    }
}
Title: Re: Custom plugin & product discount price not working
Post by: GJC Web Design on June 25, 2020, 23:08:49 PM
If u mean the "over ride" price in the product management this over rides everything..
It is an old legacy method that may be removed at some stage in the future as it is not a reliable way of setting discounts
It is advised not to use it
Title: Re: Custom plugin & product discount price not working
Post by: Ventsi Genchev on June 26, 2020, 08:44:47 AM
@vmfyelloq19
Try to use " Overwrite price to be taxed " in the product.
If you use "Tax & Calculation Rule" try "Price modifier before tax per bill" or whatever is good for you.

@GJC Web Design
I really hope this method is not eliminated in the future. Better @Max to add new features rather than remove.

Here's my experience and why I use "Overwrite final":
1.   This is the only way to promote a product with a specific price.
2.   I use the "product_price_publish_up" and "product_price_publish_down" fields to start and end the promotion. I don't use them to publish prices, which is their purpose, because I don't think it makes much sense.
3.   I export all the fields I need for all groups in one file. Then I set the promotional prices, start and end of the promotion and import the changes.
4.   Then everything is automatic. My settings in CRON take care to add or remove products from the category "Promotions" according to the specified dates.

For example:
I choose 10 products, each with a different discount (not in percentages) to be in promotion from July 1 to July 15. Then I don't care to follow them. Their promotion starts on July 1 and they are added to the "Promotions" category. On July 16, they are no longer in promotion and are automatically removed from the "Promotions" category.
I can set a permanent promotion by simply not specifying an end date.


I can choose a more general promotion for a category in the "Tax & Calculation Rule".
Then if I choose "Overwrite final" in the product, the category promotion will not affect the price.
For example: The product is reduced by "Override" from 120 to 100 euros and "Overwrite final" is selected. It is included in a 10% discount for a category. Its price is still 100 euros.

But if I select "Overwrite price to be taxed" in the product, the category promotion is added to the selected price in "Override".
For example: The product is reduced by "Override" from 120 to 100 euros and "Overwrite price to be taxed" is selected. It is included in a 10% discount for a category. Its price becomes 90 euros.
Title: Re: Custom plugin & product discount price not working
Post by: vmfyelloq19 on June 26, 2020, 13:34:40 PM
Thanks GJC for your reply.

> If u mean the "over ride" price in the product management this over rides everything..
Yes, that's what I use. DB table column is named product_discounted_price


> It is an old legacy method that may be removed at some stage in the future as it is not a reliable way of setting discounts
> It is advised not to use it

Wow. I does not say so anywhere in the management backend UI, not in any manual i've read and nowhere obvious in the source code. I'm seriously supprised!
Almost all shop owners I know use this heavily, and we've coded several product import tools that make use of it. With the current pita of Germany's "Corona VAT reduction" it is essential.

Could you provide a link to a manual on how discount a price correcty in a non-deprecated way?

TIA!

Title: Re: Custom plugin & product discount price not working
Post by: pinochico on June 26, 2020, 13:48:32 PM
Quotewe've coded several product import tools that make use of it

Why are you doing a job that already exists? :)

Product Import for Virtuemart
CSVI Pro
Title: Re: Custom plugin & product discount price not working
Post by: vmfyelloq19 on June 26, 2020, 15:57:13 PM
Custom filemaker application with very crude xml export and a lot of implicit assumptions on product data.
Title: Re: Custom plugin & product discount price not working
Post by: pinochico on June 26, 2020, 16:25:53 PM
you are welcome :)
Title: Re: Custom plugin & product discount price not working
Post by: GJC Web Design on June 26, 2020, 18:47:04 PM
in what table is this "product_discounted_price"  -- do u mean  #__virtuemart_product_prices.product_override_price ?

I have never looked deeply into it but if u look at the function getProductPrices() in the calculationh.php you see that

      if ($override==1) {
         $this->productPrices['salesPrice'] = $product_override_price;
      }
comes quite late in the day so I assume over riding/replacing the plugin modified price.

I didn't want to scare any horses with the mention of it possibly being depreciated but i do remember some discussions about this a while back....
I also agree it is a handy way of quickly changing a price but its limitations have to be recognised...

As to an alternative to providing a single discount on a single product ... hmmm .. as you suggest it is very clonky to set up indv. rules for indv. products..
I'm sure Max would welcome any input to make this particular price entry fully compliant with custom plugin adjustments etc
Title: Re: Custom plugin & product discount price not working
Post by: PRO on June 27, 2020, 14:05:23 PM
why dont you check for the discounted price first?
HOW ARE YOU CHECKING THE PRICE?
also, are you using it like this?   $product->allPrices[$product->selectedPrice]["product_price"])

also my plugins use    $modificatorSum+=
^^^    +=

&&& You also have the ability to overwrite   product_discounted_price = 9   from within prepareCartproduct function


below is just an example of one of my plugins, sometimes it helps to see others way.

//Prepare Cart
   public function plgVmPrepareCartProduct(&$product, &$customfield,$selected,&$modificatorSum = 0){
      if ($customfield->custom_element !==$this->_name) return;
   if (!empty($customfield->under_disc)){
   if ($product->quantity <= $customfield->under_disc){$product->product_weight=$customfield->under_discmod;}
   }
   if (!empty($customfield->modifier)){
   if ($product->quantity>=$customfield->modifier){$product->product_weight=0;}
   }
   if (!empty($customfield->disc)){
   if ($product->quantity >=$customfield->disc && $product->quantity <$customfield->modifier){$product->product_weight=$customfield->discmod;}
   }
   // return prices
$modificatorSum+= $this->applyDiscount($customfield->qdisc1,$customfield->qdisc2,$customfield->qdisc3,$product->quantity,$product->allPrices[$product->selectedPrice]["product_price"])-$product->allPrices[$product->selectedPrice]["product_price"];
   
      return ;
      //vmdebug('plgVmPrepareCartProduct we can modify the product here');

   }