Example #1
0
 public function calculate(\Moltin\Cart\Cart $cart)
 {
     // Variables
     $price = $cart->total();
     $weight = 0;
     // Loop and build weight
     foreach ($cart->contents() as $item) {
         $weight += (double) $item->weight;
     }
     // Get available methods
     return $this->getValid($price, $weight);
 }
 public static function generate($opcoes = array())
 {
     $cart = new Cart(new Session(), new Cookie());
     self::$token = $opcoes['token'];
     self::$email = $opcoes['email'];
     $sessao = self::setSession();
     $html = self::getScript();
     $html .= '<div class="checkout-pagseguro">';
     $html .= '<div class="page-header"><h5>Cartão de crédito</h5></div>';
     $html .= self::setForm();
     $html .= '</div>';
     $html .= self::getSession($sessao);
     $html .= self::getPaymentMethods($cart->total());
     return $html;
 }
 public function indexAction()
 {
     if (!$this->session->has("logado")) {
         $this->session->set('checkout', true);
         return $this->response->redirect('user/login');
     }
     $cart = new Cart(new Session(), new Cookie());
     $this->view->subtotal = number_format($cart->total(), 2, ',', '.');
     if ($this->session->has('frete')) {
         $this->view->frete = number_format($this->session->get('frete')['valor'], 2, ',', '.');
     }
     $this->view->endereco_form = new CheckOutForm();
     $this->view->total = number_format($cart->total() + $this->session->get('frete')['valor'], 2, ',', '.');
     $widgets = Widgets::find("tipo_id = 1 AND ativo = 1 AND valor_minimo <=  {$cart->total()} ");
     $this->view->widgets = array_map(array($this, 'setForms'), $widgets->toArray());
 }