0

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');
    }

}
1
  • See i have update my answer. Commented Oct 2, 2018 at 13:31

1 Answer 1

0

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()];
    }
9
  • now it shows this error Fatal error: Non-abstract method Sugarcode\Test\Model\Total\Fee::getIdentities() must contain body in /home/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/Total/Fee.php on line 55 Commented Oct 2, 2018 at 13:14
  • have you need to impletement that interface ? Commented Oct 2, 2018 at 13:17
  • i just echo that values that i fetched Commented Oct 2, 2018 at 13:18
  • means you get value from that interface ? Commented Oct 2, 2018 at 13:18
  • where you use it in your code ? Commented Oct 2, 2018 at 13:19

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.