News:

Looking for documentation? Take a look on our wiki

Main Menu

Custom plugin & product discount price not working

Started by vmfyelloq19, June 25, 2020, 20:51:16 PM

Previous topic - Next topic

vmfyelloq19

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;
    }
}

GJC Web Design

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
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

Ventsi Genchev

@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.
Audio Store:
https://vsystem.bg - Bulgarian language
https://vsystem.bg/en - English

vmfyelloq19

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!


pinochico

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
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

vmfyelloq19

Custom filemaker application with very crude xml export and a lot of implicit assumptions on product data.

pinochico

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

GJC Web Design

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
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

PRO

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');

   }