Zen Cart Logo
Forums / Managing Customers and Orders / PhP question about a line of code in includes/classes/order.php

PhP question about a line of code in includes/classes/order.php

Locked

Views: 7,789

Results 1 to 13 of 13
This thread is locked. New replies are disabled.
4 Jan 2007, 9:03 PM
#1
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

PhP question about a line of code in includes/classes/order.php

Howdy.

I really wasn't sure where to post this question. Perhaps a custom code questions forum is needed, for snippets like this? I reckon this is a code issue dealing with orders, so here goes.

I want to reconcile a line that controls the HTML display of our custom purchase order module, with the new code that displays credit card type. I didn't get it to work in 1.3.6 and I still haven't gotten it to work in 1.3.7.

Here's your code in includes/classes/order.php approx line 956

$html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']] && $GLOBALS[$payment_class]->email_footer != '') ? $GLOBALS[$payment_class]->email_footer : $this->info['cc_type'] );

Here's my code for displaying purchase order info in emails, invoices, browser, and packing slips. This works fine, but doesn't show credit card type:

$html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']]) ? sprintf($GLOBALS[$payment_class]->email_footer, $this->info['account_name'], $this->info['account_number'], $this->info['po_number']) : ' ');

How to mush these together? Each works on its own. I've tried a few variations in webmonkey manner, but I only get parsing errors.

Bountiful thanks in advance to PHP code-knowledgeable persons.

---Diana

4 Jan 2007, 9:19 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: PhP question about a line of code in includes/classes/order.php

If you set a $this->email_footer variable within your custom module to contain the required information, then the order class will display it automatically without having to be changed.
Something like this might work?:

