Magento rounding problems product prices without tax - magento

This is not the first time we come across this issue, but it is the first time we cannot solve it with the "known" bug fixes. We have tryed a couple of fixes but none are working. I hope somebody can assist me in the resolution for me and all others facing this annoying problem.
The problem ocurres here in a Magento 1.6.2 install
http://www.trampoline.nl/outdoor/voetbalgoals/aluminium-goal-3-00-x-2-00-incl-net.html
Frontend price: 398,99€
Backend price :329.75€
Our tax rate here in The Netherlands is 21%, calculated tax is: 69.25€
So this should be: (69.25€ + 329.75€) = 399.00€
Magento Bug still active in 1.6.2:
http://www.magentocommerce.com/bug-tracking/issue?issue=7978
I tryed the following:
Magento & Paypal tax rounding issue
Magento tax rounding issue
http://www.mageext.com/MageExt_FixRound-0.1.0.rar
http://www.magentocommerce.com/boards/viewthread/247201/P15/#t361474
return round($price, 3);
return round($price, 4);
return $price;
etc etc
I hope somebody can help me with this one.
Greetings Gijs
ShopWorks

Ok fixed it.
First of check if php has the module bcMath installed (--enable-bcmath) if not, compile it.
After that i installed the module:
http://www.mageext.com/MageExt_FixRound-0.1.0.rar
And changed:
public function roundPrice($price)
{
return round($price,2);
}
After that you should see round prices.
To:
public function roundPrice($price)
{
return round($price);
}

Related

Magento: Bundled price is 0.00

Magento v1.7.0.2
We've been using this version several years now.
We have several free and paid extensions and last month we created our first bundled product.
When in list view the price is shown as 'Start at 0,00' for some products.
Other bundles products are fine and show the correct minimum price.
I've been searching for a while now, but can't find a workable solution.
Here's a sample page: http://www.scrapwebshop.nl/kado-tip.html
I finally got it working. It is probably not the right nor most efficient way, but the result is what I need. And that is what counts ;)
I now I have a grouped product, so I loop through all associated products, put their prices in an array. Next I sort to get the lowest value on top and get the first array entry.
I hope it helps somebody else:
$associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
foreach ($associatedProducts as $assoc) {
$prices[] = $assoc->price;
}
sort($prices, SORT_NUMERIC);
$_minimalPrice = array_shift($prices);
$_exclTax = $_taxHelper->getPrice($_product, $_minimalPrice);
$_inclTax = $_taxHelper->getPrice($_product, $_minimalPrice, true)

To add discount to the product which is 15 days old from created date

I want to add discount to the product when that product exceeds more than 15 days from created date.
Generally i know how to add discount to the product, but i felt this is difficult to set the discount with that condition. It make me as so confused. I have found where to add that attribute in combo box.
\app\code\core\Mage\SalesRule\Model\Rule\Condition\address.php
I got created date of product by $product->getCreatedAt()
But i totally confused "how to do that action?". If anybody know, Please help me guys!
Here i am givin you some brief idea to make customization in catalog rule to check if your product is old from created with 15 days and more.
Try to build your own module to manage this kind of catalog rule in your applicaion
you can take understand from this tutorial to manage catalog rule
specially just go throw last 4 slides to make your own rule to achieve your goal.
I have simply used shopping cart price rules by the following way.
first i had created product attribute named as days. Then I have set the value to that days textbox as programmatically as follows
require_once("app/Mage.php");
Mage::app();
$productCollection = Mage::getModel('catalog/product')->getCollection();
$date2=Date("Y-m-d");
foreach($productCollection as $_product)
{
$product = Mage::getModel('catalog/product')->load($_product->getEntityId());
$date1=$product->getCreatedAt();
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$product->setDays($days);
$product->save();
}
After that i have added that product attribute promo rules. Then i set the condition as if differerence between dates which are from product creation date to now is more than 15 days, to add discount to that particular product.

Magento & Paypal tax rounding issue

