forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.4-develop' into 2.4-develop-temporary-three-prs
- Loading branch information
Showing
144 changed files
with
4,838 additions
and
853 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
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
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
31 changes: 31 additions & 0 deletions
31
app/code/Magento/CatalogImportExport/Model/Export/Product/CategoryFilter.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,31 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogImportExport\Model\Export\Product; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\Collection; | ||
use Magento\CatalogImportExport\Model\Export\ProductFilterInterface; | ||
|
||
/** | ||
* Category filter for products export | ||
*/ | ||
class CategoryFilter implements ProductFilterInterface | ||
{ | ||
private const NAME = 'category_ids'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function filter(Collection $collection, array $filters): Collection | ||
{ | ||
$value = trim($filters[self::NAME] ?? ''); | ||
if ($value) { | ||
$collection->addCategoriesFilter(['in' => explode(',', $value)]); | ||
} | ||
return $collection; | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
app/code/Magento/CatalogImportExport/Model/Export/Product/Stock.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,111 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogImportExport\Model\Export\Product; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\Collection; | ||
use Magento\CatalogInventory\Model\Configuration; | ||
use Magento\CatalogInventory\Model\ResourceModel\Stock\Item as StockItemResourceModel; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Stock status collection filter | ||
*/ | ||
class Stock | ||
{ | ||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
/** | ||
* @var StockItemResourceModel | ||
*/ | ||
private $stockItemResourceModel; | ||
|
||
/** | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param StockItemResourceModel $stockItemResourceModel | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $scopeConfig, | ||
StockItemResourceModel $stockItemResourceModel | ||
) { | ||
$this->scopeConfig = $scopeConfig; | ||
$this->stockItemResourceModel = $stockItemResourceModel; | ||
} | ||
|
||
/** | ||
* Filter provided collection to return only "in stock" products | ||
* | ||
* @param Collection $collection | ||
* @return Collection | ||
*/ | ||
public function addInStockFilterToCollection(Collection $collection): Collection | ||
{ | ||
$manageStock = $this->scopeConfig->getValue( | ||
Configuration::XML_PATH_MANAGE_STOCK, | ||
ScopeInterface::SCOPE_STORE | ||
); | ||
$cond = [ | ||
'{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=1', | ||
'{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=0' | ||
]; | ||
|
||
if ($manageStock) { | ||
$cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=1'; | ||
} else { | ||
$cond[] = '{{table}}.use_config_manage_stock = 1'; | ||
} | ||
return $this->addFilterToCollection($collection, '(' . join(') OR (', $cond) . ')'); | ||
} | ||
|
||
/** | ||
* Filter provided collection to return only "out of stock" products | ||
* | ||
* @param Collection $collection | ||
* @return Collection | ||
*/ | ||
public function addOutOfStockFilterToCollection(Collection $collection): Collection | ||
{ | ||
$manageStock = $this->scopeConfig->getValue( | ||
Configuration::XML_PATH_MANAGE_STOCK, | ||
ScopeInterface::SCOPE_STORE | ||
); | ||
$cond = [ | ||
'{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=0', | ||
]; | ||
|
||
if ($manageStock) { | ||
$cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=0'; | ||
} | ||
return $this->addFilterToCollection($collection, '(' . join(') OR (', $cond) . ')'); | ||
} | ||
|
||
/** | ||
* Add stock status filter to the collection | ||
* | ||
* @param Collection $collection | ||
* @param string $condition | ||
* @return Collection | ||
*/ | ||
private function addFilterToCollection(Collection $collection, string $condition): Collection | ||
{ | ||
$condition = str_replace( | ||
'{{table}}', | ||
'inventory_stock_item_filter', | ||
'({{table}}.product_id=e.entity_id) AND (' . $condition . ')' | ||
); | ||
$collection->getSelect() | ||
->joinInner( | ||
['inventory_stock_item_filter' => $this->stockItemResourceModel->getMainTable()], | ||
$condition, | ||
[] | ||
); | ||
return $collection; | ||
} | ||
} |
Oops, something went wrong.