I'm using Magento 2 as PIM for other shop solution. I need to export the backorders value once per hour until we have made an API.
The script below works fine, but values for 'backorders' are not exported. How can I fix that?
<?php
require './app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$_objectManager = $bootstrap->getObjectManager();
$state = $_objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');
$registry = $_objectManager->get('Magento\Framework\Registry');
$registry->register('isSecureArea', true);
//Store id of exported products, This is useful when we have multiple stores.
$store_id = 0;
$fp = fopen("export2.csv","w+");
$collection = $_objectManager-
>create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')
->create()->addStoreFilter($store_id)
->addAttributeToFilter('type_id', 'simple')
->addAttributeToSelect(array('updated_at','sku','status','backorders','price'));
foreach ($collection as $product)
{
$data = array();
$data[] = $product->getUpdated_at();
$data[] = $product->getSku();
$data[] = $product->getStatus();
$data[] = $product->getBackorders(); (doesn´t export value)
$data[] = $product->getPrice();
fputcsv($fp, $data);
}
fclose($fp);
?>