ApplyBaseJoins.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\InventoryLowQuantityNotification\Model\ResourceModel\Rss\NotifyStock;
  8. use Magento\Catalog\Api\Data\ProductInterface;
  9. use Magento\CatalogInventory\Api\Data\StockItemInterface;
  10. use Magento\Framework\App\ResourceConnection;
  11. use Magento\Framework\DB\Select;
  12. use Magento\Inventory\Model\ResourceModel\Source;
  13. use Magento\Inventory\Model\ResourceModel\SourceItem;
  14. use Magento\InventoryApi\Api\Data\SourceInterface;
  15. use Magento\InventoryApi\Api\Data\SourceItemInterface;
  16. use Magento\InventoryLowQuantityNotificationApi\Api\Data\SourceItemConfigurationInterface;
  17. class ApplyBaseJoins
  18. {
  19. /**
  20. * @var ResourceConnection
  21. */
  22. private $resourceConnection;
  23. /**
  24. * @param ResourceConnection $resourceConnection
  25. */
  26. public function __construct(
  27. ResourceConnection $resourceConnection
  28. ) {
  29. $this->resourceConnection = $resourceConnection;
  30. }
  31. /**
  32. * @param Select $select
  33. *
  34. * @return void
  35. */
  36. public function execute(Select $select)
  37. {
  38. $configurationJoinCondition =
  39. 'source_item_config.' . SourceItemConfigurationInterface::SKU . ' = product.' . ProductInterface::SKU . ' '
  40. . Select::SQL_AND
  41. . ' source_item_config.' . SourceItemConfigurationInterface::SOURCE_CODE
  42. . ' = main_table.' . SourceItemInterface::SOURCE_CODE;
  43. $select->join(
  44. ['source' => $this->resourceConnection->getTableName(Source::TABLE_NAME_SOURCE)],
  45. 'source.' . SourceInterface::SOURCE_CODE . ' = main_table.' . SourceItemInterface::SOURCE_CODE,
  46. ['source_name' => 'source.' . SourceInterface::NAME]
  47. )->join(
  48. ['product' => $this->resourceConnection->getTableName('catalog_product_entity')],
  49. 'main_table.' . SourceItemInterface::SKU . ' = product.' . ProductInterface::SKU,
  50. ['*']
  51. )->join(
  52. [
  53. 'source_item_config' => $this->resourceConnection->getTableName(
  54. 'inventory_low_stock_notification_configuration'
  55. )
  56. ],
  57. $configurationJoinCondition,
  58. ['source_item_config.' . SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY]
  59. )->join(
  60. ['legacy_stock_item' => $this->resourceConnection->getTableName('cataloginventory_stock_item')],
  61. 'legacy_stock_item.product_id = product.entity_id',
  62. [
  63. 'legacy_stock_item.' . StockItemInterface::LOW_STOCK_DATE,
  64. 'use_config' => 'legacy_stock_item.' . StockItemInterface::USE_CONFIG_NOTIFY_STOCK_QTY
  65. ]
  66. )->group('main_table.' . SourceItem::ID_FIELD_NAME);
  67. }
  68. }