Skip to content

Commit 91beb89

Browse files
authored
Merge pull request #32 from akeneo/release/100.2.1
Release/100.2.1
2 parents 7b8ab36 + f94f45e commit 91beb89

File tree

16 files changed

+415
-60
lines changed

16 files changed

+415
-60
lines changed

CHANGELOG.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
# Akeneo Connector change Log
1+
# Akeneo Connector change log
22

3-
### 100.1.0 :
4-
Initial Akeneo Connector Release
3+
### Version 100.1.0 :
4+
* Initial Akeneo Connector Release
55

6-
### 100.1.1 :
7-
Fix attribute mapping key
6+
### Version 100.1.1 :
7+
* Fix attribute mapping key
8+
9+
### Version 100.2.1 :
10+
* Add website mapping from select or multiselect attribute in Akeneo
11+
* Use native Magento serializer
12+
* Fix proxy class injection in command construct
13+
* Fix association import when result is empty
14+
* Fix url_key mapping and generation

Console/Command/AkeneoConnectorImportCommand.php

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Magento\Framework\Data\Collection;
88
use Magento\Framework\Exception\LocalizedException;
99
use Magento\Framework\Phrase;
10-
use Akeneo\Connector\Api\ImportRepositoryInterface\Proxy;
10+
use Akeneo\Connector\Api\ImportRepositoryInterface;
1111
use Akeneo\Connector\Job\Import;
1212
use \Symfony\Component\Console\Command\Command;
1313
use \Symfony\Component\Console\Input\InputInterface;
@@ -48,12 +48,12 @@ class AkeneoConnectorImportCommand extends Command
4848
/**
4949
* AkeneoConnectorImportCommand constructor.
5050
*
51-
* @param Proxy $importRepository
51+
* @param ImportRepositoryInterface $importRepository
5252
* @param State $appState
5353
* @param null $name
5454
*/
5555
public function __construct(
56-
Proxy $importRepository,
56+
ImportRepositoryInterface $importRepository,
5757
State $appState,
5858
$name = null
5959
) {

Controller/Adminhtml/Import/Run.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function execute()
9090
return $this->arrayToJsonResponseConverter->convert($response);
9191
}
9292

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

9595
/** @var array $response */
9696
$response = $import->execute();

Helper/Config.php

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Config extends AbstractHelper
6060
const PRODUCTS_CATEGORY_IS_ANCHOR = 'akeneo_connector/category/is_anchor';
6161
const PRODUCTS_CATEGORY_CATEGORIES = 'akeneo_connector/category/categories';
6262
const PRODUCT_ATTRIBUTE_MAPPING = 'akeneo_connector/product/attribute_mapping';
63+
const PRODUCT_WEBSITE_ATTRIBUTE = 'akeneo_connector/product/website_attribute';
6364
const PRODUCT_CONFIGURABLE_ATTRIBUTES = 'akeneo_connector/product/configurable_attributes';
6465
const PRODUCT_TAX_CLASS = 'akeneo_connector/product/tax_class';
6566
const PRODUCT_URL_GENERATION_ENABLED = 'akeneo_connector/product/url_generation_enabled';
@@ -388,6 +389,17 @@ public function getAdminDefaultChannel()
388389
return $this->scopeConfig->getValue(self::AKENEO_API_ADMIN_CHANNEL);
389390
}
390391

