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
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
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
The solution was already given above.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
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
It's enough to replace this:opencartmart wrote: ↑Thu Oct 31, 2019 3:26 pmBecause 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.
$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
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
And where exactly am I wrong?opencartmart wrote: ↑Thu Oct 31, 2019 4:50 pmIntelligent 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); }
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
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
Replace this:opencartmart wrote: ↑Thu Oct 31, 2019 5:28 pmBecause 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
$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
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
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.opencartmart wrote: ↑Thu Oct 31, 2019 10:28 pmStill 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.
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
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.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.
XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart
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
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.opencartmart wrote: ↑Thu Oct 31, 2019 10:42 pmAre 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.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
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.
This is called racism.If you want to follow this direction, be my guest. If you want to keep coding like a Hindu newbie coder - your choice.
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.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.
XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart
Users browsing this forum: No registered users and 431 guests