Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 10 additions & 29 deletions Plugin/InsertNewProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,25 @@

use Akeneo\Connector\Job\Product;
use Akeneo\Connector\Helper\Import\Entities;
use Magento\Store\Model\ScopeInterface as scope;
use Magento\Store\Model\ScopeInterface as Scope;
use Magento\Framework\App\Config\ScopeConfigInterface;

class InsertNewProducts
{
protected $config;
protected $entitiesHelper;

/**
* __construct function
* @param ScopeConfigInterface $config
* @param Entities $entitiesHelper
*/
public function __construct(
ScopeConfigInterface $config,
Entities $entitiesHelper
protected ScopeConfigInterface $config,
protected Entities $entitiesHelper
) {
$this->config = $config;
$this->entitiesHelper = $entitiesHelper;
}

/**
* afterInsertData function
* @param product $subject
* @param bool $result
* @return bool $result
*/
public function afterInsertData(product $subject, $result)
public function afterInsertData(Product $subject)
{
$extensionEnabled = $this->config->getValue('akeneo_connector/justbetter/insertnewproducts', scope::SCOPE_WEBSITE);
if (!$extensionEnabled) {
return $result;
$extensionEnabled = $this->config->getValue('akeneo_connector/justbetter/insertnewproducts', Scope::SCOPE_WEBSITE);
if ($extensionEnabled) {
$connection = $this->entitiesHelper->getConnection();
$tmpTableName = $this->entitiesHelper->getTableName($subject->getCode());

$connection->delete($tmpTableName, ['_is_new = ?' => 1]);
}

$connection = $this->entitiesHelper->getConnection();
$tmpTableName = $this->entitiesHelper->getTableName($subject->getCode());

$connection->delete($tmpTableName, ['_is_new = ?' => 1]);
return $result;
}
}
47 changes: 47 additions & 0 deletions Plugin/RemoveRedundantEav.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace JustBetter\AkeneoBundle\Plugin;

use Akeneo\Connector\Executor\JobExecutor;
use Akeneo\Connector\Helper\Import\Entities;
use Akeneo\Connector\Helper\Output;
use Magento\Framework\App\ResourceConnection;

class RemoveRedundantEav
{
public const CATALOG_PRODUCT_ENTITY_DATA_TYPES = ['int', 'text', 'decimal', 'gallery', 'varchar', 'datetime'];

public function __construct(
protected Entities $entities,
protected ResourceConnection $resourceConnection,
protected JobExecutor $jobExecutor,
protected Output $outputHelper
) {
}

public function beforeRefreshIndex(): void
{
self::removeRedundantEAV();
}

public function removeRedundantEAV(): void
{
$this->jobExecutor->displayInfo((string)$this->outputHelper->getPrefix() . __('Remove Redundant EAV attribute values'));
$connection = $this->resourceConnection->getConnection();

foreach (self::CATALOG_PRODUCT_ENTITY_DATA_TYPES as $dataType) {
$query = "
DELETE cpe{$dataType}
FROM catalog_product_entity_{$dataType} as cpe{$dataType}
LEFT JOIN catalog_product_entity as cpe on cpe.entity_id = cpe{$dataType}.entity_id
LEFT JOIN eav_attribute as ea on ea.attribute_id = cpe{$dataType}.attribute_id
WHERE cpe{$dataType}.store_id = 0 AND cpe.attribute_set_id NOT IN (
SELECT attribute_set_id
FROM eav_entity_attribute
WHERE attribute_set_id = cpe.attribute_set_id AND attribute_id = cpe{$dataType}.attribute_id
)
";
$connection->query($query);
}
}
}
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<plugin name="JustBetter_SetStockStatus" type="JustBetter\AkeneoBundle\Plugin\SetStockStatus" sortOrder="2" />
<plugin name="JustBetter_ImportFinished" type="JustBetter\AkeneoBundle\Plugin\ImportFinished" sortOrder="10" />
<plugin name="JustBetter_CheckWebsiteAssociation" type="JustBetter\AkeneoBundle\Plugin\CheckWebsiteAssociation" />
<plugin name="JustBetter_RemoveRedundantEav" type="JustBetter\AkeneoBundle\Plugin\RemoveRedundantEav" />
</type>

<type name="Akeneo\Connector\Job\Category">
Expand Down