Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WZ-4212: Added more details in Wizzy section on Product Details Page … #145

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions Block/Adminhtml/Sync/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@
use Magento\Store\Model\StoreManagerInterface;
use Wizzy\Search\Services\Store\StoreManager;
use Magento\Framework\View\Element\Template;
use Wizzy\Search\Services\Model\SyncSkippedEntities;

class Status extends Template
{
protected $_template = 'sync/status.phtml';
public $syncSkippedEntities;
public function __construct(
EntitiesSync $entitiesSync,
Context $context,
Registry $registry,
StoreManagerInterface $storeManager,
StoreManager $_storemanager,
SyncSkippedEntities $syncSkippedEntities,
array $data = []
) {
$this->entitiesSync = $entitiesSync;
$this->registry = $registry;
$this->storeManager = $storeManager;
$this->_storemanager = $_storemanager;
$this->syncSkippedEntities = $syncSkippedEntities;
parent::__construct($context, $data);
}

Expand All @@ -32,22 +36,31 @@ public function getSyncStatus()
$entityId = $this->registry->registry('current_product')->getId();
$storeId = $this->storeManager->getStore()->getId();
$storeIds = $this->_storemanager->getToSyncStoreIds($storeId);
$syncResults = [];

$entitiesSyncStatus_ = [];
foreach ($storeIds as $storeId) {
$entityStatus = $this->entitiesSync->getEntitiesSyncStatus($entityId, $storeId, 'product');
if (count($entityStatus) == 0) {
$entityStatus = [
[
$entitiesSyncStatus = $this->entitiesSync->getEntitiesSyncStatus($entityId, $storeId, 'product');
$skippedEntitiesData = $this->syncSkippedEntities->getSkippedEntityById($storeId, $entityId, 'product');

if ($entitiesSyncStatus) {
foreach ($entitiesSyncStatus as $entitySyncStatus) {
$entitiesSyncStatus_[] = [
"store_id" => $entitySyncStatus['store_id'],
"status" => $entitySyncStatus['status'],
"updated_at" => $entitySyncStatus['updated_at'],
"skipped_data" => ($skippedEntitiesData && !empty($skippedEntitiesData))
? $skippedEntitiesData
: null,
];
}
} else {
$entitiesSyncStatus_[] = [
"store_id" => $storeId,
"status" => -1,
"updated_at" => " -"
]
"updated_at" => "-"
];
}
$syncResults[] = $entityStatus;
}

return $syncResults;
}
return $entitiesSyncStatus_;
}
}
23 changes: 22 additions & 1 deletion Services/Model/SyncSkippedEntities.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Wizzy\Search\Helpers\DB\WizzyTables;
use Wizzy\Search\Model\SyncSkippedEntitiesFactory;
use Wizzy\Search\Services\DB\ConnectionManager;
use Wizzy\Search\Model\ResourceModel\SyncSkippedEntities\CollectionFactory;

class SyncSkippedEntities
{
Expand All @@ -13,13 +14,16 @@ class SyncSkippedEntities

private $syncSkippedEntitiesFactory;
private $connectionManager;
public $syncSkippedEntitiesCollectionFactory;

public function __construct(
SyncSkippedEntitiesFactory $syncSkippedEntitiesFactory,
ConnectionManager $connectionManager
ConnectionManager $connectionManager,
CollectionFactory $syncSkippedEntitiesCollectionFactory
) {
$this->syncSkippedEntitiesFactory = $syncSkippedEntitiesFactory;
$this->connectionManager = $connectionManager;
$this->syncSkippedEntitiesCollectionFactory = $syncSkippedEntitiesCollectionFactory;
}

public function addSkippedEntities($skippedEntities, $storeId, $entityType = self::ENTITY_TYPE_PRODUCT)
Expand Down Expand Up @@ -57,4 +61,21 @@ public function deleteSkippedEntities($entityIds, $storeId, $entityType = self::

return $entities;
}
public function getSkippedEntityById($storeId, $entityId, $entityType = null)
{
$collection = $this->syncSkippedEntitiesCollectionFactory->create();
$collection->addFieldToFilter('store_id', $storeId);
$collection->addFieldToFilter('entity_id', $entityId);

if ($entityType !== null) {
$collection->addFieldToFilter('entity_type', $entityType);
}

$skippedEntities = null;
foreach ($collection->getItems() as $item) {
$skippedEntities = $item->getData('entity_data');
}

return $skippedEntities;
}
}
49 changes: 27 additions & 22 deletions view/adminhtml/templates/sync/status.phtml
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
<?php
/** @var $block \Magento\Framework\View\Element\Template */
$syncResults = $block->getSyncStatus();
foreach ($syncResults as $syncResult) {
foreach ($syncResult as $sync) { ?>
<div class="admin__fieldset-wrapper-title">
<p class="product-id"> <?= "<b>Store ID</b> : ",$sync['store_id'];?></p>
<span><?= $block->escapeHtmlAttr(('Sync Status :'));?></span>
<?php if ($sync['status'] == 1) {
?> <b><?= $block->escapeHtmlAttr(('Synced'));?></b> <?php
} elseif ($sync['status'] == 0) {
?> <b><?= $block->escapeHtmlAttr(('In sync'));?></b> <?php
} elseif ($sync['status'] == -1) {
?> <b><?= $block->escapeHtmlAttr(('No entities to be synced !'));?></b> <?php
}
?>
</div>
<div class="admin__fieldset-wrapper-title">
<span><?= $block->escapeHtmlAttr(('Last Updated At :'));?></span>
<b> <?= "", $sync['updated_at']; ?></b>
</div> </br>
<?php }
}

?>
foreach ($syncResults as $syncResult) { ?>
<div class="admin__fieldset-wrapper-title">
<p class="product-id"><?= "<b>Store ID</b> : ", $block->escapeHtml($syncResult['store_id']); ?></p>
<span><?= $block->escapeHtml('Sync Status :'); ?></span>
<?php
if ($syncResult['status'] == 1 && !$syncResult['skipped_data']) { ?>
<b><?= $block->escapeHtml('Synced'); ?></b>
<?php
} elseif ($syncResult['status'] == 0) { ?>
<b><?= $block->escapeHtml('In sync'); ?></b>
<?php
} elseif ($syncResult['status'] == -1) { ?>
<b><?= $block->escapeHtml('Product is not added in sync yet'); ?></b>
<?php
} elseif ($syncResult['skipped_data']) { ?>
<b><?= $block->escapeHtml('Product Skipped during Sync'); ?></b>
<div class="admin__fieldset-note admin__scope-old"></div>
<span><?= $block->escapeHtml('Reason: '); ?></span>
<b><?= $block->escapeHtml($syncResult['skipped_data']); ?></b>
<?php } ?>
</div>
<div class="admin__fieldset-wrapper-title">
<span><?= $block->escapeHtml('Last Updated At :'); ?></span>
<b><?= $block->escapeHtml($syncResult['updated_at']); ?></b>
</div>
<br>
<?php } ?>
Loading