protected function storeEntity()
    {
        $request = $this->getRequest();
        $id = $request->getParameter('id');
        // Try to find an existing instance of the entity.
        $entity = NULL;
        try {
            $entity = $this->getFactory()->findEntity($id);
        } catch (NotFoundException $exception) {
            // Not found? Create it.
            $className = $this->getFactory()->getEntitiesClassName();
            $entity = new $className(array(
                'id' => $id,
            ));
        }


        // Get the data from the request.
        $dataFromRequest = $this->getEntityDataFromRequest();
        if ($this->nullsIgnoredOnStore) {
            // Remove unspecified values, so that they are not modified.
            $dataFromRequest = array_filter(
                $dataFromRequest,
                function ($value) {
                    return !is_null($value);
                }
            );
        }
        // Update the product from the request data.
        $entity->update($dataFromRequest);
        // Store the entity.
        $entity->store();

        return $entity;
    }