1

I need to export products several times a day using cron job. I have little experience with Magento 2.1 and I don't know how to develop the script.
I hope you can help me.
Thank you.

1
  1. Create a console command in magento to run the following

     $attributes = ['entity_id','sku', 'name', 'type_id', 'status', 'visibility', 'created_at', 'updated_at'];
    $collection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create();
    
    
            $output = fopen('php://stdout','w');
    
            $collection = $collection->addAttributeToSelect('*');
    
            foreach ($collection as $item) {
                $line = array();
                foreach ($attributes as $attributeCode) {
                    $attr = $item->getResource()->getAttribute($attributeCode);
                    if ($attr->usesSource()) {
                        $line[$attributeCode] = $attr->getSource()->getOptionText($item->getData($attributeCode));
                    } else {
                        $line[$attributeCode] = $item->getData($attributeCode);
                    }
                }
                fputcsv($output, $line);
            }
    
  2. create a cron to run this script time to time.

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.