Exemplo n.º 1
0
 public function cartAction()
 {
     $this->_helper->layout()->setLayout('redesign-2014');
     $this->view->cart_page = 1;
     //@todo replace iwth pagetype
     $this->view->pagetype = 'cart';
     $shop = new Model_Shop();
     $product = new Model_Products();
     $generic = new Model_Generic();
     $login_info = $this->isLoggedIn();
     $this->view->loginInfo = $login_info;
     $cookie_items = isset($_COOKIE['cart_items']) ? $_COOKIE['cart_items'] : array();
     $items = $shop->listCartItems($cookie_items);
     foreach ($items as $row) {
         $images[$row['ProductID']] = $product->DisplayProductImages($row['ProductID']);
     }
     if (isset($images)) {
         $this->view->images = $images;
     }
     $this->view->itemcount = count($items);
     $this->view->items = $items;
     if ($_POST) {
         // Empty the Basket
         if (isset($_POST['emptycart'])) {
             $shop->emptyCart();
             $this->_redirect('/cart/');
         }
         // Refresh Cart
         if (isset($_POST['refreshcart'])) {
             $products = new Model_Products();
             $updated_quantities = $products->CheckInventory($_POST['Quantity']);
             //validation for item quantities
             //$this->view->updated_quantities = $updated_quantities;
             $this->_redirect('/cart/');
             //this is done to refresh the cart items
         }
         // Checkout
         if (isset($_POST['checkout'])) {
             $this->view->showCheckOutForm = 1;
             //$this->view->updated_quantities = $_POST['Quantity'] ;
             if (isset($_POST['Quantity'])) {
                 $products = new Model_Products();
                 $products->CheckInventory($_POST['Quantity']);
                 $this->view->updated_quantities = $_POST['Quantity'];
             }
             // Member Checkout
             if ($this->isLoggedIn()) {
                 $user_details = $this->isLoggedIn();
                 $this->view->isLoggedIn = 1;
                 $this->view->User = $user_details;
                 $this->view->states = $shop->shippingTable();
                 $this->view->shipping_rate = $generic->getData("Shipping", "", "State asc");
                 if (isset($_POST['StoreCredits'])) {
                     $this->view->store_credits_to_use = $_POST['StoreCredits'];
                     if ($_POST['StoreCredits'] > $user_details['StoreCredits']) {
                         $this->view->StoreCreditError = 'Error!  You have entered more than your available store credits.  ';
                         $this->view->store_credits_to_use = 0;
                     }
                 }
                 // Member Transaction
                 if (isset($_POST['memcheckout'])) {
                     //echo '<pre>'; print_r($_POST);exit;
                     $state = isset($_POST['State']) ? $_POST['State'] : 0;
                     $shipping_details = $generic->getData("Shipping", "ID=" . $state);
                     //$shipping_fee = isset($shipping_details[0]['Fee']) ? $shipping_details[0]['Fee'] : 0;
                     //unset($_POST['ShippingFee']);
                     $data = $_POST;
                     $data['ShippingFee'] = $_POST['ShippingFee'];
                     $Transaction = new Model_Transaction();
                     $process = $Transaction->AddMemberTransaction($data, $user_details);
                     if ($process) {
                         $shop->emptyCart();
                         $trackingid = $process;
                         $this->_redirect('/thankyou/?esig1234=' . $user_details['SiteEmail'] . '&trackingID=' . $trackingid);
                     }
                 } else {
                     $this->render('cartuser');
                 }
             }
             // Create Transaction
             if (isset($_POST['excheckout'])) {
                 $Transaction = new Model_Transaction();
                 $process = $Transaction->Add($_POST);
                 if ($process) {
                     $shop->emptyCart();
                     //$this->view->trackingid = $_POST['excheckout'];
                     $this->view->trackingid = $process;
                     $this->view->email = $_POST['Email'];
                     $this->render('confirm');
                 }
                 //else {
                 //$this->render('confirm'); //@todo why is this here?
                 //}
             }
         }
     }
 }