Post by nureddin21 » Tue Apr 05, 2022 7:44 am

Hello everyone.

Can coupon code be applied to the basic price of the product instead of the discount price?

Any feedback is greatly appreciated..
Version 3.0.3.8

Thank you.

New member

Posts

Joined
Tue Feb 23, 2021 2:48 am

Post by straightlight » Tue Apr 05, 2022 8:07 am

nureddin21 wrote:
Tue Apr 05, 2022 7:44 am
Hello everyone.

Can coupon code be applied to the basic price of the product instead of the discount price?

Any feedback is greatly appreciated..
Version 3.0.3.8

Thank you.
- https://www.opencart.com/index.php?rout ... n_id=26976
- https://www.opencart.com/index.php?rout ... n_id=26977

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by nureddin21 » Tue Apr 05, 2022 8:11 am

straightlight wrote:
Tue Apr 05, 2022 8:07 am
nureddin21 wrote:
Tue Apr 05, 2022 7:44 am
Hello everyone.

Can coupon code be applied to the basic price of the product instead of the discount price?

Any feedback is greatly appreciated..
Version 3.0.3.8

Thank you.
- https://www.opencart.com/index.php?rout ... n_id=26976
- https://www.opencart.com/index.php?rout ... n_id=26977
I know these extensions from Jonathan..
I need help from here...

Thanks for your speed reply.

New member

Posts

Joined
Tue Feb 23, 2021 2:48 am

Post by straightlight » Tue Apr 05, 2022 8:13 am

nureddin21 wrote:
Tue Apr 05, 2022 8:11 am
straightlight wrote:
Tue Apr 05, 2022 8:07 am
nureddin21 wrote:
Tue Apr 05, 2022 7:44 am
Hello everyone.

Can coupon code be applied to the basic price of the product instead of the discount price?

Any feedback is greatly appreciated..
Version 3.0.3.8

Thank you.
- https://www.opencart.com/index.php?rout ... n_id=26976
- https://www.opencart.com/index.php?rout ... n_id=26977
I know these extensions from Jonathan..
I need help from here...

Thanks for your speed reply.
While your first post does not address that, it does state that: Any feedback is greatly appreciated. You have two feedbacks, so far.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by phpscript7 » Tue Apr 05, 2022 2:03 pm

The logic of this function must be changed upload\catalog\model\extension\total\coupon.php -> gettotal() function,
because the default system saves data in the cart table with a discount.
ex( mainprice 100 - discount 10% ) result-> total=90
And saves the total value 90 in the cart table and applies the coupon to the total value (90).

New member

Posts

Joined
Wed Jan 04, 2017 3:55 pm

Post by phpscript7 » Tue Apr 05, 2022 2:09 pm

When you apply a coupon, get the total of the product and apply the coupon on it

New member

Posts

Joined
Wed Jan 04, 2017 3:55 pm

Post by phpscript7 » Tue Apr 05, 2022 2:41 pm

change this code in upload\catalog\model\extension\total\coupon.php -> gettotal() function
if ($status) {
if ($coupon_info['type'] == 'F') {
$discount = $coupon_info['discount'] * ($product['total'] / $sub_total);
} elseif ($coupon_info['type'] == 'P') {
$discount = $product['total'] / 100 * $coupon_info['discount'];
}

if ($product['tax_class_id']) {
$tax_rates = $this->tax->getRates($product['total'] - ($product['total'] - $discount), $product['tax_class_id']);

foreach ($tax_rates as $tax_rate) {
if ($tax_rate['type'] == 'P') {
$total['taxes'][$tax_rate['tax_rate_id']] -= $tax_rate['amount'];
}
}
}
}


to this code

if ($status) {
$product_total = $this->db->query("SELECT p.price FROM " . DB_PREFIX . "product p WHERE p.product_id = '" . (int)$product['product_id'] . "'");
if ($coupon_info['type'] == 'F') {
$discount = $coupon_info['discount'] * ((float)$product_total->row['price'] / $sub_total);
} elseif ($coupon_info['type'] == 'P') {
$discount = (float)$product_total->row['price'] / 100 * $coupon_info['discount'];
}

if ($product['tax_class_id']) {
$tax_rates = $this->tax->getRates($product['total'] - ($product['total'] - $discount), $product['tax_class_id']);

foreach ($tax_rates as $tax_rate) {
if ($tax_rate['type'] == 'P') {
$total['taxes'][$tax_rate['tax_rate_id']] -= $tax_rate['amount'];
}
}
}
}

New member

Posts

Joined
Wed Jan 04, 2017 3:55 pm

Post by phpscript7 » Tue Apr 05, 2022 2:46 pm

So create a function in the model file for the sql query and load this model and call that function
-> $product_total = $this->db->query("SELECT p.price FROM " . DB_PREFIX . "product p WHERE p.product_id = '" . (int)$product['product_id'] . "'");

New member

Posts

Joined
Wed Jan 04, 2017 3:55 pm

Post by paulfeakins » Tue Apr 05, 2022 6:03 pm

nureddin21 wrote:
Tue Apr 05, 2022 8:11 am
I know these extensions from Jonathan..
I need help from here...
Well just ask him then, he's incredibly helpful.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by nureddin21 » Tue Apr 05, 2022 7:51 pm

phpscript7 wrote:
Tue Apr 05, 2022 2:09 pm
When you apply a coupon, get the total of the product and apply the coupon on it
It worked for me, and the discount was applied to the price before the discount.
But It had a new problem. In this case, the price of the product still appears after the discount. The customer gets the discount twice.

Is it possible to get the price of the product before the discount only if a coupon code is applied?

for example
Product x, price is $200 and there is a discount on it to become $100

If no coupon is applied, price still $100, but if a coupon code is applied, the price appears before the discount is $200, and the coupon is applied to this number while still calculating it in the totals correctly.

That is, forcing the customer to take advantage of one discount (either product discount or coupon discount)

New member

Posts

Joined
Tue Feb 23, 2021 2:48 am

Post by straightlight » Tue Apr 05, 2022 8:23 pm

nureddin21 wrote:
Tue Apr 05, 2022 7:51 pm
phpscript7 wrote:
Tue Apr 05, 2022 2:09 pm
When you apply a coupon, get the total of the product and apply the coupon on it
It worked for me, and the discount was applied to the price before the discount.
But It had a new problem. In this case, the price of the product still appears after the discount. The customer gets the discount twice.

Is it possible to get the price of the product before the discount only if a coupon code is applied?

for example
Product x, price is $200 and there is a discount on it to become $100

If no coupon is applied, price still $100, but if a coupon code is applied, the price appears before the discount is $200, and the coupon is applied to this number while still calculating it in the totals correctly.

That is, forcing the customer to take advantage of one discount (either product discount or coupon discount)
You simply need to apply a rule. Those two extensions I provided on the above does have the functionality.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: Majestic-12 [Bot], Semrush [Bot] and 59 guests