Forums / Addon Order Total Modules / Creating a Order Total Module

Creating a Order Total Module

Views: 10,773

Results 1 to 9 of 9
11 Oct 2018, 9:01 PM
#1
kwright avatar

kwright

Zen Follower

Join Date:
Nov 2004
Posts:
355
Plugin Contributions:
0

Creating a Order Total Module

Greetings,

I'v been working on a new Order Total module and looking at the ot_gv code as a guide and been modifying and rewriting the gift card orders total code addon.

My questions is that I can't seen to figure out how and where to add the code such that the module name / method shows on the invoice and the Payment/Shipping column on the admin orders page when it is used to cover the order balance? Currently, the GV name/method shows even though I'm not using it?

I could update the GV defines here to what I want them to say:

  define('PAYMENT_METHOD_GV', 'Gift Certificate/Coupon');
  define('PAYMENT_MODULE_GV', 'GV/DC');

But that isn't the proper way to do it I'm sure!

Suggestions?

Thanks :D

Experience is what you get when you don’t get what you want…

12 Oct 2018, 8:35 AM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Creating a Order Total Module

There's a lot of possible directions to take this and/or the cause at this point. This new order_total module... how much/what has been changed away from the ot_gv code? Has it been modified to be a unique set of code?

It almost sounds like the code still has at least some remnant of the ot_gv "definition" and based on the description that it may have a coding error causing it to always attach to those documents (unless I misunderstood).

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Oct 2018, 1:55 PM
#3
kwright avatar

kwright

Zen Follower

Join Date:
Nov 2004
Posts:
355
Plugin Contributions:
0

Re: Creating a Order Total Module

mc12345678:

There's a lot of possible directions to take this and/or the cause at this point. This new order_total module... how much/what has been changed away from the ot_gv code? Has it been modified to be a unique set of code?

It almost sounds like the code still has at least some remnant of the ot_gv "definition" and based on the description that it may have a coding error causing it to always attach to those documents (unless I misunderstood).

Hi mc12345678,

Originally, I started with a copy of the ot_gv code and made it unique by renaming all references to that module (vars, defines, etc.).

I abandoned that route once I found the gift card addon. I installed the gift card addon, which is an orders total module. Since my goal is to have a gift card type function and use it like a customer loyalty program where a customer can earn $$ that is credited to their card, I thought this would be a better route and modify from there.

I first tested the GC module as is to make sure it was working as described. After a few fixes, it seemed to be working except for the issue that prompted my question about the code registering as if it was the GV module.

I have gone through most of the gift card code line-by-line since I have made several modifications to fit my needs. I traced back where the GV defines get inserted to the order.php class. It is the only reference to the GV defines in all of the Zen Cart code.

includes/classes/order.php

'payment_method' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_METHOD_GV : $this->info['payment_method']),
'payment_module_code' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_MODULE_GV : $this->info['payment_module_code']),

Looking at the code above, I would need to set those array elements to my gift card defines so the GV ones are not used. So, the question would be where in my code and how would I correctly set these so they are used when an order is paid for using a gift card?

$this->info['payment_method'] = PAYMENT_METHOD_GIFTCARD;
$this->info['payment_module_code'] = PAYMENT_MODULE_GIFTCARD;

Hope I'm explaining this clearly, thanks!

Experience is what you get when you don’t get what you want…

12 Oct 2018, 3:13 PM
#5
kwright avatar

kwright

Zen Follower

Join Date:
Nov 2004
Posts:
355
Plugin Contributions:
0

Re: Creating a Order Total Module

lat9:

You could also review the documentation that I put together a couple of years ago: https://docs.zen-cart.com/Developer_Documentation/1.6/code_docs/modules/order_total_modules

Thanks lat9,

This is very helpful. I knew there was some documentation, but not for 1.5.4 which I am using. The Order Total docs you referenced (1.6.0) would be the same for 1.5.4?

I looked through the docs, but still couldn't find where you set the OT modules payment_method and payment_module_code such that it will show in the admin orders pages?

Experience is what you get when you don’t get what you want…

12 Oct 2018, 3:26 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Creating a Order Total Module

That documentation applies to order-total modules back to the Zen Cart 1.5.1 time-frame. Order-total modules don't have a payment method or a payment-module-code; that's for (er) payment modules.

12 Oct 2018, 4:59 PM
#7
kwright avatar

kwright

Zen Follower

Join Date:
Nov 2004
Posts:
355
Plugin Contributions:
0

Re: Creating a Order Total Module

lat9:

That documentation applies to order-total modules back to the Zen Cart 1.5.1 time-frame. Order-total modules don't have a payment method or a payment-module-code; that's for (er) payment modules.

lat9,

Good to know about the ZC versions covered by your docs! :smile:

That's what's confusing me when using gift vouchers, which is an order total module. The GV defines:

  define('PAYMENT_METHOD_GV', 'Gift Certificate/Coupon');
  define('PAYMENT_MODULE_GV', 'GV/DC');

are getting set here (notice it is using the GV as a payment method even though it is an order total module):

includes/classes/order.php ```
'payment_method' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_METHOD_GV : $this->info['payment_method']),
'payment_module_code' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_MODULE_GV : $this->info['payment_module_code']),


If I had to guess, since the Gift Certificate/Coupon (GV) is built into ZC, it is hard coded to be the default (as show in the above code) payment if no other payment (credit card, money order, etc) is used. Even though the Gift Certificate/Coupon is an order total module!

Maybe I need to modify the order.php class to look at my gift card order total module as a payment method similar to how it does this for the Gift Certificate/Coupon order total module?

Can I set $this->info['payment_module_code'] and $this->info['payment_method'] from an order total module? If so, where?

Experience is what you get when you don’t get what you want…

12 Oct 2018, 7:31 PM
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Creating a Order Total Module

The Gift Voucher (aka ot_gv) and Coupon (aka ot_coupon) order-totals are credit-class totals, so they're pseudo-payment modules.

13 Oct 2018, 2:06 AM
#9
kwright avatar

kwright

Zen Follower

Join Date:
Nov 2004
Posts:
355
Plugin Contributions:
0

Re: Creating a Order Total Module

lat9:

The Gift Voucher (aka ot_gv) and Coupon (aka ot_coupon) order-totals are credit-class totals, so they're pseudo-payment modules.

OK, that makes sense! So, I guess the gift card module I'm working on is as well.

Currently, when either a Gift Voucher or Coupon is used to complete an order, you see the Gift Certificate/Coupon and GV/DC labels show up under the Payment Shipping column (GV/DC) on the admin orders list and order details page under payment type (Gift Certificate/Coupon).

I would like for my gift card pseudo-payment module to show (GC) under the Payment Shipping column and (Gift Card) on the orders detail page as payment type when it is used to complete an order! :D

Experience is what you get when you don’t get what you want…