I hope this is the right place to post to have a hack added to the core. If not, hopefully this will help someone out.
I needed to add a flat fee to an order when at least one of the products in the cart was from a certain category. I originally thought this was built in, but found it didn't work as expected. If you create a DATaxBill rule that adds a flat amount to the bill, and choose a category or categories, they are ignored and the calculation shows in the cart regardless of what categories are represented by the products in the cart. To make this work, I made some minor changes to the calculationh.php file found in administrator/components/com_virtuemart/helpers/. Everything I needed was there, it just wasn't being taken into a consideration as I assume the category filter was meant for per/product calculations. I didn't change any existing code...just added a few lines. Here's what I changed (additions bolded):
Around line 648
//Initiate an array to hold category IDs represented by items in the cart
$this->prodcats = array();
foreach ($cart->products as $name => $product) {
//$product = $productModel->getProduct($product->virtuemart_product_id,false,false,true);
$productId = $product->virtuemart_product_id;
if (empty($product->quantity) || empty($product->virtuemart_product_id)) {
JError::raiseWarning(710, 'Error the quantity of the product for calculation is 0, please notify the shopowner, the product id ' . $product->virtuemart_product_id);
continue;
}
$this->productCurrency = isset($product->product_currency)? $product->product_currency:0;
$variantmods = $this->parseModifier($name);
$variantmod = $this->calculateModificators($product, $variantmods);
$cartproductkey = $name; //$product->virtuemart_product_id.$variantmod;
$product->prices = $pricesPerId[$cartproductkey] = $this->getProductPrices($product, $variantmod, $product->quantity, true, false);
//Load the product categories array - since each product can have multiple, merge the arrays together
$this->prodcats = array_merge($this->prodcats,$this->_cats);
Around Line 1246
$q = 'SELECT `virtuemart_category_id` FROM #__virtuemart_calc_categories WHERE `virtuemart_calc_id`="' . $rule['virtuemart_calc_id'] . '"';
$this->_db->setQuery($q);
$rule['calc_categories'] = $this->_db->loadResultArray();
//Use existing function to test product categories against calculation categories
if(!empty($rule['calc_categories'])) {
$hitsCats = $this->testRulePartEffecting($rule['calc_categories'], $this->prodcats);
}
//Add category test variable to the if statement that determines what calcs are shown
if ($hitsDeliveryArea && $hitsShopper && $hitsCats) {
if ($this->_debug)
echo '<br/ >Add Checkout rule ' . $rule["virtuemart_calc_id"] . '<br/ >';
$testedRules[$rule['virtuemart_calc_id']] = $rule;
}
Hi
This doesnt work for my virtuemart 2.0.8a
!! http://forum.virtuemart.net/index.php?topic=118683.0
Means?
Quote from: jenkinhill on October 09, 2014, 11:04:10 AM
!! http://forum.virtuemart.net/index.php?topic=118683.0
Nobody should be using old versions any more!
Can anybody help me with modifying my calculationh.php for category based datax
Yes, just update. the featuer is in the core since around 2.0.16 or so. and I think bugfree since almost a year now.
Hope u understood my requirement, I need dataxbill to be charged when a product from specific category is ordered, if yes its possible then we would upgrade to 2.6.
Or if we can change a specific file and achieve it.
Warm Regards
Hi Mibo,
We tried a fresh installation of 2.6.x but the issue is still there any tax on bill is not category specific defined in tax / calculation rules.
Regards