Exemple #1
0
 /**
  * @throw Markzero\Http\Exception\ResourceNotFoundException
  *        Markzero\Validation\Exception\ValidationException
  */
 public static function update($id, ParameterBag $params)
 {
     $em = self::getEntityManager();
     $product = Product::find($id);
     self::validateParams($params, $product);
     if ($product === null) {
         throw new ResourceNotFoundException();
     }
     $product->name = $params->get('product[name]', '', true);
     $product->short_desc = $params->get('product[short_desc]', '', true);
     $product->description = $params->get('product[description]', '', true);
     $product->price = floatval($params->get('product[price]', 0, true));
     $product->updated_at = new \DateTime("now");
     $isbn10 = $params->get('product[isbn_10]', null, true);
     $isbn13 = $params->get('product[isbn_13]', null, true);
     $issn = $params->get('product[issn]', null, true);
     $product->updateBarcode(Barcode::ISBN_10, $isbn10);
     $product->updateBarcode(Barcode::ISBN_13, $isbn13);
     $product->updateBarcode(Barcode::ISSN, $issn);
     $catid = $params->get('product[category_id]', null, true);
     $cat = Category::find($catid);
     if ($cat === null) {
         throw new ResourceNotFoundException('Category cannot be found');
     }
     $product->category = $cat;
     $em->persist($product);
     $em->flush();
     return $product;
 }
 public function uploadPicture($id)
 {
     $this->respondTo('html', function () use($id) {
         $response = $this->getResponse();
         $flash = $this->getSession()->getFlashBag();
         $files_bag = $this->getRequest()->getFiles();
         $picfile = $files_bag->get('picture');
         if ($picfile == null) {
             $flash->add('errors', 'no file uploaded');
             $response->redirect('App\\Admin\\Controllers\\ProductController', 'editPictures', [$id]);
             return;
         }
         $product = Product::find($id);
         if ($product == null) {
             $flash->add('errors', "Product #{$id} cannot be found");
             $response->redirect('App\\Admin\\Controllers\\ProductController', 'index');
             return;
         }
         Image::saveUploadedImage($product, $picfile);
         $response->redirect('App\\Admin\\Controllers\\ProductController', 'editPictures', [$id]);
     });
 }