Skip to content

Commit

Permalink
Merge pull request #32 from akeneo/release/100.2.1
Browse files Browse the repository at this point in the history
Release/100.2.1
  • Loading branch information
Dnd-Gimix authored Sep 5, 2019
2 parents 7b8ab36 + f94f45e commit 91beb89
Show file tree
Hide file tree
Showing 16 changed files with 415 additions and 60 deletions.
17 changes: 12 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Akeneo Connector change Log
# Akeneo Connector change log

### 100.1.0 :
Initial Akeneo Connector Release
### Version 100.1.0 :
* Initial Akeneo Connector Release

### 100.1.1 :
Fix attribute mapping key
### Version 100.1.1 :
* Fix attribute mapping key

### Version 100.2.1 :
* Add website mapping from select or multiselect attribute in Akeneo
* Use native Magento serializer
* Fix proxy class injection in command construct
* Fix association import when result is empty
* Fix url_key mapping and generation
6 changes: 3 additions & 3 deletions Console/Command/AkeneoConnectorImportCommand.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Magento\Framework\Data\Collection;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
use Akeneo\Connector\Api\ImportRepositoryInterface\Proxy;
use Akeneo\Connector\Api\ImportRepositoryInterface;
use Akeneo\Connector\Job\Import;
use \Symfony\Component\Console\Command\Command;
use \Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -48,12 +48,12 @@ class AkeneoConnectorImportCommand extends Command
/**
* AkeneoConnectorImportCommand constructor.
*
* @param Proxy $importRepository
* @param ImportRepositoryInterface $importRepository
* @param State $appState
* @param null $name
*/
public function __construct(
Proxy $importRepository,
ImportRepositoryInterface $importRepository,
State $appState,
$name = null
) {
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Import/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function execute()
return $this->arrayToJsonResponseConverter->convert($response);
}

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

/** @var array $response */
$response = $import->execute();
Expand Down
12 changes: 12 additions & 0 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Config extends AbstractHelper
const PRODUCTS_CATEGORY_IS_ANCHOR = 'akeneo_connector/category/is_anchor';
const PRODUCTS_CATEGORY_CATEGORIES = 'akeneo_connector/category/categories';
const PRODUCT_ATTRIBUTE_MAPPING = 'akeneo_connector/product/attribute_mapping';
const PRODUCT_WEBSITE_ATTRIBUTE = 'akeneo_connector/product/website_attribute';
const PRODUCT_CONFIGURABLE_ATTRIBUTES = 'akeneo_connector/product/configurable_attributes';
const PRODUCT_TAX_CLASS = 'akeneo_connector/product/tax_class';
const PRODUCT_URL_GENERATION_ENABLED = 'akeneo_connector/product/url_generation_enabled';
Expand Down Expand Up @@ -388,6 +389,17 @@ public function getAdminDefaultChannel()
return $this->scopeConfig->getValue(self::AKENEO_API_ADMIN_CHANNEL);
}

/**
* Retrieve the name of the website association attribute
*
* @return array
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getWebsiteAttribute()
{
return $this->scopeConfig->getValue(self::PRODUCT_WEBSITE_ATTRIBUTE);
}

/**
* Retrieve website mapping
*
Expand Down
72 changes: 68 additions & 4 deletions Helper/Import/Entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Magento\Framework\Config\ConfigOptionsListConstants;
use Zend_Db_Expr as Expr;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use Akeneo\Connector\Helper\Config as ConfigHelper;
use Magento\Catalog\Model\Product as BaseProductModel;

/**
* Class Entities
Expand Down Expand Up @@ -51,6 +53,18 @@ class Entities extends AbstractHelper
* @var ResourceConnection $connection
*/
protected $connection;
/**
* This variable contains a ProductModel
*
* @var BaseProductModel $product
*/
protected $product;
/**
* This variable contains a ConfigHelper
*
* @var ConfigHelper $configHelper
*/
protected $configHelper;
/**
* @var DeploymentConfig $deploymentConfig
*/
Expand All @@ -77,19 +91,25 @@ class Entities extends AbstractHelper
/**
* Entities constructor
*
* @param Context $context
* @param Context $context
* @param ResourceConnection $connection
* @param DeploymentConfig $deploymentConfig
* @param DeploymentConfig $deploymentConfig
* @param ConfigHelper $configHelper
* @param BaseProductModel $product
*/
public function __construct(
Context $context,
ResourceConnection $connection,
DeploymentConfig $deploymentConfig
DeploymentConfig $deploymentConfig,
BaseProductModel $product,
ConfigHelper $configHelper
) {
parent::__construct($context);

$this->connection = $connection->getConnection();
$this->connection = $connection->getConnection();
$this->deploymentConfig = $deploymentConfig;
$this->configHelper = $configHelper;
$this->product = $product;
}

