Skip to content

Commit

Permalink
Merge branch 'release/v103.4.0' into 'master'
Browse files Browse the repository at this point in the history
release/v103.4.0 into master

See merge request agence-dnd/marketplace/magento-2/external/magento2-connector-community!78
  • Loading branch information
magentix committed Mar 23, 2023
2 parents a1a2592 + 4a492b0 commit 7faa82c
Show file tree
Hide file tree
Showing 41 changed files with 1,485 additions and 234 deletions.
33 changes: 33 additions & 0 deletions Api/Data/AttributeTypeInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types = 1);

namespace Akeneo\Connector\Api\Data;

/**
* @author Agence Dn'D <[email protected]>
* @copyright 2004-present Agence Dn'D
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://www.dnd.fr/
*/
interface AttributeTypeInterface
{
public const PIM_CATALOG_IDENTIFIER = 'pim_catalog_identifier';
public const PIM_CATALOG_TEXT = 'pim_catalog_text';
public const PIM_CATALOG_TEXTAREA = 'pim_catalog_textarea';
public const PIM_CATALOG_SIMPLESELECT = 'pim_catalog_simpleselect';
public const PIM_CATALOG_MULTISELECT = 'pim_catalog_multiselect';
public const PIM_CATALOG_BOOLEAN = 'pim_catalog_boolean';
public const PIM_CATALOG_DATE = 'pim_catalog_date';
public const PIM_CATALOG_NUMBER = 'pim_catalog_number';
public const PIM_CATALOG_METRIC = 'pim_catalog_metric';
public const PIM_CATALOG_PRICE_COLLECTION = 'pim_catalog_price_collection';
public const PIM_CATALOG_IMAGE = 'pim_catalog_image';
public const PIM_CATALOG_FILE = 'pim_catalog_file';
public const PIM_CATALOG_ASSET_COLLECTION = 'pim_catalog_asset_collection';
public const AKENEO_REFERENCE_ENTITY = 'akeneo_reference_entity';
public const AKENEO_REFERENCE_ENTITY_COLLECTION = 'akeneo_reference_entity_collection';
public const PIM_REFERENCE_DATA_SIMPLESELECT = 'pim_reference_data_simpleselect';
public const PIM_REFERENCE_DATA_MULTISELECT = 'pim_reference_data_multiselect';
public const PIM_CATALOG_TABLE = 'pim_catalog_table';
}
6 changes: 6 additions & 0 deletions Api/Data/JobInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ interface JobInterface
* @var string NAME
*/
public const NAME = 'name';
/**
* Default family code for product job
*
* @var string DEFAULT_PRODUCT_JOB_FAMILY_CODE
*/
public const DEFAULT_PRODUCT_JOB_FAMILY_CODE = 'init_default_family_code';
}
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/Form/Field/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Attribute extends AbstractFieldArray
protected function _construct()
{
$this->addColumn('akeneo_attribute', ['label' => __('Akeneo')]);
$this->addColumn('magento_attribute', ['label' => __('Magento')]);
$this->addColumn('magento_attribute', ['label' => __('Adobe Commerce')]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');

Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/Form/Field/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(
*/
protected function _construct()
{
$this->addColumn('attribute', ['label' => __('Magento Attribute')]);
$this->addColumn('attribute', ['label' => __('Adobe Commerce Attribute')]);
$this->addColumn('column', ['label' => __('Akeneo Attribute')]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
Expand Down
75 changes: 75 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/SwatchType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace Akeneo\Connector\Block\Adminhtml\System\Config\Form\Field;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Data\Form\Element\Factory as ElementFactory;
use Akeneo\Connector\Helper\Import\Attribute as AttributeHelper;

/**
* @author Agence Dn'D <[email protected]>
* @copyright 2004-present Agence Dn'D
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://www.dnd.fr/
*/
class SwatchType extends AbstractFieldArray
{
protected ElementFactory $elementFactory;
protected AttributeHelper $attributeHelper;

public function __construct(
Context $context,
ElementFactory $elementFactory,
AttributeHelper $attributeHelper,
array $data = []
) {
parent::__construct($context, $data);

$this->attributeHelper = $attributeHelper;
$this->elementFactory = $elementFactory;
}

/**
* Initialise form fields
*/
protected function _construct(): void
{
$this->addColumn('pim_type', ['label' => __('Akeneo')]);
$this->addColumn('magento_type', ['label' => __('Magento')]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
parent::_construct();
}

/**
* Render array cell for prototypeJS template
*
* @param string $columnName
*/
public function renderCellTemplate($columnName): string
{
if ($columnName != 'magento_type' || !isset($this->_columns[$columnName])) {
return parent::renderCellTemplate($columnName);
}

/** @var array $options */
$options = $this->attributeHelper->getAvailableSwatchTypes();
/** @var AbstractElement $element */
$element = $this->elementFactory->create('select');
$element->setForm(
$this->getForm()
)->setName(
$this->_getCellInputElementName($columnName)
)->setHtmlId(
$this->_getCellInputElementId('<%- _id %>', $columnName)
)->setValues(
$options
);

return str_replace("\n", '', $element->getElementHtml());
}
}
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/Form/Field/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(
protected function _construct()
{
$this->addColumn('pim_type', ['label' => __('Akeneo')]);
$this->addColumn('magento_type', ['label' => __('Magento')]);
$this->addColumn('magento_type', ['label' => __('Adobe Commerce')]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
parent::_construct();
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,15 @@

### Version 103.3.1 :
* Fix product job import for a family with only the SKU attribute inside it

### Version 103.4.0 :
* Fix error return value must be of type string
* New endpoint to link product with the UUID
* Last Successful updated import date by family
* Allow to import product visibility from Akeneo attribute
* Improve filter and options in the log grid on family
* Manage visual and text swatch attributes
* Export configuration improvement
* "Product Status Mode" parameter missing when selecting version 5.0 Akeneo edition
* Magento to Adobe Commerce rebranding
* Error while importing the attribute option
14 changes: 8 additions & 6 deletions Console/Command/AkeneoConnectorImportCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Akeneo\Connector\Console\Command;

use Akeneo\Connector\Api\Data\JobInterface;
Expand Down Expand Up @@ -79,7 +81,7 @@ public function __construct(
*/
protected function configure()
{
$this->setName('akeneo_connector:import')->setDescription('Import Akeneo data to Magento')->addOption(
$this->setName('akeneo_connector:import')->setDescription('Import Akeneo data to Adobe Commerce/Magento')->addOption(
self::IMPORT_CODE,
null,
InputOption::VALUE_REQUIRED,
Expand Down Expand Up @@ -129,12 +131,12 @@ protected function usage(OutputInterface $output)
$jobs = $this->jobRepository->getList();

// Options
$this->displayComment(__('Options:'), $output);
$this->displayInfo(__('--code'), $output);
$this->displayComment((string)__('Options:'), $output);
$this->displayInfo((string)__('--code'), $output);
$output->writeln('');

// Codes
$this->displayComment(__('Available codes:'), $output);
$this->displayComment((string)__('Available codes:'), $output);
/** @var JobInterface $job */
foreach ($jobs as $job) {
$this->displayInfo($job->getCode(), $output);
Expand All @@ -147,8 +149,8 @@ protected function usage(OutputInterface $output)
/** @var string $code */
$code = $job->getCode();
if ($code) {
$this->displayComment(__('Example:'), $output);
$this->displayInfo(__('akeneo_connector:import --code=%1', $code), $output);
$this->displayComment((string)__('Example:'), $output);
$this->displayInfo((string)__('akeneo_connector:import --code=%1', $code), $output);
}
}

Expand Down
47 changes: 42 additions & 5 deletions Executor/JobExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface;
use Magento\Framework\Phrase;
use Magento\Framework\Serialize\SerializerInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand Down Expand Up @@ -152,10 +153,20 @@ class JobExecutor implements JobExecutorInterface
* @var MessageManagerInterface $messageManager
*/
protected $messageManager;

/**
* JobExecutor constructor
* Description $json field
*
* @var SerializerInterface $json
*/
protected SerializerInterface $json;
/**
* Description $lastSuccessExecutedDate field
*
* @var string[] $lastSuccessExecutedDate
*/
protected array $lastSuccessExecutedDate;

/**
* @param JobRepository $jobRepository
* @param ProcessClassFactory $processClassFactory
* @param ConfigHelper $configHelper
Expand All @@ -164,6 +175,7 @@ class JobExecutor implements JobExecutorInterface
* @param Authenticator $authenticator
* @param CollectionFactory $jobCollectionFactory
* @param MessageManagerInterface $messageManager
* @param SerializerInterface $json
*/
public function __construct(
JobRepository $jobRepository,
Expand All @@ -173,7 +185,8 @@ public function __construct(
ManagerInterface $eventManager,
Authenticator $authenticator,
CollectionFactory $jobCollectionFactory,
MessageManagerInterface $messageManager
MessageManagerInterface $messageManager,
SerializerInterface $json
) {
$this->jobRepository = $jobRepository;
$this->processClassFactory = $processClassFactory;
Expand All @@ -183,6 +196,7 @@ public function __construct(
$this->authenticator = $authenticator;
$this->jobCollectionFactory = $jobCollectionFactory;
$this->messageManager = $messageManager;
$this->json = $json;
}

/**
Expand Down Expand Up @@ -311,6 +325,16 @@ public function execute(string $code, ?OutputInterface $output = null)
return false;
}

$this->lastSuccessExecutedDate = [];
if ($this->currentJob->getLastSuccessExecutedDate()) {
try {
$this->lastSuccessExecutedDate = $this->json->unserialize(
$this->currentJob->getLastSuccessExecutedDate()
);
} catch (\InvalidArgumentException $invalidArgumentException) {
$this->lastSuccessExecutedDate = [];
}
}
$this->beforeRun();

/** @var bool $isError */
Expand All @@ -329,6 +353,8 @@ public function execute(string $code, ?OutputInterface $output = null)
$isError = true;
}

$this->lastSuccessExecutedDate[$this->getCurrentJobClass()->getFamily()] = date('y-m-d H:i:s');

// If last family, force proceed with after run steps
if (array_slice($productFamiliesToImport, -1)[0] === $family
&& $this->currentJob->getStatus() !== JobInterface::JOB_ERROR
Expand Down Expand Up @@ -710,9 +736,20 @@ public function afterRun($error = null, $onlyStop = null)
);
}

if ($error === null && $this->currentJob->getStatus() !== JobInterface::JOB_ERROR) {
if ($this->currentJob->getCode() === JobExecutor::IMPORT_CODE_PRODUCT) {
$this->currentJob->setLastSuccessDate(date('y-m-d H:i:s'));
$this->currentJob->setLastSuccessExecutedDate($this->currentJob->getLastExecutedDate());
$this->currentJob->setLastSuccessExecutedDate($this->json->serialize($this->lastSuccessExecutedDate));

if ($this->currentJob->getStatus() === JobInterface::JOB_ERROR) {
$this->setJobStatus(JobInterface::JOB_ERROR);
}
}

if ($error === null && $this->currentJob->getStatus() !== JobInterface::JOB_ERROR) {
if ($this->currentJob->getCode() !== JobExecutor::IMPORT_CODE_PRODUCT) {
$this->currentJob->setLastSuccessDate(date('y-m-d H:i:s'));
$this->currentJob->setLastSuccessExecutedDate($this->currentJob->getLastExecutedDate());
}
$this->setJobStatus(JobInterface::JOB_SUCCESS);
$this->eventManager->dispatch(
'akeneo_connector_import_on_success',
Expand Down
1 change: 1 addition & 0 deletions Helper/AttributeFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function createAttributeTypeFilter($attributeTypes, $isConfig = false)
|| $edition == Edition::GREATER_OR_FIVE
|| $edition === Edition::SERENITY
|| $edition === Edition::GROWTH
|| $edition === Edition::SEVEN
) {
$filters['search']['type'][] = [
'operator' => 'IN',
Expand Down
7 changes: 4 additions & 3 deletions Helper/CategoryFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ public function getParentFilters()
$edition = $this->configHelper->getEdition();

if ($edition === Edition::GREATER_OR_FOUR_POINT_ZERO_POINT_SIXTY_TWO
|| $edition === Edition::GREATER_OR_FIVE ||
$edition === Edition::SERENITY ||
$edition === Edition::GROWTH
|| $edition === Edition::GREATER_OR_FIVE
|| $edition === Edition::SERENITY
|| $edition === Edition::GROWTH
|| $edition === Edition::SEVEN
) {
$this->searchBuilder = $this->searchBuilderFactory->create();
/** @var string[] $categoriesToImport */
Expand Down
Loading

0 comments on commit 7faa82c

Please sign in to comment.