0

I have a model,resource model,collection file shown below.

app/code/Magge/Custom/Model/Categrory.php

namespace Magge\Custom\Model;

use Magento\Framework\Model\AbstractModel;

class Categrory extends AbstractModel
{
protected function _construct()
{
    $this->_init('Magge\Custom\Model\ResourceModel\Categrory');
    }
}

app/code/Magge/Custom/Model/ResourceModel/Categrory.php

namespace Magge\Custom\Model\ResourceModel;

use Magento\Framework\Model\ResourceModel\Db\AbstractDb;

class Categrory extends AbstractDb
{
protected function _construct()
{
    $this->_init('customer_products', 'customproduct_id');
}
}

app/code/Magge/Custom/Model/ResourceModel/Categrory/Collection.php

namespace Magge\Custom\Model\ResourceModel\Categrory;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;

class Collection extends AbstractCollection
{

protected function _construct()
{
    $this->_init('Magge\Custom\Model\Categrory', 'Morello\Customproducts\Model\ResourceModel\Categrory');
}

}

I have a another module named CustomPriceApi within which I have a price.php file in Model .From this file I am try use the factory class but got the error.

namespace Insigma\CustomPriceApi\Model;

class Price implements PriceInterface {

public function __construct(
\Magge\Custom\Model\CategoryFactory $factoryCategory,
.....
)
{
$this->factoryCategory   = $factoryCategory;
}

Within its public method I use

$category = $this->factoryCategory->create()->addFieldToFilter('price_id',array('eq' => $priceId))->getData();

And I get error.I tried using addAttributetoFilter() but still get undefined method.Please help me in this regard.

0

Try below:

$category = $this->factoryCategory->create()->getCollection()->addFieldToFilter('price_id',array('eq' => $priceId))->getData();
  • Hi @Rutvee,I use it.Each time I use getCollection() I get varnish cache error. – Magento Learner Sep 5 '18 at 10:34
  • please check after clearing your generated folder and cache – Rutvee Sojitra Sep 5 '18 at 10:38
0

You did the mistake at collection class:

$this->_init('Magge\Custom\Model\Categrory', 'Morello\Customproducts\Model\ResourceModel\Categrory');

You have put wrong resource class at here

it should be

Magge\Custom\Model\ResourceModel\Category

from

'Morello\Customproducts\Model\ResourceModel\Categrory'

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.