예제 #1
0
 /**
  * Creates a Cart object based on a DB row.
  *
  * @param array $row The DB row containing Category data.
  * @return \Soundify\Domain\ProductCart
  */
 protected function buildDomainObject($row)
 {
     $productCart = new ProductCart();
     $productCart->setCount($row['cart_count']);
     if (array_key_exists('cart_product', $row)) {
         // Find and set the associated product
         $productId = $row['cart_product'];
         $product = $this->productDAO->find($productId);
         $productCart->setProduct($product);
     }
     if (array_key_exists('cart_user', $row)) {
         // Find and set the associated user
         $userId = $row['cart_user'];
         $user = $this->userDAO->find($userId);
         $productCart->setUser($user);
     }
     return $productCart;
 }
예제 #2
0
        $user->setPassword($password);
        $app['dao.user']->save($user);
        $app['session']->getFlashBag()->add('success', 'Votre compte a bien été mis à jour.');
    }
    return $app['twig']->render('user_form.html.twig', array('categories' => $categories, 'title' => 'Modifier mon compte', 'userForm' => $userForm->createView(), 'number' => $number));
})->bind('myaccount');
// Cart page
$app->get('/cart', function () use($app) {
    $categories = $app['dao.category']->findAll();
    $number = $app['dao.cart']->getCountByUser($app['user']->getId());
    $cart = $app['dao.cart']->findAllByUser($app['user']->getId());
    return $app['twig']->render('cart.html.twig', array('categories' => $categories, 'cart' => $cart, 'number' => $number));
})->bind('cart');
// Add product in cart
$app->match('/cart/{id}/add', function ($id, Request $request) use($app) {
    $productCart = new ProductCart();
    $productCart->setUser($app['dao.user']->find($app['user']->getId()));
    $productCart->setProduct($app['dao.product']->find($id));
    $productCart->setCount(1);
    $app['dao.cart']->save($productCart);
    $app['session']->getFlashBag()->add('success', 'Le produit a bien été ajouté au panier.');
    // Redirect to product page
    return $app->redirect($app['url_generator']->generate('cart'));
})->bind('add_product_cart');
// Add product in cart
$app->match('/cart/{id}/edit', function ($id, Request $request) use($app) {
    $productCart = $app['dao.cart']->find($id, $app['user']->getId());
    $productCart->setCount($request->get('count'));
    $app['dao.cart']->save($productCart);
    $app['session']->getFlashBag()->add('success', 'La modificiation a bien été effectuée.');
    // Redirect to product page