Skip to content

Commit

Permalink
Merge pull request #202 from akeneo/release/100.4.6
Browse files Browse the repository at this point in the history
Release/100.4.6
  • Loading branch information
Dnd-Gimix authored May 27, 2020
2 parents 1e87e2f + 3363d62 commit 30f7011
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 91 deletions.
13 changes: 13 additions & 0 deletions Block/Adminhtml/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ public function _toHtml()
{
/** @var string $runUrl */
$runUrl = $this->_getRunUrl();
/** @var string $runProductUrl */
$runProductUrl = $this->_getRunProductUrl();

$this->assign(
[
'runProductUrl' => $this->_escaper->escapeHtml($runProductUrl),
'runUrl' => $this->_escaper->escapeHtml($runUrl),
]
);
Expand All @@ -103,4 +106,14 @@ public function _getRunUrl()
{
return $this->urlModel->getUrl('akeneo_connector/import/run');
}

/**
* Retrieve run URL
*
* @return string
*/
public function _getRunProductUrl()
{
return $this->urlModel->getUrl('akeneo_connector/import/runProduct');
}
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@
* Fix metric option creation when a value is set on a product model specific attribute
* Fix metric value set to "0" when empty on Akeneo
* Fix website association not deleted when website attribute value is empty for a product
* Optimize deletion of akeneo_connector_product_model columns during product model import job
* Optimize deletion of akeneo_connector_product_model columns during product model import job

### Version 100.4.6 :
* Add product import job batching family after family (https://help.akeneo.com/magento2-connector/v100/articles/overview.html#product-import-process)
* Optimize product model column number in temporary table by adding filter for API request on mapped channels and available locales
47 changes: 46 additions & 1 deletion Console/Command/AkeneoConnectorImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class AkeneoConnectorImportCommand extends Command
* @var string IMPORT_CODE
*/
const IMPORT_CODE = 'code';
/**
* This constant contains a string
*
* @var string IMPORT_CODE_PRODUCT
*/
const IMPORT_CODE_PRODUCT = 'product';
/**
* This variable contains a State
*
Expand Down Expand Up @@ -98,7 +104,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}


/**
* Check if multiple entities have been specified
* in the command line
Expand Down Expand Up @@ -154,8 +159,48 @@ protected function import(string $code, OutputInterface $output)
return false;
}

// If product import, run the import once per family
/** @var array $productFamiliesToImport */
$productFamiliesToImport = [];
if ($code == self::IMPORT_CODE_PRODUCT) {
$productFamiliesToImport = $import->getFamiliesToImport();

if (!count($productFamiliesToImport)) {
$message = __('No family to import');
$this->displayError($message, $output);

return false;
}

foreach ($productFamiliesToImport as $family) {
$this->runImport($import, $output, $family);
$import->setIdentifier(null);
}

return true;
}

// Run the import normaly
$this->runImport($import, $output);

return true;
}

/**
* Run the import
*
* @param Import $import
* @param OutputInterface $output
* @param null|string $family
*
* @return void
*/
protected function runImport(Import $import, OutputInterface $output, $family = null) {
try {
$import->setStep(0);
if ($family) {
$import->setFamily($family);
}

while ($import->canExecute()) {
/** @var string $comment */
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Import/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public function execute()
$code = $request->getParam('code');
/** @var string $identifier */
$identifier = $request->getParam('identifier');

/** @var string $family */
$family = $request->getParam('family');
/** @var Import $import */
$import = $this->importRepository->getByCode($code);

Expand All @@ -92,6 +93,9 @@ public function execute()

$import->setIdentifier($identifier)->setStep($step)->setSetFromAdmin(true);

if ($family) {
$import->setFamily($family);
}
/** @var array $response */
$response = $import->execute();

Expand Down
99 changes: 99 additions & 0 deletions Controller/Adminhtml/Import/RunProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Akeneo\Connector\Controller\Adminhtml\Import;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\Json;
use Akeneo\Connector\Api\ImportRepositoryInterface;
use Akeneo\Connector\Converter\ArrayToJsonResponseConverter;
use Akeneo\Connector\Helper\Output as OutputHelper;
use Akeneo\Connector\Job\Import;
use Akeneo\Connector\Job\Product as JobProduct;

/**
* Class RunProduct
*
* @package Akeneo\Connector\Controller\Adminhtml\Import
* @author Agence Dn'D <[email protected]>
* @copyright 2020 Agence Dn'D
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://www.dnd.fr/
*/
class RunProduct extends Action
{
/**
* This variable contains an OutputHelper
*
* @var OutputHelper $outputHelper
*/
protected $outputHelper;
/**
* This variable contains an ImportRepositoryInterface
*
* @var ImportRepositoryInterface $importRepository
*/
protected $importRepository;
/**
* This variable contains a ArrayToJsonResponseConverter
*
* @var ArrayToJsonResponseConverter $arrayToJsonResponseConverter
*/
protected $arrayToJsonResponseConverter;
/**
* This variable contains a JobProduct
*
* @var JobProduct $jobProduct
*/
protected $jobProduct;

/**
* Run constructor.
*
* @param Context $context
* @param ImportRepositoryInterface $importRepository
* @param OutputHelper $output
* @param ArrayToJsonResponseConverter $arrayToJsonResponseConverter
* @param JobProduct $jobProduct
*/
public function __construct(
Context $context,
ImportRepositoryInterface $importRepository,
OutputHelper $output,
ArrayToJsonResponseConverter $arrayToJsonResponseConverter,
JobProduct $jobProduct
) {
parent::__construct($context);

$this->outputHelper = $output;
$this->importRepository = $importRepository;
$this->arrayToJsonResponseConverter = $arrayToJsonResponseConverter;
$this->jobProduct = $jobProduct;
}

/**
* Action triggered by request
*
* @return Json
*/
public function execute()
{
/** @var string[] $families */
$families = $this->jobProduct->getFamiliesToImport();

if (!count($families)) {
$families['message'] = __('No family to import');
}

return $this->arrayToJsonResponseConverter->convert($families);
}

/**
* {@inheritdoc}
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Akeneo_Connector::import');
}
}
88 changes: 86 additions & 2 deletions Helper/ProductFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ public function __construct(
/**
* Get the filters for the product API query
*
* @param string|null $productFamily
*
* @return mixed[]|string[]
*/
public function getFilters()
public function getFilters($productFamily = null)
{
/** @var mixed[] $mappedChannels */
$mappedChannels = $this->configHelper->getMappedChannels();
Expand All @@ -91,12 +93,38 @@ public function getFilters()
$filters = [];
/** @var mixed[] $search */
$search = [];

/** @var $productFilterAdded */
$productFilterAdded = false;
/** @var string $mode */
$mode = $this->configHelper->getFilterMode();
if ($mode == Mode::ADVANCED) {
/** @var mixed[] $advancedFilters */
$advancedFilters = $this->getAdvancedFilters();
// If product import gave a family, add it to the filter
if ($productFamily) {
if (isset($advancedFilters['search']['family'])) {
/**
* @var int $key
* @var string[] $familyFilter
*/
foreach ($advancedFilters['search']['family'] as $key => $familyFilter) {
if (isset($familyFilter['operator']) && $familyFilter['operator'] == 'IN') {
$advancedFilters['search']['family'][$key]['value'][] = $productFamily;
$productFilterAdded = true;

break;
}
}
}

if (!$productFilterAdded) {
/** @var string[] $familyFilter */
$familyFilter = ['operator' => 'IN', 'value' => [$productFamily]];
$advancedFilters['search']['family'][] = $familyFilter;
$productFilterAdded = true;
}
}

if (!empty($advancedFilters['scope'])) {
if (!in_array($advancedFilters['scope'], $mappedChannels)) {
/** @var string[] $error */
Expand All @@ -121,6 +149,13 @@ public function getFilters()
$search = $this->searchBuilder->getFilters();
}

// If import product gave a family, add this family to the search
if ($productFamily && !$productFilterAdded) {
$familyFilter = ['operator' => 'IN', 'value' => [$productFamily]];
$search['family'][] = $familyFilter;
$productFilterAdded = true;
}

/** @var string $channel */
foreach ($mappedChannels as $channel) {
/** @var string[] $filter */
Expand Down Expand Up @@ -166,6 +201,55 @@ public function getFilters()
return $filters;
}


/**
* Get the filters for the product model API query
*
* @return mixed[]|string[]
*/
public function getModelFilters()
{
/** @var mixed[] $mappedChannels */
$mappedChannels = $this->configHelper->getMappedChannels();
if (empty($mappedChannels)) {
/** @var string[] $error */
$error = [
'error' => __('No website/channel mapped. Please check your configurations.'),
];

return $error;
}

/** @var mixed[] $filters */
$filters = [];

/** @var string $channel */
foreach ($mappedChannels as $channel) {
/** @var string[] $filter */
$filter = [
'scope' => $channel,
];

/** @var string[] $locales */
$locales = $this->storeHelper->getChannelStoreLangs($channel);
if (!empty($locales)) {
/** @var string $locales */
$akeneoLocales = $this->localesHelper->getAkeneoLocales();
if (!empty($akeneoLocales)) {
$locales = array_intersect($locales, $akeneoLocales);
}

/** @var string $locales */
$locales = implode(',', $locales);
$filter['locales'] = $locales;
}

$filters[] = $filter;
}

return $filters;
}

/**
* Retrieve advanced filters config
*
Expand Down
Loading

0 comments on commit 30f7011

Please sign in to comment.