Magento – Facing this issue, It contains 1 abstract method and must therefore be declared abstract or implement the remaining method

abstract classdatabasefactoryfatal errormagento2

Facing fatal error given as below.

Fatal error: Class Sugarcode\Test\Model\Total\Fee contains 1 abstract
method and must therefore be declared abstract or implement the
remaining methods
(Magento\Framework\DataObject\IdentityInterface::getIdentities) in
/home/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/Total/Fee.php
on line 7

Here is my code

    <?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Sugarcode\Test\Model\Total;
class Fee extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface {

     const CACHE_TAG = 'mr_dukaaniatest';
    protected $_cacheTag = 'mr_dukaaniatest';
    protected $_eventPrefix = 'mr_dukaaniatest';

    protected function _construct()
    {
        $this->_init('Sugarcode\Test\Model\ResourceModel\Fee.php');
    }

    /**
     * Collect grand total address amount
     *
     * @param \Magento\Quote\Model\Quote $quote
     * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
     * @param \Magento\Quote\Model\Quote\Address\Total $total
     * @return $this
     */

   protected $_feeFactory;

    public function __construct(
            \Sugarcode\Test\Model\Total\FeeFactory $feeFactory
            ) {
                  parent::__construct($context);

        $this->_feeFactory = $feeFactory;

    }

    public function collect(

    ) {
        parent::collect($quote, $shippingAssignment, $total);
    }

public function getIdentities();

 public function fetch() {      

        $fee = $this->_feeFactory->create();
        $collection = $fee->getCollection();
        foreach($collection as $item){
            \Zend_Debug::dump($item->getData());
        }
        exit();
    }

      public function execute()
    {
        $fee = $this->_feeFactory->create();
        $collection = $fee->getCollection();
        foreach($collection as $item){
            \Zend_Debug::dump($item->getData());
        }
        exit();
    }

    /**
     * Get Subtotal label
     *
     * @return \Magento\Framework\Phrase
     */
    public function getLabel() {
        return __('Fee');
    }

}

Best Answer

If you have implements anything then you need to implement all the method of that class or interface etc.

In your you can't implament the method of IdentityInterface.

So you need to implement the method of that interface which i given below please check.

public function getIdentities();

Please implement this method in your class where you use that interface.

You can also refer this link for using identityinterface. IdentityInterface

Also you can use something like it.

/**
 * Return identifiers for produced content
 *
 * @return array
 */
public function getIdentities()
{
    $identities = [];
    foreach ($this->_getProductCollection() as $item) {
        $identities = array_merge($identities, $item->getIdentities());
    }
    $category = $this->getLayer()->getCurrentCategory();
    if ($category) {
        $identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId();
    }
    return $identities;
}

Also use like this.

public function getIdentities()
    {
        return [self::CACHE_TAG . '_' . $this->getId()];
    }