Welcome Guest, Not a member yet? Register   Sign In
flexi cart - A comprehensive shopping cart library for CodeIgniter

[eluser]koichirose[/eluser]
@haseydesign

Did you have the chance to look at the discount error?
I also don't understand if 'tax_method' is actually working.

Here's some code:
Code:
$discount_data = array(
   'id' => $i,
   'description' => 'Example Description',
   'value' => 10,
   'column' => 'item_summary_total',
   'calculation' => '1',
   'tax_method' => '1',
   'void_reward_points' => TRUE //Void any reward points being earnt
  );
  $this->flexi_cart->set_discount($discount_data);

Cart contents: 1 product, 100€ including VAT.
The discount will be 9.99€ in this case. It should be 10€.

By setting 'tax_method' to 1 ( apply tax before discount ) I'd expect this:
82.644 + vat (21%) = 100
discount: 10% of 100 = 10

It looks like the discount is always applied before tax:
10% of 82.644 = 8.26
8.26 + vat (21%) = 9.99

Could you help me out with this?

Thank you!

[eluser]haseydesign[/eluser]
@koichirose

Sorry for the delay in response, I'm particularly busy on other work at the moment.

------------------------------------------------------------

Regarding your 2nd question about discounts and tax, I believed we've touched on this before via email.
Your cart is setup to calculate item prices excluding tax, therefore the discount values are also shown excluding tax.

To the customers point of view, they are buying an item that costs 82.64€, 10% of that is 8.26€, when all taxes are applied to the item and discount, the 10% is 10.00€.
To show the customer a 10% discount on 82.64€ @ 10.00€ would (to me at least) seem more confusing - I would think "how does 10% of 82.64 equal 10.00€?".

In your example, when the cart total is calculated, the total price for the cart will be 90.00€ - as it should be with the 10€ discount.
If you really want to calculate the discount to show tax, just display the untaxed discount price multiplied against the tax rate of 21%.

------------------------------------------------------------

As for your previous comment regarding decimal rounding and discounts, if I get time in the next few days I'll try and track down where the 2 decimal rounding is happening so you can change it accordingly.

Regarding changing it for the whole repo, I seem to remember from my testing whilst developing the library that although the extra decimals would sometimes display calculations correct to the exact decimal, they would also sometimes return the wrong decimal when 2 decimals did work.

For this reason I'm a little reluctant to spend time updating the library to another method that just has different rounding issues.

It needs a fundamental solution to the question posed in the examples at the bottom of my previous post @ http://ellislab.com/forums/viewreply/1042040/

As annoying as it is, I sadly haven't got the time for the foreseeable future to reinvest into solving the issue. If someone can provide a definite solution, I will try and make the time to implement it.

[eluser]koichirose[/eluser]
@haseydesign

I'm afraid I didn't explain what I meant correctly.
Yes, I am saving prices in the cart without taxes (82.64).
I thought that setting the discount calculation method to '1', would produce the following:
82.644 + vat (21%) = 100
discount: 10% of 100 = 10

Instead, you explained that the calculated discount is 8.26 in both cases (with calculation method = 1 and = 2).

So this is happening:
82.644 + vat (21%) = 100
discount: 10% of 82.644 = 8.26
discount with vat: 8.26 + vat (21%) = 9.994, which becomes 9.99 instead of 10.

So I think that to solve the issue I'd have to allow 3 decimals in the discount calculation:
discount: 10% of 82.644 = 8.264
discount with vat: 8.264 + vat (21%) = 9.999 which becomes 10.00 correctly.

Can this be done? I couldn't track down where the discount rounding happens.

Thank you for all your work Smile

[eluser]haseydesign[/eluser]
@koichirose

Does changing the following line help you out with your discount issue?

flexi_cart_model.php
Line: 3067
Code:
$discount['total'] = $this->format_calculation($total, 3);

[eluser]koichirose[/eluser]
@haseydesign

It doesn't, I still get a 9.99€ discount.

var_dumping $discount at line 3068 there produces this, though:
Code:
array
  'tax_method' => string '1' (length=1)
  'taxable_value' => float 74.376
  'non_taxable_value' => float 0
  'tax_value' => float 15.624
  'total' => float 74.376

