Skip to content

Commit

Permalink
Merge pull request #1258 from algolia/develop
Browse files Browse the repository at this point in the history
Release/3.9.0
  • Loading branch information
mohitalgolia authored Oct 28, 2022
2 parents 923dcaa + b175117 commit f5d7f97
Show file tree
Hide file tree
Showing 56 changed files with 1,756 additions and 924 deletions.
54 changes: 54 additions & 0 deletions Block/Cart/Recommend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Algolia\AlgoliaSearch\Block\Cart;

use Algolia\AlgoliaSearch\Helper\ConfigHelper;
use Magento\Checkout\Model\Session;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

class Recommend extends Template
{
/**
* @var Session
*/
protected $checkoutSession;

/**
* @var ConfigHelper
*/
protected $configHelper;

/**
* @param Context $context
* @param Session $checkoutSession
* @param ConfigHelper $configHelper
* @param array $data
*/
public function __construct(
Context $context,
Session $checkoutSession,
ConfigHelper $configHelper,
array $data = []
) {
parent::__construct($context, $data);
$this->checkoutSession = $checkoutSession;
$this->configHelper = $configHelper;
}

/**
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getAllCartItems()
{
$cartItems = array();
$itemCollection = $this->checkoutSession->getQuote()->getAllVisibleItems();
foreach ( $itemCollection as $item) {
$cartItems[] = $item->getProductId();
}
return array_unique($cartItems);
}

}
12 changes: 12 additions & 0 deletions Block/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,20 @@ public function getConfiguration()
'recommend' => [
'enabledFBT' => $config->isRecommendFrequentlyBroughtTogetherEnabled(),
'enabledRelated' => $config->isRecommendRelatedProductsEnabled(),
'enabledFBTInCart' => $config->isRecommendFrequentlyBroughtTogetherEnabledOnCartPage(),
'enabledRelatedInCart' => $config->isRecommendRelatedProductsEnabledOnCartPage(),
'limitFBTProducts' => $config->getNumberOfFrequentlyBoughtTogetherProducts(),
'limitRelatedProducts' => $config->getNumberOfRelatedProducts(),
'limitTrendingItems' => $config->getNumberOfTrendingItems(),
'enabledTrendItems' => $config->isRecommendTrendingItemsEnabled(),
'trendItemFacetName' => $config->getTrendingItemsFacetName(),
'trendItemFacetValue' => $config->getTrendingItemsFacetValue(),
'isTrendItemsEnabledInPDP' => $config->isTrendItemsEnabledInPDP(),
'isTrendItemsEnabledInCartPage' => $config->isTrendItemsEnabledInShoppingCart(),
'isAddToCartEnabledInFBT' => $config->isAddToCartEnabledInFrequentlyBoughtTogether(),
'isAddToCartEnabledInRelatedProduct' => $config->isAddToCartEnabledInRelatedProducts(),
'isAddToCartEnabledInTrendsItem' => $config->isAddToCartEnabledInTrendsItem(),
'addToCartParams' => $addToCartParams,
],
'extensionVersion' => $config->getExtensionVersion(),
'applicationId' => $config->getApplicationID(),
Expand Down
39 changes: 39 additions & 0 deletions Block/Widget/TrendsItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Algolia\AlgoliaSearch\Block\Widget;

use Magento\Framework\Math\Random;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Widget\Block\BlockInterface;

class TrendsItem extends Template implements BlockInterface
{
protected $_template = 'recommend/widget/trends-item.phtml';

/**
* @param Context $context
* @param Random $mathRandom
* @param array $data
*/
public function __construct(
Context $context,
Random $mathRandom,
array $data = []
) {
$this->mathRandom = $mathRandom;
parent::__construct(
$context,
$data
);
}

/**
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function generateUniqueToken()
{
return $this->mathRandom->getRandomString(5);
}
}
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# CHANGE LOG

## 3.9.0

### New Features
- 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.
- Added an option to show Recommend Related and Frequently Bought Together products on the shopping cart page.
- Added an option to enable the Add To Cart button for all types of recommended products (Related, Frequently Bought Together, and Trending Items).
- Added Algolia Recommend dashboard link on the Magento dashboard
- Added Algolia Search extensions release notes link in the Magento admin to be able to access release notes easily.
- Implemented Recommended Product click event using personalization.

### UPDATES
- Refactored the Algolia Insight functionality in the extension code base per Magento standard (moved the observer directory in the module root).
- Refactored the autocomplete 2.0 code to make it more developer-friendly to allow for customization per customer needs.
- 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.


### FIXES
- Click event in autocomplete
- Autocomplete errors if the product is not assigned a category and indexed into Algolia
- Issues with the price attribute in autocomplete when price attribute is set to Non-Retrievable
- The autocomplete in Query merchandiser (in the Magento admin) shows products from the default store on switching stores [Fixed]
- Issues with triggering Add to Cart Conversion for Configurable Product
- Issues with indexer not updating when product goes out of stock when the last of the inventory is done


## 3.8.1

### UPDATES
Expand Down
158 changes: 152 additions & 6 deletions Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,23 @@ class ConfigHelper

public const DEFAULT_MAX_RECORD_SIZE = 10000;

public const IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED = 'algoliasearch_recommend/recommend/is_frequently_bought_together_enabled';
public const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED = 'algoliasearch_recommend/recommend/is_related_products_enabled';
public const NUM_OF_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_PRODUCTS = 'algoliasearch_recommend/recommend/num_of_frequently_bought_together_products';
public const NUM_OF_RECOMMEND_RELATED_PRODUCTS = 'algoliasearch_recommend/recommend/num_of_related_products';
public const IS_REMOVE_RELATED_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/is_remove_core_related_products_block';
public const IS_REMOVE_UPSELL_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/is_remove_core_upsell_products_block';
protected const IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED = 'algoliasearch_recommend/recommend/frequently_bought_together/is_frequently_bought_together_enabled';
protected const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED = 'algoliasearch_recommend/recommend/related_product/is_related_products_enabled';
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';
protected const IS_RECOMMEND_RELATED_PRODUCTS_ENABLED_ON_CART_PAGE = 'algoliasearch_recommend/recommend/related_product/is_related_products_enabled_in_cart_page';
protected const NUM_OF_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_PRODUCTS = 'algoliasearch_recommend/recommend/frequently_bought_together/num_of_frequently_bought_together_products';
protected const NUM_OF_RECOMMEND_RELATED_PRODUCTS = 'algoliasearch_recommend/recommend/related_product/num_of_related_products';
protected const IS_REMOVE_RELATED_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/related_product/is_remove_core_related_products_block';
protected const IS_REMOVE_UPSELL_PRODUCTS_BLOCK = 'algoliasearch_recommend/recommend/frequently_bought_together/is_remove_core_upsell_products_block';
protected const IS_RECOMMEND_TRENDING_ITEMS_ENABLED = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled';
protected const NUM_OF_TRENDING_ITEMS = 'algoliasearch_recommend/recommend/trends_item/num_of_trending_items';
protected const TREND_ITEMS_FACET_NAME = 'algoliasearch_recommend/recommend/trends_item/facet_name';
protected const TREND_ITEMS_FACET_VALUE = 'algoliasearch_recommend/recommend/trends_item/facet_value';
protected const IS_TREND_ITEMS_ENABLED_IN_PDP = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled_on_pdp';
protected const IS_TREND_ITEMS_ENABLED_IN_SHOPPING_CART = 'algoliasearch_recommend/recommend/trends_item/is_trending_items_enabled_on_cart_page';
protected const IS_ADDTOCART_ENABLED_IN_FREQUENTLY_BOUGHT_TOGETHER = 'algoliasearch_recommend/recommend/frequently_bought_together/is_addtocart_enabled';
protected const IS_ADDTOCART_ENABLED_IN_RELATED_PRODUCTS= 'algoliasearch_recommend/recommend/related_product/is_addtocart_enabled';
protected const IS_ADDTOCART_ENABLED_IN_TRENDS_ITEM= 'algoliasearch_recommend/recommend/trends_item/is_addtocart_enabled';

private $configInterface;
private $objectManager;
Expand Down Expand Up @@ -452,6 +463,26 @@ public function isRecommendRelatedProductsEnabled($storeId = null)
return $this->configInterface->isSetFlag(self::IS_RECOMMEND_RELATED_PRODUCTS_ENABLED, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param int $storeId
*
* @return int
*/
public function isRecommendFrequentlyBroughtTogetherEnabledOnCartPage($storeId = null)
{
return $this->configInterface->isSetFlag(self::IS_RECOMMEND_FREQUENTLY_BOUGHT_TOGETHER_ENABLED_ON_CART_PAGE, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param int $storeId
*
* @return int
*/
public function isRecommendRelatedProductsEnabledOnCartPage($storeId = null)
{
return $this->configInterface->isSetFlag(self::IS_RECOMMEND_RELATED_PRODUCTS_ENABLED_ON_CART_PAGE, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param int $storeId
*
Expand Down Expand Up @@ -499,6 +530,121 @@ public function getNumberOfFrequentlyBoughtTogetherProducts($storeId = null)
$storeId
);
}

/**
* @param int $storeId
*
* @return int
*/
public function isRecommendTrendingItemsEnabled($storeId = null)
{
return (int) $this->configInterface->getValue(
self::IS_RECOMMEND_TRENDING_ITEMS_ENABLED,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @param int $storeId
*
* @return int
*/
public function getNumberOfTrendingItems($storeId = null)
{
return (int) $this->configInterface->getValue(
self::NUM_OF_TRENDING_ITEMS,
ScopeInterface::SCOPE_STORE,
$storeId
);
}


/**
* @param int $storeId
*
* @return string
*/
public function getTrendingItemsFacetName($storeId = null)
{
return $this->configInterface->getValue(
self::TREND_ITEMS_FACET_NAME,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @param int $storeId
*
* @return string
*/
public function getTrendingItemsFacetValue($storeId = null)
{
return $this->configInterface->getValue(
self::TREND_ITEMS_FACET_VALUE,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @param int $storeId
*
* @return int
*/
public function isTrendItemsEnabledInPDP($storeId = null)
{
return (int) $this->configInterface->getValue(
self::IS_TREND_ITEMS_ENABLED_IN_PDP,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @param int $storeId
*
* @return int
*/
public function isTrendItemsEnabledInShoppingCart($storeId = null)
{
return (int) $this->configInterface->getValue(
self::IS_TREND_ITEMS_ENABLED_IN_SHOPPING_CART,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @param int $storeId
*
* @return int
*/
public function isAddToCartEnabledInFrequentlyBoughtTogether($storeId = null)
{
return $this->configInterface->isSetFlag(self::IS_ADDTOCART_ENABLED_IN_FREQUENTLY_BOUGHT_TOGETHER, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param int $storeId
*
* @return int
*/
public function isAddToCartEnabledInRelatedProducts($storeId = null)
{
return $this->configInterface->isSetFlag(self::IS_ADDTOCART_ENABLED_IN_RELATED_PRODUCTS, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param int $storeId
*
* @return int
*/
public function isAddToCartEnabledInTrendsItem($storeId = null)
{
return $this->configInterface->isSetFlag(self::IS_ADDTOCART_ENABLED_IN_TRENDS_ITEM, ScopeInterface::SCOPE_STORE, $storeId);
}

public function useAdaptiveImage($storeId = null)
{
Expand Down
9 changes: 7 additions & 2 deletions Helper/Configuration/AssetHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ class AssetHelper extends \Magento\Framework\App\Helper\AbstractHelper
'icon' => 'iconFaq',
],
[
'title' => 'Issues',
'url' => 'https://github.com/algolia/algoliasearch-magento-2/issues/',
'title' => 'Support',
'url' => 'https://www.algolia.com/support/?contact=',
'icon' => 'iconIssues',
],
[
'title' => 'Release Notes',
'url' => 'https://github.com/algolia/algoliasearch-magento-2/releases',
'icon' => 'iconDocs',
]
],
'algoliasearch_autocomplete' => [
[
Expand Down
23 changes: 23 additions & 0 deletions Helper/Configuration/NoticeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper
'getVersionNotice',
'getClickAnalyticsNotice',
'getPersonalizationNotice',
'getRecommendNotice',
];

/** @var array[] */
Expand Down Expand Up @@ -317,4 +318,26 @@ public function getNewVersionNotification()
{
return $this->extensionNotification->checkVersion();
}

/**
* Function created for adding the Algolia Dashboard link in the Magento recommend system configuration
* @return void
*/
protected function getRecommendNotice()
{
if (!$this->configHelper->getApplicationID()) {
return;
}
$noticeContent = '<div class="algolia-perso"><br/><h2>Algolia Dashboard</h2>
<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>';

$selector = '#algoliasearch_recommend_recommend';
$method = 'after';

$this->notices[] = [
'selector' => $selector,
'method' => $method,
'message' => $noticeContent,
];
}
}
9 changes: 7 additions & 2 deletions Helper/Configuration/PersonalizationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ class PersonalizationHelper extends \Magento\Framework\App\Helper\AbstractHelper
/** @var ConfigResourceInterface */
private $configResourceInterface;

/**
* @param \Magento\Framework\App\Helper\Context $context
* @param ScopeConfigInterface $configInterface
* @param ConfigResourceInterface $configResourceInterface
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
ScopeConfigInterface $configInterface,
ConfigResourceInterface $configResourceInterface
ScopeConfigInterface $configInterface,
ConfigResourceInterface $configResourceInterface
) {
$this->configInterface = $configInterface;
$this->configResourceInterface = $configResourceInterface;
Expand Down
Loading

0 comments on commit f5d7f97

Please sign in to comment.