stocks.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. use Magento\Framework\Api\DataObjectHelper;
  8. use Magento\InventoryApi\Api\Data\StockInterface;
  9. use Magento\InventoryApi\Api\Data\StockInterfaceFactory;
  10. use Magento\InventoryApi\Api\StockRepositoryInterface;
  11. use Magento\TestFramework\Helper\Bootstrap;
  12. /** @var StockInterfaceFactory $stockFactory */
  13. $stockFactory = Bootstrap::getObjectManager()->get(StockInterfaceFactory::class);
  14. /** @var DataObjectHelper $dataObjectHelper */
  15. $dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
  16. /** @var StockRepositoryInterface $stockRepository */
  17. $stockRepository = Bootstrap::getObjectManager()->get(StockRepositoryInterface::class);
  18. $stocksData = [
  19. [
  20. // define only required and needed for tests fields
  21. StockInterface::STOCK_ID => 10,
  22. StockInterface::NAME => 'EU-stock',
  23. ],
  24. [
  25. StockInterface::STOCK_ID => 20,
  26. StockInterface::NAME => 'US-stock',
  27. ],
  28. [
  29. StockInterface::STOCK_ID => 30,
  30. StockInterface::NAME => 'Global-stock',
  31. ],
  32. ];
  33. foreach ($stocksData as $stockData) {
  34. /** @var StockInterface $stock */
  35. $stock = $stockFactory->create();
  36. $dataObjectHelper->populateWithArray($stock, $stockData, StockInterface::class);
  37. $stockRepository->save($stock);
  38. }