예제 #1
0
 /**
  * Removes an item from the shopping cart.
  *
  * @access   public
  * @param    string
  * @return   void
  */
 public function getRemove($item_id = null)
 {
     try {
         // Remove the item from the cart.
         //
         Shpcart::cart()->remove($item_id);
     } catch (Shpcart\CartInvalidItemRowIdException $e) {
         // Redirect back to the shopping cart page.
         //
         return Redirect::to('cart')->with('error', 'Invalid Item Row ID!');
     } catch (Shpcart\CartItemNotFoundException $e) {
         // Redirect back to the shopping cart page.
         //
         return Redirect::to('cart')->with('error', 'Item was not found in your shopping cart!');
     } catch (Shpcart\CartException $e) {
         // Redirect back to the home page.
         //
         return Redirect::to('cart')->with('error', 'An unexpected error occurred!');
     }
     // Redirect back to the shopping cart page.
     //
     return Redirect::to('cart')->with('success', 'The item was removed from the shopping cart.');
 }
예제 #2
0
 /**
  * Adds an item from the wishlist to the shopping cart.
  *
  * @access   public
  * @param    string
  * @return   Redirect
  */
 public function get_add_to_cart($rowid = null)
 {
     try {
         // Get the item information from the wishlist cart.
         //
         $item = Shpcart::wishlist()->item($rowid);
         // Make sure the quantity is 1, since we can add the item to the wishlist multiple times!
         //
         $item['qty'] = 1;
         // Add the item to the shopping cart.
         //
         Shpcart::cart()->insert($item);
     } catch (Shpcart\CartInvalidItemIdException $e) {
         // Redirect back to the wishlist page.
         //
         return Redirect::to('wishlist')->with('error', 'Invalid Item Row ID!');
     } catch (Shpcart\CartItemNotFoundException $e) {
         // Redirect back to the wishlist page.
         //
         return Redirect::to('wishlist')->with('error', 'Item was not found in your wishlist!');
     }
     // Redirect to the shopping cart page.
     //
     return Redirect::to('cart')->with('success', 'The item was added to your shopping cart!');
 }
예제 #3
0
 /**
  * Adds a product to the shopping cart or to the wishlist.
  *
  * @access   public
  * @return   Redirect
  */
 public function postIndex()
 {
     // 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.
             //
             Shpcart::wishlist()->insert($item);
         } catch (Shpcart\CartInvalidDataException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid data passed.');
         } catch (Shpcart\CartRequiredIndexException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', $e->getMessage());
         } catch (Shpcart\CartInvalidItemQuantityException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid item quantity.');
         } catch (Shpcart\CartInvalidItemRowIdException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid item row id.');
         } catch (Shpcart\CartInvalidItemNameException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid item name.');
         } catch (Shpcart\CartInvalidItemPriceException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid item price.');
         } catch (Shpcart\CartException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'An unexpected error occurred!');
         }
         // Redirect to the wishlist page.
         //
         return Redirect::to('wishlist')->with('success', 'The item was added to your wishlist!');
     } elseif ($action === 'add_to_cart') {
         try {
             // Add the item to the shopping cart.
             //
             Shpcart::cart()->insert($item);
         } catch (Shpcart\CartInvalidDataException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid data passed.');
         } catch (Shpcart\CartRequiredIndexException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', $e->getMessage());
         } catch (Shpcart\CartInvalidItemQuantityException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid item quantity.');
         } catch (Shpcart\CartInvalidItemRowIdException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid item row id.');
         } catch (Shpcart\CartInvalidItemNameException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid item name.');
         } catch (Shpcart\CartInvalidItemPriceException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'Invalid item price.');
         } catch (Shpcart\CartException $e) {
             // Redirect back to the home page.
             //
             return Redirect::to('shpcart')->with('error', 'An unexpected error occurred!');
         }
         // Redirect to the cart page.
         //
         return Redirect::to('cart')->with('success', 'The item was added to your shopping cart!');
     }
     // Invalid action, redirect to the home page.
     //
     return Redirect::to('shpcart');
 }