Skip to content

Commit f5d7f97

Browse files
authored
Merge pull request #1258 from algolia/develop
Release/3.9.0
2 parents 923dcaa + b175117 commit f5d7f97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1756
-924
lines changed

Block/Cart/Recommend.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Block\Cart;
4+
5+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
6+
use Magento\Checkout\Model\Session;
7+
use Magento\Framework\View\Element\Template;
8+
use Magento\Framework\View\Element\Template\Context;
9+
10+
class Recommend extends Template
11+
{
12+
/**
13+
* @var Session
14+
*/
15+
protected $checkoutSession;
16+
17+
/**
18+
* @var ConfigHelper
19+
*/
20+
protected $configHelper;
21+
22+
/**
23+
* @param Context $context
24+
* @param Session $checkoutSession
25+
* @param ConfigHelper $configHelper
26+
* @param array $data
27+
*/
28+
public function __construct(
29+
Context $context,
30+
Session $checkoutSession,
31+
ConfigHelper $configHelper,
32+
array $data = []
33+
) {
34+
parent::__construct($context, $data);
35+
$this->checkoutSession = $checkoutSession;
36+
$this->configHelper = $configHelper;
37+
}
38+
39+
/**
40+
* @return array
41+
* @throws \Magento\Framework\Exception\LocalizedException
42+
* @throws \Magento\Framework\Exception\NoSuchEntityException
43+
*/
44+
public function getAllCartItems()
45+
{
46+
$cartItems = array();
47+
$itemCollection = $this->checkoutSession->getQuote()->getAllVisibleItems();
48+
foreach ( $itemCollection as $item) {
49+
$cartItems[] = $item->getProductId();
50+
}
51+
return array_unique($cartItems);
52+
}
53+
54+
}

Block/Configuration.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,20 @@ public function getConfiguration()
165165
'recommend' => [
166166
'enabledFBT' => $config->isRecommendFrequentlyBroughtTogetherEnabled(),
167167
'enabledRelated' => $config->isRecommendRelatedProductsEnabled(),
168+
'enabledFBTInCart' => $config->isRecommendFrequentlyBroughtTogetherEnabledOnCartPage(),
169+
'enabledRelatedInCart' => $config->isRecommendRelatedProductsEnabledOnCartPage(),
168170
'limitFBTProducts' => $config->getNumberOfFrequentlyBoughtTogetherProducts(),
169171
'limitRelatedProducts' => $config->getNumberOfRelatedProducts(),
172+
'limitTrendingItems' => $config->getNumberOfTrendingItems(),
173+
'enabledTrendItems' => $config->isRecommendTrendingItemsEnabled(),
174+
'trendItemFacetName' => $config->getTrendingItemsFacetName(),
175+
'trendItemFacetValue' => $config->getTrendingItemsFacetValue(),
176+
'isTrendItemsEnabledInPDP' => $config->isTrendItemsEnabledInPDP(),
177+
'isTrendItemsEnabledInCartPage' => $config->isTrendItemsEnabledInShoppingCart(),
178+
'isAddToCartEnabledInFBT' => $config->isAddToCartEnabledInFrequentlyBoughtTogether(),
179+
'isAddToCartEnabledInRelatedProduct' => $config->isAddToCartEnabledInRelatedProducts(),
180+
'isAddToCartEnabledInTrendsItem' => $config->isAddToCartEnabledInTrendsItem(),
181+
'addToCartParams' => $addToCartParams,
170182
],
171183
'extensionVersion' => $config->getExtensionVersion(),
172184
'applicationId' => $config->getApplicationID(),

Block/Widget/TrendsItem.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Block\Widget;
4+
5+
use Magento\Framework\Math\Random;
6+
use Magento\Framework\View\Element\Template;
7+
use Magento\Framework\View\Element\Template\Context;
8+
use Magento\Widget\Block\BlockInterface;
9+
10+
class TrendsItem extends Template implements BlockInterface
11+
{
12+
protected $_template = 'recommend/widget/trends-item.phtml';
13+
14+
/**
15+
* @param Context $context
16+
* @param Random $mathRandom
17+
* @param array $data
18+
*/
19+
public function __construct(
20+
Context $context,
21+
Random $mathRandom,
22+
array $data = []
23+
) {
24+
$this->mathRandom = $mathRandom;
25+
parent::__construct(
26+
$context,
27+
$data
28+
);
29+
}
30+
31+
/**
32+
* @return string
33+
* @throws \Magento\Framework\Exception\LocalizedException
34+
*/
35+
public function generateUniqueToken()
36+
{
37+
return $this->mathRandom->getRandomString(5);
38+
}
39+
}

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# CHANGE LOG
22

