Post by Keejos » Mon May 15, 2017 2:04 am

Alright, I have been reading tons of topics on this 'issue', however none of them seem to be headed anywhere near a solution.

I'll give it another shot. Please restrain yourself from debating whether or not this is either legal, "the way to go" or plain retarded.
The question is (and remains): how do I get this OpenSource software to calculate the shopping cart as I would like it to do.

Currently:

Item ex. VAT: € 100
VAT (21%): € 21
Fixed price coupon: € 120
Grand total: € 21

(It deducts € 100 of item price, however VAT remains 21% on €100).

My wish:

Item ex. VAT: € 100
VAT (21%): € 21
Fixed price coupon: € 120
Grand total: € 1

(It deducts € 120 of Item ex. VAT + VAT).

We could debate for months and months whether this is how coupons suppose to be deducted. I rather would like to focus on a solution on how to get there. Please, PLEASE help :) ;D

P.S. The order of my shopping cart display will not change the functionality. So regardless if I put coupons on order 1, 3, 5 or 198543948, it will always be applied to sub-total amount only.

Hugs,

Keejos

Newbie

Posts

Joined
Sun Jan 08, 2017 5:55 am

Post by thekrotek » Mon May 15, 2017 7:16 am

Short answer: you can't. Total is a sum of ALL order totals, including coupon, so you can't apply coupon to it. Period.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by Keejos » Mon May 15, 2017 5:47 pm

thekrotek wrote:
Mon May 15, 2017 7:16 am
Short answer: you can't. Total is a sum of ALL order totals, including coupon, so you can't apply coupon to it. Period.
As rephrase: How would I apply a coupon on 'sub-total + VAT', instead of only being able to apply coupon on 'sub-total'?

Newbie

Posts

Joined
Sun Jan 08, 2017 5:55 am

Post by thekrotek » Mon May 15, 2017 7:22 pm

Set Coupon sort order value HIGHER than Tax sort order on Order Totals page.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by Keejos » Tue May 16, 2017 12:28 am

thekrotek wrote:
Mon May 15, 2017 7:22 pm
Set Coupon sort order value HIGHER than Tax sort order on Order Totals page.
It already is.
Doesn't affect the way it is calculating.

Newbie

Posts

Joined
Sun Jan 08, 2017 5:55 am

Post by thbr02 » Thu Oct 31, 2019 3:35 am

Keejos wrote:
Tue May 16, 2017 12:28 am
thekrotek wrote:
Mon May 15, 2017 7:22 pm
Set Coupon sort order value HIGHER than Tax sort order on Order Totals page.
It already is.
Doesn't affect the way it is calculating.
Did you get any solution at this issue? I have the same problem with 3.0.2.0.

Active Member

Posts

Joined
Wed Jun 22, 2011 10:30 pm
Location - Sweden

Post by thekrotek » Thu Oct 31, 2019 4:13 am

thbr02 wrote:
Thu Oct 31, 2019 3:35 am
Did you get any solution at this issue? I have the same problem with 3.0.2.0.
The solution was already given above.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by opencartmart » Thu Oct 31, 2019 3:26 pm

Keejos wrote:
Mon May 15, 2017 2:04 am
P.S. The order of my shopping cart display will not change the functionality. So regardless if I put coupons on order 1, 3, 5 or 198543948, it will always be applied to sub-total amount only.
Because this is how it's coded. Coupon amounts can not be greater than the product total. So if you want to have the logic you described, you must modify code Or use any extension that can do it. Anyway, You have to modify code in the file catalog/model/{extension}/total/coupon.php and method name is getTotal. I tried to modify the code quickly that would be as follows. Note I have not tested code and it does not consider applicable products of the coupon.

Code: Select all

public function getTotal($total) {

        if (isset($this->session->data['coupon'])) {
            $this->load->language('extension/total/coupon', 'coupon');
            $coupon_info = $this->getCoupon($this->session->data['coupon']);

            if ($coupon_info) {
                $discount_total = $coupon_info['type'] == 'F' ? $coupon_info['discount'] : ($coupon_info['discount'] * $total['total']) / 100;

                // If discount greater than total
                if ($discount_total > $total['total']) {
                    $discount_total = $total['total'];
                }


                if ($discount_total > 0) {
                    $total['totals'][] = array(
                        'code'       => 'coupon',
                        'title'      => sprintf($this->language->get('coupon')->get('text_coupon'), $this->session->data['coupon']),
                        'value'      => -$discount_total,
                        'sort_order' => $this->config->get('total_coupon_sort_order')
                    );

                    $total['total'] -= $discount_total;
                }
            }
        }
    }

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by thekrotek » Thu Oct 31, 2019 3:58 pm

opencartmart wrote:
Thu Oct 31, 2019 3:26 pm
Because this is how it's coded. Coupon amounts can not be greater than the product total. So if you want to have the logic you described, you must modify code Or use any extension that can do it. Anyway, You have to modify code in the file catalog/model/{extension}/total/coupon.php and method name is getTotal. I tried to modify the code quickly that would be as follows. Note I have not tested code and it does not consider applicable products of the coupon.
It's enough to replace this:

$sub_total = $this->cart->getSubTotal();

With this:

$sub_total = $total['total'];

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by opencartmart » Thu Oct 31, 2019 4:50 pm

thekrotek wrote:
Thu Oct 31, 2019 3:58 pm
It's enough to replace this:

$sub_total = $this->cart->getSubTotal();

With this:

$sub_total = $total['total'];
Intelligent solution indeed but unfortunately you are wrong! Reference code (copied from catalog/model/extension/total/coupon.php):

Code: Select all

