Skip to content

Commit

Permalink
Merge pull request #226 from akeneo/release/100.4.9
Browse files Browse the repository at this point in the history
Release/100.4.9
  • Loading branch information
Dnd-Gimix authored Jun 22, 2020
2 parents 5ae8b2d + d277055 commit c58d766
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 53 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,10 @@
### Version 100.4.8 :
* Fix strict type for Akeneo PHP client pagination variable
* Fix product count during product model job
* Optimize product association deletion request
* Optimize product association deletion request

### Version 100.4.9 :
* Fix product filters not being reseted after each family during command line execution
* Fix create table function causing some products and product models not being imported in multi-website environment
* Fix misleading warning label during image import
* Fix Akeneo API connection being initialized in construct on the admin configuration page of the connector
26 changes: 17 additions & 9 deletions Helper/ProductFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Akeneo\Connector\Helper;

use Akeneo\Pim\ApiClient\Search\SearchBuilder;
use Akeneo\Pim\ApiClient\Search\SearchBuilderFactory;
use Magento\Framework\App\Helper\AbstractHelper;
use Akeneo\Connector\Helper\Config as ConfigHelper;
use Akeneo\Connector\Helper\Store as StoreHelper;
Expand Down Expand Up @@ -42,6 +43,12 @@ class ProductFilters
* @var Akeneo\Connector\Helper\Locales $localesHelper
*/
protected $localesHelper;
/**
* This variable contains a SearchBuilderFactory
*
* @var SearchBuilderFactory $searchBuilderFactory
*/
protected $searchBuilderFactory;
/**
* This variable contains a SearchBuilder
*
Expand All @@ -52,21 +59,21 @@ class ProductFilters
/**
* ProductFilters constructor
*
* @param ConfigHelper $configHelper
* @param Store $storeHelper
* @param Locales $localesHelper
* @param SearchBuilder $searchBuilder
* @param ConfigHelper $configHelper
* @param Store $storeHelper
* @param Locales $localesHelper
* @param SearchBuilderFactory $searchBuilderFactory
*/
public function __construct(
ConfigHelper $configHelper,
StoreHelper $storeHelper,
LocalesHelper $localesHelper,
SearchBuilder $searchBuilder
SearchBuilderFactory $searchBuilderFactory
) {
$this->configHelper = $configHelper;
$this->storeHelper = $storeHelper;
$this->localesHelper = $localesHelper;
$this->searchBuilder = $searchBuilder;
$this->configHelper = $configHelper;
$this->storeHelper = $storeHelper;
$this->localesHelper = $localesHelper;
$this->searchBuilderFactory = $searchBuilderFactory;
}

/**
Expand Down Expand Up @@ -142,6 +149,7 @@ public function getFilters($productFamily = null)
}

if ($mode == Mode::STANDARD) {
$this->searchBuilder = $this->searchBuilderFactory->create();
$this->addCompletenessFilter();
$this->addStatusFilter();
$this->addFamiliesFilter();
Expand Down
21 changes: 14 additions & 7 deletions Job/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,26 @@ public function createTable()

/** @var mixed[] $filters */
$filters = $this->getFilters($this->getFamily());
$filters = reset($filters);
/** @var PageInterface $products */
$products = $this->akeneoClient->getProductApi()->listPerPage(1, false, $filters);
/** @var mixed[] $products */
$products = $products->getItems();
$product = reset($products);

foreach ($filters as $filter) {
/** @var PageInterface $products */
$products = $this->akeneoClient->getProductApi()->listPerPage(1, false, $filter);
/** @var mixed[] $products */
$products = $products->getItems();

if (!empty($products)) {
break;
}
}

if (empty($products)) {
$this->setMessage(__('No results from Akeneo for the family: %1', $this->getFamily()));
$this->stop(true);

return;
}

$product = reset($products);
$this->entitiesHelper->createTmpTableFromApi($product, $this->getCode());