I have some rounding issues with Paypal and Magento 1.7.0.2 - All prices on the site include tax and the tax is worked out at 20% (VAT).
I will go to checkout and everything is correct:
I will then click on place order, and Paypal will be like this, which is incorrect because the grand total is now 1p less. This appears to be cause by how the tax is rounded.
In some cases, it works ok, but in others the tax is rounded incorrectly. I have tried making changes to the tax calculation method calcTaxAmount() in app/code/core/Mage/Tax/Model/Calculation.php
I added this to the calcTaxAmount method which seemed to fix it, but it cause the prices on the product page to then be incorrect (1p less).
$amount = $this->roundUp($amount);
I'm pretty certain this is a bug, but I'm out of ideas. If anyone has come across this before and has a solution I'd be happy to hear it. Any help much appreciated.
EDIT: Here are my tax settings in Magento
I think I've found the solution to this issue plaguing the community.
If your prices include tax, the tax calculation is wrong.
Here's the fix - In Mage_Tax_Model_Calculation::calcTaxAmount():
change the condition:
if ($priceIncludeTax)...
to:
if ( ! $priceIncludeTax ) ...
So the condition looks like:
if ( ! $priceIncludeTax ) {
$amount = $price*(1-1/(1+$taxRate));
} else {
$amount = $price*$taxRate;
}
For details, check out my comments: http://www.magentocommerce.com/boards/viewthread/247201/P45/
Remember not to modify the core files - create a copy in local
I "fixed" this today for i client but not really happy with the solution. But it works.
It is better if you copy this file to your local folder:
app/code/core/Mage/Paypal/Model/Api/Nvp.php
I added this code (Only for the express checkout) on line 606 so it look like this.
$request['SHIPPINGAMT'] = ($request['AMT'] - ($request['TAXAMT'] + $request['ITEMAMT']));
$response = $this->call(self::SET_EXPRESS_CHECKOUT, $request);
$this->_importFromResponse($this->_setExpressCheckoutResponse, $response);
And you need to turn of Transfer Cart Line Items in the paypal moule in the backend
If somebody knows a better solution then just overwriting the shippingcost let me know
This problem has been plaguing me (and by looks of it the magento community for ages), thanks to ShopWorks push in the right direction (inclusive of his code snippet, thanks mate! However it would bug out if going back to the cart from express checkout, added a check in to prevent this.) of the $request parameters I came up with the following fix (/hack):
On line 606 of Nvp.php place the following:
$totalValue = $request['TAXAMT'] + $request['ITEMAMT'];
$finalValue = $totalValue - $request['AMT'];
if($request['SHIPPINGAMT'] > 0) {
$request['SHIPPINGAMT'] = ($request['AMT'] - ($request['TAXAMT'] + $request['ITEMAMT']));
$totalValue = $request['TAXAMT'] + $request['ITEMAMT'] + $request['SHIPPINGAMT'];
$finalValue = $totalValue - $request['AMT'];
}
if($request['AMT'] != $totalValue) {
if($totalValue > $request['AMT']) {
$request['TAXAMT'] = $request['TAXAMT'] - $finalValue;
} elseif($totalValue < $request['AMT']) {
$request['TAXAMT'] = $request['TAXAMT'] + $finalValue;
} else {
$request['AMT'] = $request['TAXAMT'] + $request['ITEMAMT'];
}
}
Additionally, the following needs to be also placed within the call() function (line 938 of Nvp.php):
$totalValue = $request['TAXAMT'] + $request['ITEMAMT'] + $request['SHIPPINGAMT'];
$finalValue = $totalValue - $request['AMT'];
if($request['AMT'] != $totalValue) {
if($totalValue > $request['AMT']) {
if($finalValue > 0) {
// its preferable that we change the tax amount over the grand total amount
$request['TAXAMT'] = $request['TAXAMT'] - $finalValue;
} else {
$request['AMT'] = $totalValue;
}
} elseif($totalValue < $request['AMT']) {
if($finalValue > 0) {
// its preferable that we change the tax amount over the grand total amount
$request['TAXAMT'] = $request['TAXAMT'] + $finalValue;
} else {
$request['AMT'] = $totalValue;
}
} else {
$request['AMT'] = $totalValue;
}
}
This is a hack, and treat it as such. My colleague is currently testing it but seems to be OK for the moment, it is also helpful to set the tax calculation method by unit price (our accountants are happy with this arrangement, but this is for the UK, i'm not sure if other countries will frown upon that particular tax calculation method).
The reason I am manipulating the $request['AMT'] is because occasionally the calculation of the $finalValue variable would produce a -0.9999 repeating integer which is of no use to anyone, my maths sucks so if anyone wants to improve upon this, please do so!
As always don't overwrite the nvp.php in the core directory, create a seperate rewrite module or do this in app/local/mage. First option preferably! :-)
There is a "bug" on Paypal in magento module (at least on my Magento 1.8.0);
It resides in the Mage_Paypal_Model_Cart class.
To validate that the amounts are correct, the method _validate() on line 381 sums up all items prices from the order, adds shipping fees and taxes, and compares the result with the total value of the order (got from order method getBaseGrandTotal())
But sometimes, there is a 0.009999999999999999 difference between the amounts (it must come from different roundings methods, I don't know); so the items are not valid and the method getItems() from line 146 returns false.
In my case this resulted in customers paying a different amount and a "fraud suspicion" flag on their orders.
I fixed it by changing the comparison method (line 404) from :
if (sprintf('%.4F', $sum) == sprintf('%.4F', $referenceAmount)) {
$this->_areItemsValid = true;
}
to
$diff = abs(sprintf('%.4F', $sum) - sprintf('%.4F', $referenceAmount));
if ($diff < 0.01) {
$this->_areItemsValid = true;
}
I still hope that there will not be diffs of more than 0.009999999 in the future...
Hope this helps.
I'm using CE1.7.0.2 and have been stuck on this problem for days, tried several solutions, and finally landed on Adam Hall's fix/hack. The ideal looks reasonable to me, so I applied it on my site and everything went well until this morning, I realized that the adjustment on tax amount doesn't work for our situation.
We're in California and selling stuff all over the states, customers in California will be charged for sales tax while others outside will not. So when tax amount is zero and have to subtract the difference, it will generate a negative tax amount which obviously will be rejected by paypal. So when subtracting difference from tax amount, I added a conditional statement
if ($request['TAXAMT'] > 0) {
$request['TAXAMT'] = $request['TAXAMT'] - $finalValue;
} else {
$request['SHIPPINGAMT'] = $request['SHIPPINGAMT'] - $finalValue;
}
If tax amount is zero, I will adjust shipping amount instead of tax amount. (Sure if both tax and shipping are free, this will not work, but I don't think that will happen in real business.) Hope this could help those who have the same problem as us.
i just changed transfer cart line items to "NO", without the above code change.. and it worked.
Magento 1.9.0.1
just FYI - test if it works for you.
Dmytro

Magento set quantity in shopping cart -> quantity not available

I use Magento 1.5.1 to power a fashion webshop. I noticed a strange behaviour from Magento which I hope you can help me resolve:
Here is the scenario:
An item has 5 pieces in stock.
A user adds 5 to its cart
In the mean time someone has bought 1 item so 5 is not available any more. New stock is 4. In my opinion the user should be able to reset the qty to 4.
The user tries to reset the qty to 4. That, however,does not work. All I get at this stage is that the qty is not available and the quantity stays at 5.
EDIT:
To clarify step 4 a little bit more:
I receive a message that the item is out of stock once I try to set the qty to 4.
Is this a known Magento bug? How can I check what is causing this?
Thanks
Oke, finally found a workaround:
\app\code\core\mage\checkout\model\cart.php Line 383 - 386
change:
$item->setQty($qty);
if ($item->getHasError()) {
Mage::throwException($item->getMessage());
}
to:
$oldqty = $item->getQty();
$item->setQty($qty);
if ($item->getHasError() && $qty > $oldqty) {
Mage::throwException($item->getMessage());
}
Now it checks if the new qty is lower then the old qty. If so, continue. Otherwise do the old behaviour.

Magento: Fixed shipping cost BELOW certain basket price

How can I set the shipping cost for Magento for all baskets that are below a certain point. For example, all baskets under £5 have fixed shipping of £1.99.
I think this is what you are looking for, unless I have the wrong thing. It seems to be called Table Rate Shipping.
the only way i've managed to get it working is to add an extra case statement in my shipping module.
$result = Mage::getModel('shipping/rate_result');
...
} else if ($request->getPackageValue() < 6) {
$price = '1.99';
...

Resources