392+
/**
393+
* Retrieve the name of the website association attribute
394+
*
395+
* @return array
396+
* @throws \Magento\Framework\Exception\NoSuchEntityException
397+
*/
398+
public function getWebsiteAttribute()
399+
{
400+
return $this->scopeConfig->getValue(self::PRODUCT_WEBSITE_ATTRIBUTE);
401+
}
402+
391403
/**
392404
* Retrieve website mapping
393405
*

Helper/Import/Entities.php

+68-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Framework\Config\ConfigOptionsListConstants;
1414
use Zend_Db_Expr as Expr;
1515
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
16+
use Akeneo\Connector\Helper\Config as ConfigHelper;
17+
use Magento\Catalog\Model\Product as BaseProductModel;
1618

1719
/**
1820
* Class Entities
@@ -51,6 +53,18 @@ class Entities extends AbstractHelper
5153
* @var ResourceConnection $connection
5254
*/
5355
protected $connection;
56+
/**
57+
* This variable contains a ProductModel
58+
*
59+
* @var BaseProductModel $product
60+
*/
61+
protected $product;
62+
/**
63+
* This variable contains a ConfigHelper
64+
*
65+
* @var ConfigHelper $configHelper
66+
*/
67+
protected $configHelper;
5468
/**
5569
* @var DeploymentConfig $deploymentConfig
5670
*/
@@ -77,19 +91,25 @@ class Entities extends AbstractHelper
7791
/**
7892
* Entities constructor
7993
*
80-
* @param Context $context
94+
* @param Context $context
8195
* @param ResourceConnection $connection
82-
* @param DeploymentConfig $deploymentConfig
96+
* @param DeploymentConfig $deploymentConfig
97+
* @param ConfigHelper $configHelper
98+
* @param BaseProductModel $product
8399
*/
84100
public function __construct(
85101
Context $context,
86102
ResourceConnection $connection,
87-
DeploymentConfig $deploymentConfig
103+
DeploymentConfig $deploymentConfig,
104+
BaseProductModel $product,
105+
ConfigHelper $configHelper
88106
) {
89107
parent::__construct($context);
90108

91-
$this->connection = $connection->getConnection();
109+
$this->connection = $connection->getConnection();
92110
$this->deploymentConfig = $deploymentConfig;
111+
$this->configHelper = $configHelper;
112+
$this->product = $product;
93113
}
94114

95115
/**
@@ -698,4 +718,48 @@ public function prefixToLowerCase($values)
698718
}
699719
return $newValues;
700720
}
721+
722+
/**
723+
* Format the url_key column of a given table, suffix is optional
724+
*
725+
* @param string $tmpTable
726+
* @param null|string $local
727+
*
728+
* @return void
729+
*/
730+
public function formatUrlKeyColumn($tmpTable, $local = null) {
731+
/** @var bool $isUrlKeyMapped */
732+
$isUrlKeyMapped = $this->configHelper->isUrlKeyMapped();
733+
/** @var string $columnKey */
734+
$columnKey = 'url_key';
735+
if ($local !== null) {
736+
$columnKey = 'url_key-' . $local;
737+
}
738+
if ($isUrlKeyMapped && $this->connection->tableColumnExists($tmpTable, $columnKey)) {
739+
/** @var \Magento\Framework\DB\Select $select */
740+
$select = $this->connection->select()->from(
741+
$tmpTable,
742+
[
743+
'identifier' => 'identifier',
744+
'url_key' => $columnKey,
745+
]
746+
);
747+
/** @var \Magento\Framework\DB\Statement\Pdo\Mysql $query */
748+
$query = $this->connection->query($select);
749+
750+
/** @var array $row */
751+
while (($row = $query->fetch())) {
752+
if (isset($row['url_key'])) {
753+
$row['url_key'] = $this->product->formatUrlKey($row['url_key']);
754+
$this->connection->update(
755+
$tmpTable,
756+
[
757+
$columnKey => $row['url_key'],
758+
],
759+
['identifier = ?' => $row['identifier']]
760+
);
761+
}
762+
}
763+
}
764+
}
701765
}

Helper/Import/Product.php

