Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mage-os-ci committed Dec 15, 2023
2 parents 9c8bbcb + 076ed7f commit 0f8abc1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

namespace Magento\ProductVariantDataExporter\Model\Query;

use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\DataExporter\Model\Indexer\FeedIndexMetadata;
use Magento\Eav\Model\Config;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Select;
use Magento\DataExporter\Model\Query\MarkRemovedEntitiesQuery as DefaultMarkRemovedEntitiesQuery;
Expand All @@ -20,28 +18,17 @@
*/
class MarkRemovedEntitiesQuery extends DefaultMarkRemovedEntitiesQuery
{
private const STATUS_ATTRIBUTE_CODE = "status";

private const STATUS_DISABLED = Status::STATUS_DISABLED;

/**
* @var ResourceConnection
*/
private ResourceConnection $resourceConnection;

/**
* @var Config
*/
private Config $eavConfig;

/**
* @param ResourceConnection $resourceConnection
* @param Config $eavConfig
*/
public function __construct(ResourceConnection $resourceConnection, Config $eavConfig)
public function __construct(ResourceConnection $resourceConnection)
{
$this->resourceConnection = $resourceConnection;
$this->eavConfig = $eavConfig;

parent::__construct($resourceConnection);
}
Expand All @@ -63,9 +50,6 @@ public function getQuery(array $ids, FeedIndexMetadata $metadata): Select
$catalogProductTable = $this->resourceConnection->getTableName($metadata->getSourceTableName());
$productEntityJoinField = $connection->getAutoIncrementField($catalogProductTable);

$statusAttribute = $this->eavConfig->getAttribute('catalog_product', self::STATUS_ATTRIBUTE_CODE);
$statusAttributeId = $statusAttribute?->getId();

return $connection->select()
->from(
['f' => $this->resourceConnection->getTableName($metadata->getFeedTableName())]
Expand Down Expand Up @@ -94,30 +78,11 @@ public function getQuery(array $ids, FeedIndexMetadata $metadata): Select
),
[]
)
->joinLeft(
['disabled_product' => $catalogProductTable],
\sprintf('f.product_id = disabled_product.%s', $fieldName),
[]
)
->joinLeft(
['disabled_product_status' => $this->resourceConnection->getTableName('catalog_product_entity_int')],
\sprintf(
'disabled_product_status.%s = disabled_product.%s
AND disabled_product_status.attribute_id = %s
AND disabled_product_status.store_id = 0',
$productEntityJoinField,
$productEntityJoinField,
$statusAttributeId,
),
[]
)
->where('f.product_id IN (?)', $ids)
->where(
\sprintf(
'removed_product.entity_id IS NULL
OR disabled_product_status.value = %d
OR unassigned_product.entity_id IS NULL',
self::STATUS_DISABLED
OR unassigned_product.entity_id IS NULL'
)
);
}
Expand Down
24 changes: 5 additions & 19 deletions ProductVariantDataExporter/Model/Query/ProductVariantsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
*/
class ProductVariantsQuery
{
private const STATUS_ATTRIBUTE_CODE = "status";

/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @var Config
*/
private Config $eavConfig;

/**
Expand Down Expand Up @@ -52,9 +54,6 @@ public function getQuery(array $parentIds): Select
$this->resourceConnection->getTableName('catalog_product_entity')
);

$statusAttribute = $this->eavConfig->getAttribute('catalog_product', self::STATUS_ATTRIBUTE_CODE);
$statusAttributeId = $statusAttribute?->getId();

$subSelect = $connection->select()
->from(
['cpsa' => $this->resourceConnection->getTableName('catalog_product_super_attribute')],
Expand Down Expand Up @@ -95,18 +94,6 @@ public function getQuery(array $parentIds): Select
'option_value.option_id = cpei.value',
[]
)
->joinLeft(
['product_status' => $this->resourceConnection->getTableName('catalog_product_entity_int')],
\sprintf(
'product_status.%s = product.%s
AND product_status.attribute_id = %s
AND product_status.store_id = 0',
$joinField,
$joinField,
$statusAttributeId,
),
[]
)
->columns(
[
'parentId' => 'cpep.entity_id',
Expand All @@ -119,8 +106,7 @@ public function getQuery(array $parentIds): Select
'optionLabel' => 'option_value.value'
]
)
->where('product.entity_id IN (?)', $parentIds)
->where('product_status.value = ?', Status::STATUS_ENABLED);
->where('product.entity_id IN (?)', $parentIds);

return $select;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ public function testDisabledAndReanableChildFromConfigurableProductVariants(): v
$variantsData = $this->getVariantByIds([$variantSimple10, $variantSimple20]);
$this->assertCount(2, $variantsData); //id20, id10 (disabled)
$this->assertEquals('simple_10', $variantsData[0]['productSku']);
$this->assertTrue($variantsData[0]['deleted'], "simple_10 should have been flag as deleted");
$this->assertFalse($variantsData[0]['deleted'], "simple_10 should not have been flag as deleted");

$this->assertEquals('simple_20', $variantsData[1]['productSku']);
$this->assertFalse($variantsData[1]['deleted'], "simple_20 should not have been flag as deleted");
$this->assertFalse($variantsData[1]['deleted'], "simple_20 should not not have been flag as deleted");

// enable variant && verify "deleted" is set to false
// verify enabling child product back works
Expand All @@ -206,6 +206,41 @@ public function testDisabledAndReanableChildFromConfigurableProductVariants(): v
}
}

/**
* Test that disabled product variant is exported in feed
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
*
* @return void
*/
public function testDisabledVariantIsStillExportedInFeed(): void
{
try {
$configurable = $this->productRepository->get('configurable');
$configurableId = $configurable->getId();

$simple10 = $this->productRepository->get('simple_10');

$variantSimple10 = $this->idResolver->resolve([
ConfigurableId::PARENT_SKU_KEY => 'configurable',
ConfigurableId::CHILD_SKU_KEY => 'simple_10'
]);

// disable variant and run indexer
$this->changeProductStatusProduct('simple_10', Status::STATUS_DISABLED);
$this->runIndexer([$configurableId, $simple10->getId()]);

$variantsData = $this->getVariantByIds([$variantSimple10]);
$this->assertCount(1, $variantsData);
$this->assertEquals('simple_10', $variantsData[0]['productSku']);
$this->assertFalse($variantsData[0]['deleted'], "simple_10 should not have been flag as deleted");
} catch (Throwable $e) {
$this->fail($e->getMessage());
}
}

/**
* @param $childSku
* @param $status
Expand Down

0 comments on commit 0f8abc1

Please sign in to comment.