I have a function from a 3rd party plugin that uploads data using a CSV. The beginning of the function in the resource model that does the work looks like this

public function uploadAndImport(\Magento\Framework\DataObject $object)
        try {

I want to call this function using a cron job (which is already set up), and call this with a csv every 15 minutes. How can I pass the csv to this function?

This is what my cron job looks like now


namespace company\ImportCustomerpricing\Cron;

use Magento\Framework\App\ObjectManager;
use Psr\Log\LoggerInterface;
use Magedelight\Customerprice\Model\ResourceModel\Customerprice;

class ImportPricing {
    protected $logger;

    protected $customerprice;

    public function __construct(LoggerInterface $logger, Customerprice $customerprice) {
        $this->logger = $logger;
        $this->customerprice = $customerprice;

     * Write to system.log
     * @return void
     * @throws \Magento\Framework\Exception\LocalizedException
    public function execute() {
        //$this->logger->info('Cron Works');



For your requirement you need to do like this one.

  1. Upload the csv file on particular location on the crone file.
  2. Set that uploaded file name into the session variable.
  3. Now in your original function, get the value from the session variable and use that one.
  • Thank you.Why do I have to set it as a session variable? Why can't I just change the function to accept a string instead of the data object?
    – web master
    Jun 16 at 15:01
  • Yes, you can do into that way as well, if you are able to manage the pass the whole file or data there. Jun 17 at 4:01
  • I guess that's my question. Can I pass the file in by uploading it to the server and passing the path into that function, or do I have to pass it in another way?
    – web master
    Jun 17 at 13:31

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.