Does someone know how to get the tax rate in Opencart 1.5.6.
It should be $string = $this->tax->getRate($tax_class_id); but that was depreciated. When I get the taxrate from config $this->config->get('config_tax'); I only get the tax ID
Is there a way to get the current tax rate build in opencart or has that to be done by using $this->config->get('config_tax') and a new function?
Hope some one can give me a clue
$this->config->get('config_tax') is used to determine if you want to apply tax rates to your items at all (simply an on-off switch if you like).
1.5.6 is no different to most of the 1.5.X series in that you get tax. Tax rates can also be multiple not just one, so getRates() will return an array of values. You call it using $this->tax->getRates($price_value, $tax_class_id) and it will return all of the tax associated with that. However, you really shouldn't be calling that directly, you should be calling the $this->tax->calculate($price, $tax_class_id, $this->config->get('config_tax')) to correctly determine tax values on a price.
For reference, you should check out the file /system/library/tax.php if you haven't already for the full tax methods.
Related
I'm having issue with calculation of price without tax, when I put price without discount it counts okay, because I made some changes in presta core, for example if I put product with price of 4,5 tax incl and 8% tax I get price - 4,17 tax excl, and that is correct.
(4,5*100)/108 = 4,16666 rounds up.
After giving specific price -15% I get price tax incl 3,83 which is correct, but I get 3,54 price tax excl which is incorrect (correct should be 3,55), I assume that everything counts using price tax excl instead of incl and counts like this
4,17 - (4,17*0,15) = 3,5445 (which php rounds to 3,54 instead of 3,55),
Do you have any idea in which controller or source file should I look to modify PrestaShop behaviour?
Inside "Product" class, check the static method getPriceStatic that is basically handling everything related to retrieving a product price.
You'll end to explore Product::priceCalculation and many methods on the SpecificPrice class that are related to calculation of discounts.
I'm trying to take account of the package weight in the total weight of the cart so I can bill the right shipping cost.
I tried adding a filter on 'woocommerce_cart_contents_weight' like explained there
So I added the following code snippet
function add_package_weight_to_cart_contents_weight( $weight ) {
$weight = $weight * 1.3; // add 30%
return $weight;
}
add_filter('woocommerce_cart_contents_weight', 'add_package_weight_to_cart_contents_weight');
I've also added a snippet to print cart weight on cart page, and I can see that the weight filter isn't applied : The total weight of the cart doesn't change wether the snippet is active or not.
I also tried putting exactly 900g articles in the cart so that, with the box weight, it goes over 1kg and change price, but the shipping price is still the one for under 1kg.
Any idea on why it isn't applied and how I could fix it ?
Your code works and only affects WC_Cart method get_cart_contents_weight() usage.
Now for shipping methods, as cart items can be divided into packages, the weight is calculated for each shipping package and doesn't use WC_Cart method get_cart_contents_weight(). Instead it will make a calculation on the cart items for each package.
A possible way should be to use the filter hook woocommerce_package_rates to alter cost based on the package weight calculation. But this is going to be much more complicated as it seems that you are using 3rd party plugins.
The problem is: If we sell a ticket to our customer, we pay the tax not where the customer lives and not where the company of the shop is located. We pay the tax, where the event is held.
We can use a workaround where we can define a tax class for each country, with the rate. But this is very ugly.
I would like to develope something where I can set the country for the events and WooCommerce will use this country as a tax base, just for this product.
My problem is, that I don't know which filter I should apply. I found some, but the filter don't give the product object or the product id as parameter.
For example: https://docs.woocommerce.com/wc-apidocs/source-class-WC_Checkout.html#468
Does someone have an idea?
thanks for getting back to me. That's the "hack" I implemented but it solved for me
I used the filter woocommerce_price_ex_tax_amount (there is also, woocommerce_price_inc_tax_amount) for inclusive tax calculation.
It receives $tax_amount (already calculated), $key, $rate, $price.
You can setup a fictitious tax rate for every ticket and modify it programatically. As you'll receive the price as well, you can recalculate the rate base on it and return it.
Hope it helps,
hey i'm implementing a custom discount system since magento discount system does not feet my requirements so i'm trying to apply a discount on an Mage_Sales_Model_Quote_Item I've read some and I've found the following function setOriginalCustomPrice the thing is that it applies on the item, and if the user changes the quantity he will get the discount on the item with the new quantity, so i'm trying to use a different method addOption on the item and only on the cart page show the calculations based on the quantity in the option value
$item->addOption(array('code'=>'promo','value' => serialize(['amount'=>10,'qty'=>1])));
and in the cart page
$promo = $item->getOptionByCode('promo');
echo '<div class="orig-price">'.$item->getOriginalPrice().'</div>';
echo '<div class="new-price">'.$item->getOriginalPrice() - ($promo['amount'] * $promo['qty']).'</div>';
the problem is that it does'nt actually apply the new price on the product,
so i want to customize Mage_Sales_Model_Quote->collectTotals() to show my discounts
and send it to the admin back-end when order is completed
how can i achieve that?
thanks in advance
I think there is a fundamental flaw in your approach. I'm not sure what you don't like in standard discounts, and what you can't achieve with catalog or shopping cart rules, but what you're trying to do definitely breaks these features (along with my heart).
However, if you're sure about what you're trying to do, then don't customize Mage_Sales_Model_Quote->collectTotals().
This function just... well, it collects all totals: subtotal, shipping, discount, etc. And it looks like you're changing only price output, but Magento itself doesn't know anything about it.
So if you want to let Magento know that you're changing the item price, you have to either add your own total, or change one of the existing totals. After that Magento will do everything else. Since after your changes Magento outputs already calculated price instead of original one, it may be strange for customer to see the original price in the cart and the additional discount total. So it looks like you will have to change subtotal total.
To do that you have to rewrite Mage_Sales_Model_Quote_Address_Total_Subtotal class in your extension and insert your calculation in _initItem() method. Around line 111 in the original file you will see the code:
$item->setPrice($finalPrice)
->setBaseOriginalPrice($finalPrice);
And this is where Magento sets price for the item, so you can insert your calculations and change $finalPrice before that. If you have virtual products, you will have to change collect() method too.
I am working on a Opencart project and it is for Australia customers. So I have to set GST 10% to all items. The items are already added to the cart and I figured a way to add tax classes and I added it to a product and it works good.
The problem is the catalog has more than 10000 products already and I need to update tax classes to all the products. I knew we can run a query to do that but my question is "Is there a way to set a tax class to default" Please let me know. Thanks
My Opencart version is 1.5.1.3
The easiest way to do this would be to use SQL. You will need to run the following code in your phpMyAdmin or whatever other tool you use for SQL on your server
UPDATE `product` SET `tax_class_id` = '123';
changing 123 to the tax class ID. You may also need to add a database prefix to the table name product depending on your setup
EDIT
To get this to work with new products by default, open /admin/controller/catalog/product.php and change this line
$this->data['tax_class_id'] = 0;
setting the 0 to the tax class ID
I tried this on my setup (1.5.3.1) and it seemed to work ok; Assuming that all those products you have entered are set to the same existing Tax Class? If that's the case, then you can edit that Tax Class that the majority of products are on, and then change the Tax Rate for that class to a GST Tax Rate you create. You should also be able to rename that Tax Class so it appears as GST on the actual website. I hope that helps.