Skip to content

Commit 184d66f

Browse files
authored
Update Category Merchandising (#795)
1 parent a37d31f commit 184d66f

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed

Block/Adminhtml/Category/Merchandising.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,24 @@ public function getCurrentStore()
116116

117117
return $this->storeManager->getDefaultStoreView();
118118
}
119+
120+
/**
121+
* @return string
122+
*/
123+
public function getPageModeOnly()
124+
{
125+
return Category::DM_PAGE;
126+
}
127+
128+
/**
129+
* @return bool
130+
*/
131+
public function canDisplayProducts()
132+
{
133+
if ($this->getCategory()->getDisplayMode() == $this->getPageModeOnly()) {
134+
return false;
135+
}
136+
137+
return true;
138+
}
119139
}

view/adminhtml/templates/catalog/category/edit/merchandising.phtml

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ $configHelper = $this->getConfigHelper();
77
?>
88

99
<div class="algolia_block blue icon-documentation">
10-
<b>Merchandising tool</b> allows you to promote specific products on your category page.
11-
It is based on <b>query rules</b>, as it helps you influence the results for a given query
10+
<strong>Merchandising tool</strong> allows you to promote specific products on your category page.
11+
It is based on <strong>query rules</strong>, as it helps you influence the results for a given query
1212
(here, an empty search on a category). For each category you merchandize, a new query rule will be created.
1313
<br><br>
1414
Find out more about Algolia Merchandising, please refer to <a href="https://www.algolia.com/doc/integration/magento-2/merchandising/category-merchandising/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link" target="_blank">documentation</a>.
@@ -40,17 +40,22 @@ $configHelper = $this->getConfigHelper();
4040

4141
<div class="algolia_block icon-stars">
4242
To merchandise products using Algolia
43-
you need to enable <b>Instant search</b> with <b>Replace category pages</b> feature.
43+
you need to enable <strong>Instant search</strong> with <strong>Replace category pages</strong> feature.
4444
You can do it in Algolia's <a href="<?php echo $instantSearchLink; ?>" target="_blank">Instant Search configuration</a>.
4545
<br><br>
46-
<b>Instant search</b> with enabled <b>Replace category pages</b> feature gives your customers a great experience
46+
<strong>Instant search</strong> with enabled <strong>Replace category pages</strong> feature gives your customers a great experience
4747
while browsing your catalog. It enables your customers to search and filter for products at real time resulting
4848
in better customer journey. With the speed and relevancy of Algolia your customers are more likely to purchase
4949
and enjoy the shopping on your store(s).
5050
</div>
5151

5252
<?php return; endif; ?>
5353

54+
<div class="algolia_block display-product-msg icon-warning" <?php echo !$this->canDisplayProducts() ?: 'style="display:none;"' ?>>
55+
<p><strong>Products are not displayed for this category</strong></p>
56+
<p>Please note that you've selected "Static block only" in Display Settings. Since no products are shown on the page, changes you make with Algolia Merchandising won't be visible to your customers.</p>
57+
</div>
58+
5459
<?php
5560

5661
$indexName = $this->getCoreHelper()->getBaseIndexName();
@@ -248,6 +253,8 @@ $isConfig = [
248253
initAutocomplete();
249254

250255
initSortableTable();
256+
257+
checkCurrentPins();
251258
});
252259

253260
search.start();
@@ -264,6 +271,7 @@ $isConfig = [
264271
$(this).closest('tr').removeClass('pinned');
265272

266273
regeneratePositionsValue();
274+
checkCurrentPins();
267275

268276
e.preventDefault();
269277
return false;
@@ -356,6 +364,12 @@ $isConfig = [
356364
};
357365

358366
var pinIt = function($row) {
367+
368+
if (!validatePin()) {
369+
alert('Algolia Warning: You have reached the 50 pins limit. Your pin has not been added.');
370+
return false;
371+
}
372+
359373
if ($row.hasClass('pinned') === false) {
360374
$row.addClass('pinned');
361375
}
@@ -384,6 +398,38 @@ $isConfig = [
384398

385399
return ui;
386400
};
401+
402+
var validatePin = function() {
403+
return $('.algolia_merchandising_items_table tr.pinned').length < 50;
404+
}
405+
406+
var checkCurrentPins = function() {
407+
408+
if ($('.algolia_merchandising_items_table tr.pinned').length > 50) {
409+
410+
if (!$('.pin-limit-warning').length) {
411+
var html = '<div class="algolia_block pin-limit-warning icon-warning">' +
412+
'<p><strong>Warning</strong></p>';
413+
html += '<p>You have more than 50 pins set. Please remove some pins so that you can' +
414+
' save your merchandising changes.</p>';
415+
html +='</div>';
416+
417+
$('#algolia_merchandising_search_box').before(html);
418+
}
419+
420+
return false;
421+
422+
} else {
423+
424+
if ($('.pin-limit-warning').length > 0) {
425+
$('.pin-limit-warning').remove();
426+
}
427+
428+
return true;
429+
}
430+
}
431+
387432
});
388433
});
434+
389435
</script>

view/adminhtml/web/css/common.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
border-radius: 5px;
1616
padding: 15px 20px 15px 93px;
1717
line-height: 21px;
18+
margin-bottom: 10px;
1819
}
1920

2021
.algolia_block.blue {

view/adminhtml/web/css/merchandising.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
.algoliasearch-merchandising-options {
4949
max-width: 1400px;
50+
margin: 70px auto 75px;
5051
}
5152

5253
}

0 commit comments

Comments
 (0)