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;
 }
 /**
  * Migrates products in a category to another
  */
 function migrate($id)
 {
     $this->respondTo('html', function () use($id) {
         $response = $this->getResponse();
         $flash = $this->getSession()->getFlashBag();
         $params = $this->getRequest()->getParams();
         $alt_cat_id = $params->get('alt_category_id');
         $cat = Category::find($id);
         $alt_cat = Category::find($alt_cat_id);
         if ($cat == null || $alt_cat == null) {
             $flash->add('errors', "Category #{$id} or #{$cat_id} not found");
             $response->redirect('App\\Admin\\Controllers\\CategoryController', 'delete', [$id]);
             return;
         }
         $cat->migrateTo($alt_cat);
         $response->redirect('App\\Admin\\Controllers\\CategoryController', 'delete', [$id]);
     });
 }