if ($coupon_info['type'] == 'F') {
	$discount = $coupon_info['discount'] * ($product['total'] / $sub_total);
}

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by thekrotek » Thu Oct 31, 2019 5:13 pm

opencartmart wrote:
Thu Oct 31, 2019 4:50 pm
Intelligent solution indeed but unfortunately you are wrong! Reference code (copied from catalog/model/extension/total/coupon.php):

Code: Select all

if ($coupon_info['type'] == 'F') {
	$discount = $coupon_info['discount'] * ($product['total'] / $sub_total);
}
And where exactly am I wrong?

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by opencartmart » Thu Oct 31, 2019 5:28 pm

thekrotek wrote:
Thu Oct 31, 2019 5:13 pm
if ($coupon_info['type'] == 'F') {
$discount = $coupon_info['discount'] * ($product['total'] / $sub_total);
}
And where exactly am I wrong?
Because it will reduce the actual coupon amount as OC calculates it by the taking ratio of product total and sub_total whereas you are replacing sub_total with grand total

Example: Let's say actually coupon amount is: $110. Now you will get the following according to your change:

Sub-Total: $100.00
VAT (20%): $20.00
Coupon: $-91.67 ( Instead of $110 )
Total: $28.33

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by thekrotek » Thu Oct 31, 2019 8:09 pm

opencartmart wrote:
Thu Oct 31, 2019 5:28 pm
Because it will reduce the actual coupon amount as OC calculates it by the taking ratio of product total and sub_total whereas you are replacing sub_total with grand total

Example: Let's say actually coupon amount is: $110. Now you will get the following according to your change:

Sub-Total: $100.00
VAT (20%): $20.00
Coupon: $-91.67 ( Instead of $110 )
Total: $28.33
Replace this:

$coupon_info['discount'] = min($coupon_info['discount'], $sub_total);

With this:

$coupon_info['discount'] = min($coupon_info['discount'], $this->cart->getSubTotal());

Problem solved.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by opencartmart » Thu Oct 31, 2019 10:28 pm

thekrotek wrote:
Thu Oct 31, 2019 8:09 pm
Replace this:

$coupon_info['discount'] = min($coupon_info['discount'], $sub_total);
With this:
$coupon_info['discount'] = min($coupon_info['discount'], $this->cart->getSubTotal());

Problem solved.
Still not solved. Because you are restricting the coupon amount limit up to subtotal again and this is not what the user looking for. Also, this will not solve the problem that I stated in my last reply. Anyway, I am not going to reply to this post anymore. Basically I would not have replied unless you had referred my code with your buggy code.

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by thekrotek » Thu Oct 31, 2019 10:37 pm

opencartmart wrote:
Thu Oct 31, 2019 10:28 pm
Still not solved. Because you are restricting the coupon amount limit up to subtotal again and this is not what the user looking for. Anyway, I am not going to reply to this post anymore. Basically I would not have replied unless you had referred my code with your buggy code.
No, I'm not restricting it to subtotal, because this particular code shouldn't even exist. Why in the world do you recalculate the FIXED value? The whole point of this line of code it so keep the given discount value, nothing else.

Your code is unnecessary big and can be reduced to a couple simple modifications.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by opencartmart » Thu Oct 31, 2019 10:42 pm

thekrotek wrote:
Thu Oct 31, 2019 10:37 pm

No, I'm not restricting it to subtotal, because this particular code shouldn't even exist. Why in the world do you recalculate the FIXED value? The whole point of this line of code it so keep the given discount value, nothing else.

Your code is unnecessary big and can be reduced to a couple simple modifications.
Are you sure? Well, if you are damn sure, why don't you post your code instead of correcting me with buggy code? I must say you have not understood the user question.

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by opencartmart » Thu Oct 31, 2019 10:44 pm

By the way, according to your new changes, now the result is:

Sub-Total: $100.00
VAT (20%): $20.00
Coupon (3333): $-83.33 (!!)
Total: $36.67

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by thekrotek » Thu Oct 31, 2019 10:58 pm

opencartmart wrote:
Thu Oct 31, 2019 10:42 pm
Are you sure? Well, if you are damn sure, why don't you post your code instead of correcting me with buggy code? I must say you have not understood the user question.
I understood everything correctly. But I don't have time to create a code and post it here for free. I gave you a direction on how to implement it the shorter way since you decided to provide a code yourself. If you want to follow this direction, be my guest. If you want to keep coding like a Hindu newbie coder - your choice. You basically cut everything from getTotal() function instead of thinking a bit and adding modifications to the correct parts of the code. And this is supposed to be a solution? Nice... I hope OP doesn't need Free Shipping option and tax recalculation, because your "non buggy code" apparently missing them.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by opencartmart » Fri Nov 01, 2019 2:29 am

thekrotek wrote:
Thu Oct 31, 2019 10:58 pm
I understood everything correctly. But I don't have time to create a code and post it here for free. I gave you a direction on how to implement it the shorter way since you decided to provide a code yourself.
But have you ever thought whether your shorter way really works or not? I have given two examples where your shorter answer yielded absolutely wrong answers and exacerbate the problem. By the way, I don't need your direction. Post your own code without tagging me. If you don't have time, don't post. Plain and simple.
If you want to follow this direction, be my guest. If you want to keep coding like a Hindu newbie coder - your choice.
This is called racism.
You basically cut everything from getTotal() function instead of thinking a bit and adding modifications to the correct parts of the code. And this is supposed to be a solution? Nice... I hope OP doesn't need Free Shipping option and tax recalculation, because your "non buggy code" apparently missing them.
I never said that was the final code. I said `it could be` and `untested` code though it will work properly unless the free shipping option is needed. Interestingly OP does not want to consider tax issues according to his/her example.

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am
Who is online

Users browsing this forum: No registered users and 431 guests