Skip to content

Commit d277cb5

Browse files
committed
WZ-4212: Added more details in Wizzy section on Product Details Page - When a Product is Skipped
1 parent 43b16f3 commit d277cb5

File tree

3 files changed

+73
-34
lines changed

3 files changed

+73
-34
lines changed

Block/Adminhtml/Sync/Status.php

+24-11
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@
88
use Magento\Store\Model\StoreManagerInterface;
99
use Wizzy\Search\Services\Store\StoreManager;
1010
use Magento\Framework\View\Element\Template;
11+
use Wizzy\Search\Services\Model\SyncSkippedEntities;
1112

1213
class Status extends Template
1314
{
1415
protected $_template = 'sync/status.phtml';
16+
public $syncSkippedEntities;
1517
public function __construct(
1618
EntitiesSync $entitiesSync,
1719
Context $context,
1820
Registry $registry,
1921
StoreManagerInterface $storeManager,
2022
StoreManager $_storemanager,
23+
SyncSkippedEntities $syncSkippedEntities,
2124
array $data = []
2225
) {
2326
$this->entitiesSync = $entitiesSync;
2427
$this->registry = $registry;
2528
$this->storeManager = $storeManager;
2629
$this->_storemanager = $_storemanager;
30+
$this->syncSkippedEntities = $syncSkippedEntities;
2731
parent::__construct($context, $data);
2832
}
2933

@@ -32,22 +36,31 @@ public function getSyncStatus()
3236
$entityId = $this->registry->registry('current_product')->getId();
3337
$storeId = $this->storeManager->getStore()->getId();
3438
$storeIds = $this->_storemanager->getToSyncStoreIds($storeId);
35-
$syncResults = [];
36-
39+
$entitiesSyncStatus_ = [];
3740
foreach ($storeIds as $storeId) {
38-
$entityStatus = $this->entitiesSync->getEntitiesSyncStatus($entityId, $storeId, 'product');
39-
if (count($entityStatus) == 0) {
40-
$entityStatus = [
41-
[
41+
$entitiesSyncStatus = $this->entitiesSync->getEntitiesSyncStatus($entityId, $storeId, 'product');
42+
$skippedEntitiesData = $this->syncSkippedEntities->getSkippedEntityById($storeId, $entityId, 'product');
43+
44+
if ($entitiesSyncStatus) {
45+
foreach ($entitiesSyncStatus as $entitySyncStatus) {
46+
$entitiesSyncStatus_[] = [
47+
"store_id" => $entitySyncStatus['store_id'],
48+
"status" => $entitySyncStatus['status'],
49+
"updated_at" => $entitySyncStatus['updated_at'],
50+
"skipped_data" => ($skippedEntitiesData && !empty($skippedEntitiesData))
51+
? $skippedEntitiesData
52+
: null,
53+
];
54+
}
55+
} else {
56+
$entitiesSyncStatus_[] = [
4257
"store_id" => $storeId,
4358
"status" => -1,
44-
"updated_at" => " -"
45-
]
59+
"updated_at" => "-"
4660
];
4761
}
48-
$syncResults[] = $entityStatus;
49-
}
5062

51-
return $syncResults;
63+
}
64+
return $entitiesSyncStatus_;
5265
}
5366
}

Services/Model/SyncSkippedEntities.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Wizzy\Search\Helpers\DB\WizzyTables;
66
use Wizzy\Search\Model\SyncSkippedEntitiesFactory;
77
use Wizzy\Search\Services\DB\ConnectionManager;
8+
use Wizzy\Search\Model\ResourceModel\SyncSkippedEntities\CollectionFactory;
89

