public function update($id, $data)
 {
     $hydrator = new ObjectProperty();
     $array = $hydrator->extract($data);
     $orderData = $array;
     unset($orderData['item']);
     $items = $array['item'];
     $tableGateway = $this->repository->getTablegateway();
     try {
         $tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction();
         $itensAtuais = $this->repository->getOrderItems($id);
         foreach ($items as $item) {
             $item['order_id'] = $id;
             $buscaItem = $this->repository->getOrderItemTablegateway()->select(['order_id' => $item['order_id'], 'product_id' => $item['product_id']]);
             $idItem = 0;
             if (count($buscaItem) > 0) {
                 $idItem = (int) $buscaItem->current()->getId();
                 $this->repository->getOrderItemTablegateway()->update($item, ['id' => $idItem]);
             } else {
                 $this->repository->insertItem($item);
             }
             if (isset($itensAtuais[$idItem])) {
                 unset($itensAtuais[$idItem]);
             }
         }
         foreach ($itensAtuais as $itemExcluir) {
             $this->repository->getOrderItemTablegateway()->delete(['id' => $itemExcluir['id']]);
         }
         $this->repository->update($id, $orderData);
         $tableGateway->getAdapter()->getDriver()->getConnection()->commit();
         return ['order_id' => $id];
     } catch (\Exception $exc) {
         $tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
         return 'error';
         //            echo $exc->getTraceAsString();
     }
 }