3+
## 3.9.0
4+
5+
### New Features
6+
- Trends Recommendations: We have added the ability to add Trending Items to the PDP and the shopping cart page. More information can be found <a href="https://www.algolia.com/doc/integration/magento-2/how-it-works/recommend/?client=php#trending-items">here</a>. We also provide a <a href="https://www.algolia.com/doc/integration/magento-2/how-it-works/recommend/?client=php#configure-the-trending-items-widget">Trending Items widget</a> that can be used to add Trending Items to any page.
7+
- Added an option to show Recommend Related and Frequently Bought Together products on the shopping cart page.
8+
- Added an option to enable the Add To Cart button for all types of recommended products (Related, Frequently Bought Together, and Trending Items).
9+
- Added Algolia Recommend dashboard link on the Magento dashboard
10+
- Added Algolia Search extensions release notes link in the Magento admin to be able to access release notes easily.
11+
- Implemented Recommended Product click event using personalization.
12+
13+
### UPDATES
14+
- Refactored the Algolia Insight functionality in the extension code base per Magento standard (moved the observer directory in the module root).
15+
- Refactored the autocomplete 2.0 code to make it more developer-friendly to allow for customization per customer needs.
16+
- Collated all autocomplete-specific logic in a single autocomplete.js file and segregated JS-based templates that control the layout of the different autocomplete sources to be more developer-friendly. This enables the customers to easily override the layout of the autocomplete menu in the custom theme and the extension.
17+
18+
19+
### FIXES
20+
- Click event in autocomplete
21+
- Autocomplete errors if the product is not assigned a category and indexed into Algolia
22+
- Issues with the price attribute in autocomplete when price attribute is set to Non-Retrievable
23+
- The autocomplete in Query merchandiser (in the Magento admin) shows products from the default store on switching stores [Fixed]
24+
- Issues with triggering Add to Cart Conversion for Configurable Product
25+
- Issues with indexer not updating when product goes out of stock when the last of the inventory is done
26+
27+
328
## 3.8.1
429

530
### UPDATES

Helper/ConfigHelper.php

Lines changed: 152 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,23 @@ class ConfigHelper
109109

110110
public const DEFAULT_MAX_RECORD_SIZE = 10000;
111111

112-
public const IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED = 'algoliasearch_recommend/recommend/is_frequently_bought_together_enabled';
113-
public const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED = 'algoliasearch_recommend/recommend/is_related_products_enabled';
114-
public const NUM_OF_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_PRODUCTS = 'algoliasearch_recommend/recommend/num_of_frequently_bought_together_products';
115-
public const NUM_OF_RECOMMEND_RELATED_PRODUCTS = 'algoliasearch_recommend/recommend/num_of_related_products';
116-
public const IS_REMOVE_RELATED_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/is_remove_core_related_products_block';
117-
public const IS_REMOVE_UPSELL_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/is_remove_core_upsell_products_block';
112+
protected const IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED = 'algoliasearch_recommend/recommend/frequently_bought_together/is_frequently_bought_together_enabled';
113+
protected const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED = 'algoliasearch_recommend/recommend/related_product/is_related_products_enabled';
114+
protected const IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED_ON_CART_PAGE = 'algoliasearch_recommend/recommend/frequently_bought_together/is_frequently_bought_together_enabled_in_cart_page';
115+
protected const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED_ON_CART_PAGE = 'algoliasearch_recommend/recommend/related_product/is_related_products_enabled_in_cart_page';
116+
protected const NUM_OF_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_PRODUCTS = 'algoliasearch_recommend/recommend/frequently_bought_together/num_of_frequently_bought_together_products';
117+
protected const NUM_OF_RECOMMEND_RELATED_PRODUCTS = 'algoliasearch_recommend/recommend/related_product/num_of_related_products';
118+
protected const IS_REMOVE_RELATED_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/related_product/is_remove_core_related_products_block';
119+
protected const IS_REMOVE_UPSELL_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/frequently_bought_together/is_remove_core_upsell_products_block';
120+
protected const IS_RECOMMEND_TRENDING_ITEMS_ENABLED = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled';
121+
protected const NUM_OF_TRENDING_ITEMS = 'algoliasearch_recommend/recommend/trends_item/num_of_trending_items';
122+
protected const TREND_ITEMS_FACET_NAME = 'algoliasearch_recommend/recommend/trends_item/facet_name';
123+
protected const TREND_ITEMS_FACET_VALUE = 'algoliasearch_recommend/recommend/trends_item/facet_value';
124+
protected const IS_TREND_ITEMS_ENABLED_IN_PDP = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled_on_pdp';
125+
protected const IS_TREND_ITEMS_ENABLED_IN_SHOPPING_CART = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled_on_cart_page';
126+
protected const IS_ADDTOCART_ENABLED_IN_FREQUENTLY_BOUGHT_TOGETHER = 'algoliasearch_recommend/recommend/frequently_bought_together/is_addtocart_enabled';
127+
protected const IS_ADDTOCART_ENABLED_IN_RELATED_PRODUCTS= 'algoliasearch_recommend/recommend/related_product/is_addtocart_enabled';
128+
protected const IS_ADDTOCART_ENABLED_IN_TRENDS_ITEM= 'algoliasearch_recommend/recommend/trends_item/is_addtocart_enabled';
118129

