I would like to set Notify Qty from a script that reads a CSV file with Source, SKU and NotifyQty. It would probably need to enable notify qty for the products as well.

I can do it with SQL query to inventory_low_stock_notification_configuration.notify_stock_qty, but that's probably not the right way.

  • Hi! You have sku and qty inside some csv file and you want to import it from PHP script, is that right?
    – dudzio
    May 29, 2021 at 10:13
  • Hi! Yes, that's right. I have the rest of the script ready, so it's reading the csv, but I don't know how to access the notify qty correctly
    – Dandy
    May 29, 2021 at 10:16
  • Ok, let me prepare answer for you :)
    – dudzio
    May 29, 2021 at 10:21
  • Could you change your answer so it contains information about import from CSV file?
    – dudzio
    May 29, 2021 at 10:22
  • Are you ok with cli run script?
    – dudzio
    May 29, 2021 at 10:24

1 Answer 1


This is example CSV file (sku_qty.csv):


This is the code to run:


require __DIR__ . './../app/bootstrap.php';

use Magento\Framework\App\Bootstrap;

// Init Magento
$bootstrap = Bootstrap::create(BP, $_SERVER);

// Get Object Manager instance
$objectManager = $bootstrap->getObjectManager();

// Construct Factory object
/* @var $sourceItemConfigurationFactory \Magento\InventoryLowQuantityNotification\Model\SourceItemConfigurationFactory */
$sourceItemConfigurationFactory = $objectManager->get('Magento\InventoryLowQuantityNotification\Model\SourceItemConfigurationFactory');

// Construct Multiple Save object
/* @var $saveMultiple \Magento\InventoryLowQuantityNotification\Model\ResourceModel\SourceItemConfiguration\SaveMultiple */
$saveMultiple = $objectManager->get('Magento\InventoryLowQuantityNotification\Model\ResourceModel\SourceItemConfiguration\SaveMultiple');

// Create CSV file handle
$inputFile = fopen(__DIR__ . "/sku_qty.csv", "r");

// Get CSV headers
$headers = fgetcsv($inputFile);

// Init array of config objects
$sourceItemsConfiguration = [];

// Iterate CSV file
$n = 0;
while (($row = fgetcsv($inputFile)) !== false) {
    // Init source item config instance and set data
    $sourceItemConfiguration = $sourceItemConfigurationFactory->create();

    $sourceItemsConfiguration[] = $sourceItemConfiguration;

try {
    // Save data
} catch (\Exception $e) {
    echo $e->getMessage();

I like to put my file inside script directory, so I run them like that php script/test.php from Magento root directory.

  • Thank you so much @dudzio, it worked like a charm! I've upvoted, but I have not reached 15 reps yet.
    – Dandy
    May 29, 2021 at 12:05
  • Happy to hear! :) Thanks! I tried to run save() method on $sourceItemConfiguration inside while loop, but unfortunately there is a bug that results in The resource isn't set. error :(
    – dudzio
    May 29, 2021 at 12:09
  • 1
    That's what I was trying too, but I thought it was my lack of knowledge, not a bug! Happy that you found a different solution!
    – Dandy
    May 29, 2021 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.