Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #120 from DivanteLtd/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
afirlejczyk authored Sep 18, 2019
2 parents 186fd1d + 8c08f4f commit e586c16
Show file tree
Hide file tree
Showing 25 changed files with 645 additions and 112 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

## Unreleased



## [1.3.0] (2019.09.18)

### Fixes
- Fixed Backward compatibility with 2.2.x (< 2.2.6) ([#53](https://github.com/DivanteLtd/magento2-vsbridge-indexer/issues/53))

### Changed/Improved
- Skip exporting configurable products without "configurable_options".

### Added
- Export ratings for reviews.

## [1.2.0] (2019.08.05)

### Fixed
Expand All @@ -27,7 +40,7 @@

### Changed/Improved
- Change mapping for "category.name" field in product type
- Remove dependency from catalog_product_price and cataloginventory_stock indexer. On product save multiple request has been send
- Remove dependency from catalog_product_price and cataloginventory_stock indexer. On product save multiple request has been send to ES
- Change "Use Short Catalog Urls" setting option to "Use Catalog Url Keys"
- Add option to generate product/category slug base on Magento Url Key and ID. By default slug (and url_key) field is generated base on NAME and ID.

Expand Down
100 changes: 84 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ php bin/magento setup:upgrade
- Configure the module in Magento admin panel and run full indexation


### Configuration
### Magento Configuration
Go to the new ‘Indexer’ section (Stores → Configuration → Vuestorefront → Indexer), available now in the in the Magento Panel, and configure it in the listed areas:
1. General settings → Enable VS Bridge

Expand All @@ -98,18 +98,21 @@ Go to the new ‘Indexer’ section (Stores → Configuration → Vuestorefront

Index Name Prefix → define prefixes for ElasticSearch indexes. The panel allows adding prefix only to the catalog name e.g.: "vue_storefront_catalog". For each store (store view) index name is generated on the base of defined prefix and either ID or Store Code. Aliases cannot be created.
Example: When we define following indexes: "vue_storefront_catalog_1", "vue_storefront_catalog_2", "vue_storefront_catalog_3".
Important: It is crucial to update this configuration in the VSF and VSF-API (one change at the beginning of the whole configuration process).

**Important**: It is crucial to update this configuration in the VSF and VSF-API (one change at the beginning of the whole configuration process).

Index Identifier → defines the unique store identifier to append to the ElasticSearch indexes. The default value is ID which will append the Store ID to the index name e.g.: "vue_storefront_catalog_1". You can choose to change this to Store Code which will add the Store Code to the index name e.g.: "vue_storefront_catalog_storecode".

Example with Store ID

####Example with Store ID

"vue_storefront_magento_1" - index for store view with id 1

VSF config (base on default index prefix name: vue_storefront_magento)
```json
"elasticsearch": {
"httpAuth": "",
"host": "localhost:8080/api/catalog",
"index": "vue_storefront_magento_1" //index for store view with id 1
"index": "vue_storefront_magento_1"
}
```

Expand All @@ -121,18 +124,20 @@ Go to the new ‘Indexer’ section (Stores → Configuration → Vuestorefront
"user": "elastic",
"password": "changeme",
"indices": [
"vue_storefront_magento_1" //index for store view with id 1
"vue_storefront_magento_1"
],
```

Example with Store Code

####Example with Store Code

"vue_storefront_magento_en_us" - index for store view with code "en_us"

VSF config (base on default index prefix name: vue_storefront_magento)
```json
"elasticsearch": {
"httpAuth": "",
"host": "localhost:8080/api/catalog",
"index": "vue_storefront_magento_en_us" //index for store view with code "en_us"
"index": "vue_storefront_magento_en_us"
}
```

Expand All @@ -144,7 +149,7 @@ Go to the new ‘Indexer’ section (Stores → Configuration → Vuestorefront
"user": "elastic",
"password": "changeme",
"indices": [
"vue_storefront_magento_en_us" //index for store view with store code "en_us"
"vue_storefront_magento_en_us"
],
```

Expand Down Expand Up @@ -177,6 +182,67 @@ Go to the new ‘Indexer’ section (Stores → Configuration → Vuestorefront
After updating the configuration, you can run the indexation.
It is also worth query ElasticSearch using CURL, to be sure that the communication works.

### Update VSF/VSF-API configuration
**Important**: It is crucial to update configuration `elasticsearch.index` in the VSF and `elasticsearch.indices` in VSF-API

*Index Name Prefix* → define prefixes for ElasticSearch indexes. The panel allows adding prefix only to the catalog name e.g.: *vue_storefront_catalog*. For each store (store view) index name is generated on the base of defined prefix and either ID or Store Code. Aliases cannot be created.
*Example*: When we define following indexes: *vue_storefront_catalog_1*, *vue_storefront_catalog_2*, "vue_storefront_catalog_3".

*Index Identifier* → defines the unique store identifier to append to the ElasticSearch indexes. The default value is ID which will append the Store ID to the index name e.g.: *vue_storefront_catalog_1*. You can choose to change this to Store Code which will add the Store Code to the index name e.g.: *vue_storefront_catalog_storecode*.

*Example with Store ID*

VSF config (base on default index prefix name: vue_storefront_magento)

"vue_storefront_magento_1" - index for store view with id 1
```json
"elasticsearch": {
"httpAuth": "",
"host": "localhost:8080/api/catalog",
"index": "vue_storefront_magento_1"
}
```

VSF-API config

```json
"elasticsearch": {
"host": "localhost",
"port": 9200,
"user": "elastic",
"password": "changeme",
"indices": [
"vue_storefront_magento_1"
],
```

*Example with Store Code*

VSF config (base on default index prefix name: vue_storefront_magento)

"vue_storefront_magento_en_us" - index for store view with code "en_us"
```json
"elasticsearch": {
"httpAuth": "",
"host": "localhost:8080/api/catalog",
"index": "vue_storefront_magento_en_us"
}
```

VSF-API config

```json
"elasticsearch": {
"host": "localhost",
"port": 9200,
"user": "elastic",
"password": "changeme",
"indices": [
"vue_storefront_magento_en_us"
],
}
```

### Running the full indexation:
There are two options to run full indexations

Expand All @@ -202,7 +268,7 @@ php bin/magento indexer:reindex

or
```php
php bin/magento vsbridge:reindex --store=[STORE_ID]
php bin/magento vsbridge:reindex --store=[STORE ID|STORE CODE]
php bin/magento vsbridge:reindex --store=1
```

Expand All @@ -226,14 +292,16 @@ Note: If a docker with ElasticSearch is disabled, Indexer will display error: "N

-- Vue Storefront >= 1.4.4
Module was tested on:
-- Magento Community version 2.2.7 It should perform without any issues on Magento 2.2.6 and above versions.
-- Magento Enterprise version 2.3.0. The bridge indexer cannot be installed on lower versions of Magento Enterprise.
-- Magento Community version 2.2.7. It should perform without any issues on Magento 2.2.* and above versions.

-- Magento Commerce version 2.3.0. The bridge indexer cannot be installed on lower versions of Magento Enterprise.

-- You can install module on Magento 2.3.* Commerce, but you still need `ES 5.*` to export data.
Module will work with library [elasticsearch/elastichserach](https://github.com/elastic/elasticsearch/) (`5.*`, `6.*`)


Module was not tested on version 2.3.

### TODO
- check the Vue Storefront - Magento 2 Indexer bridge for Magento 2.3 (for Commerce and Enterprise versions).
- add MSI support
- add a limitation of the attributes (products, categories) sent to ElasticSearch
- add a limitation of the categories sent to ElasticSearch, by adding new configurations: send only categories visible in the menu, send only active categories @Agata
- add a new command allowing to enable/disable following indexes: CMS Block, CMS Page.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Agata",
"email": "[email protected]"
}],
"version": "1.2.0",
"version": "1.3.0",
"keywords": [
"magento",
"magento2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @package Divante\VsbridgeIndexerCatalog
* @author Agata Firlejczyk <[email protected]>
* @copyright 2019 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/

namespace Divante\VsbridgeIndexerCatalog\Api\DataProvider\Category;

use Divante\VsbridgeIndexerCore\Api\DataProviderInterface;

/**
* Interface AttributeDataProviderInterface
*/
interface AttributeDataProviderInterface extends DataProviderInterface
{
/**
* @param array $categoryDTO
*
* @return array
*/
public function prepareParentCategory(array $categoryDTO);

/**
* @param array $categoryDTO
*
* @return array
*/
public function prepareChildCategory(array $categoryDTO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* @package Divante\VsbridgeIndexerCatalog
* @author Agata Firlejczyk <[email protected]>
* @copyright 2019 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/

namespace Divante\VsbridgeIndexerCatalog\Logger;

use Monolog\Logger;

/**
* Class CatalogIndexerLogger
*/
class CatalogIndexerLogger extends Logger
{
}
30 changes: 30 additions & 0 deletions src/module-vsbridge-indexer-catalog/Logger/Handler/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* @package Divante\VsbridgeIndexerCatalog
* @author Agata Firlejczyk <[email protected]>
* @copyright 2019 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/

namespace Divante\VsbridgeIndexerCatalog\Logger\Handler;

use Magento\Framework\Logger\Handler\Base;
use Monolog\Logger;

/**
* Class Error
*/
class Error extends Base
{
/**
* Logging level
* @var int
*/
protected $loggerType = Logger::ERROR;

/**
* File name
* @var string
*/
protected $fileName = '/var/log/vsbridge-indexer/catalog_error.log';
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
use Divante\VsbridgeIndexerCatalog\Api\ApplyCategorySlugInterface;
use Divante\VsbridgeIndexerCatalog\Model\ResourceModel\Category\AttributeDataProvider;
use Divante\VsbridgeIndexerCatalog\Model\ResourceModel\Category\ProductCount as ProductCountResourceModel;
use Divante\VsbridgeIndexerCatalog\Api\DataProvider\Category\AttributeDataProviderInterface;

/**
* Class AttributeData
*/
class AttributeData
class AttributeData implements AttributeDataProviderInterface
{
/**
* List of fields from category
Expand Down Expand Up @@ -132,7 +133,7 @@ public function addData(array $indexData, $storeId)

foreach ($attributes as $entityId => $attributesData) {
$categoryData = array_merge($indexData[$entityId], $attributesData);
$categoryData = $this->prepareCategory($categoryData);
$categoryData = $this->prepareParentCategory($categoryData);
$categoryData = $this->addSortOptions($categoryData, $storeId);
$categoryData['product_count'] = $productCount[$entityId];

Expand Down Expand Up @@ -217,7 +218,7 @@ private function plotTree(array $categories, $rootId)
}

$categoryData['product_count'] = $this->childrenProductCount[$categoryId];
$categoryData = $this->prepareCategory($categoryData);
$categoryData = $this->prepareChildCategory($categoryData);
$categoryData['children_data'] = $this->plotTree($categories, $categoryId);
$categoryData['children_count'] = count($categoryData['children_data']);
$categoryTree[] = $categoryData;
Expand All @@ -227,6 +228,26 @@ private function plotTree(array $categories, $rootId)
return empty($categoryTree) ? [] : $categoryTree;
}

/**
* @param array $categoryDTO
*
* @return array
*/
public function prepareParentCategory(array $categoryDTO)
{
return $this->prepareCategory($categoryDTO);
}

/**
* @param array $categoryDTO
*
* @return array
*/
public function prepareChildCategory(array $categoryDTO)
{
return $this->prepareCategory($categoryDTO);
}

/**
* @param array $categoryDTO
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ private function applySlug(array $productData): array
{
$entityId = $productData['id'];

if ($this->settings->useMagentoUrlKeys()) {
if ($this->settings->useMagentoUrlKeys() && isset($productData['url_key'])) {
$productData['slug'] = $productData['url_key'];
} else {
$text = $productData['name'];

if ($this->settings->useUrlKeyToGenerateSlug()) {
if ($this->settings->useUrlKeyToGenerateSlug() && isset($productData['url_key'])) {
$text = $productData['url_key'];
}

Expand Down
Loading

0 comments on commit e586c16

Please sign in to comment.