Post by caaarl » Tue Nov 22, 2016 3:58 am

Hi everyone,

I have an order total module that adds a discount to the order when a specific order total sum has been reached. My problem is that this discount will be removed after updating the products from admin area and the total sum falls below the discount limit (which is the expected behaviour of the extension of course). Is there some ready to use function I can use to change that behaviour or do I have to build an ocmod for this?

I'm running OpenCart 2.3.0.2 and the discount extension can be found here: https://www.opencart.com/index.php?rout ... n_id=23304

Newbie

Posts

Joined
Tue Nov 25, 2014 1:06 am

Post by thekrotek » Tue Nov 22, 2016 3:29 pm

You mean, discount is removed, when you edit the order?

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 caaarl » Wed Nov 23, 2016 2:53 am

yes, the discount is removed after editing the order and the discount conditions are not longer fulfilled.

Newbie

Posts

Joined
Tue Nov 25, 2014 1:06 am

Post by thekrotek » Wed Nov 23, 2016 11:24 am

Discount is removed only when conditions are no longer met. For example, if your discount depends on certain quantity of products, then, if you lower this quantity when editing order, discount will not be applied. This is absolutely normal behavior and this is exactly, how it should work.

But if your order still meet the conditions of the discount, but discount is not applied, when you edit the order, this means, that this particular discounting extension is faulty. You need to contact its developer.

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 caaarl » Fri Nov 25, 2016 5:03 am

Thank you for the answer.

As I already mentioned in my initial post I know that the discount will be removed because the order did not meet the conditions of the discount any longer and that this is the common behavior in open cart.

I wanted to know if anybody else needed to solve the same task before or has a good tip for solving this problem.

I started modifing the products() method /catalog/controller/api/cart.php in such a way that before recalculating the order total modules I load the existing discount entry from database and push it into the new computed order total entries. But after saving the order the discount is still lost.

Any help would be welcome!

Newbie

Posts

Joined
Tue Nov 25, 2014 1:06 am

Post by thekrotek » Fri Nov 25, 2016 6:24 am

A lot of people wanted to solve this before, but it's not solvable, because this is the core functionality. Well, this behavior, of course, can be changed, but you will have to do tons of modifications. OpenCart doesn't actually 100% edit order, it simply deletes and inserts again many things, including discounts, vouchers etc. Moreover, order editing in OC 2.0 works via API, which does a bunch of tests, runs tons of queries etc. Every solution you choose will have consequences due to this.

I'd really suggest you to accept this "as is" and find a workaround. For example, before editing order, you can temporarily set discount back, save order and then delete discount. If you don't have much visitors, this is a good solution. Otherwise you might have a few discounted orders from lucky customers. But, like I said, EVERY solution will have its consequences.

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 caaarl » Fri Nov 25, 2016 9:45 pm

Hi thekrotek,
thanks for clearifying this! I'm realizing that it would be much more complecated as it looked at first glance :(
I'll convince my client to accept this or maybe to try out your trick with the tempoary discount (maybe a working hack could be to do the temporary discount programmatically right inside the order update method ;) but that sounds a bit exaggerated for such an issue).

Eventually, using the api for a lot of internal things seems not to be the best design decision. This makes customizations unnecessary complicated :-/ Nevertheless I like most of the rest of the system.

Newbie

Posts

Joined
Tue Nov 25, 2014 1:06 am

Post by thekrotek » Sat Nov 26, 2016 1:26 am

caaarl wrote:Eventually, using the api for a lot of internal things seems not to be the best design decision. This makes customizations unnecessary complicated :-/ Nevertheless I like most of the rest of the system.
As far as I understand, main API idea is to make things generic and avoid duplicating controller/model files for admin and catalog. If it is so, then it's a pretty strange solution, because you can simply put most popular functions in "system" folder and use them everywhere you want. Also API constantly produces permission errors, because it looses session data. There're multiple other issues, which I encountered in my OpenCart programming career. Believe me, disappearing discount is the lesser evil.

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 caaarl » Mon Dec 12, 2016 2:43 am

thekrotek wrote:As far as I understand, main API idea is to make things generic and avoid duplicating controller/model files for admin and catalog. If it is so, then it's a pretty strange solution, because you can simply put most popular functions in "system" folder and use them everywhere you want.
Yes, that's what I read about it, too. "Strange solution" is the correct description, yes ::) I already fought with permission errors and other annoying issues related to the api concept...
I bet if starting opencart from scratch he wouldn't use an internal api solution again but re-usable modules. ;) But sadly, we have to deal with this api thing for the next time and have to wait for oc 3.0 :crazy:

Newbie

Posts

Joined
Tue Nov 25, 2014 1:06 am
Who is online

Users browsing this forum: No registered users and 12 guests