News:

Looking for documentation? Take a look on our wiki

Main Menu

Mandatory vmcustom field + VatTax

Started by sandomatyas, April 24, 2019, 18:15:23 PM

Previous topic - Next topic

sandomatyas

I wrote a small vmcustom plugin which adds a dropdown list as cart input.
It uses plgVmOnDisplayProductFEVM3 to display the list and plgVmPrepareCartProduct to calculate the modificator.
I have only two questions.
It shows a dropdown like this:
variant1 (+extra fee1)
variant2 (+extra fee2)
variant3 (+extra fee3)
etc
These options are created dinamically, there's no child products or so.

Question1:
There is a zero option, like "choose an option". How should I prevent adding the product to the cart when the customer does not selected any option? Is there a vmcustom method to trigger which can handle this?

Question2:
It's about the prices. The prices are also dinamically calculated. I dispaly them in the dropdown and use them in plgVmPrepareCartProduct method. I have the base price but when I select it, VM recalculates the product price and adds the price but the gross one.
The the gross  product price is €10, the VatTax is 20%, the modificator is €1. There is €1 in my dropdown and when I select it, the product's price become 10+1*1.2=€11.2
Which is fine but in this case I need to display the gross price in my dropdown too, which is €1.2 instead €1
Which function should I use to process the calculation rules to my net prices?

sandomatyas

If I'm right the VatTax solution is something like this:
$calculator = calculationHelper::getInstance();
$vatTaxRule = $calculator->gatherEffectingRulesForProductPrice('VatTax', $product->product_tax_id);

$priceToDropdown = $calculator->roundInternal($calculator->executeCalculation($vatTaxRule, $priceToDropdown), 'salesPrice');

sandomatyas

And I can make it mandatory via plgVmOnAddToCartFilter method of the plugin :)

Milbo

Quote from: sandomatyas on April 24, 2019, 18:15:23 PM
Question1:
There is a zero option, like "choose an option". How should I prevent adding the product to the cart when the customer does not selected any option? Is there a vmcustom method to trigger which can handle this?

In the trigger plgVmOnDisplayProductFEVM3

set the product to unorderable with $product->orderable = false;

Quote from: sandomatyas on April 24, 2019, 18:15:23 PM
Question2:

If the variants are displayed with tax or without is a vm config setting. Just work within the normal workflow.

Use plgVmPrepareCartProduct not plgVmOnAddToCartFilter, which is for filtering input variables.

In this trigger, you just add your net price to the modificatorSum, or to the $product->prices['product_price'], but that will only work with outdated versions or this one http://dev.virtuemart.net/attachments/1163/com_virtuemart.3.4.5.10057_package_or_extract.zip.

You can completly change the product with this trigger and that will also kept in the cart. Even renaming, or changing the weight.


Just in case your plugin reminds me to mine https://extensions.virtuemart.net/product/products/custom-size-detail you can also create with this one dropdowns for fixed values.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/