0

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

1 Answer 1

0

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
1
  • 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 given Did you manage to get this working? Commented Jun 15, 2020 at 15:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.