Пример #1
0
 /**
  * Return human readable name of payment
  * @return string 
  * @param string
  */
 public function get_name($id)
 {
     $shipping = new Shipping_Model();
     return $shipping->get_name($id);
 }
Пример #2
0
 /**
  * Checkout 
  * @return void
  */
 public function checkout()
 {
     // Check user permission
     if (user::is_logged()) {
         if ($this->cart->count_cart() != 0) {
             $customer = new Customer_Model();
             if ($customer->has_info()) {
                 // check if customer profile is set (at least personal informations)
                 // Settings
                 $this->set_title(Kohana::lang('eshop.checkout'));
                 $this->add_breadcrumb(Kohana::lang('eshop.checkout'), '/cart/checkout');
                 // Other needed models, and data
                 $shipping = new Shipping_Model();
                 $payment = new Payment_Model();
                 $order = new Order_Model();
                 // Fetching values
                 $cart = $this->cart->get_cart();
                 $total = $this->cart->get_total();
                 $shipping_methods = $shipping->get_all();
                 $payment_methods = $payment->get_all();
                 $profile = $customer->get_profile(user::user_id());
                 // Default values
                 $form = array('delivery_name' => $profile['name'], 'delivery_street' => $profile['customer_street'], 'delivery_city' => $profile['customer_city'], 'delivery_postal_code' => $profile['customer_postal_code'], 'shipping' => $shipping->get_default(), 'payment' => $payment->get_default());
                 $errors = array();
                 // Validation
                 if ($_POST) {
                     $post = new Validation($_POST);
                     // Some filters
                     $post->pre_filter('trim', TRUE);
                     // Rules
                     $post->add_rules('delivery_name', 'required', 'length[0,255]');
                     $post->add_rules('delivery_street', 'required');
                     $post->add_rules('delivery_city', 'required');
                     $post->add_rules('delivery_postal_code', 'required', 'length[0,255]');
                     $post->add_rules('shipping', 'required');
                     $post->add_callbacks('shipping', array($shipping, '_exists'));
                     $post->add_rules('payment', 'required');
                     $post->add_callbacks('payment', array($payment, '_exists'));
                     if ($post->validate()) {
                         // Everything seems to be ok, insert to db
                         $id = $order->add_data($post, $profile, $cart);
                         $this->cart->empty_cart();
                         // Now payment
                         url::redirect('/cart/payment/' . $id);
                     } else {
                         // Repopulate form with error and original values
                         $form = arr::overwrite($form, $post->as_array());
                         $errors = $post->errors('cart_checkout_errors');
                     }
                 }
                 // View
                 $this->template->content = new View('cart_checkout');
                 $this->template->content->cart = $cart;
                 $this->template->content->total = $total;
                 $this->template->content->profile = $profile;
                 $this->template->content->shipping_methods = $shipping_methods;
                 $this->template->content->payment_methods = $payment_methods;
                 $this->template->content->form = $form;
                 $this->template->content->errors = $errors;
             } else {
                 url::redirect('/customer/profile/needed');
             }
         } else {
             url::redirect('/cart/show');
         }
     } else {
         url::redirect('/user/login/login');
     }
 }