Test Failed
Push — master ( 39548d...2a5b8d )
by David
06:29
created

UtilityController::updateItemInCart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GGGGino\SkuskuCartBundle\Controller;
4
5
use GGGGino\SkuskuCartBundle\Form\CartFlow;
6
use GGGGino\SkuskuCartBundle\Model\SkuskuCartProduct;
7
use GGGGino\SkuskuCartBundle\Model\SkuskuCartProductInterface;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\Routing\Annotation\Route;
12
13
/**
14
 * Class UtilityController
15
 * @package GGGGino\SkuskuCartBundle\Controller
16
 */
17
class UtilityController extends Controller
18
{
19
    /**
20
     * Cart page
21
     *
22
     * @Route("/remove_item/{product}", name="remove_item_from_cart")
23
     */
24
    public function removeItemFromCart(SkuskuCartProduct $product)
25
    {
26
        $em = $this->getDoctrine()->getManager();
27
        $em->remove($product);
28
        $em->flush();
29
30
        return new Response('ok');
31
    }
32
    /**
33
     * Cart page
34
     *
35
     * @Route("/update_item/{product}", name="update_item_in_cart", methods={"POST"})
36
     */
37
    public function updateItemInCart(Request $request, SkuskuCartProduct $product)
38
    {
39
        $em = $this->getDoctrine()->getManager();
40
        $product->setQuantity(intval($request->request->get('quantity')));
41
        $em->flush();
42
43
        return new Response('ok');
44
    }
45
}