I am making a module that will create a product feed and save it. The module uses cron to create the feed in regular intervals. However, I have run into a couple of problems…
- I get this error:
Item (MagentoCatalogModelProductInterceptor) with the same ID “<id>” already exists
. I searched the database using various queries but I did not find any duplicates. - I used the code from this page to fix the above problem, but now all calls to
$product->getFinalPrice()
return 0
Stuff that may help:
- When running the same helper code using a command, I do not get the duplicate ID error
- I am using an iterator to loop through the product collection, since it’s quite large
- In the cron job
execute()
function, I am using the below code to run the helper function that generates the feed:
foreach ($this->storeManager->getStores() as $store) {
$this->_helper->generateXML($store->getId());
}
- To get the product collection, I am using something like this:
private function getProducts(int $storeId)
{
$this->collection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
... //Other filters here
$this->collection->addFinalPrice();
$this->collection->addStoreFilter($storeId);
$this->collection->load();
$this->iterator->walk(
$this->collection->getSelect(),
[[$this, 'productCallback']],
[
'store' => $storeId,
]
);
}
(Yes, I know object manager is not recommended, but this is a proof of concept module)
-
In my callback function, I am using
MagentoCatalogApiProductRepositoryInterface
to load the product data -
I am using Magento 2.3.6
Can anyone help me out? I am sure I am missing something, but I am not sure what that is…