Пример #1
0
 /**
  * Persists current basket to the database and starts checkout process.
  * @attribute[RequestParam('fname','string')]
  * @attribute[RequestParam('lname','string')]
  * @attribute[RequestParam('street','string')]
  * @attribute[RequestParam('zip','string')]
  * @attribute[RequestParam('city','string')]
  * @attribute[RequestParam('email','string')]
  * @attribute[RequestParam('provider','string')]
  */
 function StartCheckout($fname, $lname, $street, $zip, $city, $email, $provider)
 {
     log_debug("StartCheckout({$fname},{$lname},{$street},{$zip},{$city},{$email},{$provider})");
     if (!$fname || !$lname || !$street || !$zip || !$city || !$email) {
         redirect('Basket', 'Index', array('error' => 'Missing some data'));
     }
     // create a new customer. note that we do not check for existance or stuff.
     // this should be part of a real shop system!
     $cust = new SampleCustomer();
     $cust->fname = $fname;
     $cust->lname = $lname;
     $cust->street = $street;
     $cust->zip = $zip;
     $cust->city = $city;
     $cust->email = $email;
     $cust->price_total = 0;
     $cust->Save();
     // create a new order and assign the customer (from above)
     $order = new SampleShopOrder();
     $order->customer_id = $cust->id;
     $order->created = 'now()';
     $order->Save();
     // now loop thru the basket-items and add them to the order...
     $ds = model_datasource('system');
     foreach ($_SESSION['basket'] as $id => $amount) {
         //... by creating a dataset for each item
         $prod = $ds->Query('products')->eq('id', $id)->current();
         $item = new SampleShopOrderItem();
         $item->order_id = $order->id;
         $item->price = $prod->price;
         $item->amount = $amount;
         $item->title = $prod->title;
         $item->tagline = $prod->tagline;
         $item->body = $prod->body;
         $item->Save();
         $order->price_total += $amount * $prod->price;
     }
     // save the order again to persist the total amount
     $order->Save();
     $_SESSION['basket'] = array();
     // finally start the checkout process using the given payment provider
     log_debug("Handing control over to payment provider '{$provider}'");
     $p = new $provider();
     $p->StartCheckout($order, buildQuery('Basket', 'PostPayment'));
 }
 /**
  * Returns all items.
  * 
  * @return array A list of <IShopOrderItem> objects
  */
 public function ListItems()
 {
     return SampleShopOrderItem::Make()->eq('order_id', $this->id)->orderBy('id');
 }