Comma Seperated w Single Title

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sully210
Forum Newbie
Posts: 17
Joined: Sat Sep 11, 2010 4:09 pm

Comma Seperated w Single Title

Post by sully210 »

I had a programmer, a really bad one, modify a version of OpenCart to be an online ordering engine for restaurants. When the order comes in with options selected by the consumer, they take up way too much room on the 3.25" wide receipt tape that comes through. Here is the code for the email with the order:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $title; ?></title>
</head>
<body>
<table style="font-family: Arial, Verdana,sans-serif; font-size: 11px; color: #000000; width: 212px;">
  <tr>
    <td align="left"><a href="<?php echo $store_url; ?>" title="<?php echo $store_name; ?>"><img src="<?php echo $logo; ?>" alt="<?php echo $store_name; ?>" style="border: none;" ></a></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="left"><?php echo $text_greeting; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="left"><?php echo $text_order_id; ?> <span style="color: #000000; font-weight: bold;"><?php echo $order_id; ?></span><br />
      <?php echo $text_date_added; ?> <?php echo $date_added; ?><br >
      <?php echo $text_payment_method; ?> <strong><?php echo $payment_method; ?></strong><br />
      <?php echo $text_shipping_method; ?> <strong><?php echo $shipping_method; ?></strong><br />
	  <br />
	  <?php echo $text_email; ?> <strong><?php echo $customer_email; ?></strong><br />
	  <?php echo $text_telephone; ?> <strong><?php echo $customer_telephone; ?></strong><br />
	  <?php echo $text_ip; ?> <strong><?php echo $customer_ip; ?></strong>
	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table style="width: 100%; font-family: Arial, Verdana,sans-serif; font-size: 11px; color: #FFFFFF;">
        <tr style="text-transform: uppercase;">
          <th style="text-align: left; padding: 0.3em;"><?php echo $text_shipping_address; ?></th>
          <th style="text-align: left; padding: 0.3em;"><?php echo $text_payment_address; ?></th>
        </tr>
        <tr>
          <td style="padding: 0.3em; color: #000;"><?php echo $shipping_address; ?></td>
          <td style="padding: 0.3em; color: #000;"><?php echo $payment_address; ?></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="left"><table style="width: 100%; font-family: Arial, Verdana,sans-serif; font-size: 11px; color: #000000;">
        <tr style="background-color: #NONE;">
          <th align="left" style="padding: 0.3em; color: #000000;"><?php echo $column_product; ?></th>
          
          <th align="right" style="width: 15%; padding: 0.3em; color: #000000;"><?php echo $column_price; ?></th>
          <th align="right" style="width: 15%; padding: 0.3em; color: #000000;"><?php echo $column_quantity; ?></th>
          <th align="right" style="width: 20%; padding: 0.3em; color: #000000;"><?php echo $column_total; ?></th>
    </tr>
        
        <?php foreach ($products as $product) { ?>
        <tr style="background-color: #NONE;">
          <td align="left" style="font-weight: bold;"><?php echo $product['name']; ?></td>
          <td align="right"><?php echo $product['price']; ?></td>
          <td align="right"><?php echo $product['quantity']; ?></td>
          <td align="right"><?php echo $product['total']; ?></td>
        </tr>
        <?php foreach ($product['option'] as $option) { ?>
            <tr style="background-color: NONE;">
                <td style="font-weight: bold;"><?php echo $option['name']; ?>:</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr style="background-color: NONE;">
                <td><?php echo $option['value']; ?></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        <?php } ?>
                       
        <tr style="background-color: NONE;">
            <td align="left" style="font-weight: bold;"><?php echo $column_instructions; ?></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr> 
        <tr style="background-color: NONE;"><td colspan="4"><?php echo $product['instruction']; ?></td></tr>       
        <?php } ?>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <?php if ($comment) { ?>
          <tr style="background-color: NONE;">
            <td align="left" style="font-size: 11px; font-weight: bold; color: #000000;"><?php echo $text_comment; ?></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr style="background-color: NONE;">
            <td align="left" colspan="4"><?php echo $comment; ?></td>
          </tr>
        <?php } ?>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <?php if(isset($text_delivery)):?>  
         <tr style="background-color: NONE; color: #000000;">
            <td align="left" colspan="1" style="font-size: 11px; font-weight: bold;"><?php echo $text_delivery ?></td>
            <td colspan="3" align="right"><?php echo $delivery_date?>&nbsp;<?php echo $delivery_time?></td>
         </tr>          
         <?php endif?>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <?php foreach ($totals as $total) { ?>
        <tr>          
          <td style="background-color: NONE; font-weight: bold; padding: 0.3em; text-align: left;" colspan="3"><?php echo $total['title']; ?></td>
          <td style="background-color: NONE; padding: 0.3em; text-align: right;"><?php echo $total['text']; ?></td>
        </tr>
        <?php } ?>
      </table></td>
  </tr>
  
  <?php if ($customer_id) { ?>
  <tr>
    <td align="left" style="color: #000000; font-size: 11px; font-weight: bold;"><?php echo $text_invoice; ?></td>
  </tr>  
  <tr>
    <td align="left"><a href="<?php echo $invoice; ?>"><?php echo $invoice; ?></a></td>
  </tr>  
  <?php } ?>
  
  <tr>

    <td align="center" style="font-size: 10px; border-top: 1px solid #069;"><a href="<?php echo $store_url; ?>" style="color: #069; font-weight: bold; text-decoration: none;"><?php echo $store_name; ?></a> <?php echo $text_powered_by; ?> <a href="http://www.opencart.com" style="text-decoration: none; color: #374953;">OpenCart</a></td>

 </tr>
  
