Part of the EllisLab Network
   
 
Building my first CodeIgniter App—need advice on XML, etc.
Posted: 23 May 2009 09:41 PM   [ Ignore ]  
Summer Student
Total Posts:  3
Joined  05-23-2009

Hello,

I am building basically this: You go to a URL, there’s a menu for a Mexican restaurant around the corner. You check off what food you want and as you check the boxes your “shopping cart” fills up in the lower right hand corner with a running total underneath it. When you’re done, you click ‘order’ and it sends a fax to the machine by the cash register with the order.

OK so my very general question is: What’s the best way to do this?

Here’s the more specific question in depth:

Initially I started using jCart for this project. This is very close to what I’m trying to do. One slight difference is that there are going to be extras (i.e. sour cream, avocado) to add to an item so I’ll have subitems. Also I prefer togglable check boxes to submit buttons.

My plan now is to put the menu in an XML file (which I’ve done) so it’s easy to edit items and pricing. The event handling will be done with jQuery (which I have started). I’ve been looking around and I can’t find a lot about rendering XML in CodeIgniter. I also noticed that jCart appears to submit a form every time you add an item, and I don’t see why everything prior to checkout can’t be done strictly with javascript. I don’t even know where to start with the fax part but I suppose I’ll cross that bridge when I get there.

So my main questions are: 1) Am I going about this the right way? 2) Is there a decent resource for using simple XML with CodeIgniter? 3) Do you know of anyone who’s already built a plugin or plugins to help with what I’m trying to do, or any element of it (i.e. real-time total calculator w. tax)? 4) Any tips on the fax thing? I’m thinking just sending the order through smtp through an email-to-fax program.

Thanks a million if you can point me in the right direction with regards to any of these questions.

Profile
 
 
Posted: 24 May 2009 02:56 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  663
Joined  08-26-2006

For XML You need to consider 2 things :

1. in PHP with short tags enabled the introducing ‘<?xml ’ declaration does not work. You can use

echo '<?xml'

2. Some browsers require the appropriate content header

header("Content-Type: text/xml"); 

I use :

// set header
$this->output->set_header("Content-Type: text/xml");
        
// set xml doc type
$this->output->set_output('<?xml version="1.0" encoding="utf-8"?>' ."\n"); 


I don’t know jCart.

For ‘email-to-fax program’ : You’ll need a fax gateway service, that surely exists.

 Signature 

Die Wirklichkeit ist das, was übrig bleibt, wenn man aufgehört hat, daran zu glauben.

Profile
 
 
Posted: 24 May 2009 03:12 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  3
Joined  05-23-2009

OK well, here’s what I have come up with since posting:

This blog shows how to parse xml using ‘CodeIgniter’s SimpleXML library’. Now this library doesn’t appear to be in CodeIgniter at all but if you click ‘view plain’ you can grab the code and put it in /libraries (note: there is one small revision that needs to be made to the code and you can find this correction in the comments. Also, the view that’s displayed is missing tr tags in the thead. Otherwise this should work correctly if you follow the directions.)

I could still use help if there are any shortcuts to developing my shopping cart that I mentioned.

Profile
 
 
Posted: 25 May 2009 09:38 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  3
Joined  05-23-2009

Alright, I have my menu set up just right in an XML document. I am parsing it correctly in my controller. I’ve posted the code below just for reference.

There’s going to be more markup than this, though, including a lot of redundant markup for stylized checkboxes and things like this. I can’t figure out how I would move the markup }(i.e. uls, h3s etc) into a view because of all the foreach loops and conditional statements.

I also wonder if a model is necessary at all for this project. Wouldn’t the parsing and the calculating all be done in the controller?

 

foreach($sxe->food as $food{

      
echo '<div class="jcart" id="'.$food->name.'"><h3>'.$food->name;
        
//display big base price
        
if ($food->basePrice){
          
echo '<big>'.$food->basePrice.'</big>';
        
}
        
echo '</h3>';

      
//start subitems
      
echo '<ul>';

      foreach(
$food->item as $item{      
        
echo '<li>';
        echo 
'<div class="en">'.$item->itemName.'</div><div class="es">'.$item->articuloNombre.'</div> ';
        if(
intval ($item->price) != intval ($food->basePrice)) {
          
echo '<strong>'.$item->price.'</strong>';
        
}
        
if ($item->extras && $item->extras->attributes()->lettuceTomato){
          
echo '
          <ul>
            <li>Lettuce and tomato</li>
            <li>Onion and Cilantro</li>
          </ul>'
;
        
}
        
if ($item->extras){
          
echo '<ul>';

          if (
$item->extras->attributes()->avocado && $item->extras->attributes()->avocado == "yes"){
            
echo '<li>Avocado <strong>'.$sxe->avocadoPrice.'</strong></li>';
          
}
          
if ($item->extras->attributes()->cheesecream && $item->extras->attributes()->cheesecream == "yes"){
            
echo '<li>Cheese <strong>'.$sxe->cheesePrice.'</strong></li><li>Sour Cream <strong>'.$sxe->creamPrice.'</strong></li>';
          
}
          
if ($item->extras->attributes()->tacodinner){
            
echo '<li>Taco Dinner <strong>'.$sxe->tacoDinnerPrice.'</strong></li>';
          
}
          
echo '</ul>';
        
}
      
echo '</li>';
    
}

    
echo '</ul>';
    echo 
'</div>';
  
}

  
echo $sxe;
  
}
Profile