forked from mage-os/mirror-commerce-data-export
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/mage-os/mirror-commerce-dat…
- Loading branch information
Showing
16 changed files
with
353 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQuery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogInventoryDataExporter\Model\Query; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\DB\Select; | ||
|
||
/** | ||
* Class CatalogInventoryQuery | ||
* | ||
* Gets information about product inventory | ||
*/ | ||
class CatalogInventoryStockQuery implements CatalogInventoryStockQueryInterface | ||
{ | ||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resourceConnection; | ||
|
||
/** | ||
* @param ResourceConnection $resourceConnection | ||
*/ | ||
public function __construct( | ||
ResourceConnection $resourceConnection | ||
) { | ||
$this->resourceConnection = $resourceConnection; | ||
} | ||
|
||
/** | ||
* Get table name | ||
* | ||
* @param string $tableName | ||
* @return string | ||
*/ | ||
private function getTable(string $tableName) : string | ||
{ | ||
return $this->resourceConnection->getTableName($tableName); | ||
} | ||
|
||
/** | ||
* Get query with information about in_stock status | ||
* | ||
* @param array $arguments | ||
* @return Select | ||
*/ | ||
public function getInStock(array $arguments) : Select | ||
{ | ||
$productIds = isset($arguments['productId']) ? $arguments['productId'] : []; | ||
$storeViewCodes = isset($arguments['storeViewCode']) ? $arguments['storeViewCode'] : []; | ||
$connection = $this->resourceConnection->getConnection(); | ||
$select = $connection->select() | ||
->from(['cpe' => $this->getTable('catalog_product_entity')], '') | ||
->joinCross( | ||
['s' => $this->getTable('store')], | ||
'' | ||
) | ||
->joinInner( | ||
['csi' => $this->getTable('cataloginventory_stock_status')], | ||
"cpe.entity_id = csi.product_id", | ||
'' | ||
) | ||
->columns( | ||
[ | ||
'productId' => 'csi.product_id', | ||
'storeViewCode' => 's.code', | ||
'qty' => 'csi.qty', | ||
'is_in_stock' => 'csi.stock_status' | ||
] | ||
) | ||
->where('s.code IN (?)', $storeViewCodes) | ||
->where('csi.product_id IN (?)', $productIds); | ||
return $select; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQueryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogInventoryDataExporter\Model\Query; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\DB\Select; | ||
|
||
/** | ||
* Gets information about product inventory | ||
*/ | ||
interface CatalogInventoryStockQueryInterface | ||
{ | ||
/** | ||
* Get query with information about in_stock status | ||
* | ||
* @param array $arguments | ||
* @return Select|null | ||
*/ | ||
public function getInStock(array $arguments) : ?Select; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.