</table>
</body>
</html>
Here is the major part of the problem, let's say a customer orders a Turkey Sandwich, like the one in the attached image, they want the size to be 12", they want to add lettuce, Jalapenos and Broccoli, they want Swiss and Cheddar cheese, and they want to add Oil, Mayo and Yellow mustard. As you can see in the image there is a title for each option selected under each option title on a separate line. I need the order to come in and look like the order on the right of the image below with the:
Option Title: choice, choice, choice, etc.
Option Title: choice, choice, etc.
I would ideally like to have a line separate each menu item, and for the output to look like the Turkey with the option followed by: and comma separated values on the same line, however, if this is a problem in a table and the text won't wrap properly, I could certainly save a lot of space by doing it like the Wings with the option title: and then the option choices on the line below as long as they wrap if the text is too long for the printer width. but the critical part is getting the order to print correctly. Any help is greatly appreciated :D
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Comma Seperated w Single Title

Post by Christopher »

You refer to an image, but none is embedded in your post.
(#10850)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Comma Seperated w Single Title

Post by califdon »

What is your expectation? Are you going to try to modify the script yourself? If you are, what is your experience level? If you are totally a beginner, this may not be something you can expect to do, even with help.
sully210
Forum Newbie
Posts: 17
Joined: Sat Sep 11, 2010 4:09 pm

Re: Comma Seperated w Single Title

Post by sully210 »

Christopher wrote:You refer to an image, but none is embedded in your post.
Here is the image:[img]http:210usa.com/assets/images/mtg_order_both.png[/img]
sully210
Forum Newbie
Posts: 17
Joined: Sat Sep 11, 2010 4:09 pm

Re: Comma Seperated w Single Title

Post by sully210 »

califdon wrote:What is your expectation? Are you going to try to modify the script yourself? If you are, what is your experience level? If you are totally a beginner, this may not be something you can expect to do, even with help.
I am indeed a complete novice, newbie, idiot. So please tell me where to go to get someone who can do this, I thought it was quite simple to fix, apparently I am mistaken.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Comma Seperated w Single Title

Post by Eric! »

I would ideally like to have a line separate each menu item, and for the output to look like the Turkey with the option followed by: and comma separated values on the same line, however, if this is a problem in a table and the text won't wrap properly, I could certainly save a lot of space by doing it like the Wings with the option title: and then the option choices on the line below as long as they wrap if the text is too long for the printer width. but the critical part is getting the order to print correctly.
Looking at your image with the link:

Image

It's hard to see exactly what you are after. This image is a summary of three items being ordered and it sounds like you really only want the short summary version on the right (for the wings, turkey and burger items). Is that correct? Would disabling the detailed summary which is generating the line-by-line text on the left fix your problem?

Or does this image represent what you're getting from the code on the left, vs. what you want on the right?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Comma Seperated w Single Title

Post by califdon »

sully210 wrote:I am indeed a complete novice, newbie, idiot. So please tell me where to go to get someone who can do this, I thought it was quite simple to fix, apparently I am mistaken.
I'm sure you're not an idiot, it's no sin to be new to any technical skill--we all were, at some point. The point is, though, that what you described (if I understand just exactly what that is) is surely not simple. Maybe others will disagree with me, but my take is that it's a fairly substantial task for even an experienced web developer. So if your main objective is to get the application working, I would recommend that you seek a professional web developer and pay him or her to do it for you. Yes, it will cost money, but you should be able to have the results you want in a short time. If, on the other hand, you are more interested in learning web development skills than in getting the results, we might be able to guide you along the way, but it could take a considerable amount of time and a lot of frustration for you--but you would be learning a skill to use on other projects. So, in my opinion, it depends on what your objectives are.

If you want to hire someone to do this for you, you could post your need on our Job Hunt or Volunteer Work forums (at the top of this page, click on Board Index and then scroll down to find those forums) or you could seek a local web developer in your area.
sully210
Forum Newbie
Posts: 17
Joined: Sat Sep 11, 2010 4:09 pm

Re: Comma Seperated w Single Title

Post by sully210 »

Eric, the image on the left is what I get now, the image on the right is what I want it to look like. Sorry for the confusion :banghead:
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Comma Seperated w Single Title

Post by Eric! »

Looking at your code, you'll need to rearrange your template and combine elements into single strings. It is very basic, but for us to fix your format requires a little guessing when all we can see is a template. And the philosophy around here is not to write code for other people but to help them write it for themselves. You'll need to learn about loops, strings and arrays for starters.

But if you really don't want to take on the beginner programmer role I suggest you follow califdon's suggestions to find someone to help do the job for you. This shouldn't be hard to do, even for the person who originally wrote it. Did the programmer not have an example of your desired output to work from?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Comma Seperated w Single Title

Post by Christopher »

sully210 wrote:
Christopher wrote:You refer to an image, but none is embedded in your post.
Here is the image:Image
(#10850)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Comma Seperated w Single Title

Post by Christopher »

Easiest might be to loop through your $product['option'] array and assign the results to a new array that will be displayed:

Code: Select all

        <?php
 $product_options = array();   // initialize first
 foreach ($product['option'] as $option) {
      $product_options[$option['name']][] = $option['value'];
 }
 foreach ($product_options as $option_name => $option_values) { ?>
            <tr style="background-color: NONE;">
                <td style="font-weight: bold;"><?php echo $option_name; ?>:</td>
                <td><?php echo implode(', ', $option_values); ?></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        <?php } ?>
(#10850)
Post Reply