I'm new to Symfony2 and PHP but I'm learning my ways.
I created a simple shopping cart. After they click 'Buy' I want the items in the cart to be cleared and effectively render that cart useless because a field would change from false to true in my database (which shows what carts are active and which ones aren't).
How come my code isn't doing anything I want it to do? The cart remains in-tact after I click 'Buy' (items are still in there) and in my DB my field doesn't change.
I would really appreciate some help with this, thanks.
/**
* Displays the products bought from products 'added to cart'
*
* @Route("/bought", name="product_bought")
* @Method("GET")
* @Template()
*/
public function boughtAction(Request $request) {
$em = $this->getDoctrine()->getManager();
$user = $this->getUser();
$cart = $em->getRepository('ShopBundle:UserCart')->findOneBy(['user' => $this->getUser()]);
$totalCostOfAllProducts = 0;
$cart->getSubmitted(); //it's false
var_dump($cart->getSubmitted());
$cart->setSubmitted(true);
$sub = $cart->getSubmitted(); //it's true
if ($sub == true) {
$cart = null;
}
// var_dump($cart);
var_dump($sub);
return array(
'user' => $user,
'quantity' => $cart->getQuantities(),
'totalCostOfAllProducts' => $totalCostOfAllProducts,
);
}