UpdateGeoNames.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryDistanceBasedSourceSelection\Model\ResourceModel;
  8. use Magento\Framework\App\ResourceConnection;
  9. /**
  10. * Update geonames for a specific country
  11. */
  12. class UpdateGeoNames
  13. {
  14. /**
  15. * @var ResourceConnection
  16. */
  17. private $resourceConnection;
  18. /**
  19. * UpdateGeoNames constructor.
  20. * @param ResourceConnection $resourceConnection
  21. */
  22. public function __construct(ResourceConnection $resourceConnection)
  23. {
  24. $this->resourceConnection = $resourceConnection;
  25. }
  26. /**
  27. * Update country geo names
  28. *
  29. * @param array $geoNames
  30. * @param string $countryCode
  31. */
  32. public function execute(array $geoNames, string $countryCode): void
  33. {
  34. $connection = $this->resourceConnection->getConnection();
  35. $tableName = $this->resourceConnection->getTableName('inventory_geoname');
  36. $connection->beginTransaction();
  37. $connection->delete($tableName, $connection->quoteInto('country_code = ?', $countryCode));
  38. $connection->insertMultiple($tableName, $geoNames);
  39. $connection->commit();
  40. }
  41. }