public function deleteBasketBasketelementsAction($basketId, $elementId)
    {
        $basket = $this->getBasket($basketId);
        $this->basketBuilder->build($basket);

        $elements = $basket->getBasketElements();

        foreach ($elements as $key => $basketElement) {
            if ($basketElement->getId() === $elementId) {
                unset($elements[$key]);
                $this->basketBuilder->build($basket);
            }
        }

        try {
            $basket->setBasketElements($elements);
            $this->basketManager->save($basket);
        } catch (\Exception $e) {
            return FOSRestView::create(['error' => $e->getMessage()], 400);
        }

        $context = new Context();
        $context->setGroups(['sonata_api_read']);

        // simplify when dropping FOSRest < 2.1
        if (method_exists($context, 'enableMaxDepth')) {
            $context->enableMaxDepth();
        } else {
            $context->setMaxDepth(10);
        }

        $view = FOSRestView::create($basket);
        $view->setContext($context);

        return $view;
    }
public function deleteBasketBasketelementsAction($basketId, $elementId)
    {
        $basket = $this->getBasket($basketId);
        $this->basketBuilder->build($basket);

        $elements = $basket->getBasketElements();

        foreach ($elements as $key => $basketElement) {
            if ($basketElement->getId() === $elementId) {
                unset($elements[$key]);
                $this->basketBuilder->build($basket);
            }
        }

        try {
            $basket->setBasketElements($elements);
            $this->basketManager->save($basket);
        } catch (\Exception $e) {
            return FOSRestView::create(['error' => $e->getMessage()], 400);
        }

        $context = new Context();
        $context->setGroups(['sonata_api_read']);

        // simplify when dropping FOSRest < 2.1
        if (method_exists($context, 'enableMaxDepth')) {
            $context->enableMaxDepth();
        } else {
            $context->setMaxDepth(10);
        }

        $view = FOSRestView::create($basket);
        $view->setContext($context);

        return $view;
    }
public function deleteBasketBasketelementsAction ( $ basketId , $ elementId ) { $ basket = $ this -> getBasket ( $ basketId ) ; $ this -> basketBuilder -> build ( $ basket ) ; $ elements = $ basket -> getBasketElements ( ) ; foreach ( $ elements as $ key => $ basketElement ) { if ( $ basketElement -> getId ( ) === $ elementId ) { unset ( $ elements [ $ key ] ) ; $ this -> basketBuilder -> build ( $ basket ) ; } } try { $ basket -> setBasketElements ( $ elements ) ; $ this -> basketManager -> save ( $ basket ) ; } catch ( \ Exception $ e ) { return FOSRestView :: create ( [ 'error' => $ e -> getMessage ( ) ] , 400 ) ; } $ context = new Context ( ) ; $ context -> setGroups ( [ 'sonata_api_read' ] ) ; // simplify when dropping FOSRest < 2.1 if ( method_exists ( $ context , 'enableMaxDepth' ) ) { $ context -> enableMaxDepth ( ) ; } else { $ context -> setMaxDepth ( 10 ) ; } $ view = FOSRestView :: create ( $ basket ) ; $ view -> setContext ( $ context ) ; return $ view ; }
Deletes a basket element from a basket.

@ApiDoc(
requirements={
{"name"="basketId", "dataType"="integer", "requirement"="\d+", "description"="basket identifier"},
{"name"="elementId", "dataType"="integer", "requirement"="\d+", "description"="element identifier"},
},
statusCodes={
200="Returned when basket is successfully deleted",
400="Returned when an error has occurred while basket element deletion",
404="Returned when unable to find basket or basket element"
}
)

@param int $basketId  A basket identifier
@param int $elementId A basket element identifier

@throws NotFoundHttpException

@return \FOS\RestBundle\View\View
Deletes a basket element from a basket .