I have created a custom module (Blog) which contains a save() method, it is executed but values are not saved and it returns an empty object.
<?php
namespace Learning\Blog\Model\Resource;
use Learning\Blog\Api\Data\BlogInterface;
class BlogRepository implements BlogRepositoryInterface
{
protected $blogFactory;
public function __construct
(
\Learning\Blog\Model\BlogFactory $blogFactory
){
$this->blogFactory = $blogFactory;
}
public function save(BlogInterface $blog){
$blog_Data = $this->blogFactory->create();
$blog_Data->save();
return $blog_Data;
}
}
Did I miss anything?
Fabian Schmengler
66.2k25 gold badges191 silver badges422 bronze badges
asked Oct 6, 2015 at 9:24
Bojjaiah
3,8024 gold badges59 silver badges125 bronze badges
1 Answer 1
Finally I have achieved to update.
class BlogRepository implements BlogRepositoryInterface
{
protected $blogFactory;
protected $blogBuilder;
protected $extensibleDataObjectConverter;
public function __construct
(
\Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter,
\Learning\Blog\Model\BlogFactory $blogFactory
){
$this->extensibleDataObjectConverter = $extensibleDataObjectConverter;
$this->blogBuilder = $blogDataBuilder;
$this->blogFactory = $blogFactory;
}
public function save(BlogInterface $blog){
$customerData = $this->extensibleDataObjectConverter->toNestedArray(
$blog,
[],
'\Learning\Blog\Api\Data\BlogInterface'
);
$blog_Data = $this->blogFactory->create();
$blog_Data->setData($customerData);
$item = $blog_Data->save();
return $item;
}
}
answered Oct 6, 2015 at 14:04
Bojjaiah
3,8024 gold badges59 silver badges125 bronze badges
-
I was not able to do this I've got error :
Fatal Error: 'Uncaught TypeError: Argument 1 passed to Magento\\Framework\\Api\\ExtensibleDataObjectConverter::toNestedArray() must implement interface Magento\\Framework\\Api\\ExtensibleDataInterface, instance of Vendor\\Module\\Model\\CustomModel givenDid you manage to get this working?Juliano Vargas– Juliano Vargas2020年06月15日 15:42:40 +00:00Commented Jun 15, 2020 at 15:42
default