VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: stemithy on January 23, 2014, 20:08:55 PM

Title: After Tax Bill Calc (DATaxBill) Restricted by Category [SOLVED] - Hack
Post by: stemithy on January 23, 2014, 20:08:55 PM
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;
            }


Title: Re: After Tax Bill Calc (DATaxBill) Restricted by Category [SOLVED] - Hack
Post by: khemapema on October 09, 2014, 10:47:15 AM
Hi

This doesnt work for my virtuemart 2.0.8a
Title: Re: After Tax Bill Calc (DATaxBill) Restricted by Category [SOLVED] - Hack
Post by: jenkinhill on October 09, 2014, 11:04:10 AM
!!   http://forum.virtuemart.net/index.php?topic=118683.0
Title: Re: After Tax Bill Calc (DATaxBill) Restricted by Category [SOLVED] - Hack
Post by: khemapema on October 09, 2014, 11:08:39 AM
Means?

Quote from: jenkinhill on October 09, 2014, 11:04:10 AM
!!   http://forum.virtuemart.net/index.php?topic=118683.0
Title: Re: After Tax Bill Calc (DATaxBill) Restricted by Category [SOLVED] - Hack
Post by: jenkinhill on October 09, 2014, 12:50:13 PM
Nobody should be using old versions any more!
Title: Re: After Tax Bill Calc (DATaxBill) Restricted by Category [SOLVED] - Hack
Post by: khemapema on October 09, 2014, 13:25:36 PM
Can anybody help me with modifying my calculationh.php for category based datax
Title: Re: After Tax Bill Calc (DATaxBill) Restricted by Category [SOLVED] - Hack
Post by: Milbo on October 09, 2014, 17:43:47 PM
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.
Title: Re: After Tax Bill Calc (DATaxBill) Restricted by Category [SOLVED] - Hack
Post by: khemapema on October 09, 2014, 20:16:16 PM
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
Title: Re: After Tax Bill Calc (DATaxBill) Restricted by Category [SOLVED] - Hack
Post by: khemapema on October 09, 2014, 20:37:35 PM
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