100644100755
+4-1
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,12 @@ private function formatAssociations(array $values)
171171
foreach ($values as $group => $types) {
172172
/**
173173
* @var string $key
174-
* @var array $product
174+
* @var array $product
175175
*/
176176
foreach ($types as $key => $products) {
177+
if (empty($products)) {
178+
continue;
179+
}
177180
/** @var string $name */
178181
$name = $group . '-' . $key;
179182

Helper/Serializer.php

100644100755
+24-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Akeneo\Connector\Helper;
44

55
use Magento\Framework\App\Helper\AbstractHelper;
6+
use Magento\Framework\App\Helper\Context;
7+
use Magento\Framework\Serialize\Serializer\Serialize as Serialize;
68

79
/**
810
* Class Serializer
@@ -16,6 +18,27 @@
1618
*/
1719
class Serializer extends AbstractHelper
1820
{
21+
/**
22+
* This variable contains a Serialize
23+
*
24+
* @var Serialize $serialize
25+
*/
26+
protected $serialize;
27+
28+
/**
29+
* Config constructor
30+
*
31+
* @param Context $context
32+
* @param Serialize $serialize
33+
*/
34+
public function __construct(
35+
Context $context,
36+
Serialize $serialize
37+
) {
38+
parent::__construct($context);
39+
$this->serialize = $serialize;
40+
}
41+
1942
/**
2043
* Unserialize data from config (keep compatibility with Magento < 2.2)
2144
* This will be replaced by \Magento\Framework\Serialize\Serializer\Json in some time
@@ -34,7 +57,7 @@ public function unserialize($value)
3457
}
3558

3659
try {
37-
$data = unserialize($value);
60+
$data = $this->serialize->unserialize($value);
3861
} catch (\Exception $exception) {
3962
$data = [];
4063
}

Job/Import.php

+71-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ abstract class Import extends DataObject implements ImportInterface
9494
* @var bool $continue
9595
*/
9696
private $continue;
97+
/**
98+
* This variable contains a bool value
99+
*
100+
* @var bool $setFromAdmin
101+
*/
102+
private $setFromAdmin;
97103

98104
/**
99105
* Import constructor.
@@ -119,6 +125,7 @@ public function __construct(
119125
$this->outputHelper = $outputHelper;
120126
$this->eventManager = $eventManager;
121127
$this->step = 0;
128+
$this->setFromAdmin = false;
122129
$this->initStatus();
123130
$this->initSteps();
124131
}
@@ -201,6 +208,30 @@ public function getIdentifier()
201208
return $this->identifier;
202209
}
203210

211+
/**
212+
* Set set from admin
213+
*
214+
* @param $value
215+
*
216+
* @return $this
217+
*/
218+
public function setSetFromAdmin($value)
219+
{
220+
$this->setFromAdmin = $value;
221+
222+
return $this;
223+
}
224+
225+
/**
226+
* Get set from admin
227+
*
228+
* @return bool
229+
*/
230+
public function getSetFromAdmin()
231+
{
232+
return $this->setFromAdmin;
233+
}
234+
204235
/**
205236
* Set current step index
206237
*
@@ -225,6 +256,21 @@ public function getStep()
225256
return $this->step;
226257
}
227258

259+
/**
260+
* Get end of line for command line or console
261+
*
262+
* @return string
263+
*/
264+
public function getEndOfLine()
265+
{
266+
if ($this->getSetFromAdmin() === false) {
267+
268+
return PHP_EOL;
269+
}
270+
271+
return '</br>';
272+
}
273+
228274
/**
229275
* Set import comment
230276
*
@@ -253,6 +299,20 @@ public function setMessage($message)
253299
return $this;
254300
}
255301

302+
/**
303+
* Set additional message during import
304+
*
305+
* @param $message
306+
*
307+
* @return $this
308+
*/
309+
public function setAdditionalMessage($message)
310+
{
311+
$this->message = $this->getMessageWithoutPrefix() . $this->getEndOfLine() . $message;
312+
313+
return $this;
314+
}
315+
256316
/**
257317
* Set import status
258318
*
@@ -304,7 +364,7 @@ public function getComment()
304364
}
305365

306366
/**
307-
* Description getMessage function
367+
* Return current message with the timestamp prefix
308368
*
309369
* @return string
310370
*/
@@ -313,6 +373,16 @@ public function getMessage()
313373
return (string)$this->outputHelper->getPrefix().$this->message;
314374
}
315375

376+
/**
377+
* Return current message without the timestamp prefix
378+
*
379+
* @return string
380+
*/
381+
public function getMessageWithoutPrefix()
382+
{
383+
return (string)$this->message;
384+
}
385+
316386
/**
317387
* Get method to execute
318388
*

0 commit comments

Comments
 (0)