119130
private $configInterface;
120131
private $objectManager;
@@ -452,6 +463,26 @@ public function isRecommendRelatedProductsEnabled($storeId = null)
452463
return $this->configInterface->isSetFlag(self::IS_RECOMMEND_RELATED_PRODUCTS_ENABLED, ScopeInterface::SCOPE_STORE, $storeId);
453464
}
454465

466+
/**
467+
* @param int $storeId
468+
*
469+
* @return int
470+
*/
471+
public function isRecommendFrequentlyBroughtTogetherEnabledOnCartPage($storeId = null)
472+
{
473+
return $this->configInterface->isSetFlag(self::IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED_ON_CART_PAGE, ScopeInterface::SCOPE_STORE, $storeId);
474+
}
475+
476+
/**
477+
* @param int $storeId
478+
*
479+
* @return int
480+
*/
481+
public function isRecommendRelatedProductsEnabledOnCartPage($storeId = null)
482+
{
483+
return $this->configInterface->isSetFlag(self::IS_RECOMMEND_RELATED_PRODUCTS_ENABLED_ON_CART_PAGE, ScopeInterface::SCOPE_STORE, $storeId);
484+
}
485+
455486
/**
456487
* @param int $storeId
457488
*
@@ -499,6 +530,121 @@ public function getNumberOfFrequentlyBoughtTogetherProducts($storeId = null)
499530
$storeId
500531
);
501532
}
533+
534+
/**
535+
* @param int $storeId
536+
*
537+
* @return int
538+
*/
539+
public function isRecommendTrendingItemsEnabled($storeId = null)
540+
{
541+
return (int) $this->configInterface->getValue(
542+
self::IS_RECOMMEND_TRENDING_ITEMS_ENABLED,
543+
ScopeInterface::SCOPE_STORE,
544+
$storeId
545+
);
546+
}
547+
548+
/**
549+
* @param int $storeId
550+
*
551+
* @return int
552+
*/
553+
public function getNumberOfTrendingItems($storeId = null)
554+
{
555+
return (int) $this->configInterface->getValue(
556+
self::NUM_OF_TRENDING_ITEMS,
557+
ScopeInterface::SCOPE_STORE,
558+
$storeId
559+
);
560+
}
561+
562+
563+
/**
564+
* @param int $storeId
565+
*
566+
* @return string
567+
*/
568+
public function getTrendingItemsFacetName($storeId = null)
569+
{
570+
return $this->configInterface->getValue(
571+
self::TREND_ITEMS_FACET_NAME,
572+
ScopeInterface::SCOPE_STORE,
573+
$storeId
574+
);
575+
}
576+
577+
/**
578+
* @param int $storeId
579+
*
580+
* @return string
581+
*/
582+
public function getTrendingItemsFacetValue($storeId = null)
583+
{
584+
return $this->configInterface->getValue(
585+
self::TREND_ITEMS_FACET_VALUE,
586+
ScopeInterface::SCOPE_STORE,
587+
$storeId
588+
);
589+
}
590+
591+
/**
592+
* @param int $storeId
593+
*
594+
* @return int
595+
*/
596+
public function isTrendItemsEnabledInPDP($storeId = null)
597+
{
598+
return (int) $this->configInterface->getValue(
599+
self::IS_TREND_ITEMS_ENABLED_IN_PDP,
600+
ScopeInterface::SCOPE_STORE,
601+
$storeId
602+
);
603+
}
604+
605+
/**
606+
* @param int $storeId
607+
*
608+
* @return int
609+
*/
610+
public function isTrendItemsEnabledInShoppingCart($storeId = null)
611+
{
612+
return (int) $this->configInterface->getValue(
613+
self::IS_TREND_ITEMS_ENABLED_IN_SHOPPING_CART,
614+
ScopeInterface::SCOPE_STORE,
615+
$storeId
616+
);
617+
}
618+
619+
/**
620+
* @param int $storeId
621+
*
622+
* @return int
623+
*/
624+
public function isAddToCartEnabledInFrequentlyBoughtTogether($storeId = null)
625+
{
626+
return $this->configInterface->isSetFlag(self::IS_ADDTOCART_ENABLED_IN_FREQUENTLY_BOUGHT_TOGETHER, ScopeInterface::SCOPE_STORE, $storeId);
627+
}
628+
629+
/**
630+
* @param int $storeId
631+
*
632+
* @return int
633+
*/
634+
public function isAddToCartEnabledInRelatedProducts($storeId = null)
635+
{
636+
return $this->configInterface->isSetFlag(self::IS_ADDTOCART_ENABLED_IN_RELATED_PRODUCTS, ScopeInterface::SCOPE_STORE, $storeId);
637+
}
638+
639+
/**
640+
* @param int $storeId
641+
*
642+
* @return int
643+
*/
644+
public function isAddToCartEnabledInTrendsItem($storeId = null)
645+
{
646+
return $this->configInterface->isSetFlag(self::IS_ADDTOCART_ENABLED_IN_TRENDS_ITEM, ScopeInterface::SCOPE_STORE, $storeId);
647+
}
502648

