I'm getting a strange error on code which previously worked and now dont.
<?php
namespace Itstod\LinkedProducts\Model;
use Itstod\LinkedProducts\Api\LinkInterface;
use Itstod\LinkedProducts\Model\ResourceModel\LinkedProducts\Collection;
use Itstod\LinkedProducts\Model\ResourceModel\LinkedProducts\CollectionFactory;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Api\ProductRepositoryInterface;
class Resthandler implements LinkInterface
{
/**
* @var Product
*/
protected $product;
/**
* @var LinkedProduct[]
*/
private $instances = [];
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var CollectionFactory
*/
private $collectionFactory;
public function __construct(ProductRepositoryInterface $productRepository,CollectionFactory $collectionFactory)
{
$this->productRepository = $productRepository;
$this->collectionFactory = $collectionFactory;
}
/**
* @api
* @param string $sku product sku.
* @return LinkedProduct[].
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function get($sku) {
/**
* @var LinkedProduct[]
*/
$returnvalue = [];
$this->product = $this->productRepository->get($sku);
$id = $this->product->getId();
/** @var Collection $collection**/
$collection = $this->collectionFactory->create()->addFieldToFilter('head_product_id', $id);
// $collection = $collection->getSelect();
/** @var \Itstod\LinkedProducts\Model\LinkedProduct $prod */
/*
foreach ($collection as $prod)
{
$returnvalue[] = $this->productRepository->getById($prod->getData('linked_product_id'));
}
*/
return $returnvalue;
}
}
this code is giving me:
"Fatal Error: 'Allowed memory size of 1073741824 bytes exhausted (tried to allocate 803225600 bytes)' in '\/home\/<url>\/public_html\/vendor\/magento\/module-eav\/Model\/Entity\/Collection\/AbstractCollection.php' on line 249"
and as you can i see i commented out most of the code to find this error. The crash is happening in the ->create() function as i have tried it on its own and its still crashing.
Update!
Found the error, i was trying to extend the wrong abstract collection, in my collection class.