From 2a1651ea420ee0aeca2eb9ad0a3a55510c1676e6 Mon Sep 17 00:00:00 2001 From: arzynik Date: Mon, 17 Sep 2012 20:55:53 -0400 Subject: [PATCH 1/2] fixes #231 --- .../default/crunchbutton/api/order/index.php | 56 +++++++++++++------ include/library/Crunchbutton/Order.php | 56 +++++++++++++++++-- 2 files changed, 90 insertions(+), 22 deletions(-) diff --git a/include/controllers/default/crunchbutton/api/order/index.php b/include/controllers/default/crunchbutton/api/order/index.php index 2a8bb1e6b..eb57559df 100644 --- a/include/controllers/default/crunchbutton/api/order/index.php +++ b/include/controllers/default/crunchbutton/api/order/index.php @@ -18,42 +18,66 @@ class Controller_api_order extends Crunchbutton_Controller_Rest { case 'say': header('Content-type: text/xml'); + $message = 'Press 1 to hear the order. Otherwise we will call back in 2 minutes.' + .''; + echo ''."\n" .'' .''.c::config()->twilio->greeting.' with an order for '.($order->delivery_type == 'delivery' ? 'delivery' : 'pickup').'.' - .'' - .'Press 1 to hear the order. Otherwise we will call back in 2 minutes.' - .'' - .'Press 1 to hear the order. Otherwise we will call back in 2 minutes.' - .'' - .'Press 1 to hear the order. Otherwise we will call back in 2 minutes.' - .'' - .''; - exit; + .''; + + for ($x = 0; $x <= 5; $x++) { + echo $message; + } + echo ''; + exit; + break; case 'sayorder': + header('Content-type: text/xml'); + echo ''."\n" + .'' + .'Thank you. At the end of the message, you must confirm the order.' + .'' + .''.$order->message('phone').'' + .'' + .'Press 1 to confirm the order. Press 2 repeat the order. Press 3 to spell out the street name.' + .'' + .''; + exit; + break; + + case 'sayorderonly': header('Content-type: text/xml'); echo ''."\n"; switch ($this->request()['Digits']) { - case '1': + case '2': default: - echo '' - .'Thank you. At the end of the message, you must confirm the order.' - .'' + echo '' .''.$order->message('phone').'' .'' - .'Press 1 to repeat this message, or press 2 to confirm this order.'; + .'Press 1 to confirm the order. Press 2 repeat the order. Press 3 to spell out the street name.' + .''; break; - case '2': + + case '1': echo 'Thank you. This order has been confirmed.'; $order->confirmed = 1; $order->save(); break; + case '3': + echo '' + .''.$order->streetName().'' + .'' + .'Press 1 to confirm the order. Press 2 repeat the order. Press 3 to spell out the street name.' + .''; + break; + } - echo ''; + echo ''; exit; break; diff --git a/include/library/Crunchbutton/Order.php b/include/library/Crunchbutton/Order.php index 67b5ac63c..2fd1bc6d8 100644 --- a/include/library/Crunchbutton/Order.php +++ b/include/library/Crunchbutton/Order.php @@ -318,7 +318,6 @@ class Crunchbutton_Order extends Cana_Table { $type = 'twilio'; - foreach ($message as $msg) { switch ($type) { case 'googlevoice': @@ -371,7 +370,6 @@ class Crunchbutton_Order extends Cana_Table { case 'phone': $with = 'with'; break; - } if ($type == 'phone') { @@ -380,10 +378,18 @@ class Crunchbutton_Order extends Cana_Table { } else { $pFind = $pReplace = []; } + + $i = 1; + $d = new DateTime('01-01-2000'); foreach ($this->dishes() as $dish) { - $foodItem = "\n- ".preg_replace($pFind, $pReplace, $dish->dish()->name); + if ($type == 'phone') { + $prefix = $d->format('jS').' item: '; + $d->modify('+1 day'); + } + + $foodItem = "\n- ".$prefix.preg_replace($pFind, $pReplace, $dish->dish()->name); if ($dish->options()->count()) { $foodItem .= ' '.$with.' '; @@ -399,12 +405,34 @@ class Crunchbutton_Order extends Cana_Table { } else { $foodItem .= '. '; } + + if ($type == 'phone') { + $foodItem .= ']]>address); + $name = preg_replace('/^[0-9]+ (.*)$/i','\\1',$name[0]); + $spaceName = ''; + + for ($x=0; $xorderMessage($type); @@ -435,22 +463,38 @@ class Crunchbutton_Order extends Cana_Table { for ($x=0; $xname.'.]]>Phone number. '.$spacedPhones.'.Customer paying by '.$this->pay_type.'.'; + $msg = 'name.'.]]>Phone number. '.$spacedPhones.'.'; + if ($this->delivery_type == 'delivery') { - $msg .= 'Deliver to '.$this->address; + $msg .= 'Deliver to '.$this->phoneticStreet($this->address); } + + if ($this->pay_type == 'card') { + $msg .= 'This order has been prepaid by credit card.'; + } else { + $msg .= 'The customer will pay for this order with cash.'; + } + if ($this->notes) { $msg .= 'Customer Notes. '.$this->notes; } if ($this->pay_type == 'card' && $this->tip) { - $msg .= 'A tip of '.$this->tip().' dollars has been included.'; + $msg .= 'A tip of '.$this->phoeneticNumber($this->tip()).' has been charged to the customer\'s credit card.'; } + + $msg .= 'Order total: '.$this->phoeneticNumber($this->final_price); + break; } return $msg; } + public function phoeneticNumber($num) { + $num = explode('.',$num); + return $num[0].' dollar'.($num[0] == 1 ? '' : 's').' and '.$num[1].' cent'.($num[1] == '1' ? '' : 's'); + } + public function exports() { $out = $this->properties(); unset($out['id_user']);