Skip to content

Commit

Permalink
Unplugged-840 | Fix marketplace review issues (#274)
Browse files Browse the repository at this point in the history
* Fix marketplace review
  • Loading branch information
frobs committed May 24, 2023
1 parent c14d32c commit b235eb9
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Controller/Adminhtml/Integration/CreateStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Integration\Block\Adminhtml\Integration\Tokens;
use Magento\Store\Api\Data\StoreInterface;
use Psr\Log\LoggerInterface;
use Doofinder\Feed\Helper\JsonSerialization;

class CreateStore extends Action implements HttpGetActionInterface
{
Expand Down Expand Up @@ -233,7 +234,7 @@ private function setCustomAttributes()
];
}

$customAttributes = json_encode($attributes);
$customAttributes = JsonSerialization::encode($attributes);
$this->storeConfig->setCustomAttributes($customAttributes);
}

Expand Down
7 changes: 4 additions & 3 deletions Cron/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doofinder\Feed\Model\ResourceModel\ChangedProduct\CollectionFactory as ChangedProductCollectionFactory;
use Magento\Framework\Indexer\SaveHandler\Batch;
use Psr\Log\LoggerInterface;
use Doofinder\Feed\Helper\JsonSerialization;

class Processor
{
Expand Down Expand Up @@ -107,7 +108,7 @@ private function createProducts($store, $indice)
if (count($items)) {
try {
$this->logger->debug('[CreateInBulk]');
$this->logger->debug(json_encode($items));
$this->logger->debug(JsonSerialization::encode($items));
$this->itemHelper->createItemsInBulk($items, $store, $indice);
} catch (\Exception $e) {
$this->logger->error(
Expand Down Expand Up @@ -136,7 +137,7 @@ private function updateProducts($store, $indice)
if (count($items)) {
try {
$this->logger->debug('[UpdateInBulk]');
$this->logger->debug(json_encode($items));
$this->logger->debug(JsonSerialization::encode($items));
$this->itemHelper->updateItemsInBulk($items, $store, $indice);
} catch (\Exception $e) {
$this->logger->error(
Expand Down Expand Up @@ -164,7 +165,7 @@ private function deleteProducts($store, $indice)
if (count($items)) {
try {
$this->logger->debug('[DeleteInBulk]');
$this->logger->debug(json_encode($items));
$this->logger->debug(JsonSerialization::encode($items));
$this->itemHelper->deleteItemsInBulk($items, $store, $indice);
} catch (\Exception $e) {
$this->logger->error(
Expand Down
27 changes: 27 additions & 0 deletions Helper/JsonSerialization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Doofinder\Feed\Helper;

class JsonSerialization
{

/**
* Encodes PHP data structure to a JSON string using available JSON encoding classes
*
* @param mixed $data The PHP data structure to encode into JSON format
*
* @return string The JSON string representation of the input data
*/
public static function encode($data)
{
$json = null;
if (class_exists('\Laminas\Json\Json')) {
$json = \Laminas\Json\Json::encode($data);
} else {
$json = \Zend_Json::encode($data);
}
return $json;
}
}
3 changes: 2 additions & 1 deletion Helper/StoreConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Magento\Eav\Model\Config;
use Doofinder\Feed\Errors\NotFound;
use Magento\Backend\Helper\Data;
use Doofinder\Feed\Helper\JsonSerialization;

/**
* Store config helper
Expand Down Expand Up @@ -911,7 +912,7 @@ public function getIndexationStatus(int $storeId): array {
*/
public function setIndexationStatus(array $status, int $storeId){
$status = $this->indexationHelper->sanitizeProcessTaskStatus($status);
$status = json_encode($status);
$status = JsonSerialization::encode($status);
$this->configWriter->save(self::INDEXATION_STATUS, $status, ScopeInterface::SCOPE_STORES, $storeId);
}

Expand Down
7 changes: 5 additions & 2 deletions Model/Data/StoreStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ class StoreStruct implements JsonSerializable {
private $code;
private $language;
private $currency;
private $installationId;

public function __construct(int $id, string $code, string $language, string $currency)
public function __construct(int $id, string $code, string $language, string $currency, string $installationId)
{
$this->id = $id;
$this->code = $code;
$this->language = $language;
$this->currency = $currency;
$this->installationId = $installationId;
}

public function jsonSerialize(): array
Expand All @@ -25,7 +27,8 @@ public function jsonSerialize(): array
'id' => $this->id,
'code' => $this->code,
'language' => $this->language,
'currency' => $this->currency
'currency' => $this->currency,
'installationId' => $this->installationId
);
}
}
5 changes: 1 addition & 4 deletions Model/Data/WebsiteStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ class WebsiteStruct implements JsonSerializable {
private $id;
private $name;
private $code;
private $installationId;
private $storeStructs;

public function __construct(int $id, string $name, string $code, string $installationId = null, array $storeStructs)
public function __construct(int $id, string $name, string $code, array $storeStructs)
{
$this->id = $id;
$this->name = $name;
$this->code = $code;
$this->installationId = $installationId;
$this->storeStructs = $storeStructs;
}

Expand All @@ -27,7 +25,6 @@ public function jsonSerialize(): array
'id' => $this->id,
'name' => $this->name,
'code' => $this->code,
'installation_id' => $this->installationId,
'stores' => $this->storeStructs
);
}
Expand Down
17 changes: 10 additions & 7 deletions Model/ModuleData.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,33 @@ private function getWebsiteStructures()
$storeStructs = [];
$websiteId = $website->getId();
foreach ($this->storeConfig->getWebsiteStores($websiteId) as $store) {
$storeCode = $store->getCode();
$storeStructs[] = new StoreStruct(
$store->getId(),
$store->getCode(),
$storeCode,
$this->storeConfig->getLanguageFromStore($store),
$store->getCurrentCurrencyCode()
$store->getCurrentCurrencyCode(),
$this->getInstallationId($store),

);
}
$websiteStructs[] = new WebsiteStruct(
$websiteId,
$website->getName(),
$website->getCode(),
$this->getInstallationId($websiteId),
$storeStructs
);
}
return $websiteStructs;
}

private function getInstallationId($websiteId)
private function getInstallationId($store)
{
return $this->scopeConfig->getValue(
$storeGroupId = $store->getStoreGroupId();
return $this->storeConfig->getValueFromConfig(
'doofinder_config_config/doofinder_layer/installation_id',
ScopeInterface::SCOPE_WEBSITE,
$websiteId
ScopeInterface::SCOPE_GROUP,
$storeGroupId
);
}
}
40 changes: 22 additions & 18 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,29 @@ public function __construct(
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();

if (version_compare($context->getVersion(), '0.10.7', '<')) {
$groupCollection = $this->groupCollectionFactory->create();
$scriptIdPath = 'doofinder_config_config/doofinder_layer/script';
$installationIdPath = 'doofinder_config_config/doofinder_layer/installation_id';

foreach ($groupCollection as $group) {
$websiteId = $group->getWebsiteId();
$script = $this->scopeConfig->getValue($scriptIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
$this->configWriter->save($scriptIdPath, $script, ScopeInterface::SCOPE_GROUP, $group->getId());
$this->configWriter->delete($scriptIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);

$installationId = $this->scopeConfig->getValue($installationIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
$this->configWriter->save($installationIdPath, $installation_id, ScopeInterface::SCOPE_GROUP, $group->getId());
$this->configWriter->delete($installationIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);

if(version_compare($context->getVersion(), '0.0.1', '>')) {
if (version_compare($context->getVersion(), '0.10. 7', '<')) {
$groupCollection = $this->groupCollectionFactory->create();
$scriptIdPath = 'doofinder_config_config/doofinder_layer/script';
$installationIdPath = 'doofinder_config_config/doofinder_layer/installation_id';

foreach ($groupCollection as $group) {
$websiteId = $group->getWebsiteId();
$script = $this->scopeConfig->getValue($scriptIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
if(!empty($script)){
$this->configWriter->save($scriptIdPath, $script, ScopeInterface::SCOPE_GROUP, $group->getId());
$this->configWriter->delete($scriptIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
}

$installationId = $this->scopeConfig->getValue($installationIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
if(!empty($installationId)){
$this->configWriter->save($installationIdPath, $installationId, ScopeInterface::SCOPE_GROUP, $group->getId());
$this->configWriter->delete($installationIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
}
}
}
$setup->endSetup();
}

$setup->endSetup();
}

}

0 comments on commit b235eb9

Please sign in to comment.