/** @var string $message */
Expand Down Expand Up @@ -2417,7 +2424,7 @@ public function importMedia()
];
foreach ($gallery as $image) {
if (!$connection->tableColumnExists($tmpTable, $image)) {
$this->setMessage(__('Warning: %1 attribute does not exist', $image));
$this->setMessage(__('Info: No value found in the current batch for the attribute %1', $image));
continue;
}
$data[$image] = $image;
Expand Down
22 changes: 15 additions & 7 deletions Job/ProductModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,26 @@ public function createTable()
{
/** @var mixed[] $filters */
$filters = $this->getFilters();
$filters = reset($filters);
/** @var PageInterface $productModels */
$productModels = $this->akeneoClient->getProductModelApi()->listPerPage(1, false, $filters);
/** @var array $productModel */
$productModel = $productModels->getItems();
if (empty($productModel)) {

foreach ($filters as $filter) {
/** @var PageInterface $productModels */
$productModels = $this->akeneoClient->getProductModelApi()->listPerPage(1, false, $filter);
/** @var array $productModel */
$productModels = $productModels->getItems();

if (!empty($productModels)) {
break;
}
}

if (empty($productModels)) {
$this->setMessage(__('No results from Akeneo'));
$this->stop(1);

return;
}
$productModel = reset($productModel);

$productModel = reset($productModels);
$this->entitiesHelper->createTmpTableFromApi($productModel, $this->getCode());
}

Expand Down
25 changes: 12 additions & 13 deletions Model/Source/Filters/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ class Category implements ArrayInterface
*/
protected $logger;

/**
* This variable contains Categories options
*
* @var string[] $options
*/
protected $options = [];

/**
* Category constructor
*
Expand All @@ -52,31 +45,35 @@ public function __construct(
) {
$this->akeneoAuthenticator = $akeneoAuthenticator;
$this->logger = $logger;
$this->init();
}

/**
* Initialize options
*
* @return void
*/
public function init()
public function getCategories()
{
/** @var array $categories */
$categories = [];

try {
/** @var AkeneoPimClientInterface $client */
$client = $this->akeneoAuthenticator->getAkeneoApiClient();
if (empty($client)) {
return;
}
/** @var ResourceCursorInterface $categories */
$categories = $client->getCategoryApi()->all();
$akeneoCategories = $client->getCategoryApi()->all();
/** @var mixed[] $category */
foreach ($categories as $category) {
foreach ($akeneoCategories as $category) {
if (!isset($category['code']) || isset($category['parent'])) {
continue;
}
$this->options[$category['code']] = $category['code'];
$categories[$category['code']] = $category['code'];
}

return $categories;
} catch (\Exception $exception) {
$this->logger->warning($exception->getMessage());
}
Expand All @@ -89,14 +86,16 @@ public function init()
*/
public function toOptionArray()
{
/** @var array $categories */
$categories = $this->getCategories();
/** @var array $optionArray */
$optionArray = [];

/**
* @var int $optionValue
* @var string $optionLabel
*/
foreach ($this->options as $optionValue => $optionLabel) {
foreach ($categories as $optionValue => $optionLabel) {
$optionArray[] = [
'value' => $optionValue,
'label' => $optionLabel,
Expand Down
24 changes: 12 additions & 12 deletions Model/Source/Filters/Family.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ class Family implements ArrayInterface
* @var \Psr\Log\LoggerInterface $logger
*/
protected $logger;
/**
* List of options
*
* @var string[] $options
*/
protected $options = [];

/**
* Family constructor
Expand All @@ -49,16 +43,18 @@ public function __construct(
) {
$this->akeneoAuthenticator = $akeneoAuthenticator;
$this->logger = $logger;
$this->init();
}

/**
* Initialize options
*
* @return void
*/
public function init()
public function getFamilies()
{
/** @var array $families */
$families = [];

try {
/** @var AkeneoPimClientInterface $client */
$client = $this->akeneoAuthenticator->getAkeneoApiClient();
Expand All @@ -68,14 +64,16 @@ public function init()
}

/** @var ResourceCursorInterface $families */
$families = $client->getFamilyApi()->all();
$akeneoFamilies = $client->getFamilyApi()->all();
/** @var mixed[] $family */
foreach ($families as $family) {
foreach ($akeneoFamilies as $family) {
if (!isset($family['code'])) {
continue;
}
$this->options[$family['code']] = $family['code'];
$families[$family['code']] = $family['code'];
}

return $families;
} catch (\Exception $exception) {
$this->logger->warning($exception->getMessage());
}
Expand All @@ -88,13 +86,15 @@ public function init()
*/
public function toOptionArray()
{
/** @var array $families */
$families = $this->getFamilies();
/** @var array $optionArray */
$optionArray = [];
/**
* @var int $optionValue
* @var string $optionLabel
*/
foreach ($this->options as $optionValue => $optionLabel) {
foreach ($families as $optionValue => $optionLabel) {
$optionArray[] = [
'value' => $optionValue,
'label' => $optionLabel,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"php-http/guzzle6-adapter": "^1.1"
},
"type": "magento2-module",
"version": "100.4.8",
"version": "100.4.9",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
3 changes: 2 additions & 1 deletion i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,5 @@ Zum Beispiel :<br/>
"Akeneo Metric Attribute","Akeneo Metrikattribut"
"Used As Variant","Als Variante verwenden"
"Concat Metric Unit","Metrische Einheit zum Wert hinzufügen"
"No family to import","Keine Familie zu importieren"
"No family to import","Keine Familie zu importieren"
"Info: No value found in the current batch for the attribute %1","Info: Im aktuellen Stapel wurde kein Wert für das Attribut gefunden %1"
3 changes: 2 additions & 1 deletion i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,5 @@ For example :<br/>
"Akeneo Metric Attribute","Akeneo Metric Attribute"
"Used As Variant","Used As Variant"
"Concat Metric Unit","Add metric unit to value"
"No family to import","No family to import"
"No family to import","No family to import"
"Info: No value found in the current batch for the attribute %1","Info: No value found in the current batch for the attribute %1"
3 changes: 2 additions & 1 deletion i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,5 @@ Par exemple :<br/>
"Akeneo Metric Attribute","Attribut métrique Akeneo"
"Used As Variant","Utiliser comme Variante"
"Concat Metric Unit","Ajouter l'unité métrique à la valeur"
"No family to import","Aucune famille à importer"
"No family to import","Aucune famille à importer"
"Info: No value found in the current batch for the attribute %1","Information: Aucune valeur trouvée pour l'attribut %1 dans l'import actuel"

0 comments on commit c58d766

Please sign in to comment.