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
Quote:
$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:
Quote:
$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
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?:
Code:
$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 ?
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()
Code:
global $order;
$this->email_footer = MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER;
in includes/languages/english/modules/payment/po.php
Code:
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?
Quote:
$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:
Code:
Parse error: parse error, unexpected ','
---Diana
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.
Quote:
$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.
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 [FONT="Courier New"]$html_msg['PAYMENT_METHOD_FOOTER'] =[/FONT] 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
Quote:
$GLOBALS[$payment_class]->email_footer : $this->info['cc_type']
By the way, the following code works for line feeds in the footer:
Quote:
$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
Re: PhP question about a line of code in includes/classes/order.php
Quote:
Originally Posted by
dbrewster
in includes/modules/payment/po.php
in function po()
Code:
global $order;
$this->email_footer = MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER;
in includes/languages/english/modules/payment/po.php
Code:
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:
Code:
global $order;
$this->email_footer = MODULE_PAYMENT_PO_TEXT_EMAIL_FOOTER;
to this:
Code:
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:
Code:
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:
Code:
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:
Code:
$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:
Code:
$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'] );
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:
Quote:
$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
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?
Re: PhP question about a line of code in includes/classes/order.php
Quote:
Originally Posted by
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
Re: PhP question about a line of code in includes/classes/order.php