/**
Expand Down Expand Up @@ -698,4 +718,48 @@ public function prefixToLowerCase($values)
}
return $newValues;
}

/**
* Format the url_key column of a given table, suffix is optional
*
* @param string $tmpTable
* @param null|string $local
*
* @return void
*/
public function formatUrlKeyColumn($tmpTable, $local = null) {
/** @var bool $isUrlKeyMapped */
$isUrlKeyMapped = $this->configHelper->isUrlKeyMapped();
/** @var string $columnKey */
$columnKey = 'url_key';
if ($local !== null) {
$columnKey = 'url_key-' . $local;
}
if ($isUrlKeyMapped && $this->connection->tableColumnExists($tmpTable, $columnKey)) {
/** @var \Magento\Framework\DB\Select $select */
$select = $this->connection->select()->from(
$tmpTable,
[
'identifier' => 'identifier',
'url_key' => $columnKey,
]
);
/** @var \Magento\Framework\DB\Statement\Pdo\Mysql $query */
$query = $this->connection->query($select);

/** @var array $row */
while (($row = $query->fetch())) {
if (isset($row['url_key'])) {
$row['url_key'] = $this->product->formatUrlKey($row['url_key']);
$this->connection->update(
$tmpTable,
[
$columnKey => $row['url_key'],
],
['identifier = ?' => $row['identifier']]
);
}
}
}
}
}
5 changes: 4 additions & 1 deletion Helper/Import/Product.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@ private function formatAssociations(array $values)
foreach ($values as $group => $types) {
/**
* @var string $key
* @var array $product
* @var array $product
*/
foreach ($types as $key => $products) {
if (empty($products)) {
continue;
}
/** @var string $name */
$name = $group . '-' . $key;

Expand Down
25 changes: 24 additions & 1 deletion Helper/Serializer.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Akeneo\Connector\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Serialize\Serializer\Serialize as Serialize;

/**
* Class Serializer
Expand All @@ -16,6 +18,27 @@
*/
class Serializer extends AbstractHelper
{
/**
* This variable contains a Serialize
*
* @var Serialize $serialize
*/
protected $serialize;

/**
* Config constructor
*
* @param Context $context
* @param Serialize $serialize
*/
public function __construct(
Context $context,
Serialize $serialize
) {
parent::__construct($context);
$this->serialize = $serialize;
}

/**
* Unserialize data from config (keep compatibility with Magento < 2.2)
* This will be replaced by \Magento\Framework\Serialize\Serializer\Json in some time
Expand All @@ -34,7 +57,7 @@ public function unserialize($value)
}

try {
$data = unserialize($value);
$data = $this->serialize->unserialize($value);
} catch (\Exception $exception) {
$data = [];
}
Expand Down
72 changes: 71 additions & 1 deletion Job/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ abstract class Import extends DataObject implements ImportInterface
* @var bool $continue
*/
private $continue;
/**
* This variable contains a bool value
*
* @var bool $setFromAdmin
*/
private $setFromAdmin;

/**
* Import constructor.
Expand All @@ -119,6 +125,7 @@ public function __construct(
$this->outputHelper = $outputHelper;
$this->eventManager = $eventManager;
$this->step = 0;
$this->setFromAdmin = false;
$this->initStatus();
$this->initSteps();
}
Expand Down Expand Up @@ -201,6 +208,30 @@ public function getIdentifier()
return $this->identifier;
}

/**
* Set set from admin
*
* @param $value
*
* @return $this
*/
public function setSetFromAdmin($value)
{
$this->setFromAdmin = $value;

return $this;
}

/**
* Get set from admin
*
* @return bool
*/
public function getSetFromAdmin()
{
return $this->setFromAdmin;
}

/**
* Set current step index
*
Expand All @@ -225,6 +256,21 @@ public function getStep()
return $this->step;
}

/**
* Get end of line for command line or console
*
* @return string
*/
public function getEndOfLine()
{
if ($this->getSetFromAdmin() === false) {

return PHP_EOL;
}

return '</br>';
}

/**
* Set import comment
*
Expand Down Expand Up @@ -253,6 +299,20 @@ public function setMessage($message)
return $this;
}

/**
* Set additional message during import
*
* @param $message
*
* @return $this
*/
public function setAdditionalMessage($message)
{
$this->message = $this->getMessageWithoutPrefix() . $this->getEndOfLine() . $message;

return $this;
}

/**
* Set import status
*
Expand Down Expand Up @@ -304,7 +364,7 @@ public function getComment()
}

/**
* Description getMessage function
* Return current message with the timestamp prefix
*
* @return string
*/
Expand All @@ -313,6 +373,16 @@ public function getMessage()
return (string)$this->outputHelper->getPrefix().$this->message;
}

/**
* Return current message without the timestamp prefix
*
* @return string
*/
public function getMessageWithoutPrefix()
{
return (string)$this->message;
}

/**
* Get method to execute
*
Expand Down
Loading

0 comments on commit 91beb89

Please sign in to comment.