diff --git a/Adapter/Algolia.php b/Adapter/Algolia.php
index 80f2afb79..205d8762a 100755
--- a/Adapter/Algolia.php
+++ b/Adapter/Algolia.php
@@ -206,7 +206,9 @@ private function isReplaceAdvancedSearch($storeId)
private function getDocument20($document)
{
- return new \Magento\Framework\Search\Document($document['entity_id'], ['score' => new \Magento\Framework\Search\DocumentField('score', $document['score'])]);
+ return new \Magento\Framework\Search\Document($document['entity_id'], [
+ 'score' => new \Magento\Framework\Search\DocumentField('score', $document['score']),
+ ]);
}
private function getDocument21($document)
diff --git a/Block/Algolia.php b/Block/Algolia.php
index d6b01d7c7..785c8f234 100755
--- a/Block/Algolia.php
+++ b/Block/Algolia.php
@@ -124,10 +124,14 @@ public function getGroupId()
public function getPriceKey()
{
if ($this->priceKey === null) {
- $groupId = $this->getGroupId();
$currencyCode = $this->getCurrencyCode();
- $this->priceKey = $this->config->isCustomerGroupsEnabled($this->getStore()->getStoreId()) ? '.' . $currencyCode . '.group_' . $groupId : '.' . $currencyCode . '.default';
+ $this->priceKey = '.' . $currencyCode . '.default';
+
+ if ($this->config->isCustomerGroupsEnabled($this->getStore()->getStoreId())) {
+ $groupId = $this->getGroupId();
+ $this->priceKey = '.' . $currencyCode . '.group_' . $groupId;;
+ }
}
return $this->priceKey;
@@ -170,4 +174,3 @@ private function getAddToCartUrl($additional = [])
return $this->_urlBuilder->getUrl('checkout/cart/add', $routeParams);
}
}
-
diff --git a/Block/Configuration.php b/Block/Configuration.php
index aef78dcbb..2033a4589 100755
--- a/Block/Configuration.php
+++ b/Block/Configuration.php
@@ -67,7 +67,9 @@ public function getConfiguration()
/**
* Handle category replacement
*/
- if ($config->isInstantEnabled() && $config->replaceCategories() && $request->getControllerName() == 'category') {
+ if ($config->isInstantEnabled()
+ && $config->replaceCategories()
+ && $request->getControllerName() == 'category') {
$category = $this->getCurrentCategory();
if ($category && $category->getDisplayMode() !== 'PAGE') {
@@ -112,8 +114,7 @@ public function getConfiguration()
if ($refinementKey !== null) {
$refinementValue = $query;
$query = "";
- }
- else {
+ } else {
$refinementKey = "";
}
}
@@ -145,11 +146,16 @@ public function getConfiguration()
'extensionVersion' => $config->getExtensionVersion(),
'applicationId' => $config->getApplicationID(),
'indexName' => $coreHelper->getBaseIndexName(),
- 'apiKey' => $algoliaHelper->generateSearchSecuredApiKey($config->getSearchOnlyAPIKey(), $config->getAttributesToRetrieve($customerGroupId)),
+ 'apiKey' => $algoliaHelper->generateSearchSecuredApiKey(
+ $config->getSearchOnlyAPIKey(),
+ $config->getAttributesToRetrieve($customerGroupId)
+ ),
'facets' => $facets,
'areCategoriesInFacets' => $areCategoriesInFacets,
'hitsPerPage' => (int) $config->getNumberOfProductResults(),
- 'sortingIndices' => array_values($config->getSortingIndices($coreHelper->getIndexName($productHelper->getIndexNameSuffix()))),
+ 'sortingIndices' => array_values($config->getSortingIndices(
+ $coreHelper->getIndexName($productHelper->getIndexNameSuffix())
+ )),
'isSearchPage' => $this->isSearchPage(),
'isCategoryPage' => $isCategoryPage,
'removeBranding' => (bool) $config->isRemoveBranding(),
diff --git a/Block/Instant/Hit.php b/Block/Instant/Hit.php
index 4ba1bfeaa..fd9c8c142 100755
--- a/Block/Instant/Hit.php
+++ b/Block/Instant/Hit.php
@@ -34,7 +34,8 @@ public function getPriceKey()
$store = $this->_storeManager->getStore();
$currencyCode = $store->getCurrentCurrencyCode();
- $this->priceKey = $this->config->isCustomerGroupsEnabled($store->getStoreId()) ? '.' . $currencyCode . '.group_' . $groupId : '.' . $currencyCode . '.default';
+ $this->priceKey = $this->config->isCustomerGroupsEnabled($store->getStoreId())
+ ? '.' . $currencyCode . '.group_' . $groupId : '.' . $currencyCode . '.default';
}
return $this->priceKey;
diff --git a/Controller/Adminhtml/Queue.php b/Controller/Adminhtml/Queue.php
index 9a821d7a3..19386929a 100644
--- a/Controller/Adminhtml/Queue.php
+++ b/Controller/Adminhtml/Queue.php
@@ -24,8 +24,12 @@ abstract class Queue extends Action
protected $tableName;
protected $db;
- public function __construct(Context $context, ConfigHelper $configHelper, JsonFactory $resultJsonFactory, ResourceConnection $resourceConnection)
- {
+ public function __construct(
+ Context $context,
+ ConfigHelper $configHelper,
+ JsonFactory $resultJsonFactory,
+ ResourceConnection $resourceConnection
+ ) {
parent::__construct($context);
$this->configHelper = $configHelper;
diff --git a/Controller/Adminhtml/Queue/Clear.php b/Controller/Adminhtml/Queue/Clear.php
index a4091d70b..ef44041d3 100644
--- a/Controller/Adminhtml/Queue/Clear.php
+++ b/Controller/Adminhtml/Queue/Clear.php
@@ -11,9 +11,9 @@ public function execute()
try {
$this->db->query('TRUNCATE TABLE '.$this->tableName);
- $status = array('status' => 'ok');
+ $status = ['status' => 'ok'];
} catch (\Exception $e) {
- $status = array('status' => 'ko', 'message' => $e->getMessage());
+ $status = ['status' => 'ko', 'message' => $e->getMessage()];
}
/** @var \Magento\Framework\Controller\Result\Json $result */
diff --git a/Controller/Adminhtml/Queue/Info.php b/Controller/Adminhtml/Queue/Info.php
index 0f979ffa5..3fb576454 100644
--- a/Controller/Adminhtml/Queue/Info.php
+++ b/Controller/Adminhtml/Queue/Info.php
@@ -21,11 +21,11 @@ public function execute()
$eta = $hours . ' hours ' . $restMinutes . ' minutes';
}
- $queueInfo = array(
+ $queueInfo = [
'isEnabled' => $this->configHelper->isQueueActive(),
'currentSize' => $size,
'eta' => $eta,
- );
+ ];
/** @var \Magento\Framework\Controller\Result\Json $result */
$result = $this->resultJsonFactory->create();
diff --git a/Helper/AlgoliaHelper.php b/Helper/AlgoliaHelper.php
index e00131867..c3ca5d05f 100755
--- a/Helper/AlgoliaHelper.php
+++ b/Helper/AlgoliaHelper.php
@@ -36,8 +36,12 @@ class AlgoliaHelper extends AbstractHelper
/** @var string */
private static $lastTaskId;
- public function __construct(Context $context, ConfigHelper $configHelper, ManagerInterface $messageManager, ConsoleOutput $consoleOutput)
- {
+ public function __construct(
+ Context $context,
+ ConfigHelper $configHelper,
+ ManagerInterface $messageManager,
+ ConsoleOutput $consoleOutput
+ ) {
parent::__construct($context);
$this->config = $configHelper;
@@ -205,7 +209,13 @@ public function setSynonyms($indexName, $synonyms)
$hitsPerPage = 100;
$page = 0;
do {
- $complexSynonyms = $index->searchSynonyms('', ['altCorrection1', 'altCorrection2', 'placeholder'], $page, $hitsPerPage);
+ $complexSynonyms = $index->searchSynonyms(
+ '',
+ ['altCorrection1', 'altCorrection2', 'placeholder'],
+ $page,
+ $hitsPerPage
+ );
+
foreach ($complexSynonyms['hits'] as $hit) {
unset($hit['_highlightResult']);
@@ -217,8 +227,7 @@ public function setSynonyms($indexName, $synonyms)
if (empty($synonyms)) {
$res = $index->clearSynonyms(true);
- }
- else {
+ } else {
$res = $index->batchSynonyms($synonyms, true, true);
}
@@ -299,7 +308,8 @@ private function checkClient($methodName)
$this->resetCredentialsFromConfig();
if (!isset($this->client)) {
- throw new AlgoliaException('Operation "' . $methodName . ' could not be performed because Algolia credentials were not provided.');
+ $msg = 'Operation '.$methodName.' could not be performed because Algolia credentials were not provided.';
+ throw new AlgoliaException($msg);
}
}
@@ -336,7 +346,8 @@ private function prepareRecords(&$objects, $indexName)
if ($object === false) {
$longestAttribute = $this->getLongestAttribute($previousObject);
- $modifiedIds[] = $indexName.' - ID '.$previousObject['objectID'].' - skipped - longest attribute: '.$longestAttribute;
+ $modifiedIds[] = $indexName.'
+ - ID '.$previousObject['objectID'].' - skipped - longest attribute: '.$longestAttribute;
unset($objects[$key]);
} elseif ($previousObject !== $object) {
@@ -349,7 +360,11 @@ private function prepareRecords(&$objects, $indexName)
if (!empty($modifiedIds)) {
$separator = php_sapi_name() === 'cli' ? "\n" : '
';
- $errorMessage = 'Algolia reindexing: You have some records which are too big to be indexed in Algolia. They have either been truncated (removed attributes: '.implode(', ', $this->potentiallyLongAttributes).') or skipped completely: '.$separator.implode($separator, $modifiedIds);
+ $errorMessage = 'Algolia reindexing:
+ You have some records which are too big to be indexed in Algolia.
+ They have either been truncated
+ (removed attributes: '.implode(', ', $this->potentiallyLongAttributes).')
+ or skipped completely: '.$separator.implode($separator, $modifiedIds);
if (php_sapi_name() === 'cli') {
$this->consoleOutput->writeln($errorMessage);
@@ -401,7 +416,7 @@ private function getLongestAttribute($object)
public function castProductObject(&$productData)
{
- $nonCastableAttributes = array('sku', 'name', 'description');
+ $nonCastableAttributes = ['sku', 'name', 'description'];
foreach ($productData as $key => &$data) {
if (in_array($key, $nonCastableAttributes, true) === true) {
@@ -436,8 +451,8 @@ private function castRecord($object)
private function castAttribute($value)
{
- if (is_numeric($value) && floatval($value) == floatval(intval($value))) {
- return intval($value);
+ if (is_numeric($value) && floatval($value) == floatval((int) $value)) {
+ return (int) $value;
}
if (is_numeric($value)) {
diff --git a/Helper/ConfigHelper.php b/Helper/ConfigHelper.php
index 688e79d9f..f07e1ce2c 100755
--- a/Helper/ConfigHelper.php
+++ b/Helper/ConfigHelper.php
@@ -50,7 +50,7 @@ class ConfigHelper
const CATEGORY_ATTRIBUTES = 'algoliasearch_categories/categories/category_additional_attributes';
const INDEX_PRODUCT_COUNT = 'algoliasearch_categories/categories/index_product_count';
const CATEGORY_CUSTOM_RANKING = 'algoliasearch_categories/categories/custom_ranking_category_attributes';
- const SHOW_CATS_NOT_INCLUDED_IN_NAVIGATION = 'algoliasearch_categories/categories/show_cats_not_included_in_navigation';
+ const SHOW_CATS_NOT_INCLUDED_IN_NAV = 'algoliasearch_categories/categories/show_cats_not_included_in_navigation';
const INDEX_EMPTY_CATEGORIES = 'algoliasearch_categories/categories/index_empty_categories';
const IS_ACTIVE = 'algoliasearch_queue/queue/active';
@@ -79,7 +79,7 @@ class ConfigHelper
const MAKE_SEO_REQUEST = 'algoliasearch_advanced/advanced/make_seo_request';
const REMOVE_BRANDING = 'algoliasearch_advanced/advanced/remove_branding';
const AUTOCOMPLETE_SELECTOR = 'algoliasearch_advanced/advanced/autocomplete_selector';
- const INDEX_PRODUCT_ON_CATEGORY_PRODUCTS_UPDATE = 'algoliasearch_advanced/advanced/index_product_on_category_products_update';
+ const IDX_PRODUCT_ON_CAT_PRODUCTS_UPD = 'algoliasearch_advanced/advanced/index_product_on_category_products_update';
const SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock';
@@ -89,7 +89,8 @@ class ConfigHelper
const EXTRA_SETTINGS_CATEGORIES = 'algoliasearch_extra_settings/extra_settings/categories_extra_settings';
const EXTRA_SETTINGS_PAGES = 'algoliasearch_extra_settings/extra_settings/pages_extra_settings';
const EXTRA_SETTINGS_SUGGESTIONS = 'algoliasearch_extra_settings/extra_settings/suggestions_extra_settings';
- const EXTRA_SETTINGS_ADDITIONAL_SECTIONS = 'algoliasearch_extra_settings/extra_settings/additional_sections_extra_settings';
+ const EXTRA_SETTINGS_ADDITIONAL_SECTIONS =
+ 'algoliasearch_extra_settings/extra_settings/additional_sections_extra_settings';
protected $_productTypeMap = [];
@@ -104,17 +105,19 @@ class ConfigHelper
private $eventManager;
private $currencyManager;
- public function __construct(Magento\Framework\App\Config\ScopeConfigInterface $configInterface,
- Magento\Framework\ObjectManagerInterface $objectManager,
- StoreManagerInterface $storeManager,
- Currency $currency,
- DirCurrency $dirCurrency,
- DirectoryList $directoryList,
- Magento\Framework\Module\ResourceInterface $moduleResource,
- Magento\Framework\App\ProductMetadataInterface $productMetadata,
- Magento\Framework\Event\ManagerInterface $eventManager,
- Magento\Directory\Model\Currency $currencyManager)
- {
+ public function __construct(
+ Magento\Framework\App\Config\ScopeConfigInterface $configInterface,
+ Magento\Framework\ObjectManagerInterface $objectManager,
+ StoreManagerInterface $storeManager,
+ Currency $currency,
+ DirCurrency $dirCurrency,
+ DirectoryList $directoryList,
+ Magento\Framework\Module\ResourceInterface $moduleResource,
+ Magento\Framework\App\ProductMetadataInterface $productMetadata,
+ Magento\Framework\Event\ManagerInterface $eventManager,
+ Magento\Directory\Model\Currency $currencyManager
+ ) {
+
$this->objectManager = $objectManager;
$this->configInterface = $configInterface;
$this->currency = $currency;
@@ -129,12 +132,20 @@ public function __construct(Magento\Framework\App\Config\ScopeConfigInterface $c
public function indexOutOfStockOptions($storeId = null)
{
- return $this->configInterface->getValue(self::INDEX_OUT_OF_STOCK_OPTIONS, ScopeInterface::SCOPE_STORE, $storeId);
+ return $this->configInterface->getValue(
+ self::INDEX_OUT_OF_STOCK_OPTIONS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function showCatsNotIncludedInNavigation($storeId = null)
{
- return $this->configInterface->getValue(self::SHOW_CATS_NOT_INCLUDED_IN_NAVIGATION, ScopeInterface::SCOPE_STORE, $storeId);
+ return $this->configInterface->getValue(
+ self::SHOW_CATS_NOT_INCLUDED_IN_NAV,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function shouldIndexEmptyCategories($storeId = null)
@@ -169,33 +180,54 @@ public function getAutocompleteSelector($storeId = null)
public function indexProductOnCategoryProductsUpdate($storeId = null)
{
- return $this->configInterface->getValue(self::INDEX_PRODUCT_ON_CATEGORY_PRODUCTS_UPDATE, ScopeInterface::SCOPE_STORE, $storeId);
+ return $this->configInterface->getValue(
+ self::IDX_PRODUCT_ON_CAT_PRODUCTS_UPD,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function getNumberOfQueriesSuggestions($storeId = null)
{
- return $this->configInterface->getValue(self::NB_OF_QUERIES_SUGGESTIONS, ScopeInterface::SCOPE_STORE, $storeId);
+ return $this->configInterface->getValue(
+ self::NB_OF_QUERIES_SUGGESTIONS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function getNumberOfProductsSuggestions($storeId = null)
{
- return $this->configInterface->getValue(self::NB_OF_PRODUCTS_SUGGESTIONS, ScopeInterface::SCOPE_STORE, $storeId);
+ return $this->configInterface->getValue(
+ self::NB_OF_PRODUCTS_SUGGESTIONS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function getNumberOfCategoriesSuggestions($storeId = null)
{
- return $this->configInterface->getValue(self::NB_OF_CATEGORIES_SUGGESTIONS, ScopeInterface::SCOPE_STORE, $storeId);
+ return $this->configInterface->getValue(
+ self::NB_OF_CATEGORIES_SUGGESTIONS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function showSuggestionsOnNoResultsPage($storeId = null)
{
- return $this->configInterface->getValue(self::SHOW_SUGGESTIONS_NO_RESULTS, ScopeInterface::SCOPE_STORE, $storeId);
+ return $this->configInterface->getValue(
+ self::SHOW_SUGGESTIONS_NO_RESULTS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function isEnabledFrontEnd($storeId = null)
{
// Frontend = Backend + Frontend
- return (bool) $this->configInterface->getValue(self::ENABLE_BACKEND, ScopeInterface::SCOPE_STORE, $storeId) && (bool) $this->configInterface->getValue(self::ENABLE_FRONTEND, ScopeInterface::SCOPE_STORE, $storeId);
+ return (bool) $this->configInterface->getValue(self::ENABLE_BACKEND, ScopeInterface::SCOPE_STORE, $storeId)
+ && (bool) $this->configInterface->getValue(self::ENABLE_FRONTEND, ScopeInterface::SCOPE_STORE, $storeId);
}
public function isEnabledBackend($storeId = null)
@@ -220,12 +252,21 @@ public function getShowOutOfStock($storeId = null)
public function useSecureUrlsInFrontend($storeId = null)
{
- return (bool) $this->configInterface->getValue(self::USE_SECURE_IN_FRONTEND, ScopeInterface::SCOPE_STORE, $storeId);
+ return (bool) $this->configInterface->getValue(
+ self::USE_SECURE_IN_FRONTEND,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function getImageWidth($storeId = null)
{
- $imageWidth = $this->configInterface->getValue(self::XML_PATH_IMAGE_WIDTH, ScopeInterface::SCOPE_STORE, $storeId);
+ $imageWidth = $this->configInterface->getValue(
+ self::XML_PATH_IMAGE_WIDTH,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
+
if (empty($imageWidth)) {
return 265;
}
@@ -235,7 +276,12 @@ public function getImageWidth($storeId = null)
public function getImageHeight($storeId = null)
{
- $imageHeight = $this->configInterface->getValue(self::XML_PATH_IMAGE_HEIGHT, ScopeInterface::SCOPE_STORE, $storeId);
+ $imageHeight = $this->configInterface->getValue(
+ self::XML_PATH_IMAGE_HEIGHT,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
+
if (empty($imageHeight)) {
return 265;
}
@@ -265,7 +311,11 @@ public function isPartialUpdateEnabled($storeId = null)
public function getAutocompleteSections($storeId = null)
{
- $attrs = $this->unserialize($this->configInterface->getValue(self::AUTOCOMPLETE_SECTIONS, ScopeInterface::SCOPE_STORE, $storeId));
+ $attrs = $this->unserialize($this->configInterface->getValue(
+ self::AUTOCOMPLETE_SECTIONS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
if (is_array($attrs)) {
return array_values($attrs);
@@ -286,7 +336,11 @@ public function getMinNumberOfResults($storeId = null)
public function isAddToCartEnable($storeId = null)
{
- return (bool) $this->configInterface->getValue(self::XML_ADD_TO_CART_ENABLE, ScopeInterface::SCOPE_STORE, $storeId);
+ return (bool) $this->configInterface->getValue(
+ self::XML_ADD_TO_CART_ENABLE,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function isRemoveBranding($storeId = null)
@@ -326,7 +380,11 @@ public function getRemoveWordsIfNoResult($storeId = null)
public function getNumberOfProductResults($storeId = null)
{
- return (int) $this->configInterface->getValue(self::NUMBER_OF_PRODUCT_RESULTS, ScopeInterface::SCOPE_STORE, $storeId);
+ return (int) $this->configInterface->getValue(
+ self::NUMBER_OF_PRODUCT_RESULTS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function isPopupEnabled($storeId = null)
@@ -356,7 +414,11 @@ public function getInstantSelector($storeId = null)
public function getExcludedPages($storeId = null)
{
- $attrs = $this->unserialize($this->configInterface->getValue(self::EXCLUDED_PAGES, ScopeInterface::SCOPE_STORE, $storeId));
+ $attrs = $this->unserialize($this->configInterface->getValue(
+ self::EXCLUDED_PAGES,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
if (is_array($attrs)) {
return $attrs;
@@ -367,7 +429,11 @@ public function getExcludedPages($storeId = null)
public function getRenderTemplateDirectives($storeId = null)
{
- return $this->configInterface->getValue(self::RENDER_TEMPLATE_DIRECTIVES, ScopeInterface::SCOPE_STORE, $storeId);
+ return $this->configInterface->getValue(
+ self::RENDER_TEMPLATE_DIRECTIVES,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ );
}
public function isAutocompleteDebugEnabled($storeId = null)
@@ -377,7 +443,11 @@ public function isAutocompleteDebugEnabled($storeId = null)
public function getSortingIndices($originalIndexName, $storeId = null)
{
- $attrs = $this->unserialize($this->configInterface->getValue(self::SORTING_INDICES, ScopeInterface::SCOPE_STORE, $storeId));
+ $attrs = $this->unserialize($this->configInterface->getValue(
+ self::SORTING_INDICES,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
$currency = $this->getCurrencyCode($storeId);
@@ -454,7 +524,11 @@ public function getIndexPrefix($storeId = null)
public function getCategoryAdditionalAttributes($storeId = null)
{
- $attrs = $this->unserialize($this->configInterface->getValue(self::CATEGORY_ATTRIBUTES, ScopeInterface::SCOPE_STORE, $storeId));
+ $attrs = $this->unserialize($this->configInterface->getValue(
+ self::CATEGORY_ATTRIBUTES,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
if (is_array($attrs)) {
return $attrs;
@@ -465,15 +539,31 @@ public function getCategoryAdditionalAttributes($storeId = null)
public function getProductAdditionalAttributes($storeId = null)
{
- $attributes = $this->unserialize($this->configInterface->getValue(self::PRODUCT_ATTRIBUTES, ScopeInterface::SCOPE_STORE, $storeId));
-
- $facets = $this->unserialize($this->configInterface->getValue(self::FACETS, ScopeInterface::SCOPE_STORE,$storeId));
+ $attributes = $this->unserialize($this->configInterface->getValue(
+ self::PRODUCT_ATTRIBUTES,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
+
+ $facets = $this->unserialize($this->configInterface->getValue(
+ self::FACETS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
$attributes = $this->addIndexableAttributes($attributes, $facets, '0');
- $sorts = $this->unserialize($this->configInterface->getValue(self::SORTING_INDICES, ScopeInterface::SCOPE_STORE,$storeId));
+ $sorts = $this->unserialize($this->configInterface->getValue(
+ self::SORTING_INDICES,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
$attributes = $this->addIndexableAttributes($attributes, $sorts, '0');
- $customRankings = $this->unserialize($this->configInterface->getValue(self::PRODUCT_CUSTOM_RANKING, ScopeInterface::SCOPE_STORE,$storeId));
+ $customRankings = $this->unserialize($this->configInterface->getValue(
+ self::PRODUCT_CUSTOM_RANKING,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
$customRankings = array_filter($customRankings, function ($customRanking) {
return $customRanking['attribute'] != 'custom_attribute';
});
@@ -488,7 +578,11 @@ public function getProductAdditionalAttributes($storeId = null)
public function getFacets($storeId = null)
{
- $attrs = $this->unserialize($this->configInterface->getValue(self::FACETS, ScopeInterface::SCOPE_STORE, $storeId));
+ $attrs = $this->unserialize($this->configInterface->getValue(
+ self::FACETS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
foreach ($attrs as &$attr) {
if ($attr['type'] == 'other') {
@@ -505,7 +599,11 @@ public function getFacets($storeId = null)
public function getCategoryCustomRanking($storeId = null)
{
- $attrs = $this->unserialize($this->configInterface->getValue(self::CATEGORY_CUSTOM_RANKING, ScopeInterface::SCOPE_STORE, $storeId));
+ $attrs = $this->unserialize($this->configInterface->getValue(
+ self::CATEGORY_CUSTOM_RANKING,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
if (is_array($attrs)) {
return $attrs;
@@ -516,7 +614,11 @@ public function getCategoryCustomRanking($storeId = null)
public function getProductCustomRanking($storeId = null)
{
- $attrs = $this->unserialize($this->configInterface->getValue(self::PRODUCT_CUSTOM_RANKING, ScopeInterface::SCOPE_STORE, $storeId));
+ $attrs = $this->unserialize($this->configInterface->getValue(
+ self::PRODUCT_CUSTOM_RANKING,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
if (is_array($attrs)) {
return $attrs;
@@ -555,7 +657,7 @@ public function getCurrencyCode($storeId = null)
public function getPopularQueries($storeId = null)
{
if (!$this->isInstantEnabled($storeId) || !$this->showSuggestionsOnNoResultsPage($storeId)) {
- return array();
+ return [];
}
if ($storeId === null) {
@@ -634,7 +736,11 @@ public function isEnabledSynonyms($storeId = null)
public function getSynonyms($storeId = null)
{
- $synonyms = $this->unserialize($this->configInterface->getValue(self::SYNONYMS, ScopeInterface::SCOPE_STORE, $storeId));
+ $synonyms = $this->unserialize($this->configInterface->getValue(
+ self::SYNONYMS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
if (is_array($synonyms)) {
return $synonyms;
@@ -645,7 +751,11 @@ public function getSynonyms($storeId = null)
public function getOnewaySynonyms($storeId = null)
{
- $onewaySynonyms = $this->unserialize($this->configInterface->getValue(self::ONEWAY_SYNONYMS, ScopeInterface::SCOPE_STORE, $storeId));
+ $onewaySynonyms = $this->unserialize($this->configInterface->getValue(
+ self::ONEWAY_SYNONYMS,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ));
if (is_array($onewaySynonyms)) {
return $onewaySynonyms;
@@ -677,13 +787,26 @@ public function getAnalyticsConfig($storeId = null)
return [
'enabled' => $this->isAnalyticsEnabled(),
'delay' => $this->configInterface->getValue(self::ANALYTICS_DELAY, ScopeInterface::SCOPE_STORE, $storeId),
- 'triggerOnUiInteraction' => $this->configInterface->getValue(self::ANALYTICS_TRIGGER_ON_UI_INTERACTION, ScopeInterface::SCOPE_STORE, $storeId),
- 'pushInitialSearch' => $this->configInterface->getValue(self::ANALYTICS_PUSH_INITIAL_SEARCH, ScopeInterface::SCOPE_STORE, $storeId),
+ 'triggerOnUiInteraction' => $this->configInterface->getValue(
+ self::ANALYTICS_TRIGGER_ON_UI_INTERACTION,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ),
+ 'pushInitialSearch' => $this->configInterface->getValue(
+ self::ANALYTICS_PUSH_INITIAL_SEARCH,
+ ScopeInterface::SCOPE_STORE,
+ $storeId
+ ),
];
}
- private function addIndexableAttributes($attributes, $addedAttributes, $searchable = '1', $retrievable = '1', $indexNoValue = '1')
- {
+ private function addIndexableAttributes(
+ $attributes,
+ $addedAttributes,
+ $searchable = '1',
+ $retrievable = '1',
+ $indexNoValue = '1'
+ ) {
foreach ((array) $addedAttributes as $addedAttribute) {
foreach ((array) $attributes as $attribute) {
if ($addedAttribute['attribute'] == $attribute['attribute']) {
@@ -691,12 +814,12 @@ private function addIndexableAttributes($attributes, $addedAttributes, $searchab
}
}
- $attributes[] = array(
+ $attributes[] = [
'attribute' => $addedAttribute['attribute'],
'searchable' => $searchable,
'retrievable' => $retrievable,
'index_no_value' => $indexNoValue,
- );
+ ];
}
return $attributes;
diff --git a/Helper/Data.php b/Helper/Data.php
index 103de200a..4c6c66b5d 100755
--- a/Helper/Data.php
+++ b/Helper/Data.php
@@ -11,6 +11,7 @@
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
+use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\CatalogInventory\Api\StockRegistryInterface;
use Magento\Framework\App\ResourceConnection;
@@ -41,7 +42,8 @@ class Data
private $emulationRuns = false;
- public function __construct(AlgoliaHelper $algoliaHelper,
+ public function __construct(
+ AlgoliaHelper $algoliaHelper,
ConfigHelper $configHelper,
ProductHelper $producthelper,
CategoryHelper $categoryHelper,
@@ -53,8 +55,9 @@ public function __construct(AlgoliaHelper $algoliaHelper,
Logger $logger,
ResourceConnection $resource,
ManagerInterface $eventManager,
- StoreManagerInterface $storeManager)
- {
+ StoreManagerInterface $storeManager
+ ) {
+
$this->algoliaHelper = $algoliaHelper;
$this->pageHelper = $pageHelper;
@@ -91,16 +94,31 @@ public function saveConfigurationToAlgolia($storeId, $useTmpIndex = false)
return;
}
- $this->algoliaHelper->setSettings($this->getIndexName($this->categoryHelper->getIndexNameSuffix(), $storeId), $this->categoryHelper->getIndexSettings($storeId), false, true);
- $this->algoliaHelper->setSettings($this->getIndexName($this->pageHelper->getIndexNameSuffix(), $storeId), $this->pageHelper->getIndexSettings($storeId));
- $this->algoliaHelper->setSettings($this->getIndexName($this->suggestionHelper->getIndexNameSuffix(), $storeId), $this->suggestionHelper->getIndexSettings($storeId));
+ $this->algoliaHelper->setSettings(
+ $this->getIndexName($this->categoryHelper->getIndexNameSuffix(), $storeId),
+ $this->categoryHelper->getIndexSettings($storeId),
+ false,
+ true
+ );
+ $this->algoliaHelper->setSettings(
+ $this->getIndexName($this->pageHelper->getIndexNameSuffix(), $storeId),
+ $this->pageHelper->getIndexSettings($storeId)
+ );
+ $this->algoliaHelper->setSettings(
+ $this->getIndexName($this->suggestionHelper->getIndexNameSuffix(), $storeId),
+ $this->suggestionHelper->getIndexSettings($storeId)
+ );
+ $protectedSections = ['products', 'categories', 'pages', 'suggestions'];
foreach ($this->configHelper->getAutocompleteSections() as $section) {
- if ($section['name'] === 'products' || $section['name'] === 'categories' || $section['name'] === 'pages' || $section['name'] === 'suggestions') {
+ if (in_array($section['name'], $protectedSections, true)) {
continue;
}
- $this->algoliaHelper->setSettings($this->getIndexName($this->additionalSectionHelper->getIndexNameSuffix(), $storeId) . '_' . $section['name'], $this->additionalSectionHelper->getIndexSettings($storeId));
+ $indexName = $this->getIndexName($this->additionalSectionHelper->getIndexNameSuffix(), $storeId);
+ $indexName = $indexName . '_' . $section['name'];
+
+ $this->algoliaHelper->setSettings($indexName, $this->additionalSectionHelper->getIndexSettings($storeId));
}
$productsIndexName = $this->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId);
@@ -154,12 +172,14 @@ public function rebuildStoreAdditionalSectionsIndex($storeId)
$additionalSections = $this->configHelper->getAutocompleteSections();
+ $protectedSections = ['products', 'categories', 'pages', 'suggestions'];
foreach ($additionalSections as $section) {
- if ($section['name'] === 'products' || $section['name'] === 'categories' || $section['name'] === 'pages' || $section['name'] === 'suggestions') {
+ if (in_array($section['name'], $protectedSections, true)) {
continue;
}
- $indexName = $this->getIndexName($this->additionalSectionHelper->getIndexNameSuffix(), $storeId) . '_' . $section['name'];
+ $indexName = $this->getIndexName($this->additionalSectionHelper->getIndexNameSuffix(), $storeId);
+ $indexName = $indexName . '_' . $section['name'];
$attributeValues = $this->additionalSectionHelper->getAttributeValues($storeId, $section);
@@ -215,7 +235,12 @@ public function rebuildStoreCategoryIndex($storeId, $categoryIds = null)
$page = 1;
while ($page <= $pages) {
- $this->rebuildStoreCategoryIndexPage($storeId, $collection, $page, $this->configHelper->getNumberOfElementByPage());
+ $this->rebuildStoreCategoryIndexPage(
+ $storeId,
+ $collection,
+ $page,
+ $this->configHelper->getNumberOfElementByPage()
+ );
$page++;
}
@@ -246,7 +271,12 @@ public function rebuildStoreSuggestionIndex($storeId)
$page = 1;
while ($page <= $pages) {
- $this->rebuildStoreSuggestionIndexPage($storeId, $collection, $page, $this->configHelper->getNumberOfElementByPage());
+ $this->rebuildStoreSuggestionIndexPage(
+ $storeId,
+ $collection,
+ $page,
+ $this->configHelper->getNumberOfElementByPage()
+ );
$page++;
}
@@ -273,7 +303,10 @@ public function moveStoreSuggestionIndex($storeId)
}
$indexNameSuffix = $this->suggestionHelper->getIndexNameSuffix();
- $this->algoliaHelper->moveIndex($this->getIndexName($indexNameSuffix, $storeId, true), $this->getIndexName($indexNameSuffix, $storeId));
+ $tmpIndexName = $this->getIndexName($indexNameSuffix, $storeId, true);
+ $indexName = $this->getIndexName($indexNameSuffix, $storeId);
+
+ $this->algoliaHelper->moveIndex($tmpIndexName, $indexName);
}
public function rebuildStoreProductIndex($storeId, $productIds)
@@ -303,7 +336,14 @@ public function rebuildStoreProductIndex($storeId, $productIds)
$page = 1;
while ($page <= $pages) {
- $this->rebuildStoreProductIndexPage($storeId, $collection, $page, $this->configHelper->getNumberOfElementByPage(), null, $productIds);
+ $this->rebuildStoreProductIndexPage(
+ $storeId,
+ $collection,
+ $page,
+ $this->configHelper->getNumberOfElementByPage(),
+ null,
+ $productIds
+ );
$page++;
}
@@ -390,7 +430,8 @@ public function rebuildStoreCategoryIndexPage($storeId, $collectionDefault, $pag
$categoryObject = $this->categoryHelper->getObject($category);
- if ($this->configHelper->shouldIndexEmptyCategories($storeId) === true || $categoryObject['product_count'] > 0) {
+ if ($this->configHelper->shouldIndexEmptyCategories($storeId) === true
+ || $categoryObject['product_count'] > 0) {
array_push($indexData, $categoryObject);
}
}
@@ -414,7 +455,10 @@ protected function getProductsRecords($storeId, $collection, $potentiallyDeleted
// In $potentiallyDeletedProductsIds there might be IDs of deleted products which will not be in a collection
if (is_array($potentiallyDeletedProductsIds)) {
- $potentiallyDeletedProductsIds = array_combine($potentiallyDeletedProductsIds, $potentiallyDeletedProductsIds);
+ $potentiallyDeletedProductsIds = array_combine(
+ $potentiallyDeletedProductsIds,
+ $potentiallyDeletedProductsIds
+ );
}
$this->logger->start('CREATE RECORDS ' . $this->logger->getStoreName($storeId));
@@ -429,7 +473,8 @@ protected function getProductsRecords($storeId, $collection, $potentiallyDeleted
$productId = $product->getId();
- // If $productId is in the collection, remove it from $potentiallyDeletedProductsIds so it's not removed without check
+ // If $productId is in the collection, remove it from $potentiallyDeletedProductsIds
+ // so it's not removed without check
if (isset($potentiallyDeletedProductsIds[$productId])) {
unset($potentiallyDeletedProductsIds[$productId]);
}
@@ -440,7 +485,11 @@ protected function getProductsRecords($storeId, $collection, $potentiallyDeleted
if ($product->isDeleted() === true
|| $product->getStatus() == Status::STATUS_DISABLED
- || !in_array($product->getVisibility(), [Product\Visibility::VISIBILITY_BOTH, Product\Visibility::VISIBILITY_IN_SEARCH, Product\Visibility::VISIBILITY_IN_CATALOG])
+ || !in_array($product->getVisibility(), [
+ Visibility::VISIBILITY_BOTH,
+ Visibility::VISIBILITY_IN_SEARCH,
+ Visibility::VISIBILITY_IN_CATALOG,
+ ])
) {
$productsToRemove[$productId] = $productId;
continue;
@@ -474,13 +523,23 @@ protected function getProductsRecords($storeId, $collection, $potentiallyDeleted
];
}
- public function rebuildStoreProductIndexPage($storeId, $collectionDefault, $page, $pageSize, $emulationInfo = null, $productIds = null, $useTmpIndex = false)
- {
+ public function rebuildStoreProductIndexPage(
+ $storeId,
+ $collectionDefault,
+ $page,
+ $pageSize,
+ $emulationInfo = null,
+ $productIds = null,
+ $useTmpIndex = false
+ ) {
if ($this->isIndexingEnabled($storeId) === false) {
return;
}
- $this->logger->start('rebuildStoreProductIndexPage ' . $this->logger->getStoreName($storeId) . ' page ' . $page . ' pageSize ' . $pageSize);
+ $wrapperLogMessage = 'rebuildStoreProductIndexPage: ' . $this->logger->getStoreName($storeId) . ',
+ page ' . $page . ',
+ pageSize ' . $pageSize;
+ $this->logger->start($wrapperLogMessage);
if ($emulationInfo === null) {
$this->startEmulation($storeId);
@@ -497,7 +556,9 @@ public function rebuildStoreProductIndexPage($storeId, $collectionDefault, $page
if ($this->productHelper->isAttributeEnabled($additionalAttributes, 'rating_summary')) {
$reviewTableName = $this->resource->getTableName('review_entity_summary');
- $collection->getSelect()->columns('(SELECT MAX(rating_summary) FROM ' . $reviewTableName . ' AS o WHERE o.entity_pk_value = e.entity_id AND o.store_id = '.$storeId.') as rating_summary');
+ $collection
+ ->getSelect()
+ ->columns('(SELECT MAX(rating_summary) FROM ' . $reviewTableName . ' AS o WHERE o.entity_pk_value = e.entity_id AND o.store_id = '.$storeId.') as rating_summary');
}
$this->eventManager->dispatch(
@@ -505,12 +566,16 @@ public function rebuildStoreProductIndexPage($storeId, $collectionDefault, $page
['collection' => $collection, 'store' => $storeId]
);
- $this->logger->start('LOADING ' . $this->logger->getStoreName($storeId) . ' collection page ' . $page . ', pageSize ' . $pageSize);
+ $logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
+ collection page: ' . $page . ',
+ pageSize: ' . $pageSize;
+
+ $this->logger->start($logMessage);
$collection->load();
$this->logger->log('Loaded ' . count($collection) . ' products');
- $this->logger->stop('LOADING ' . $this->logger->getStoreName($storeId) . ' collection page ' . $page . ', pageSize ' . $pageSize);
+ $this->logger->stop($logMessage);
$indexName = $this->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId, $useTmpIndex);
@@ -564,7 +629,7 @@ public function rebuildStoreProductIndexPage($storeId, $collectionDefault, $page
$this->stopEmulation();
}
- $this->logger->stop('rebuildStoreProductIndexPage ' . $this->logger->getStoreName($storeId) . ' page ' . $page . ' pageSize ' . $pageSize);
+ $this->logger->stop($wrapperLogMessage);
}
public function startEmulation($storeId)
@@ -604,12 +669,14 @@ public function isIndexingEnabled($storeId = null)
private function setExtraSettings($storeId, $saveToTmpIndicesToo)
{
+ $additionalSectionsSuffix = $this->additionalSectionHelper->getIndexNameSuffix();
+
$sections = [
'products' => $this->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId),
'categories' => $this->getIndexName($this->categoryHelper->getIndexNameSuffix(), $storeId),
'pages' => $this->getIndexName($this->pageHelper->getIndexNameSuffix(), $storeId),
'suggestions' => $this->getIndexName($this->suggestionHelper->getIndexNameSuffix(), $storeId),
- 'additional_sections' => $this->getIndexName($this->additionalSectionHelper->getIndexNameSuffix(), $storeId),
+ 'additional_sections' => $this->getIndexName($additionalSectionsSuffix, $storeId),
];
$error = [];
@@ -628,7 +695,10 @@ private function setExtraSettings($storeId, $saveToTmpIndicesToo)
}
} catch (AlgoliaException $e) {
if (strpos($e->getMessage(), 'Invalid object attributes:') === 0) {
- $error[] = 'Extra settings for "'.$section.'" indices were not saved. Error message: "'.$e->getMessage().'"';
+ $error[] = '
+ Extra settings for "'.$section.'" indices were not saved.
+ Error message: "'.$e->getMessage().'"';
+
continue;
}
@@ -644,7 +714,8 @@ private function setExtraSettings($storeId, $saveToTmpIndicesToo)
private function getSalesData($storeId, Collection $collection)
{
$additionalAttributes = $this->configHelper->getProductAdditionalAttributes($storeId);
- if ($this->productHelper->isAttributeEnabled($additionalAttributes, 'ordered_qty') === false && $this->productHelper->isAttributeEnabled($additionalAttributes, 'total_ordered') === false) {
+ if ($this->productHelper->isAttributeEnabled($additionalAttributes, 'ordered_qty') === false
+ && $this->productHelper->isAttributeEnabled($additionalAttributes, 'total_ordered') === false) {
return [];
}
@@ -657,11 +728,14 @@ private function getSalesData($storeId, Collection $collection)
try {
$salesConnection = $this->resource->getConnectionByName('sales');
- } catch(\DomainException $e) {
+ } catch (\DomainException $e) {
$salesConnection = $this->resource->getConnection();
}
- $query = 'SELECT product_id, SUM(qty_ordered) AS ordered_qty, SUM(row_total) AS total_ordered FROM ' . $ordersTableName . ' WHERE product_id IN (' . $ids . ') GROUP BY product_id';
+ $query = 'SELECT product_id, SUM(qty_ordered) AS ordered_qty, SUM(row_total) AS total_ordered
+ FROM ' . $ordersTableName . '
+ WHERE product_id IN (' . $ids . ')
+ GROUP BY product_id';
$salesData = $salesConnection->query($query)->fetchAll(\PDO::FETCH_GROUP|\PDO::FETCH_UNIQUE|\PDO::FETCH_ASSOC);
return $salesData;
diff --git a/Helper/Entity/AdditionalSectionHelper.php b/Helper/Entity/AdditionalSectionHelper.php
index 86f307db4..28013fcab 100755
--- a/Helper/Entity/AdditionalSectionHelper.php
+++ b/Helper/Entity/AdditionalSectionHelper.php
@@ -15,8 +15,11 @@ class AdditionalSectionHelper
private $eavConfig;
- public function __construct(ManagerInterface $eventManager, ObjectManagerInterface $objectManager, Config $eavConfig)
- {
+ public function __construct(
+ ManagerInterface $eventManager,
+ ObjectManagerInterface $objectManager,
+ Config $eavConfig
+ ) {
$this->eventManager = $eventManager;
$this->objectManager = $objectManager;
$this->eavConfig = $eavConfig;
@@ -34,7 +37,10 @@ public function getIndexSettings($storeId)
];
$transport = new DataObject($indexSettings);
- $this->eventManager->dispatch('algolia_additional_sections_index_before_set_settings', ['store_id' => $storeId, 'index_settings' => $transport]);
+ $this->eventManager->dispatch(
+ 'algolia_additional_sections_index_before_set_settings',
+ ['store_id' => $storeId, 'index_settings' => $transport]
+ );
$indexSettings = $transport->getData();
return $indexSettings;
@@ -74,8 +80,14 @@ public function getAttributeValues($storeId, $section)
];
$transport = new DataObject($record);
- $this->eventManager->dispatch('algolia_additional_section_item_index_before', ['section' => $section, 'record' => $transport, 'store_id' => $storeId]);
- $this->eventManager->dispatch('algolia_additional_section_items_before_index', ['section' => $section, 'record' => $transport, 'store_id' => $storeId]);
+ $this->eventManager->dispatch(
+ 'algolia_additional_section_item_index_before',
+ ['section' => $section, 'record' => $transport, 'store_id' => $storeId]
+ );
+ $this->eventManager->dispatch(
+ 'algolia_additional_section_items_before_index',
+ ['section' => $section, 'record' => $transport, 'store_id' => $storeId]
+ );
$record = $transport->getData();
return $record;
diff --git a/Helper/Entity/CategoryHelper.php b/Helper/Entity/CategoryHelper.php
index fa0416633..689a0ec88 100755
--- a/Helper/Entity/CategoryHelper.php
+++ b/Helper/Entity/CategoryHelper.php
@@ -40,8 +40,14 @@ class CategoryHelper
protected static $_activeCategories;
protected static $_categoryNames;
- public function __construct(ManagerInterface $eventManager, ObjectManagerInterface $objectManager, StoreManagerInterface $storeManager, ResourceConnection $resourceConnection, Config $eavConfig, ConfigHelper $configHelper)
- {
+ public function __construct(
+ ManagerInterface $eventManager,
+ ObjectManagerInterface $objectManager,
+ StoreManagerInterface $storeManager,
+ ResourceConnection $resourceConnection,
+ Config $eavConfig,
+ ConfigHelper $configHelper
+ ) {
$this->eventManager = $eventManager;
$this->objectManager = $objectManager;
$this->storeManager = $storeManager;
@@ -94,13 +100,11 @@ public function getIndexSettings($storeId)
$this->eventManager->dispatch('algolia_index_settings_prepare', [ // Only for backward compatibility
'store_id' => $storeId,
'index_settings' => $transport,
- ]
- );
+ ]);
$this->eventManager->dispatch('algolia_categories_index_before_set_settings', [
'store_id' => $storeId,
'index_settings' => $transport,
- ]
- );
+ ]);
$indexSettings = $transport->getData();
return $indexSettings;
@@ -146,14 +150,17 @@ public function getCategoryCollectionQuery($storeId, $categoryIds = null)
$categories->addFieldToFilter('entity_id', ['in' => $categoryIds]);
}
- $this->eventManager->dispatch('algolia_after_categories_collection_build', ['store' => $storeId, 'collection' => $categories]);
+ $this->eventManager->dispatch(
+ 'algolia_after_categories_collection_build',
+ ['store' => $storeId, 'collection' => $categories]
+ );
return $categories;
}
public function getAllAttributes()
{
- if (is_null(self::$_categoryAttributes)) {
+ if (self::$_categoryAttributes === null) {
self::$_categoryAttributes = [];
$allAttributes = $this->eavConfig->getEntityAttributeCodes('catalog_category');
@@ -162,11 +169,12 @@ public function getAllAttributes()
$excludedAttributes = [
'all_children', 'available_sort_by', 'children', 'children_count', 'custom_apply_to_products',
- 'custom_design', 'custom_design_from', 'custom_design_to', 'custom_layout_update', 'custom_use_parent_settings',
- 'default_sort_by', 'display_mode', 'filter_price_range', 'global_position', 'image', 'include_in_menu', 'is_active',
- 'is_always_include_in_menu', 'is_anchor', 'landing_page', 'level', 'lower_cms_block',
- 'page_layout', 'path_in_store', 'position', 'small_image', 'thumbnail', 'url_key', 'url_path',
- 'visible_in_menu', ];
+ 'custom_design', 'custom_design_from', 'custom_design_to', 'custom_layout_update',
+ 'custom_use_parent_settings', 'default_sort_by', 'display_mode', 'filter_price_range',
+ 'global_position', 'image', 'include_in_menu', 'is_active', 'is_always_include_in_menu', 'is_anchor',
+ 'landing_page', 'level', 'lower_cms_block', 'page_layout', 'path_in_store', 'position', 'small_image',
+ 'thumbnail', 'url_key', 'url_path','visible_in_menu',
+ ];
$categoryAttributes = array_diff($categoryAttributes, $excludedAttributes);
@@ -189,7 +197,10 @@ public function getObject(Category $category)
$category->setProductCount($productCollection->getSize());
$transport = new DataObject();
- $this->eventManager->dispatch('algolia_category_index_before', ['category' => $category, 'custom_data' => $transport]);
+ $this->eventManager->dispatch(
+ 'algolia_category_index_before',
+ ['category' => $category, 'custom_data' => $transport]
+ );
$customData = $transport->getData();
$storeId = $category->getStoreId();
@@ -257,7 +268,10 @@ public function getObject(Category $category)
$data = array_merge($data, $customData);
$transport = new DataObject($data);
- $this->eventManager->dispatch('algolia_after_create_category_object', ['category' => $category, 'categoryObject' => $transport]);
+ $this->eventManager->dispatch(
+ 'algolia_after_create_category_object',
+ ['category' => $category, 'categoryObject' => $transport]
+ );
$data = $transport->getData();
return $data;
@@ -300,8 +314,8 @@ private function getUrl(Category $category)
public function isCategoryActive($categoryId, $storeId = null)
{
- $storeId = intval($storeId);
- $categoryId = intval($categoryId);
+ $storeId = (int) $storeId;
+ $categoryId = (int) $categoryId;
if ($path = $this->getCategoryPath($categoryId, $storeId)) {
// Check whether the specified category is active
@@ -337,8 +351,8 @@ public function isCategoryActive($categoryId, $storeId = null)
private function getCategoryPath($categoryId, $storeId = null)
{
$categories = $this->getCategories();
- $storeId = intval($storeId);
- $categoryId = intval($categoryId);
+ $storeId = (int) $storeId;
+ $categoryId = (int) $categoryId;
$path = null;
$categoryKeyId = $categoryId;
@@ -350,19 +364,19 @@ private function getCategoryPath($categoryId, $storeId = null)
}
}
- if(is_null($categoryKeyId)) {
+ if ($categoryKeyId === null) {
return $path;
}
$key = $storeId . '-' . $categoryKeyId;
if (isset($categories[$key])) {
- $path = ($categories[$key]['value'] == 1) ? strval($categories[$key]['path']) : null;
+ $path = ($categories[$key]['value'] == 1) ? (string) $categories[$key]['path'] : null;
} elseif ($storeId !== 0) {
$key = '0-' . $categoryKeyId;
if (isset($categories[$key])) {
- $path = ($categories[$key]['value'] == 1) ? strval($categories[$key]['path']) : null;
+ $path = ($categories[$key]['value'] == 1) ? (string) $categories[$key]['path'] : null;
}
}
@@ -371,20 +385,30 @@ private function getCategoryPath($categoryId, $storeId = null)
private function getCategories()
{
- if (is_null(self::$_activeCategories)) {
+ if (self::$_activeCategories === null) {
self::$_activeCategories = [];
/** @var \Magento\Catalog\Model\ResourceModel\Category $resource */
$resource = $this->objectManager->create('\Magento\Catalog\Model\ResourceModel\Category');
if ($attribute = $resource->getAttribute('is_active')) {
+ $columnId = $this->getCorrectIdColumn();
+ $key = new \Zend_Db_Expr("CONCAT(backend.store_id, '-', backend.".$columnId.")");
+
$connection = $this->resourceConnection->getConnection();
$select = $connection->select()
- ->from(['backend' => $attribute->getBackendTable()], ['key' => new \Zend_Db_Expr("CONCAT(backend.store_id, '-', backend.".$this->getCorrectIdColumn().")"), 'category.path', 'backend.value'])
- ->join(['category' => $resource->getTable('catalog_category_entity')], 'backend.'.$this->getCorrectIdColumn().' = category.'.$this->getCorrectIdColumn(), [])
+ ->from(
+ ['backend' => $attribute->getBackendTable()],
+ ['key' => $key, 'category.path', 'backend.value']
+ )
+ ->join(
+ ['category' => $resource->getTable('catalog_category_entity')],
+ 'backend.'.$columnId.' = category.'.$columnId,
+ []
+ )
->where('backend.attribute_id = ?', $attribute->getAttributeId())
->order('backend.store_id')
- ->order('backend.'.$this->getCorrectIdColumn());
+ ->order('backend.'.$columnId);
self::$_activeCategories = $connection->fetchAssoc($select);
}
@@ -403,21 +427,30 @@ public function getCategoryName($categoryId, $storeId = null)
$storeId = $storeId->getId();
}
- $categoryId = intval($categoryId);
- $storeId = intval($storeId);
+ $categoryId = (int) $categoryId;
+ $storeId = (int) $storeId;
- if (is_null(self::$_categoryNames)) {
+ if (self::$_categoryNames === null) {
self::$_categoryNames = [];
/** @var \Magento\Catalog\Model\ResourceModel\Category $categoryModel */
$categoryModel = $this->objectManager->create('\Magento\Catalog\Model\ResourceModel\Category');
if ($attribute = $categoryModel->getAttribute('name')) {
- $connection = $this->resourceConnection->getConnection();
+ $columnId = $this->getCorrectIdColumn();
+ $expression = new \Zend_Db_Expr("CONCAT(backend.store_id, '-', backend.".$columnId.")");
+ $connection = $this->resourceConnection->getConnection();
$select = $connection->select()
- ->from(['backend' => $attribute->getBackendTable()], [new \Zend_Db_Expr("CONCAT(backend.store_id, '-', backend.".$this->getCorrectIdColumn().")"), 'backend.value'])
- ->join(['category' => $categoryModel->getTable('catalog_category_entity')], 'backend.'.$this->getCorrectIdColumn().' = category.'.$this->getCorrectIdColumn(), [])
+ ->from(
+ ['backend' => $attribute->getBackendTable()],
+ [$expression, 'backend.value']
+ )
+ ->join(
+ ['category' => $categoryModel->getTable('catalog_category_entity')],
+ 'backend.'.$columnId.' = category.'.$columnId,
+ []
+ )
->where('backend.attribute_id = ?', $attribute->getAttributeId())
->where('category.level > ?', 1);
@@ -436,7 +469,7 @@ public function getCategoryName($categoryId, $storeId = null)
}
}
- if(is_null($categoryKeyId)) {
+ if ($categoryKeyId === null) {
return $categoryName;
}
@@ -444,12 +477,12 @@ public function getCategoryName($categoryId, $storeId = null)
if (isset(self::$_categoryNames[$key])) {
// Check whether the category name is present for the specified store
- $categoryName = strval(self::$_categoryNames[$key]);
+ $categoryName = (string) self::$_categoryNames[$key];
} elseif ($storeId != 0) {
// Check whether the category name is present for the default store
$key = '0-' . $categoryKeyId;
if (isset(self::$_categoryNames[$key])) {
- $categoryName = strval(self::$_categoryNames[$key]);
+ $categoryName = (string) self::$_categoryNames[$key];
}
}
@@ -481,7 +514,8 @@ public function isCategoryVisibleInMenu($categoryId, $storeId)
return $this->isCategoryVisibleInMenuCache[$key];
}
- public function getCoreCategories() {
+ public function getCoreCategories()
+ {
if (isset($this->coreCategories)) {
return $this->coreCategories;
}
@@ -511,7 +545,10 @@ private function getCorrectIdColumn()
$this->idColumn = 'entity_id';
- if ($this->configHelper->getMagentoEdition() !== 'Community' && version_compare($this->configHelper->getMagentoVersion(), '2.1.0', '>=')) {
+ $edition = $this->configHelper->getMagentoEdition();
+ $version = $this->configHelper->getMagentoVersion();
+
+ if ($edition !== 'Community' && version_compare($version, '2.1.0', '>=')) {
$this->idColumn = 'row_id';
}
diff --git a/Helper/Entity/PageHelper.php b/Helper/Entity/PageHelper.php
index 12cf8c433..c60c9b74c 100755
--- a/Helper/Entity/PageHelper.php
+++ b/Helper/Entity/PageHelper.php
@@ -25,8 +25,13 @@ class PageHelper
private $storeUrls;
- public function __construct(ManagerInterface $eventManager, ObjectManagerInterface $objectManager, ConfigHelper $configHelper, FilterProvider $filterProvider, StoreManagerInterface $storeManager)
- {
+ public function __construct(
+ ManagerInterface $eventManager,
+ ObjectManagerInterface $objectManager,
+ ConfigHelper $configHelper,
+ FilterProvider $filterProvider,
+ StoreManagerInterface $storeManager
+ ) {
$this->eventManager = $eventManager;
$this->objectManager = $objectManager;
$this->configHelper = $configHelper;
@@ -47,7 +52,10 @@ public function getIndexSettings($storeId)
];
$transport = new DataObject($indexSettings);
- $this->eventManager->dispatch('algolia_pages_index_before_set_settings', ['store_id' => $storeId, 'index_settings' => $transport]);
+ $this->eventManager->dispatch(
+ 'algolia_pages_index_before_set_settings',
+ ['store_id' => $storeId, 'index_settings' => $transport]
+ );
$indexSettings = $transport->getData();
return $indexSettings;
@@ -95,11 +103,21 @@ public function getPages($storeId)
}
$pageObject['objectID'] = $page->getId();
- $pageObject['url'] = $this->getStoreUrl($storeId)->getUrl(null, ['_direct' => $page->getIdentifier(), '_secure' => $this->configHelper->useSecureUrlsInFrontend($storeId)]);
- $pageObject['content'] = $this->strip($content, array('script', 'style'));
+ $pageObject['url'] = $this->getStoreUrl($storeId)
+ ->getUrl(
+ null,
+ [
+ '_direct' => $page->getIdentifier(),
+ '_secure' => $this->configHelper->useSecureUrlsInFrontend($storeId),
+ ]
+ );
+ $pageObject['content'] = $this->strip($content, ['script', 'style']);
$transport = new DataObject($pageObject);
- $this->eventManager->dispatch('algolia_after_create_page_object', ['page' => $transport, 'pageObject' => $page]);
+ $this->eventManager->dispatch(
+ 'algolia_after_create_page_object',
+ ['page' => $transport, 'pageObject' => $page]
+ );
$pageObject = $transport->getData();
$pages[] = $pageObject;
@@ -159,7 +177,7 @@ private function strip($s, $completeRemoveTags = [])
if (!empty($completeRemoveTags) && $s) {
$dom = new \DOMDocument();
if (@$dom->loadHTML(mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'))) {
- $toRemove = array();
+ $toRemove = [];
foreach ($completeRemoveTags as $tag) {
$removeTags = $dom->getElementsByTagName($tag);
diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php
index d9e1f9af6..f4422a074 100755
--- a/Helper/Entity/ProductHelper.php
+++ b/Helper/Entity/ProductHelper.php
@@ -111,7 +111,8 @@ public function __construct(
'options' =>[
'shouldRemovePubDir' => $this->configHelper->shouldRemovePubDirectory(),
]
- ]);
+ ]
+ );
}
public function getIndexNameSuffix()
@@ -121,7 +122,7 @@ public function getIndexNameSuffix()
public function getAllAttributes($addEmptyRow = false)
{
- if (is_null(self::$_productAttributes)) {
+ if (self::$_productAttributes === null) {
self::$_productAttributes = [];
$allAttributes = $this->eavConfig->getEntityAttributeCodes('catalog_product');
@@ -142,16 +143,19 @@ public function getAllAttributes($addEmptyRow = false)
$excludedAttributes = [
'all_children', 'available_sort_by', 'children', 'children_count', 'custom_apply_to_products',
- 'custom_design', 'custom_design_from', 'custom_design_to', 'custom_layout_update', 'custom_use_parent_settings',
- 'default_sort_by', 'display_mode', 'filter_price_range', 'global_position', 'image', 'include_in_menu', 'is_active',
- 'is_always_include_in_menu', 'is_anchor', 'landing_page', 'level', 'lower_cms_block',
- 'page_layout', 'path_in_store', 'position', 'small_image', 'thumbnail', 'url_key', 'url_path',
- 'visible_in_menu', 'quantity_and_stock_status', ];
+ 'custom_design', 'custom_design_from', 'custom_design_to', 'custom_layout_update',
+ 'custom_use_parent_settings', 'default_sort_by', 'display_mode', 'filter_price_range',
+ 'global_position', 'image', 'include_in_menu', 'is_active', 'is_always_include_in_menu', 'is_anchor',
+ 'landing_page', 'level', 'lower_cms_block', 'page_layout', 'path_in_store', 'position', 'small_image',
+ 'thumbnail', 'url_key', 'url_path', 'visible_in_menu', 'quantity_and_stock_status',
+ ];
$productAttributes = array_diff($productAttributes, $excludedAttributes);
foreach ($productAttributes as $attributeCode) {
- self::$_productAttributes[$attributeCode] = $this->eavConfig->getAttribute('catalog_product', $attributeCode)->getFrontendLabel();
+ self::$_productAttributes[$attributeCode] = $this->eavConfig
+ ->getAttribute('catalog_product', $attributeCode)
+ ->getFrontendLabel();
}
}
@@ -190,7 +194,10 @@ public function getProductCollectionQuery($storeId, $productIds = null, $onlyVis
->distinct(true);
if ($onlyVisible) {
- $products = $products->addAttributeToFilter('visibility', ['in' => $this->visibility->getVisibleInSiteIds()]);
+ $products = $products->addAttributeToFilter(
+ 'visibility',
+ ['in' => $this->visibility->getVisibleInSiteIds()]
+ );
}
if ($onlyVisible && $this->configHelper->getShowOutOfStock($storeId) === false) {
@@ -203,7 +210,10 @@ public function getProductCollectionQuery($storeId, $productIds = null, $onlyVis
->addAttributeToSelect('special_from_date')
->addAttributeToSelect('special_to_date')
->addAttributeToSelect('visibility')
- ->addAttributeToFilter('status', ['=' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED]);
+ ->addAttributeToFilter(
+ 'status',
+ ['=' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED]
+ );
$additionalAttr = $this->getAdditionalAttributes($storeId);
@@ -220,8 +230,14 @@ public function getProductCollectionQuery($storeId, $productIds = null, $onlyVis
$products = $products->addAttributeToFilter('entity_id', ['in' => $productIds]);
}
- $this->eventManager->dispatch('algolia_rebuild_store_product_index_collection_load_before', ['store' => $storeId, 'collection' => $products]); // Only for backward compatibility
- $this->eventManager->dispatch('algolia_after_products_collection_build', ['store' => $storeId, 'collection' => $products]);
+ $this->eventManager->dispatch( // Only for backward compatibility
+ 'algolia_rebuild_store_product_index_collection_load_before',
+ ['store' => $storeId, 'collection' => $products]
+ );
+ $this->eventManager->dispatch(
+ 'algolia_after_products_collection_build',
+ ['store' => $storeId, 'collection' => $products]
+ );
return $products;
}
@@ -251,7 +267,8 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
}
if ($attribute['attribute'] == 'categories') {
- $searchableAttributes[] = (isset($attribute['order']) && $attribute['order'] == 'ordered') ? 'categories_without_path' : 'unordered(categories_without_path)';
+ $searchableAttributes[] = (isset($attribute['order']) && $attribute['order'] == 'ordered') ?
+ 'categories_without_path' : 'unordered(categories_without_path)';
}
}
@@ -269,7 +286,8 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
$facet['attribute'] = 'price.' . $currency_code . '.default';
if ($this->configHelper->isCustomerGroupsEnabled($storeId)) {
- $groupCollection = $this->objectManager->create('Magento\Customer\Model\ResourceModel\Group\Collection');
+ $groupCollection = $this->objectManager
+ ->create('Magento\Customer\Model\ResourceModel\Group\Collection');
foreach ($groupCollection as $group) {
$group_id = (int) $group->getData('customer_group_id');
@@ -304,14 +322,17 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
// Additional index settings from event observer
$transport = new DataObject($indexSettings);
- $this->eventManager->dispatch('algolia_index_settings_prepare', [ // Only for backward compatibility
- 'store_id' => $storeId,
- 'index_settings' => $transport,
- ]);
- $this->eventManager->dispatch('algolia_products_index_before_set_settings', [
- 'store_id' => $storeId,
- 'index_settings' => $transport,
- ]);
+ $this->eventManager->dispatch( // Only for backward compatibility
+ 'algolia_index_settings_prepare',
+ ['store_id' => $storeId, 'index_settings' => $transport]
+ );
+ $this->eventManager->dispatch(
+ 'algolia_products_index_before_set_settings',
+ [
+ 'store_id' => $storeId,
+ 'index_settings' => $transport,
+ ]
+ );
$indexSettings = $transport->getData();
$this->algoliaHelper->setSettings($indexName, $indexSettings, false, true);
@@ -326,7 +347,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
$sortingIndices = $this->configHelper->getSortingIndices($indexName, $storeId);
if ($isInstantSearchEnabled === true && count($sortingIndices) > 0) {
- $replicas = array_values(array_map(function($sortingIndex) {
+ $replicas = array_values(array_map(function ($sortingIndex) {
return $sortingIndex['name'];
}, $sortingIndices));
@@ -416,17 +437,29 @@ protected function handlePrice(Product &$product, $subProducts, &$customData)
$price = $this->priceCurrency->convert($price, $store, $currencyCode);
}
- $price = (double) $this->catalogHelper->getTaxPrice($product, $price, $withTax, null, null, null, $product->getStore(), null);
+ $price = (double) $this->catalogHelper
+ ->getTaxPrice($product, $price, $withTax, null, null, null, $product->getStore(), null);
$customData[$field][$currencyCode]['default'] = $this->priceCurrency->round($price);
- $customData[$field][$currencyCode]['default_formated'] = $this->priceCurrency->format($price, false, PriceCurrencyInterface::DEFAULT_PRECISION, $store, $currencyCode);
+ $customData[$field][$currencyCode]['default_formated'] = $this->priceCurrency->format(
+ $price,
+ false,
+ PriceCurrencyInterface::DEFAULT_PRECISION,
+ $store,
+ $currencyCode
+ );
$specialPrices = [];
$specialPrice = [];
foreach ($groups as $group) {
$groupId = (int) $group->getData('customer_group_id');
$specialPrices[$groupId] = [];
- $specialPrices[$groupId][] = (double) $this->rule->getRulePrice(new \DateTime(), $store->getWebsiteId(), $groupId, $product->getId()); // The price with applied catalog rules
+ $specialPrices[$groupId][] = (double) $this->rule->getRulePrice(
+ new \DateTime(),
+ $store->getWebsiteId(),
+ $groupId,
+ $product->getId()
+ ); // The price with applied catalog rules
$specialPrices[$groupId][] = $product->getFinalPrice(); // The product's special price
$specialPrices[$groupId] = array_filter($specialPrices[$groupId], function ($price) {
@@ -440,11 +473,24 @@ protected function handlePrice(Product &$product, $subProducts, &$customData)
if ($specialPrice[$groupId]) {
if ($currencyCode !== $baseCurrencyCode) {
- $specialPrice[$groupId] = $this->priceCurrency->convert($specialPrice[$groupId], $store, $currencyCode);
+ $specialPrice[$groupId] = $this->priceCurrency->convert(
+ $specialPrice[$groupId],
+ $store,
+ $currencyCode
+ );
$specialPrice[$groupId] = $this->priceCurrency->round($specialPrice[$groupId]);
}
- $specialPrice[$groupId] = (double) $this->catalogHelper->getTaxPrice($product, $specialPrice[$groupId], $withTax, null, null, null, $product->getStore(), null);
+ $specialPrice[$groupId] = (double) $this->catalogHelper->getTaxPrice(
+ $product,
+ $specialPrice[$groupId],
+ $withTax,
+ null,
+ null,
+ null,
+ $product->getStore(),
+ null
+ );
}
}
@@ -461,15 +507,39 @@ protected function handlePrice(Product &$product, $subProducts, &$customData)
}
if ($discountedPrice !== false) {
- $customData[$field][$currencyCode]['group_' . $groupId] = (double) $this->catalogHelper->getTaxPrice($product, $discountedPrice, $withTax, null, null, null, $product->getStore(), null);
- $customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $this->priceCurrency->format($customData[$field][$currencyCode]['group_' . $groupId], false, PriceCurrencyInterface::DEFAULT_PRECISION, $store, $currencyCode);
-
- if ($customData[$field][$currencyCode]['default'] > $customData[$field][$currencyCode]['group_' . $groupId]) {
- $customData[$field][$currencyCode]['group_'.$groupId.'_original_formated'] = $customData[$field][$currencyCode]['default_formated'];
+ $taxPrice = (double) $this->catalogHelper->getTaxPrice(
+ $product,
+ $discountedPrice,
+ $withTax,
+ null,
+ null,
+ null,
+ $product->getStore(),
+ null
+ );
+
+ $customData[$field][$currencyCode]['group_' . $groupId] = $taxPrice;
+
+ $formated = $this->priceCurrency->format(
+ $customData[$field][$currencyCode]['group_' . $groupId],
+ false,
+ PriceCurrencyInterface::DEFAULT_PRECISION,
+ $store,
+ $currencyCode
+ );
+ $customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $formated;
+
+ if ($customData[$field][$currencyCode]['default'] >
+ $customData[$field][$currencyCode]['group_' . $groupId]) {
+ $original = $customData[$field][$currencyCode]['default_formated'];
+ $customData[$field][$currencyCode]['group_'.$groupId.'_original_formated'] = $original;
}
} else {
- $customData[$field][$currencyCode]['group_' . $groupId] = $customData[$field][$currencyCode]['default'];
- $customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $customData[$field][$currencyCode]['default_formated'];
+ $default = $customData[$field][$currencyCode]['default'];
+ $customData[$field][$currencyCode]['group_' . $groupId] = $default;
+
+ $defaultFormated = $customData[$field][$currencyCode]['default_formated'];
+ $customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $defaultFormated;
}
}
@@ -483,21 +553,40 @@ protected function handlePrice(Product &$product, $subProducts, &$customData)
foreach ($groups as $group) {
$groupId = (int) $group->getData('customer_group_id');
- if ($specialPrice[$groupId] && $specialPrice[$groupId] < $customData[$field][$currencyCode]['group_' . $groupId]) {
+ if ($specialPrice[$groupId]
+ && $specialPrice[$groupId] < $customData[$field][$currencyCode]['group_' . $groupId]) {
$customData[$field][$currencyCode]['group_' . $groupId] = $specialPrice[$groupId];
- $customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $this->priceCurrency->format($specialPrice[$groupId], false, PriceCurrencyInterface::DEFAULT_PRECISION, $store, $currencyCode);
- if ($customData[$field][$currencyCode]['default'] > $customData[$field][$currencyCode]['group_' . $groupId]) {
- $customData[$field][$currencyCode]['group_'.$groupId.'_original_formated'] = $customData[$field][$currencyCode]['default_formated'];
+ $formated = $this->priceCurrency->format(
+ $specialPrice[$groupId],
+ false,
+ PriceCurrencyInterface::DEFAULT_PRECISION,
+ $store,
+ $currencyCode
+ );
+ $customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $formated;
+
+ if ($customData[$field][$currencyCode]['default'] >
+ $customData[$field][$currencyCode]['group_' . $groupId]) {
+ $original = $customData[$field][$currencyCode]['default_formated'];
+ $customData[$field][$currencyCode]['group_'.$groupId.'_original_formated'] = $original;
}
}
}
} else {
if ($specialPrice[0] && $specialPrice[0] < $customData[$field][$currencyCode]['default']) {
- $customData[$field][$currencyCode]['default_original_formated'] = $customData[$field][$currencyCode]['default_formated'];
-
+ $defaultOriginalFormated = $customData[$field][$currencyCode]['default_formated'];
+ $customData[$field][$currencyCode]['default_original_formated'] = $defaultOriginalFormated;
+
+ $defaultFormated = $this->priceCurrency->format(
+ $specialPrice[0],
+ false,
+ PriceCurrencyInterface::DEFAULT_PRECISION,
+ $store,
+ $currencyCode
+ );
$customData[$field][$currencyCode]['default'] = $this->priceCurrency->round($specialPrice[0]);
- $customData[$field][$currencyCode]['default_formated'] = $this->priceCurrency->format($specialPrice[0], false, PriceCurrencyInterface::DEFAULT_PRECISION, $store, $currencyCode);
+ $customData[$field][$currencyCode]['default_formated'] = $defaultFormated;
}
}
@@ -517,14 +606,23 @@ protected function handlePrice(Product &$product, $subProducts, &$customData)
if (count($subProducts) > 0) {
/** @var Product $subProduct */
foreach ($subProducts as $subProduct) {
- $price = (double) $this->catalogHelper->getTaxPrice($product, $subProduct->getFinalPrice(), $withTax, null, null, null, $product->getStore(), null);
+ $price = (double) $this->catalogHelper->getTaxPrice(
+ $product,
+ $subProduct->getFinalPrice(),
+ $withTax,
+ null,
+ null,
+ null,
+ $product->getStore(),
+ null
+ );
$min = min($min, $price);
$max = max($max, $price);
}
} else {
$min = $max;
- } // avoid to have PHP_INT_MAX in case of no subproducts (Corner case of visibility and stock options)
+ }
}
if ($min != $max) {
@@ -537,11 +635,24 @@ protected function handlePrice(Product &$product, $subProducts, &$customData)
}
$dashedFormat =
- $this->priceCurrency->format($min, false, PriceCurrencyInterface::DEFAULT_PRECISION, $store, $currencyCode)
+ $this->priceCurrency->format(
+ $min,
+ false,
+ PriceCurrencyInterface::DEFAULT_PRECISION,
+ $store,
+ $currencyCode
+ )
. ' - ' .
- $this->priceCurrency->format($max, false, PriceCurrencyInterface::DEFAULT_PRECISION, $store, $currencyCode);
-
- if (isset($customData[$field][$currencyCode]['default_original_formated']) === false || $min <= $customData[$field][$currencyCode]['default']) {
+ $this->priceCurrency->format(
+ $max,
+ false,
+ PriceCurrencyInterface::DEFAULT_PRECISION,
+ $store,
+ $currencyCode
+ );
+
+ if (isset($customData[$field][$currencyCode]['default_original_formated']) === false
+ || $min <= $customData[$field][$currencyCode]['default']) {
$customData[$field][$currencyCode]['default_formated'] = $dashedFormat;
//// Do not keep special price that is already taken into account in min max
@@ -557,8 +668,8 @@ protected function handlePrice(Product &$product, $subProducts, &$customData)
$groupId = (int) $group->getData('customer_group_id');
if ($min != $max && $min <= $customData[$field][$currencyCode]['group_' . $groupId]) {
- $customData[$field][$currencyCode]['group_' . $groupId] = 0;
- $customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $dashedFormat;
+ $customData[$field][$currencyCode]['group_'.$groupId] = 0;
+ $customData[$field][$currencyCode]['group_'.$groupId.'_formated'] = $dashedFormat;
}
}
}
@@ -572,8 +683,15 @@ protected function handlePrice(Product &$product, $subProducts, &$customData)
$min = $this->priceCurrency->convert($min, $store, $currencyCode);
}
+ $minFormated = $this->priceCurrency->format(
+ $min,
+ false,
+ PriceCurrencyInterface::DEFAULT_PRECISION,
+ $store,
+ $currencyCode
+ );
$customData[$field][$currencyCode]['default'] = $min;
- $customData[$field][$currencyCode]['default_formated'] = $this->priceCurrency->format($min, false, PriceCurrencyInterface::DEFAULT_PRECISION, $store, $currencyCode);
+ $customData[$field][$currencyCode]['default_formated'] = $minFormated;
}
}
@@ -585,9 +703,10 @@ protected function handlePrice(Product &$product, $subProducts, &$customData)
$customData[$field][$currencyCode]['group_' . $groupId] = $min;
if ($min === $max) {
- $customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $customData[$field][$currencyCode]['default_formated'];
+ $default = $customData[$field][$currencyCode]['default_formated'];
+ $customData[$field][$currencyCode]['group_'.$groupId.'_formated'] = $default;
} else {
- $customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $dashedFormat;
+ $customData[$field][$currencyCode]['group_'.$groupId.'_formated'] = $dashedFormat;
}
}
}
@@ -614,11 +733,16 @@ public function getAllCategories($categoryIds)
public function getObject(Product $product)
{
$type = $product->getTypeId();
- $this->logger->start('CREATE RECORD ' . $product->getId() . ' ' . $this->logger->getStoreName($product->getStoreId()));
+ $storeId = $product->getStoreId();
+
+ $this->logger->start('CREATE RECORD ' . $product->getId() . ' ' . $this->logger->getStoreName($storeId));
$defaultData = [];
$transport = new DataObject($defaultData);
- $this->eventManager->dispatch('algolia_product_index_before', ['product' => $product, 'custom_data' => $transport]);
+ $this->eventManager->dispatch(
+ 'algolia_product_index_before',
+ ['product' => $product, 'custom_data' => $transport]
+ );
$defaultData = $transport->getData();
@@ -678,13 +802,14 @@ public function getObject(Product $product)
$path = [];
foreach ($category->getPathIds() as $treeCategoryId) {
- if (!$this->configHelper->showCatsNotIncludedInNavigation($product->getStoreId()) && !$this->categoryHelper->isCategoryVisibleInMenu($treeCategoryId, $product->getStoreId())) {
+ if (!$this->configHelper->showCatsNotIncludedInNavigation($storeId)
+ && !$this->categoryHelper->isCategoryVisibleInMenu($treeCategoryId, $storeId)) {
// If the category should not be included in menu - skip it
$path[] = null;
continue;
}
- $name = $this->categoryHelper->getCategoryName($treeCategoryId, $product->getStoreId());
+ $name = $this->categoryHelper->getCategoryName($treeCategoryId, $storeId);
if ($name) {
$path[] = $name;
}
@@ -700,7 +825,10 @@ public function getObject(Product $product)
}
}
- $categoriesWithPath = array_intersect_key($categoriesWithPath, array_unique(array_map('serialize', $categoriesWithPath)));
+ $categoriesWithPath = array_intersect_key(
+ $categoriesWithPath,
+ array_unique(array_map('serialize', $categoriesWithPath))
+ );
$categoriesHierarchical = [];
@@ -766,19 +894,22 @@ public function getObject(Product $product)
}
// skip default calculation if we have provided these attributes via the observer in $defaultData
- if (false === isset($defaultData['ordered_qty']) && $this->isAttributeEnabled($additionalAttributes, 'ordered_qty')) {
+ if (false === isset($defaultData['ordered_qty'])
+ && $this->isAttributeEnabled($additionalAttributes, 'ordered_qty')) {
$customData['ordered_qty'] = (int) $product->getData('ordered_qty');
}
- if (false === isset($defaultData['total_ordered']) && $this->isAttributeEnabled($additionalAttributes, 'total_ordered')) {
+ if (false === isset($defaultData['total_ordered'])
+ && $this->isAttributeEnabled($additionalAttributes, 'total_ordered')) {
$customData['total_ordered'] = (int) $product->getData('total_ordered');
}
- if (false === isset($defaultData['stock_qty']) && $this->isAttributeEnabled($additionalAttributes, 'stock_qty')) {
+ if (false === isset($defaultData['stock_qty'])
+ && $this->isAttributeEnabled($additionalAttributes, 'stock_qty')) {
$customData['stock_qty'] = 0;
$stockItem = $this->stockRegistry->getStockItem($product->getId());
- if($stockItem) {
+ if ($stockItem) {
$customData['stock_qty'] = (int) $stockItem->getQty();
}
}
@@ -813,7 +944,7 @@ public function getObject(Product $product)
foreach ($subProducts as $subProduct) {
$isInStock = (int) $this->stockRegistry->getStockItem($subProduct->getId())->getIsInStock();
- if ($isInStock == false && $this->configHelper->indexOutOfStockOptions($product->getStoreId()) == false) {
+ if ($isInStock == false && $this->configHelper->indexOutOfStockOptions($storeId) == false) {
continue;
}
@@ -875,7 +1006,10 @@ public function getObject(Product $product)
$customData['type_id'] = $type;
$transport = new DataObject($customData);
- $this->eventManager->dispatch('algolia_subproducts_index', ['custom_data' => $transport, 'sub_products' => $subProducts, 'productObject' => $product]);
+ $this->eventManager->dispatch(
+ 'algolia_subproducts_index',
+ ['custom_data' => $transport, 'sub_products' => $subProducts, 'productObject' => $product]
+ );
$customData = $transport->getData();
$customData = array_merge($customData, $defaultData);
@@ -883,10 +1017,13 @@ public function getObject(Product $product)
$this->algoliaHelper->castProductObject($customData);
$transport = new DataObject($customData);
- $this->eventManager->dispatch('algolia_after_create_product_object', ['custom_data' => $transport, 'sub_products' => $subProducts, 'productObject' => $product]);
+ $this->eventManager->dispatch(
+ 'algolia_after_create_product_object',
+ ['custom_data' => $transport, 'sub_products' => $subProducts, 'productObject' => $product]
+ );
$customData = $transport->getData();
- $this->logger->stop('CREATE RECORD ' . $product->getId() . ' ' . $this->logger->getStoreName($product->getStoreId()));
+ $this->logger->stop('CREATE RECORD ' . $product->getId() . ' ' . $this->logger->getStoreName($storeId));
return $customData;
}
diff --git a/Helper/Entity/SuggestionHelper.php b/Helper/Entity/SuggestionHelper.php
index 7d95aa9c9..4a2fb47b5 100755
--- a/Helper/Entity/SuggestionHelper.php
+++ b/Helper/Entity/SuggestionHelper.php
@@ -21,8 +21,12 @@ class SuggestionHelper
private $popularQueriesCacheId = 'algoliasearch_popular_queries_cache_tag';
- public function __construct(ManagerInterface $eventManager, ObjectManagerInterface $objectManager, ConfigCache $cache, ConfigHelper $configHelper)
- {
+ public function __construct(
+ ManagerInterface $eventManager,
+ ObjectManagerInterface $objectManager,
+ ConfigCache $cache,
+ ConfigHelper $configHelper
+ ) {
$this->eventManager = $eventManager;
$this->objectManager = $objectManager;
$this->cache = $cache;
@@ -44,7 +48,10 @@ public function getIndexSettings($storeId)
];
$transport = new DataObject($indexSettings);
- $this->eventManager->dispatch('algolia_suggestions_index_before_set_settings', ['store_id' => $storeId, 'index_settings' => $transport]);
+ $this->eventManager->dispatch(
+ 'algolia_suggestions_index_before_set_settings',
+ ['store_id' => $storeId, 'index_settings' => $transport]
+ );
$indexSettings = $transport->getData();
return $indexSettings;
@@ -61,7 +68,10 @@ public function getObject(Query $suggestion)
];
$transport = new DataObject($suggestionObject);
- $this->eventManager->dispatch('algolia_after_create_suggestion_object', ['suggestion' => $transport, 'suggestionObject' => $suggestion]);
+ $this->eventManager->dispatch(
+ 'algolia_after_create_suggestion_object',
+ ['suggestion' => $transport, 'suggestionObject' => $suggestion]
+ );
$suggestionObject = $transport->getData();
return $suggestionObject;
@@ -75,7 +85,11 @@ public function getPopularQueries($storeId)
}
$collection = $this->objectManager->create('\Magento\Search\Model\ResourceModel\Query\Collection');
- $collection->getSelect()->where('num_results >= ' . $this->configHelper->getMinNumberOfResults() . ' AND popularity >= ' . $this->configHelper->getMinPopularity() . ' AND query_text != "__empty__"');
+ $collection->getSelect()->where(
+ 'num_results >= ' . $this->configHelper->getMinNumberOfResults() . '
+ AND popularity >= ' . $this->configHelper->getMinPopularity() . '
+ AND query_text != "__empty__"'
+ );
$collection->getSelect()->limit(12);
$collection->setOrder('popularity', 'DESC');
$collection->setOrder('num_results', 'DESC');
@@ -108,9 +122,16 @@ public function getSuggestionCollectionQuery($storeId)
$collection = $this->objectManager->create('\Magento\Search\Model\ResourceModel\Query\Collection');
$collection = $collection->addStoreFilter($storeId)->setStoreId($storeId);
- $collection->getSelect()->where('num_results >= ' . $this->configHelper->getMinNumberOfResults($storeId) . ' AND popularity >= ' . $this->configHelper->getMinPopularity($storeId) . ' AND query_text != "__empty__"');
+ $collection->getSelect()->where(
+ 'num_results >= ' . $this->configHelper->getMinNumberOfResults($storeId) . '
+ AND popularity >= ' . $this->configHelper->getMinPopularity($storeId) . '
+ AND query_text != "__empty__"'
+ );
- $this->eventManager->dispatch('algolia_after_suggestions_collection_build', ['store' => $storeId, 'collection' => $collection]);
+ $this->eventManager->dispatch(
+ 'algolia_after_suggestions_collection_build',
+ ['store' => $storeId, 'collection' => $collection]
+ );
return $collection;
}
diff --git a/Helper/Image.php b/Helper/Image.php
index d869433ca..e962ef50b 100755
--- a/Helper/Image.php
+++ b/Helper/Image.php
@@ -90,6 +90,6 @@ public function removeDoubleSlashes($url)
public function removePubDirectory($url)
{
- return str_replace('/pub/', '/', $url);;
+ return str_replace('/pub/', '/', $url);
}
}
diff --git a/Helper/Logger.php b/Helper/Logger.php
index f54860b9d..688952dc9 100755
--- a/Helper/Logger.php
+++ b/Helper/Logger.php
@@ -14,8 +14,11 @@ class Logger
protected $timers = [];
protected $stores = [];
- public function __construct(StoreManagerInterface $storeManager, ConfigHelper $configHelper, LoggerInterface $logger)
- {
+ public function __construct(
+ StoreManagerInterface $storeManager,
+ ConfigHelper $configHelper,
+ LoggerInterface $logger
+ ) {
$this->config = $configHelper;
$this->enabled = $this->config->isLoggingEnabled();
$this->logger = $logger;
diff --git a/Model/Indexer/AdditionalSection.php b/Model/Indexer/AdditionalSection.php
index 8dbbc2e44..59fc5a041 100755
--- a/Model/Indexer/AdditionalSection.php
+++ b/Model/Indexer/AdditionalSection.php
@@ -19,8 +19,14 @@ class AdditionalSection implements Magento\Framework\Indexer\ActionInterface, Ma
private $messageManager;
private $output;
- public function __construct(StoreManagerInterface $storeManager, Data $helper, Queue $queue, ConfigHelper $configHelper, ManagerInterface $messageManager, ConsoleOutput $output)
- {
+ public function __construct(
+ StoreManagerInterface $storeManager,
+ Data $helper,
+ Queue $queue,
+ ConfigHelper $configHelper,
+ ManagerInterface $messageManager,
+ ConsoleOutput $output
+ ) {
$this->fullAction = $helper;
$this->storeManager = $storeManager;
$this->queue = $queue;
@@ -31,12 +37,16 @@ public function __construct(StoreManagerInterface $storeManager, Data $helper, Q
public function execute($ids)
{
+ return $this;
}
public function executeFull()
{
- if (!$this->configHelper->getApplicationID() || !$this->configHelper->getAPIKey() || !$this->configHelper->getSearchOnlyAPIKey()) {
- $errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
+ if (!$this->configHelper->getApplicationID()
+ || !$this->configHelper->getAPIKey()
+ || !$this->configHelper->getSearchOnlyAPIKey()) {
+ $errorMessage = 'Algolia reindexing failed:
+ You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
if (php_sapi_name() === 'cli') {
$this->output->writeln($errorMessage);
@@ -56,15 +66,22 @@ public function executeFull()
continue;
}
- $this->queue->addToQueue($this->fullAction, 'rebuildStoreAdditionalSectionsIndex', ['store_id' => $storeId], 1);
+ $this->queue->addToQueue(
+ $this->fullAction,
+ 'rebuildStoreAdditionalSectionsIndex',
+ ['store_id' => $storeId],
+ 1
+ );
}
}
public function executeList(array $ids)
{
+ return $this;
}
public function executeRow($id)
{
+ return $this;
}
}
diff --git a/Model/Indexer/Category.php b/Model/Indexer/Category.php
index 252160c6e..c43b05346 100755
--- a/Model/Indexer/Category.php
+++ b/Model/Indexer/Category.php
@@ -25,15 +25,17 @@ class Category implements Magento\Framework\Indexer\ActionInterface, Magento\Fra
public static $affectedProductIds = [];
- public function __construct(StoreManagerInterface $storeManager,
- CategoryHelper $categoryHelper,
- Data $helper,
- AlgoliaHelper $algoliaHelper,
- Queue $queue,
- ConfigHelper $configHelper,
- ManagerInterface $messageManager,
- ConsoleOutput $output)
- {
+ public function __construct(
+ StoreManagerInterface $storeManager,
+ CategoryHelper $categoryHelper,
+ Data $helper,
+ AlgoliaHelper $algoliaHelper,
+ Queue $queue,
+ ConfigHelper $configHelper,
+ ManagerInterface $messageManager,
+ ConsoleOutput $output
+ ) {
+
$this->fullAction = $helper;
$this->storeManager = $storeManager;
$this->categoryHelper = $categoryHelper;
@@ -46,8 +48,11 @@ public function __construct(StoreManagerInterface $storeManager,
public function execute($categoryIds)
{
- if (!$this->configHelper->getApplicationID() || !$this->configHelper->getAPIKey() || !$this->configHelper->getSearchOnlyAPIKey()) {
- $errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
+ if (!$this->configHelper->getApplicationID()
+ || !$this->configHelper->getAPIKey()
+ || !$this->configHelper->getSearchOnlyAPIKey()) {
+ $errorMessage = 'Algolia reindexing failed:
+ You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
if (php_sapi_name() === 'cli') {
$this->output->writeln($errorMessage);
@@ -70,15 +75,30 @@ public function execute($categoryIds)
if ($categoryIds !== null) {
$indexName = $this->fullAction->getIndexName($this->categoryHelper->getIndexNameSuffix(), $storeId);
- $this->queue->addToQueue($this->fullAction, 'deleteObjects', ['store_id' => $storeId, 'category_ids' => $categoryIds, 'index_name' => $indexName], count($categoryIds));
+ $this->queue->addToQueue(
+ $this->fullAction,
+ 'deleteObjects',
+ ['store_id' => $storeId, 'category_ids' => $categoryIds, 'index_name' => $indexName],
+ count($categoryIds)
+ );
} else {
$this->queue->addToQueue($this->fullAction, 'saveConfigurationToAlgolia', ['store_id' => $storeId], 1);
}
- $this->queue->addToQueue($this->fullAction, 'rebuildStoreCategoryIndex', ['store_id' => $storeId, 'category_ids' => $categoryIds], count($categoryIds));
+ $this->queue->addToQueue(
+ $this->fullAction,
+ 'rebuildStoreCategoryIndex',
+ ['store_id' => $storeId, 'category_ids' => $categoryIds],
+ count($categoryIds)
+ );
if ($affectedProductsCount > 0 && $this->configHelper->indexProductOnCategoryProductsUpdate($storeId)) {
- $this->queue->addToQueue($this->fullAction, 'rebuildStoreProductIndex', ['store_id' => $storeId, 'product_ids' => self::$affectedProductIds], $affectedProductsCount);
+ $this->queue->addToQueue(
+ $this->fullAction,
+ 'rebuildStoreProductIndex',
+ ['store_id' => $storeId, 'product_ids' => self::$affectedProductIds],
+ $affectedProductsCount
+ );
}
}
}
diff --git a/Model/Indexer/Page.php b/Model/Indexer/Page.php
index 6a8f86d6c..e151711cf 100755
--- a/Model/Indexer/Page.php
+++ b/Model/Indexer/Page.php
@@ -49,8 +49,11 @@ public function execute($ids)
public function executeFull()
{
- if (!$this->configHelper->getApplicationID() || !$this->configHelper->getAPIKey() || !$this->configHelper->getSearchOnlyAPIKey()) {
- $errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
+ if (!$this->configHelper->getApplicationID()
+ || !$this->configHelper->getAPIKey()
+ || !$this->configHelper->getSearchOnlyAPIKey()) {
+ $errorMessage = 'Algolia reindexing failed:
+ You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
if (php_sapi_name() === 'cli') {
$this->output->writeln($errorMessage);
diff --git a/Model/Indexer/Product.php b/Model/Indexer/Product.php
index 9197d2e2b..617a48618 100755
--- a/Model/Indexer/Product.php
+++ b/Model/Indexer/Product.php
@@ -45,8 +45,11 @@ public function __construct(
public function execute($productIds)
{
- if (!$this->configHelper->getApplicationID() || !$this->configHelper->getAPIKey() || !$this->configHelper->getSearchOnlyAPIKey()) {
- $errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
+ if (!$this->configHelper->getApplicationID()
+ || !$this->configHelper->getAPIKey()
+ || !$this->configHelper->getSearchOnlyAPIKey()) {
+ $errorMessage = 'Algolia reindexing failed:
+ You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
if (php_sapi_name() === 'cli') {
$this->output->writeln($errorMessage);
@@ -70,8 +73,12 @@ public function execute($productIds)
if (is_array($productIds) && count($productIds) > 0) {
foreach (array_chunk($productIds, $productsPerPage) as $chunk) {
- $this->queue->addToQueue($this->fullAction, 'rebuildStoreProductIndex',
- ['store_id' => $storeId, 'product_ids' => $chunk], count($chunk));
+ $this->queue->addToQueue(
+ $this->fullAction,
+ 'rebuildStoreProductIndex',
+ ['store_id' => $storeId, 'product_ids' => $chunk],
+ count($chunk)
+ );
}
continue;
@@ -106,9 +113,11 @@ public function execute($productIds)
}
if ($useTmpIndex) {
+ $suffix = $this->productHelper->getIndexNameSuffix();
+
$this->queue->addToQueue($this->fullAction, 'moveIndex', [
- 'tmpIndexName' => $this->fullAction->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId, true),
- 'indexName' => $this->fullAction->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId, false),
+ 'tmpIndexName' => $this->fullAction->getIndexName($suffix, $storeId, true),
+ 'indexName' => $this->fullAction->getIndexName($suffix, $storeId, false),
'store_id' => $storeId,
]);
}
diff --git a/Model/Indexer/QueueRunner.php b/Model/Indexer/QueueRunner.php
index 32d228a06..9cf357170 100644
--- a/Model/Indexer/QueueRunner.php
+++ b/Model/Indexer/QueueRunner.php
@@ -15,8 +15,12 @@ class QueueRunner implements Magento\Framework\Indexer\ActionInterface, Magento\
private $messageManager;
private $output;
- public function __construct(ConfigHelper $configHelper, Queue $queue, ManagerInterface $messageManager, ConsoleOutput $output)
- {
+ public function __construct(
+ ConfigHelper $configHelper,
+ Queue $queue,
+ ManagerInterface $messageManager,
+ ConsoleOutput $output
+ ) {
$this->configHelper = $configHelper;
$this->queue = $queue;
$this->messageManager = $messageManager;
@@ -25,12 +29,16 @@ public function __construct(ConfigHelper $configHelper, Queue $queue, ManagerInt
public function execute($ids)
{
+ return $this;
}
public function executeFull()
{
- if (!$this->configHelper->getApplicationID() || !$this->configHelper->getAPIKey() || !$this->configHelper->getSearchOnlyAPIKey()) {
- $errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
+ if (!$this->configHelper->getApplicationID()
+ || !$this->configHelper->getAPIKey()
+ || !$this->configHelper->getSearchOnlyAPIKey()) {
+ $errorMessage = 'Algolia reindexing failed:
+ You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
if (php_sapi_name() === 'cli') {
$this->output->writeln($errorMessage);
@@ -44,15 +52,15 @@ public function executeFull()
}
$this->queue->runCron();
-
- return;
}
public function executeList(array $ids)
{
+ return $this;
}
public function executeRow($id)
{
+ return $this;
}
}
diff --git a/Model/Indexer/Suggestion.php b/Model/Indexer/Suggestion.php
index b42da5da7..2cc1db299 100755
--- a/Model/Indexer/Suggestion.php
+++ b/Model/Indexer/Suggestion.php
@@ -49,8 +49,11 @@ public function execute($ids)
public function executeFull()
{
- if (!$this->configHelper->getApplicationID() || !$this->configHelper->getAPIKey() || !$this->configHelper->getSearchOnlyAPIKey()) {
- $errorMessage = 'Algolia reindexing failed: You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
+ if (!$this->configHelper->getApplicationID()
+ || !$this->configHelper->getAPIKey()
+ || !$this->configHelper->getSearchOnlyAPIKey()) {
+ $errorMessage = 'Algolia reindexing failed:
+ You need to configure your Algolia credentials in Stores > Configuration > Algolia Search.';
if (php_sapi_name() === 'cli') {
$this->output->writeln($errorMessage);
diff --git a/Model/Product/Url.php b/Model/Product/Url.php
index 90f2f98ca..be220c5d7 100755
--- a/Model/Product/Url.php
+++ b/Model/Product/Url.php
@@ -55,7 +55,9 @@ public function getUrl(Product $product, $params = [])
$categoryId = null;
- if (!isset($params['_ignore_category']) && $product->getCategoryId() && !$product->getData('do_not_use_category_id')) {
+ if (!isset($params['_ignore_category'])
+ && $product->getCategoryId()
+ && !$product->getData('do_not_use_category_id')) {
$categoryId = $product->getCategoryId();
}
@@ -110,9 +112,11 @@ public function getUrl(Product $product, $params = [])
/*
* This is the only line changed from the default method.
- * For reference, the original line: $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams);
- * getUrlInstance() is a private method, so a new method has been written that will create a frontend Url object if
- * the store scope is not the admin scope.
+ * For reference, the original line:
+ * $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams);
+ * getUrlInstance() is a private method, so a new method has been written that
+ * will create a frontend Url object
+ * if the store scope is not the admin scope.
*/
return $this->getStoreScopeUrlInstance($storeId)->getUrl($routePath, $routeParams);
}
diff --git a/Model/Queue.php b/Model/Queue.php
index c2852375f..d1995f077 100644
--- a/Model/Queue.php
+++ b/Model/Queue.php
@@ -37,8 +37,12 @@ class Queue
private $logRecord;
- public function __construct(ConfigHelper $configHelper, Logger $logger, ResourceConnection $resourceConnection, ObjectManagerInterface $objectManager)
- {
+ public function __construct(
+ ConfigHelper $configHelper,
+ Logger $logger,
+ ResourceConnection $resourceConnection,
+ ObjectManagerInterface $objectManager
+ ) {
$this->configHelper = $configHelper;
$this->logger = $logger;
@@ -88,11 +92,11 @@ public function runCron($nbJobs = null, $force = false)
$this->clearOldLogRecords();
- $this->logRecord = array(
+ $this->logRecord = [
'started' => date('Y-m-d H:i:s'),
'processed_jobs' => 0,
'with_empty_queue' => 0,
- );
+ ];
$started = time();
@@ -147,12 +151,22 @@ public function run($maxJobs)
$this->noOfFailedJobs++;
// Increment retries, set the job ID back to NULL
- $updateQuery = "UPDATE {$this->table} SET pid = NULL, retries = retries + 1 WHERE job_id IN (".implode(', ', (array) $job['merged_ids']).")";
+ $updateQuery = "UPDATE {$this->table}
+ SET pid = NULL, retries = retries + 1
+ WHERE job_id IN (".implode(', ', (array) $job['merged_ids']).")";
$this->db->query($updateQuery);
// Log error information
- $this->logger->log("Queue processing {$job['pid']} [KO]: Mage::getSingleton({$job['class']})->{$job['method']}(".json_encode($job['data']).')');
- $this->logger->log(date('c').' ERROR: '.get_class($e).": '{$e->getMessage()}' in {$e->getFile()}:{$e->getLine()}\n"."Stack trace:\n".$e->getTraceAsString());
+ $logMessage = 'Queue processing '.$job['pid'].' [KO]:
+ Class: '.$job['class'].',
+ Method: '.$job['method'].',
+ Parameters: '.json_encode($job['data']);
+ $this->logger->log($logMessage);
+
+ $logMessage = date('c').' ERROR: '.get_class($e).':
+ '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine().
+ "\nStack trace:\n".$e->getTraceAsString();
+ $this->logger->log($logMessage);
}
}
@@ -248,7 +262,9 @@ private function getJobs($maxJobs, $pid)
$lastJobId = $this->maxValueInArray($jobs, 'job_id');
// Reserve all new jobs since last run
- $this->db->query("UPDATE {$this->db->quoteIdentifier($this->table, true)} SET pid = ".$pid.' WHERE job_id >= '.$firstJobId." AND job_id <= $lastJobId");
+ $this->db->query("UPDATE {$this->db->quoteIdentifier($this->table, true)}
+ SET pid = ".$pid.'
+ WHERE job_id >= '.$firstJobId." AND job_id <= $lastJobId");
}
return $jobs;
@@ -284,10 +300,18 @@ protected function mergeJobs($oldJobs)
$currentJob['merged_ids'][] = $nextJob['job_id'];
if (isset($currentJob['data']['product_ids'])) {
- $currentJob['data']['product_ids'] = array_merge($currentJob['data']['product_ids'], $nextJob['data']['product_ids']);
+ $currentJob['data']['product_ids'] = array_merge(
+ $currentJob['data']['product_ids'],
+ $nextJob['data']['product_ids']
+ );
+
$currentJob['data_size'] = count($currentJob['data']['product_ids']);
} elseif (isset($currentJob['data']['category_ids'])) {
- $currentJob['data']['category_ids'] = array_merge($currentJob['data']['category_ids'], $nextJob['data']['category_ids']);
+ $currentJob['data']['category_ids'] = array_merge(
+ $currentJob['data']['category_ids'],
+ $nextJob['data']['category_ids']
+ );
+
$currentJob['data_size'] = count($currentJob['data']['category_ids']);
}
@@ -343,7 +367,17 @@ private function sortJobs($oldJobs)
private function stackSortedJobs($sortedJobs, $tempSortableJobs, $job = null)
{
if (!empty($tempSortableJobs)) {
- $tempSortableJobs = $this->arrayMultisort($tempSortableJobs, 'class', SORT_ASC, 'method', SORT_ASC, 'store_id', SORT_ASC, 'job_id', SORT_ASC);
+ $tempSortableJobs = $this->arrayMultisort(
+ $tempSortableJobs,
+ 'class',
+ SORT_ASC,
+ 'method',
+ SORT_ASC,
+ 'store_id',
+ SORT_ASC,
+ 'job_id',
+ SORT_ASC
+ );
}
$sortedJobs = array_merge($sortedJobs, $tempSortableJobs);
@@ -365,23 +399,29 @@ private function mergeable($j1, $j2)
return false;
}
- if (isset($j1['data']['store_id']) && isset($j2['data']['store_id']) && $j1['data']['store_id'] !== $j2['data']['store_id']) {
+ if (isset($j1['data']['store_id'])
+ && isset($j2['data']['store_id'])
+ && $j1['data']['store_id'] !== $j2['data']['store_id']) {
return false;
}
- if ((!isset($j1['data']['product_ids']) || count($j1['data']['product_ids']) <= 0) && (!isset($j1['data']['category_ids']) || count($j1['data']['category_ids']) < 0)) {
+ if ((!isset($j1['data']['product_ids']) || count($j1['data']['product_ids']) <= 0)
+ && (!isset($j1['data']['category_ids']) || count($j1['data']['category_ids']) < 0)) {
return false;
}
- if ((!isset($j2['data']['product_ids']) || count($j2['data']['product_ids']) <= 0) && (!isset($j2['data']['category_ids']) || count($j2['data']['category_ids']) < 0)) {
+ if ((!isset($j2['data']['product_ids']) || count($j2['data']['product_ids']) <= 0)
+ && (!isset($j2['data']['category_ids']) || count($j2['data']['category_ids']) < 0)) {
return false;
}
- if (isset($j1['data']['product_ids']) && count($j1['data']['product_ids']) + count($j2['data']['product_ids']) > $this->maxSingleJobDataSize) {
+ if (isset($j1['data']['product_ids'])
+ && count($j1['data']['product_ids']) + count($j2['data']['product_ids']) > $this->maxSingleJobDataSize) {
return false;
}
- if (isset($j1['data']['category_ids']) && count($j1['data']['category_ids']) + count($j2['data']['category_ids']) > $this->maxSingleJobDataSize) {
+ if (isset($j1['data']['category_ids'])
+ && count($j1['data']['category_ids']) + count($j2['data']['category_ids']) > $this->maxSingleJobDataSize) {
return false;
}
@@ -430,7 +470,10 @@ private function maxValueInArray($array, $keyToSearch)
private function clearOldLogRecords()
{
- $idsToDelete = $this->db->query("SELECT id FROM {$this->logTable} ORDER BY started DESC, id DESC LIMIT 25000, ".PHP_INT_MAX)
+ $idsToDelete = $this->db->query("SELECT id
+ FROM {$this->logTable}
+ ORDER BY started DESC, id DESC
+ LIMIT 25000, ".PHP_INT_MAX)
->fetchAll(\PDO::FETCH_COLUMN, 0);
if ($idsToDelete) {
diff --git a/Model/Source/AbstractTable.php b/Model/Source/AbstractTable.php
index 10e29786d..1f13aa548 100755
--- a/Model/Source/AbstractTable.php
+++ b/Model/Source/AbstractTable.php
@@ -21,12 +21,14 @@ abstract class AbstractTable extends AbstractFieldArray
abstract protected function getTableData();
- public function __construct(Context $context,
- ProductHelper $producthelper,
- CategoryHelper $categoryHelper,
- ConfigHelper $configHelper,
- array $data = [])
- {
+ public function __construct(
+ Context $context,
+ ProductHelper $producthelper,
+ CategoryHelper $categoryHelper,
+ ConfigHelper $configHelper,
+ array $data = []
+ ) {
+
$this->config = $configHelper;
$this->productHelper = $producthelper;
$this->categoryHelper = $categoryHelper;
@@ -38,7 +40,10 @@ protected function getRenderer($columnId, $columnData)
{
if (!array_key_exists($columnId, $this->selectFields) || !$this->selectFields[$columnId]) {
/** @var \Algolia\AlgoliaSearch\Block\System\Form\Field\Select $select */
- $select = $this->getLayout()->createBlock('Algolia\AlgoliaSearch\Block\System\Form\Field\Select', '', ['data' => ['is_render_to_js_template' => true]]);
+ $select = $this->getLayout()
+ ->createBlock('Algolia\AlgoliaSearch\Block\System\Form\Field\Select', '', [
+ 'data' => ['is_render_to_js_template' => true]
+ ]);
$options = $columnData['values'];
@@ -94,7 +99,10 @@ protected function _prepareArrayRow(DataObject $row)
$columnData = $data[$columnId];
if (isset($columnData['values'])) {
- $options['option_' . $this->getRenderer($columnId, $columnData)->calcOptionHash($row->getData($columnId))] = 'selected="selected"';
+ $index = 'option_' . $this->getRenderer($columnId, $columnData)
+ ->calcOptionHash($row->getData($columnId));
+
+ $options[$index] = 'selected="selected"';
}
}
diff --git a/Model/Source/Sections.php b/Model/Source/Sections.php
index c1addbce1..3db4d58bc 100755
--- a/Model/Source/Sections.php
+++ b/Model/Source/Sections.php
@@ -24,10 +24,15 @@ protected function getTableData()
if ($attribute['attribute'] == 'price') {
continue;
}
+
if ($attribute['attribute'] == 'category' || $attribute['attribute'] == 'categories') {
continue;
}
- $sections[] = ['name' => $attribute['attribute'], 'label' => $attribute['label'] ? $attribute['label'] : $attribute['attribute']];
+
+ $sections[] = [
+ 'name' => $attribute['attribute'],
+ 'label' => $attribute['label'] ? $attribute['label'] : $attribute['attribute'],
+ ];
}
foreach ($sections as $section) {
diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php
index 9751c1f58..d3e7b2c76 100644
--- a/Setup/UpgradeSchema.php
+++ b/Setup/UpgradeSchema.php
@@ -261,7 +261,9 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
/* SET DEFAULT CONFIG DATA */
$table = $setup->getTable('core_config_data');
- $alreadyInserted = $setup->getConnection()->query('SELECT path, value FROM '.$table.' WHERE path LIKE "algoliasearch_%"')->fetchAll(\PDO::FETCH_KEY_PAIR);
+ $alreadyInserted = $setup->getConnection()
+ ->query('SELECT path, value FROM '.$table.' WHERE path LIKE "algoliasearch_%"')
+ ->fetchAll(\PDO::FETCH_KEY_PAIR);
foreach ($this->defaultConfigData as $path => $value) {
if (isset($alreadyInserted[$path])) {
@@ -277,8 +279,12 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
$connection = $setup->getConnection();
$table = $connection->newTable($setup->getTable('algoliasearch_queue'));
- $table->addColumn('job_id', $table::TYPE_INTEGER, 20,
- ['identity' => true, 'nullable' => false, 'primary' => true]);
+ $table->addColumn(
+ 'job_id',
+ $table::TYPE_INTEGER,
+ 20,
+ ['identity' => true, 'nullable' => false, 'primary' => true]
+ );
$table->addColumn('pid', $table::TYPE_INTEGER, 20, ['nullable' => true, 'default' => null]);
$table->addColumn('class', $table::TYPE_TEXT, 50, ['nullable' => false]);
$table->addColumn('method', $table::TYPE_TEXT, 50, ['nullable' => false]);
@@ -300,7 +306,8 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
[
'type' => Table::TYPE_TEXT,
'length' => '2M',
- ]);
+ ]
+ );
}
if (version_compare($context->getVersion(), '1.3.0') < 0) {
@@ -314,12 +321,17 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
'nullabled' => true,
'after' => 'job_id',
'comment' => 'Date and time of job creation',
- ]);
+ ]
+ );
// LOG TABLE
$table = $connection->newTable($setup->getTable('algoliasearch_queue_log'));
- $table->addColumn('id', $table::TYPE_INTEGER, 20, ['identity' => true, 'nullable' => false, 'primary' => true]);
+ $table->addColumn('id', $table::TYPE_INTEGER, 20, [
+ 'identity' => true,
+ 'nullable' => false,
+ 'primary' => true
+ ]);
$table->addColumn('started', $table::TYPE_DATETIME, null, ['nullable' => false]);
$table->addColumn('duration', $table::TYPE_INTEGER, 20, ['nullable' => false]);
$table->addColumn('processed_jobs', $table::TYPE_INTEGER, null, ['nullable' => false]);
diff --git a/Test/Integration/CategoriesIndexingTest.php b/Test/Integration/CategoriesIndexingTest.php
index e9f83c858..06221e74e 100644
--- a/Test/Integration/CategoriesIndexingTest.php
+++ b/Test/Integration/CategoriesIndexingTest.php
@@ -23,10 +23,10 @@ public function testDefaultIndexableAttributes()
$this->algoliaHelper->waitLastTask();
- $results = $this->algoliaHelper->getObjects($this->indexPrefix.'default_categories', array('3'));
+ $results = $this->algoliaHelper->getObjects($this->indexPrefix.'default_categories', ['3']);
$hit = reset($results['results']);
- $defaultAttributes = array(
+ $defaultAttributes = [
'objectID',
'name',
'url',
@@ -37,7 +37,7 @@ public function testDefaultIndexableAttributes()
'popularity',
'algoliaLastUpdateAtCET',
'product_count',
- );
+ ];
foreach ($defaultAttributes as $key => $attribute) {
$this->assertTrue(key_exists($attribute, $hit), 'Category attribute "'.$attribute.'" should be indexed but it is not"');
diff --git a/Test/Integration/ConfigTest.php b/Test/Integration/ConfigTest.php
index 43856f974..cfad32d55 100644
--- a/Test/Integration/ConfigTest.php
+++ b/Test/Integration/ConfigTest.php
@@ -43,7 +43,7 @@ public function testAutomaticalSetOfCategoriesFacet()
// Remove categories from facets
$facets = $this->configHelper->getFacets();
foreach ($facets as $key => $facet) {
- if($facet['attribute'] === 'categories') {
+ if ($facet['attribute'] === 'categories') {
unset($facets[$key]);
break;
}
@@ -96,7 +96,7 @@ public function testAutomaticalSetOfCategoriesFacet()
public function testRetrievableAttributes()
{
- $this->resetConfigs(array('algoliasearch_products/products/product_additional_attributes', 'algoliasearch_categories/categories/category_additional_attributes'));
+ $this->resetConfigs(['algoliasearch_products/products/product_additional_attributes', 'algoliasearch_categories/categories/category_additional_attributes']);
$this->setConfig('algoliasearch_advanced/advanced/customer_groups_enable', '0');
@@ -172,7 +172,7 @@ private function replicaCreationTest($withCustomerGroups = false)
$this->algoliaHelper->waitLastTask();
$indices = $this->algoliaHelper->listIndexes();
- $indicesNames = array_map(function($indexData) {
+ $indicesNames = array_map(function ($indexData) {
return $indexData['name'];
}, $indices['items']);
@@ -192,12 +192,12 @@ public function testExtraSettings()
$helper->saveConfigurationToAlgolia(1);
$this->algoliaHelper->waitLastTask();
- $sections = array('products', 'categories', 'pages', 'suggestions');
+ $sections = ['products', 'categories', 'pages', 'suggestions'];
foreach ($sections as $section) {
$indexName = $this->indexPrefix.'default_'.$section;
- $this->algoliaHelper->setSettings($indexName, array('exactOnSingleWordQuery' => 'attribute'));
+ $this->algoliaHelper->setSettings($indexName, ['exactOnSingleWordQuery' => 'attribute']);
}
$this->algoliaHelper->waitLastTask();
@@ -233,7 +233,7 @@ public function testInvalidExtraSettings()
/** @var Data $helper */
$helper = $this->getObjectManager()->create('Algolia\AlgoliaSearch\Helper\Data');
- $sections = array('products', 'categories', 'pages', 'suggestions');
+ $sections = ['products', 'categories', 'pages', 'suggestions'];
foreach ($sections as $section) {
$this->setConfig('algoliasearch_extra_settings/extra_settings/'.$section.'_extra_settings', '{"foo":"bar"}');
@@ -241,7 +241,7 @@ public function testInvalidExtraSettings()
try {
$helper->saveConfigurationToAlgolia(1);
- } catch(AlgoliaException $e) {
+ } catch (AlgoliaException $e) {
$message = $e->getMessage();
// Check if the error message contains error for all sections
diff --git a/Test/Integration/IndexingTestCase.php b/Test/Integration/IndexingTestCase.php
index 15751cdf8..4fc2804ba 100644
--- a/Test/Integration/IndexingTestCase.php
+++ b/Test/Integration/IndexingTestCase.php
@@ -21,7 +21,7 @@ protected function processTest(ActionInterface $indexer, $indexSuffix, $expected
$this->algoliaHelper->waitLastTask();
- $resultsDefault = $this->algoliaHelper->query($this->indexPrefix.'default_'.$indexSuffix, '', array());
+ $resultsDefault = $this->algoliaHelper->query($this->indexPrefix.'default_'.$indexSuffix, '', []);
$this->assertEquals($expectedNbHits, $resultsDefault['nbHits']);
}
diff --git a/Test/Integration/PagesIndexingTest.php b/Test/Integration/PagesIndexingTest.php
index 5184829b0..31893d420 100644
--- a/Test/Integration/PagesIndexingTest.php
+++ b/Test/Integration/PagesIndexingTest.php
@@ -29,7 +29,7 @@ public function testExcludedPages()
$indexer = $this->getObjectManager()->create('\Algolia\AlgoliaSearch\Model\Indexer\Page');
$this->processTest($indexer, 'pages', 4);
- $results = $this->algoliaHelper->query($this->indexPrefix.'default_pages', '', array());
+ $results = $this->algoliaHelper->query($this->indexPrefix.'default_pages', '', []);
$noRoutePageExists = false;
$homePageExists = false;
@@ -56,10 +56,10 @@ public function testDefaultIndexableAttributes()
$this->algoliaHelper->waitLastTask();
- $results = $this->algoliaHelper->query($this->indexPrefix.'default_pages', '', array('hitsPerPage' => 1));
+ $results = $this->algoliaHelper->query($this->indexPrefix.'default_pages', '', ['hitsPerPage' => 1]);
$hit = reset($results['hits']);
- $defaultAttributes = array(
+ $defaultAttributes = [
'objectID',
'name',
'url',
@@ -68,7 +68,7 @@ public function testDefaultIndexableAttributes()
'algoliaLastUpdateAtCET',
'_highlightResult',
'_snippetResult',
- );
+ ];
foreach ($defaultAttributes as $key => $attribute) {
$this->assertTrue(key_exists($attribute, $hit), 'Pages attribute "'.$attribute.'" should be indexed but it is not"');
@@ -88,7 +88,7 @@ public function testStripTags()
->setIdentifier('example-cms-page')
->setIsActive(true)
->setPageLayout('1column')
- ->setStores(array(0))
+ ->setStores([0])
->setContent('Hello Im a test CMS page with script tags and style tags. ')
->save();
@@ -121,7 +121,7 @@ public function testUtf8()
->setIdentifier('example-cms-page-utf8')
->setIsActive(true)
->setPageLayout('1column')
- ->setStores(array(0))
+ ->setStores([0])
->setContent($utf8Content)
->save();
diff --git a/Test/Integration/ProductsIndexingTest.php b/Test/Integration/ProductsIndexingTest.php
index 51d2d5884..f6c3d0e11 100644
--- a/Test/Integration/ProductsIndexingTest.php
+++ b/Test/Integration/ProductsIndexingTest.php
@@ -46,10 +46,10 @@ public function testDefaultIndexableAttributes()
$this->algoliaHelper->waitLastTask();
- $results = $this->algoliaHelper->getObjects($this->indexPrefix.'default_products', array('994'));
+ $results = $this->algoliaHelper->getObjects($this->indexPrefix.'default_products', ['994']);
$hit = reset($results['results']);
- $defaultAttributes = array(
+ $defaultAttributes = [
'objectID',
'name',
'url',
@@ -63,7 +63,7 @@ public function testDefaultIndexableAttributes()
'price',
'type_id',
'algoliaLastUpdateAtCET',
- );
+ ];
foreach ($defaultAttributes as $key => $attribute) {
$this->assertArrayHasKey($attribute, $hit, 'Products attribute "'.$attribute.'" should be indexed but it is not"');
@@ -92,7 +92,7 @@ public function testNoProtocolImageUrls()
$this->algoliaHelper->waitLastTask();
- $results = $this->algoliaHelper->getObjects($this->indexPrefix.'default_products', array('994'));
+ $results = $this->algoliaHelper->getObjects($this->indexPrefix.'default_products', ['994']);
$hit = reset($results['results']);
$this->assertStringStartsWith('//', $hit['image_url']);
diff --git a/Test/Integration/QueueTest.php b/Test/Integration/QueueTest.php
index e4da9c4f3..a06d1eda8 100644
--- a/Test/Integration/QueueTest.php
+++ b/Test/Integration/QueueTest.php
@@ -100,7 +100,6 @@ public function testExecute()
if ($index['name'] === $this->indexPrefix.'default_products_tmp') {
$existsDefaultTmpIndex = true;
}
-
}
$this->assertFalse($existsDefaultTmpIndex, 'Default product TMP index exists and it should not'); // Was already moved
@@ -302,7 +301,7 @@ public function testMerging()
$expectedCategoryJob = [
'job_id' => 7,
'created' => '2017-09-01 12:00:00',
- 'pid' => NULL,
+ 'pid' => null,
'class' => 'Algolia\AlgoliaSearch\Helper\Data',
'method' => 'rebuildStoreCategoryIndex',
'data' => [
@@ -326,7 +325,7 @@ public function testMerging()
$expectedProductJob = [
'job_id' => 10,
'created' => '2017-09-01 12:00:00',
- 'pid' => NULL,
+ 'pid' => null,
'class' => 'Algolia\AlgoliaSearch\Helper\Data',
'method' => 'rebuildStoreProductIndex',
'data' => [
@@ -482,8 +481,8 @@ public function testMergingWithStaticMethods()
$jobs = $this->connection->query('SELECT * FROM algoliasearch_queue')->fetchAll();
- $jobs = $this->invokeMethod($queue, 'prepareJobs', array('jobs' => $jobs));
- $mergedJobs = $this->invokeMethod($queue, 'mergeJobs', array('jobs' => $jobs));
+ $jobs = $this->invokeMethod($queue, 'prepareJobs', ['jobs' => $jobs]);
+ $mergedJobs = $this->invokeMethod($queue, 'mergeJobs', ['jobs' => $jobs]);
$this->assertEquals(12, count($mergedJobs));
$this->assertEquals('rebuildStoreCategoryIndex', $jobs[0]['method']);
@@ -646,51 +645,51 @@ public function testGetJobs()
$queue = $this->getObjectManager()->create('Algolia\AlgoliaSearch\Model\Queue');
$pid = getmypid();
- $jobs = $this->invokeMethod($queue, 'getJobs', array('maxJobs' => 10, 'pid' => $pid));
+ $jobs = $this->invokeMethod($queue, 'getJobs', ['maxJobs' => 10, 'pid' => $pid]);
$this->assertEquals(6, count($jobs));
- $expectedFirstJob = array(
+ $expectedFirstJob = [
'job_id' => 7,
'created' => '2017-09-01 12:00:00',
- 'pid' => NULL,
+ 'pid' => null,
'class' => 'Algolia\AlgoliaSearch\Helper\Data',
'method' => 'rebuildStoreCategoryIndex',
- 'data' => array(
+ 'data' => [
'store_id' => '1',
- 'category_ids' => array(
+ 'category_ids' => [
0 => '9',
1 => '22',
2 => '40',
- ),
- ),
+ ],
+ ],
'max_retries' => '3',
'retries' => '0',
'error_log' => '',
'data_size' => 3,
'merged_ids' => ['1', '7'],
'store_id' => '1',
- );
+ ];
- $expectedLastJob = array(
+ $expectedLastJob = [
'job_id' => 12,
'created' => '2017-09-01 12:00:00',
- 'pid' => NULL,
+ 'pid' => null,
'class' => 'Algolia\AlgoliaSearch\Helper\Data',
'method' => 'rebuildStoreProductIndex',
- 'data' => array(
+ 'data' => [
'store_id' => '3',
- 'product_ids' => array(
+ 'product_ids' => [
0 => '448',
1 => '405',
- ),
- ),
+ ],
+ ],
'max_retries' => '3',
'retries' => '0',
'error_log' => '',
'data_size' => 2,
'merged_ids' => ['6', '12'],
'store_id' => '3',
- );
+ ];
$this->assertEquals($expectedFirstJob, reset($jobs));
$this->assertEquals($expectedLastJob, end($jobs));
@@ -722,7 +721,7 @@ public function testHugeJob()
$queue = $this->getObjectManager()->create('Algolia\AlgoliaSearch\Model\Queue');
$pid = getmypid();
- $jobs = $this->invokeMethod($queue, 'getJobs', array('maxJobs' => 10, 'pid' => $pid));
+ $jobs = $this->invokeMethod($queue, 'getJobs', ['maxJobs' => 10, 'pid' => $pid]);
$this->assertEquals(1, count($jobs));
@@ -759,7 +758,7 @@ public function testMaxSingleJobSize()
$queue = $this->getObjectManager()->create('Algolia\AlgoliaSearch\Model\Queue');
$pid = getmypid();
- $jobs = $this->invokeMethod($queue, 'getJobs', array('maxJobs' => 10, 'pid' => $pid));
+ $jobs = $this->invokeMethod($queue, 'getJobs', ['maxJobs' => 10, 'pid' => $pid]);
$this->assertEquals(2, count($jobs));
diff --git a/Test/Integration/TestCase.php b/Test/Integration/TestCase.php
index 95be3c1bd..7df8d7358 100644
--- a/Test/Integration/TestCase.php
+++ b/Test/Integration/TestCase.php
@@ -69,7 +69,7 @@ protected function clearIndices()
if (strpos($name, $this->indexPrefix) === 0) {
try {
$this->algoliaHelper->deleteIndex($name);
- } catch(AlgoliaException $e) {
+ } catch (AlgoliaException $e) {
// Might be a replica
}
}
@@ -111,7 +111,7 @@ private function bootstrap()
*
* @return mixed Method return.
*/
- protected function invokeMethod(&$object, $methodName, array $parameters = array())
+ protected function invokeMethod(&$object, $methodName, array $parameters = [])
{
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
diff --git a/dev/bin/createAuthJson.php b/dev/bin/createAuthJson.php
index 8186a5775..4976b7fb5 100644
--- a/dev/bin/createAuthJson.php
+++ b/dev/bin/createAuthJson.php
@@ -1,9 +1,9 @@
getenv('MAGENTO_AUTH_USERNAME'),
'password' => getenv('MAGENTO_AUTH_PASSWORD'),
-);
+];
$dirname = dirname(getenv('AUTH_DIR'));
if (!is_dir($dirname)) {
diff --git a/registration.php b/registration.php
index 2f594c0e5..e68cd8422 100755
--- a/registration.php
+++ b/registration.php
@@ -1,7 +1,7 @@
getCatalogSearchHelper();
$placeholder = __('Search for products, categories, ...');
/** Render form with autocomplete input **/
-if ($config->isDefaultSelector()): ?>
+if ($config->isDefaultSelector()) : ?>