src/Flowcode/ShopBundle/Controller/InventoryController.php
/**
     * Finds and displays a Inventory entity.
     *
     * @Route("/{id}/confirm", name="stock_inventory_confirm", requirements={"id"="\d+"})
     * @Method("GET")
     */
Finds and displays a Inventory entity.
Finds and displays a Inventory entity .
public function confirmAction(Inventory $inventory)
    {
        $em = $this->getDoctrine()->getManager();
        $warehouseProductRepo = $em->getRepository('FlowerStockBundle:WarehouseProduct');
        foreach ($inventory->getItems() as $item) {
            $warehouseProduct = $warehouseProductRepo->findOneBy(array(
                'product' => $item->getProduct(),
                'warehouse' => $inventory->getWarehouse(),
            ));
            if (!$warehouseProduct) {
                $warehouseProduct = new WarehouseProduct();
                $warehouseProduct->setProduct($item->getProduct());
                $warehouseProduct->setWarehouse($item->getWarehouse());
                $em->persist($warehouseProduct);
            }
            $warehouseProduct->setStock($item->getStock());
        }
        $inventory->setStatus(Inventory::STATUS_CONFIRMED);
        $em->flush();
        return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $inventory->getId())));
    }
public function confirmAction ( Inventory $ inventory ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ warehouseProductRepo = $ em -> getRepository ( 'FlowerStockBundle:WarehouseProduct' ) ; foreach ( $ inventory -> getItems ( ) as $ item ) { $ warehouseProduct = $ warehouseProductRepo -> findOneBy ( array ( 'product' => $ item -> getProduct ( ) , 'warehouse' => $ inventory -> getWarehouse ( ) , ) ) ; if ( ! $ warehouseProduct ) { $ warehouseProduct = new WarehouseProduct ( ) ; $ warehouseProduct -> setProduct ( $ item -> getProduct ( ) ) ; $ warehouseProduct -> setWarehouse ( $ item -> getWarehouse ( ) ) ; $ em -> persist ( $ warehouseProduct ) ; } $ warehouseProduct -> setStock ( $ item -> getStock ( ) ) ; } $ inventory -> setStatus ( Inventory :: STATUS_CONFIRMED ) ; $ em -> flush ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'stock_inventory_show' , array ( 'id' => $ inventory -> getId ( ) ) ) ) ; }
Finds and displays a Inventory entity.
Finds and displays a Inventory entity .