0

I have a custom rest api for PUT and POST that the post data is an empty array therefore not saving as it's empty can anyone advise why or what could be wrong?

enter image description here

/**
     * Save data.
     *
     * @param RetailerImageInterface $retailerImage
     * @return RetailerImageInterface
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function save(RetailerImageInterface $retailerImage)
    {
    /** @var RetailerImageInterface|\Magento\Framework\Model\AbstractModel $retailerImage */
        try {
            print_r($retailerImage->getData());
            $this->resource->save($retailerImage);
        } catch (\Exception $e) {
            throw new CouldNotSaveException(__($e->getMessage()));
        }
        return $retailerImage;
}

If I do $this->request->getContent() I can see post data but not through the repository save method.

Has anyone experience this It might be something silly that I'm missing but not sure what it is!

Thanks

1 Answer 1

0

Found the mistake in my model:

It looks like Magento set post array data individually with key pair value from the array to setData using setters even before I call any print_r($retailerImage->getData()); method in repository save method.

setter methods had return of getData instead of setData.

All due to copy and paste! :(

Sorted!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.