0

I am new to Magento2. I am developing a payment method and I am getting the message:

Fatal error: Interface 'Test\TestThesis\Model\Test\TestThesis\Api\Data\CryptocurrencyInterface' not found in C:\xampp\htdocs\magento\app\code\Test\TestThesis\Model\Cryptocurrency.php on line 9

I have added the dependency in di.xml. Is there something that I am missing and I am getting this message?

<?php

namespace Test\TestThesis\Model;


use Magento\Framework\Model\AbstractModel;


class Cryptocurrency extends AbstractModel implements Test\TestThesis\Api\Data\CryptocurrencyInterface 
{

    protected function _construct(){
        $this->_init('Test\TestThesis\Model\ResourceModel\Cryptocurrency');
    }

    public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = []
    ) {
        parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    }

    /**
     * 
     * {@inheritdoc}
     * @see CryptocurrencyInterface
     */
    public function getId(){
        return $this->getData(self::ENTITY_ID);
    }

    /**
     * 
     * @param type $id
     * @return type
     * @see CryptocurrencyInterface
     */
    public function setId($id){
        return $this->setData(self::ENTITY_ID, $id);
    }

And the interface:

<?php

namespace Test\TestThesis\Api\Data;

/**
 * Interface CryptocurrencyInterface
 *
 * @package Test\TestThesis\Api\Data 
*/
interface CryptocurrencyInterface
{

    const ENTITY_ID = 'id';
    const ORDER_ID = 'order_id';
    const AMOUNT_DEPOSIT = 'amount_deposit';
    const STATUS = 'status';

    /**
     * @return mixed
     */
    public function getId();

    /**
     * @param $id
     *
     * @return mixed
     */
    public function setId($id);
1

If you have already added the dependency in di.xml, then change Test\TestThesis\Api\Data\CryptocurrencyInterface to \Test\TestThesis\Api\Data\CryptocurrencyInterface and try again.

  • no luck... do I miss a class that should interact with the model? maybe a helper? i dont know – Circe Apr 4 '18 at 15:32
  • run setup:upgrade and flush the cache and try again. Also, share the di.xml code. – Anshu Mishra Apr 5 '18 at 4:39
  • <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Test\TestThesis\Api\Data\CryptocurrencyInterface" type="Test\TestThesis\Model\Cryptocurrency" /> </config> – Circe Apr 6 '18 at 12:01
0

You have obviously mistaken in the namespace of the implemented interface (prseumably in di.xml preference node):

Fatal error: Interface 'Test\TestThesis\Model\Test\TestThesis\Api\Data\CryptocurrencyInterface' not found in C:\xampp\htdocs\magento\app\code\Test\TestThesis\Model\Cryptocurrency.php on line 9

The answer is almost ALWAYS in the Error message: the path can't be Test\TestThesis\Model\Test\TestThesis\Api...

I often did some mistakes in the namespaces so I understand how it annoys ;D

Hope this will help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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