Example #1
0
 /**
  * Show a list of the products on the page.
  *
  * @access   public
  * @return   View
  */
 public function get_index()
 {
     // Get the products.
     //
     $products = Products::all();
     // Show the page.
     //
     return View::make('cartify::home')->with('products', $products);
 }
Example #2
0
 /**
  * Adds a product to the shopping cart or to the wishlist.
  *
  * @access   public
  * @return   Redirect
  */
 public function post_index()
 {
     // Get the action, this basically tells what button was pressed.
     //
     $action = Input::get('action');
     // Get the static list of products.
     //
     $products = Products::all();
     // Retrieve some data.
     //
     $item_id = Input::get('item_id');
     $qty = Input::get('qty');
     $options = Input::get('options', array());
     // Get the product information.
     //
     $info = $products[$item_id];
     // Populate a proper item array.
     //
     $item = array('id' => $info['id'], 'qty' => $qty, 'price' => $info['price'], 'name' => $info['name'], 'image' => $info['image'], 'options' => $options);
     // Do we want to add the item to the wishlist?
     //
     if ($action === 'add_to_wishlist') {
         try {
             // Add the item to the wishlist.
             //
             Cartify::wishlist()->insert($item);
         } catch (Cartify\CartInvalidDataException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid data passed.');
         } catch (Cartify\CartRequiredIndexException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', $e->getMessage());
         } catch (Cartify\CartInvalidItemQuantityException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid item quantity.');
         } catch (Cartify\CartInvalidItemRowIdException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid item row id.');
         } catch (Cartify\CartInvalidItemNameException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid item name.');
         } catch (Cartify\CartInvalidItemPriceException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid item price.');
         } catch (Cartify\CartException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'An unexpected error occurred!');
         }
         // Redirect to the wishlist page.
         //
         return Redirect::to('cartify/wishlist')->with('success', 'The item was added to your wishlist!');
     } elseif ($action === 'add_to_cart') {
         try {
             // Add the item to the shopping cart.
             //
             Cartify::cart()->insert($item);
         } catch (Cartify\CartInvalidDataException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid data passed.');
         } catch (Cartify\CartRequiredIndexException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', $e->getMessage());
         } catch (Cartify\CartInvalidItemQuantityException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid item quantity.');
         } catch (Cartify\CartInvalidItemRowIdException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid item row id.');
         } catch (Cartify\CartInvalidItemNameException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid item name.');
         } catch (Cartify\CartInvalidItemPriceException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'Invalid item price.');
         } catch (Cartify\CartException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('cartify')->with('error', 'An unexpected error occurred!');
         }
         // Redirect to the cart page.
         //
         return Redirect::to('cartify/cart')->with('success', 'The item was added to your shopping cart!');
     }
     // Invalid action, redirect to the home page.
     //
     return Redirect::to('cartify');
 }