$this->email_footer = sprintf('Account: %s (%s) -- P/O number: %s', $this->info['account_name'], $this->info['account_number'], $this->info['po_number']);
```Maybe your $this->info references might need to change to $order->info ?
5 Jan 2007, 2:25 PM
#3
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

Re: PhP question about a line of code in includes/classes/order.php

Hi, Dr. Byte!

This is correctly configured in the PO module, I think.

in includes/modules/payment/po.php
in function po()

global $order;
$this->email_footer = MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER;

in includes/languages/english/modules/payment/po.php

  define('MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER', 'with the following information:<br>
  Account name:  %s<br>
  Account number:  %s<br>
  PO Number:  %s');

If I use the 1.3.7 includes/classes/order.php email footer line, I don't get the purchase order detail in the email, although it does display nicely on screen, in invoices and packing slips. But not in email, where we need it because our order fulfillment team uses the email order notification to collect detail.

... warning, webmonkey code to follow ...

will this work?

$html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']] && $GLOBALS[$payment_class]->email_footer != '') ? $GLOBALS[$payment_class]->email_footer : $this->info['cc_type'], $this->info['account_name'], $this->info['account_number'], $this->info['po_number'] );

feh, it generated this error:

Parse error: parse error, unexpected ','

---Diana

5 Jan 2007, 2:50 PM
#4
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

Re: PhP question about a line of code in includes/classes/order.php

Progress to report!

This gets the PO info into the email, but does NOT make a line feed between the data, it strings it together, which makes it hard to decipher.

$html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']] && $GLOBALS[$payment_class]->email_footer != '') ? $GLOBALS[$payment_class]->email_footer : $this->info['cc_type'] . $this->info['account_name'] . "\n\n" . $this->info['account_number'] . "\n\n" . $this->info['po_number'] );

I'm puzzled why . "\n\n" . isn't doing the job.

5 Jan 2007, 3:20 PM
#5
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

Re: PhP question about a line of code in includes/classes/order.php

after some more testing, I think I need sprintf for the PO email footer so that it is correctly formatted, with the right surrounding text strings defined in includes/languages/english/modules/payment/po.php. The email footer is supposed to look like this, and it does, using sprintf:

Payment Method
Purchase Order
with the following information:
Account name: Blah blah Charter School
Account number: Pied02
PO Number: 188945

The problem: if I use sprintf I don't see how I can get the credit card type to display. I can't make two $html_msg['PAYMENT_METHOD_FOOTER'] = statements in sequence, the second one overwrites the first.

Actually this is a very minor problem, and I'm hoping there is a simple coding solution. If I have to choose, I won't use the 1.3.7 email payment info footer.

Perhaps the question can be boiled down to: is there a way to string sprintf statements with this

$GLOBALS[$payment_class]->email_footer : $this->info['cc_type']

By the way, the following code works for line feeds in the footer:

$html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']] && $GLOBALS[$payment_class]->email_footer != '') ? $GLOBALS[$payment_class]->email_footer : $this->info['cc_type'] . $this->info['account_name'] . "<br>" . $this->info['account_number'] . "<br>" . $this->info['po_number'] );

Output looks like this:
Payment Method
Purchase Order
TEST name
TEST number
TEST PO #

it's the content without the formatting wrapper which only sprintf generates.

---Diana

7 Jan 2007, 12:43 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: PhP question about a line of code in includes/classes/order.php

dbrewster:

in includes/modules/payment/po.php
in function po()

global $order;
$this->email_footer = MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER;

> 
> in includes/languages/english/modules/payment/po.php
> 
> ```
  define('MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER', 'with the following information:<br>
  Account name:  %s<br>
  Account number:  %s<br>
  PO Number:  %s');

Why not change the po.php code from this:

global $order;
$this->email_footer = MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER;
```to this:

global $order;
$this->email_footer = sprintf(MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER, $this->info['account_name'], $this->info['account_number'] , $this->info['po_number']);


and this:```
  define('MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER', 'with the following information:<br>
  Account name:  %s<br>
  Account number:  %s<br>
  PO Number:  %s');

to this:```
define('MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER', 'with the following information:' . "\n" . '
Account name:  %s' . "\n" . '
Account number:  %s' . "\n" . '
PO Number:  %s');



And then just fix the order class file to convert line-breaks to BR tags, like this:
$html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']] && $GLOBALS[$payment_class]->email_footer != '') ? $GLOBALS[$payment_class]->email_footer : $this->info['cc_type'] );

becomes:
$html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']] && $GLOBALS[$payment_class]->email_footer != '') ? nl2br($GLOBALS[$payment_class]->email_footer) : $this->info['cc_type'] );

8 Jan 2007, 10:05 PM
#7
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

Re: PhP question about a line of code in includes/classes/order.php

Dr. Byte:

Thank you so much for your code suggestion.

I have tried it out, but it does not print a detailed footer in the email. All I get is
**
Payment Method**
Purchase Order

You're welcome to try it out on my test site, the PO pages and order.php page have been edited there according to your post, go ahead and place a purchase order and see the resulting email:

http://register.coreknowledge.org

(for comparison feel free to place a purchase order on my real website, that is set up the way I originally did it, that site is still 1.3.6, just please use the order motive field to indicate that this is a test, and comment that you are testing, so our customer care people don't get confused.)

Invoice and packing slip still show the detail.

It seems to me that only using sprintf and $this->info['account_name'], $this->info['account_number'], $this->info['po_number'] in order.php brings out the labels that are formatted in the language defines file.

Note that the following does not work, either, but at least it does not generate an error:

$html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']] && $GLOBALS[$payment_class]->email_footer != '') ? nl2br($GLOBALS[$payment_class]->email_footer, $this->info['account_name'], $this->info['account_number'], $this->info['po_number']) : $this->info['cc_type'] );
---Diana

9 Jan 2007, 1:57 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: PhP question about a line of code in includes/classes/order.php

Where did you get your PO module from? Is it part of the super-orders contrib or otherwise?

9 Jan 2007, 3:47 PM
#9
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

Re: PhP question about a line of code in includes/classes/order.php

DrByte:

Where did you get your PO module from? Is it part of the super-orders contrib or otherwise?

As I recall, I got it from Merlin. It's a hand-me-down from OSCommerce. I looked at Superorders, but it was a lot more code than I wanted to maintain, I just wanted a simple purchase order payment module. Although nice order reporting features would be nice, it wasn't a requirement for me, and I have enough extensions to maintain as it is.

The PO module has received some updates along the way, from Absolute, as I began August 2005 with ZC 1.2.6.

So, right now, if I maintain that orders.php line the way it was, it does what I want, but I see a divergence of code for the email footer in 1.3.7 and I wanted to stay current.

It has to print out the order field detail with the labels for the fields in the email footer, for me to keep our customer service department happy.

IMO ZC needs its own purchase order payment module.

If you'd like to have a look at the PO module as it currently stands, send me a PM and I can send it to you in a zip. Y'all could include it in a ZC update!

---Diana

22 Jan 2007, 7:00 PM
#11
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

Re: PhP question about a line of code in includes/classes/order.php

Dr. Byte,

Thanks for the update!

Well, there is progress at least. The email now displays the formatted labels but it isn't passing the values.

Payment Method
Purchase Order
with the following information:

Account name: %s

Account number: %s

PO Number: %s

just %s no values.

This is using includes/modules/payment/po.php
class constructor

$this->email_footer = MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER;

per your suggestion above.

If I use the old class constructor, I get blanks for values.

$this->email_footer = sprintf(MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER, 
$this->info['account_name'], $this->info['account_number'], 
$this->info['po_number']);

MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER is defined thus, in includes/languages/english/modules/payment/po.php:

  define('MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER', 'with the following 
information:' . "\n" . '
  Account name:  %s' . "\n" . '
  Account number:  %s' . "\n" . '
  PO Number:  %s');

Any suggestions? We're on the brink of success!

---Diana

22 Jan 2007, 7:09 PM
#12
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

Re: PhP question about a line of code in includes/classes/order.php

error in what I posted... please delete previous post.

Dr. Byte,

Thanks for the update!

Well, there is progress at least. The email now displays the formatted labels but it isn't passing the values.

Payment Method
Purchase Order
with the following information:

Account name:

Account number:

PO Number:

just labels, no values.

This is using includes/modules/payment/po.php
class constructor

$this->email_footer = sprintf(MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER, 
$this->info['account_name'], $this->info['account_number'], 
$this->info['po_number']);

per your suggestion above.

If I use the old class constructor, I get %s for values.

$this->email_footer = MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER;

MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER is defined thus, in includes/languages/english/modules/payment/po.php:

  define('MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER', 'with the following 
information:' . "\n" . '
  Account name:  %s' . "\n" . '
  Account number:  %s' . "\n" . '
  PO Number:  %s');

Any suggestions? We're on the brink of success!

---Diana

1 Feb 2007, 2:30 PM
#13
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

Re: PhP question about a line of code in includes/classes/order.php

hmm, I never look at the text versions of the order confirmation emails, but it does appear that the method I have been using does not work in text emails. The order information displays as

Payment Method

Purchase Order

with the following information:
Account name: %s
Account number: %s
PO Number: %s

I'll probably be paying for custom code again to get this problem sorted out.

I sure wish ZC had a purchase order payment module built in.

---Diana