total + tax_value is 90.

I don't know if this can help you.

Thank you again!

[eluser]haseydesign[/eluser]
@koichirose

I'm back again!
I hope you realise I've created a private git branch just dedicated to your setup as I have to try and re-replicate it every time I test your problem out. Wink

To further help you with this problem, I need to confirm exactly how you have your cart setup, as I'm getting a different result from what you are saying.

#1: What is the item price that you are adding to the cart? Is it 82.64€, 82.644€ or is it 100€?
#2: Related to the first question, do you have the config option 'price_inc_tax' set to TRUE or FALSE?
#3: I'm presuming you have the config set to display prices excluding tax - correct?

For your scenario, if you are inserting the price as 100€, the config setting 'price_inc_tax' must be TRUE.
If you are inserting the price as 82.644€, the config setting 'price_inc_tax' must be FALSE.
If you are inserting the price as 82.64€ - then for your example, the grand total is going to be out by 1 decimal.

-------------------------------------

For my testing, I get the following results for BOTH setups.

Item @ 100€, 'price_inc_tax' = TRUE, 'display_tax_prices' = FALSE.
Item @ 82.644€, 'price_inc_tax' = FALSE, 'display_tax_prices' = FALSE.

Before the discount
Item Summary Total: 82.64€
VAT @ 21%: 17.36€
Grand Total: 100.00€

After the 10% discount
Item Summary Total: 82.64€
VAT @ 21%: 15.62€
Discount @ 10%: 8.26€
Grand Total: 90.00€

-------------------------------------

Isn't this correct?

[eluser]koichirose[/eluser]
@haseydesign

First of all, your questions.
1. 82.644
2. it is false
3. I'm displaying prices including taxes

The totals are ok in my setup too, meaning that the following (what you said) is valid for me, too:
After the 10% discount
Item Summary Total: 82.64€
VAT @ 21%: 15.62€
Discount @ 10%: 8.26€
Grand Total: 90.00€

Except I'm displaying everything with taxes:
Item Summary Total: 100€
Shipping: 9.68€
Discount @ 10%: 9.99€ //wrong
Grand Total: 99.68 (which is 90 + 9.68, perfect).

My only issue is that as you see I'd like to display the discount including taxes, but since the discount only has two decimals, the result is 9.99.
I'm manually adding taxes to the discount to display it, with:
Code:
$this->flexi_cart->summary_savings_total(false, true) * $current_tax_multiplier

Result: 8.26*1.21 = 9.994 => 9.99.

I couldn't find a flexi_cart function to display savings including taxes, regardless of the 'price_inc_tax' config value.

If I could have the discount with 3 decimals, the result would be correct:
8.264*1.21 = 9.9994 => 10

Thank you again Smile

[eluser]haseydesign[/eluser]
@koichirose

Alrighty, I think I have got you a (hackish) solution that should get you by.

You need to change the formatted currency within two different functions.
You need to make these changes manually yourself as they will not be added to the public library repo.
This also means if you ever update the library, you will need to ensure these settings are reinstated if they are overwritten.

models/flexi_cart_model.php : calculate_discount()
Line: 3067
Code:
$discount['total'] = $this->format_calculation($total, 3);

libraries/flexi_cart_lite.php : summary_savings_total()
Line: 352
Code:
return $this->format_currency($summary_savings_total, $format, 3, $internal_value);

Then call the code you defined in your previous comment.
Code:
$this->flexi_cart->summary_savings_total(false, true) * $current_tax_multiplier

That should give you the value to 3 decimal points!

[eluser]koichirose[/eluser]
@haseydesign

It works! Smile
That is great, thank you very much.

I'm writing down all the custom changes I make in case you choose not to include them in the official repo.

Again, thanks Smile

[eluser]lalocespedes[/eluser]
Hi, i need help, how can i add a custom line item into cart? suggestions

ive tried with form, but doesn't it work

Thks in advance




Theme © iAndrew 2016 - Forum software by © MyBB