Exemplo n.º 1
0
 public function postProductAction()
 {
     $productService = new ProductService();
     $error_msg = \Lang::get('webshoppack::myProducts.product_invalid_action');
     $sucess_msg = '';
     if (\Input::has('product_action') && \Input::has('p_id')) {
         $p_id = \Input::get('p_id');
         $product_action = \Input::get('product_action');
         //Validate product id
         $user = \Config::get('webshoppack::logged_user_id');
         $logged_user_id = $user();
         $p_details = Product::whereRaw('id = ? AND product_status != ? AND product_user_id = ?', array($p_id, 'Deleted', $logged_user_id))->first();
         if (count($p_details) > 0) {
             switch ($product_action) {
                 # Delete product
                 case 'delete':
                     $error_msg = '';
                     # Product status is changed as Deleted
                     $status = $productService->deleteProduct($p_id, $p_details);
                     # Display delete success msg
                     if ($status) {
                         $sucess_msg = \Lang::get('webshoppack::myProducts.product_success_deleted');
                     } else {
                         $error_msg = \Lang::get('webshoppack::myProducts.product_error_on_action');
                     }
                     break;
                     # Set featured
                 # Set featured
                 case 'feature':
                     # Product featured status is changed
                     if ($p_details['product_status'] == 'Ok' && $p_details['is_user_featured_product'] == 'No') {
                         $error_msg = '';
                         $status = $productService->changeFeaturedStatus($p_id, $p_details, 'Yes');
                         # Display success msg
                         if ($status) {
                             $sucess_msg = \Lang::get('webshoppack::myProducts.product_featured_success_msg');
                         } else {
                             $error_msg = \Lang::get('webshoppack::myProducts.product_error_on_action');
                         }
                     }
                     break;
                     # Remove featured
                 # Remove featured
                 case 'unfeature':
                     # Product featured status is changed
                     if ($p_details['product_status'] == 'Ok' && $p_details['is_user_featured_product'] == 'Yes') {
                         $error_msg = '';
                         $status = $productService->changeFeaturedStatus($p_id, $p_details, 'No');
                         # Display success msg
                         if ($status) {
                             $sucess_msg = \Lang::get('webshoppack::myProducts.product_unfeatured_success_msg');
                         } else {
                             $error_msg = \Lang::get('webshoppack::myProducts.product_error_on_action');
                         }
                     }
                     break;
             }
         }
     }
     if ($sucess_msg != '') {
         return \Redirect::to(\Config::get('webshoppack::myProducts'))->with('success_message', $sucess_msg);
     }
     return \Redirect::to(\Config::get('webshoppack::myProducts'))->with('error_message', $error_msg);
 }