503649
public function useAdaptiveImage($storeId = null)
504650
{

Helper/Configuration/AssetHelper.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ class AssetHelper extends \Magento\Framework\App\Helper\AbstractHelper
7171
'icon' => 'iconFaq',
7272
],
7373
[
74-
'title' => 'Issues',
75-
'url' => 'https://github.com/algolia/algoliasearch-magento-2/issues/',
74+
'title' => 'Support',
75+
'url' => 'https://www.algolia.com/support/?contact=',
7676
'icon' => 'iconIssues',
7777
],
78+
[
79+
'title' => 'Release Notes',
80+
'url' => 'https://github.com/algolia/algoliasearch-magento-2/releases',
81+
'icon' => 'iconDocs',
82+
]
7883
],
7984
'algoliasearch_autocomplete' => [
8085
[

Helper/Configuration/NoticeHelper.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper
4343
'getVersionNotice',
4444
'getClickAnalyticsNotice',
4545
'getPersonalizationNotice',
46+
'getRecommendNotice',
4647
];
4748

4849
/** @var array[] */
@@ -317,4 +318,26 @@ public function getNewVersionNotification()
317318
{
318319
return $this->extensionNotification->checkVersion();
319320
}
321+
322+
/**
323+
* Function created for adding the Algolia Dashboard link in the Magento recommend system configuration
324+
* @return void
325+
*/
326+
protected function getRecommendNotice()
327+
{
328+
if (!$this->configHelper->getApplicationID()) {
329+
return;
330+
}
331+
$noticeContent = '<div class="algolia-perso"><br/><h2>Algolia Dashboard</h2>
332+
<p>Configure your Recommend models on the <a href="https://www.algolia.com/apps/'.$this->configHelper->getApplicationID().'/recommend/models" target="_blank`">Algolia Dashboard</a></p></div>';
333+
334+
$selector = '#algoliasearch_recommend_recommend';
335+
$method = 'after';
336+
337+
$this->notices[] = [
338+
'selector' => $selector,
339+
'method' => $method,
340+
'message' => $noticeContent,
341+
];
342+
}
320343
}

Helper/Configuration/PersonalizationHelper.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ class PersonalizationHelper extends \Magento\Framework\App\Helper\AbstractHelper
3434
/** @var ConfigResourceInterface */
3535
private $configResourceInterface;
3636

37+
/**
38+
* @param \Magento\Framework\App\Helper\Context $context
39+
* @param ScopeConfigInterface $configInterface
40+
* @param ConfigResourceInterface $configResourceInterface
41+
*/
3742
public function __construct(
3843
\Magento\Framework\App\Helper\Context $context,
39-
ScopeConfigInterface $configInterface,
40-
ConfigResourceInterface $configResourceInterface
44+
ScopeConfigInterface $configInterface,
45+
ConfigResourceInterface $configResourceInterface
4146
) {
4247
$this->configInterface = $configInterface;
4348
$this->configResourceInterface = $configResourceInterface;

0 commit comments

Comments
 (0)