910
class SyncSkippedEntities
1011
{
@@ -13,13 +14,16 @@ class SyncSkippedEntities
1314

1415
private $syncSkippedEntitiesFactory;
1516
private $connectionManager;
17+
public $syncSkippedEntitiesCollectionFactory;
1618

1719
public function __construct(
1820
SyncSkippedEntitiesFactory $syncSkippedEntitiesFactory,
19-
ConnectionManager $connectionManager
21+
ConnectionManager $connectionManager,
22+
CollectionFactory $syncSkippedEntitiesCollectionFactory
2023
) {
2124
$this->syncSkippedEntitiesFactory = $syncSkippedEntitiesFactory;
2225
$this->connectionManager = $connectionManager;
26+
$this->syncSkippedEntitiesCollectionFactory = $syncSkippedEntitiesCollectionFactory;
2327
}
2428

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

5862
return $entities;
5963
}
64+
public function getSkippedEntityById($storeId, $entityId, $entityType = null)
65+
{
66+
$collection = $this->syncSkippedEntitiesCollectionFactory->create();
67+
$collection->addFieldToFilter('store_id', $storeId);
68+
$collection->addFieldToFilter('entity_id', $entityId);
69+
70+
if ($entityType !== null) {
71+
$collection->addFieldToFilter('entity_type', $entityType);
72+
}
73+
74+
$skippedEntities = null;
75+
foreach ($collection->getItems() as $item) {
76+
$skippedEntities = $item->getData('entity_data');
77+
}
78+
79+
return $skippedEntities;
80+
}
6081
}
+27-22
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
<?php
22
/** @var $block \Magento\Framework\View\Element\Template */
33
$syncResults = $block->getSyncStatus();
4-
foreach ($syncResults as $syncResult) {
5-
foreach ($syncResult as $sync) { ?>
6-
<div class="admin__fieldset-wrapper-title">
7-
<p class="product-id"> <?= "<b>Store ID</b> : ",$sync['store_id'];?></p>
8-
<span><?= $block->escapeHtmlAttr(('Sync Status :'));?></span>
9-
<?php if ($sync['status'] == 1) {
10-
?> <b><?= $block->escapeHtmlAttr(('Synced'));?></b> <?php
11-
} elseif ($sync['status'] == 0) {
12-
?> <b><?= $block->escapeHtmlAttr(('In sync'));?></b> <?php
13-
} elseif ($sync['status'] == -1) {
14-
?> <b><?= $block->escapeHtmlAttr(('No entities to be synced !'));?></b> <?php
15-
}
16-
?>
17-
</div>
18-
<div class="admin__fieldset-wrapper-title">
19-
<span><?= $block->escapeHtmlAttr(('Last Updated At :'));?></span>
20-
<b> <?= "", $sync['updated_at']; ?></b>
21-
</div> </br>
22-
<?php }
23-
}
24-
25-
?>
4+
foreach ($syncResults as $syncResult) { ?>
5+
<div class="admin__fieldset-wrapper-title">
6+
<p class="product-id"><?= "<b>Store ID</b> : ", $block->escapeHtml($syncResult['store_id']); ?></p>
7+
<span><?= $block->escapeHtml('Sync Status :'); ?></span>
8+
<?php
9+
if ($syncResult['status'] == 1 && !$syncResult['skipped_data']) { ?>
10+
<b><?= $block->escapeHtml('Synced'); ?></b>
11+
<?php
12+
} elseif ($syncResult['status'] == 0) { ?>
13+
<b><?= $block->escapeHtml('In sync'); ?></b>
14+
<?php
15+
} elseif ($syncResult['status'] == -1) { ?>
16+
<b><?= $block->escapeHtml('Product is not added in sync yet'); ?></b>
17+
<?php
18+
} elseif ($syncResult['skipped_data']) { ?>
19+
<b><?= $block->escapeHtml('Product Skipped during Sync'); ?></b>
20+
<div class="admin__fieldset-note admin__scope-old"></div>
21+
<span><?= $block->escapeHtml('Reason: '); ?></span>
22+
<b><?= $block->escapeHtml($syncResult['skipped_data']); ?></b>
23+
<?php } ?>
24+
</div>
25+
<div class="admin__fieldset-wrapper-title">
26+
<span><?= $block->escapeHtml('Last Updated At :'); ?></span>
27+
<b><?= $block->escapeHtml($syncResult['updated_at']); ?></b>
28+
</div>
29+
<br>
30+
<?php } ?>

0 commit comments

Comments
 (0)