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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Agata Firlejczyk committed Apr 25, 2019
2 parents 21d976e + 179a0c4 commit 2e6983e
Show file tree
Hide file tree
Showing 44 changed files with 1,602 additions and 41 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# Changelog

## 1.1.0
## [Unreleased]

### Added
- Adding support for video data. Small change will be needed in VSF #19
- Add support for "product_count" in category. When products are reassign to category, category data is not updated automatically in ES.
There is not need really, VSF only has to know if `product_count > 0`, so if you already had products assign to categories (before running ` bin/magento indexer:reindex vsbridge_category_indexer`)
category will be visible in menu sidebar.
- Add support for reviews. Reviews are exported without ratings (VSF does not support ratings for now)
- Add support for custom options.

## 1.0.0 (2019.04.03)
## [1.0.0] (2019.04.03)
First version

## March 2019

### Added
- Adding 'url_path' for products.
You have to delete existing index from Elasticsearch and run full reindexation.
Need to get correct mapping for new product field.
You need to get correct mapping for new product field.
- Add support for "available_sort_by" and "default_sort_by" default values.

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
"src/module-vsbridge-indexer-core/registration.php",
"src/module-vsbridge-indexer-catalog/registration.php",
"src/module-vsbridge-indexer-cms/registration.php",
"src/module-vsbridge-indexer-review/registration.php",
"src/module-vsbridge-indexer-tax/registration.php"
],
"psr-4": {
"Divante\\VsbridgeIndexerCore\\": "src/module-vsbridge-indexer-core",
"Divante\\VsbridgeIndexerCatalog\\": "src/module-vsbridge-indexer-catalog",
"Divante\\VsbridgeIndexerCms\\": "src/module-vsbridge-indexer-cms",
"Divante\\VsbridgeIndexerReview\\": "src/module-vsbridge-indexer-review",
"Divante\\VsbridgeIndexerTax\\": "src/module-vsbridge-indexer-tax"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface;
use Magento\Eav\Model\Entity\Attribute;
use Magento\Framework\Stdlib\DateTime;

/**
* Class AbstractMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function getMappingProperties()

$properties = $this->generalMapping->getCommonProperties();
$properties['children_count'] = ['type' => FieldInterface::TYPE_INTEGER];
$properties['product_count'] = ['type' => FieldInterface::TYPE_INTEGER];

$childMapping = $this->getChildrenDataMapping($attributesMapping, $properties);
$properties['children_data'] = ['properties' => $childMapping];
Expand Down
37 changes: 37 additions & 0 deletions src/module-vsbridge-indexer-catalog/Index/Mapping/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ private function getCommonMappingProperties()
'image' => ['type' => FieldInterface::TYPE_TEXT],
'lab' => ['type' => FieldInterface::TYPE_TEXT],
'pos' => ['type' => FieldInterface::TYPE_TEXT],
'vid' => [
'properties' => [
'url' => ['type' => FieldInterface::TYPE_TEXT],
'title' => ['type' => FieldInterface::TYPE_TEXT],
'desc' => ['type' => FieldInterface::TYPE_TEXT],
'video_id' => ['type' => FieldInterface::TYPE_TEXT],
'meta' => ['type' => FieldInterface::TYPE_TEXT],
'type' => ['type' => FieldInterface::TYPE_TEXT],
]
]
],
];
$attributesMapping['final_price'] = ['type' => FieldInterface::TYPE_DOUBLE];
Expand All @@ -168,6 +178,7 @@ private function getCustomProperties()
'properties' => [
'option_id' => ['type' => FieldInterface::TYPE_LONG],
'position' => ['type' => FieldInterface::TYPE_LONG],
'title' => ['type' => FieldInterface::TYPE_TEXT],
'sku' => ['type' => FieldInterface::TYPE_KEYWORD],
'product_links' => [
'properties' => [
Expand Down Expand Up @@ -214,6 +225,32 @@ private function getCustomProperties()
'name' => ['type' => FieldInterface::TYPE_TEXT],
],
],
'custom_options' => [
'properties' => [
'image_size_x' => ['type' => FieldInterface::TYPE_TEXT],
'image_size_y' => ['type' => FieldInterface::TYPE_TEXT],
'file_extension' => ['type' => FieldInterface::TYPE_TEXT],
'is_require' => ['type' => FieldInterface::TYPE_BOOLEAN],
'max_characters' => ['type' => FieldInterface::TYPE_TEXT],
'option_id' => ['type' => FieldInterface::TYPE_LONG],
'price' => ['type' => FieldInterface::TYPE_DOUBLE],
'price_type' => ['type' => FieldInterface::TYPE_TEXT],
'sku' => ['type' => FieldInterface::TYPE_KEYWORD],
'sort_order' => ['type' => FieldInterface::TYPE_LONG],
'title' => ['type' => FieldInterface::TYPE_TEXT],
'type' => ['type' => FieldInterface::TYPE_TEXT],
'values' => [
'properties' => [
'sku' => ['type' => FieldInterface::TYPE_KEYWORD],
'price' => ['type' => FieldInterface::TYPE_DOUBLE],
'title' => ['type' => FieldInterface::TYPE_TEXT],
'price_type' => ['type' => FieldInterface::TYPE_TEXT],
'sort_order' => ['type' => FieldInterface::TYPE_LONG],
'option_type_id' => ['type' => FieldInterface::TYPE_INTEGER],
]
]
]
],
'tier_prices' => [
'properties' => [
'customer_group_d' => ['type' => FieldInterface::TYPE_INTEGER],
Expand Down
54 changes: 52 additions & 2 deletions src/module-vsbridge-indexer-catalog/Model/GalleryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,34 @@
*/
class GalleryProcessor
{
/**
* Youtube regex
* @var string
*/
private $youtubeRegex =
'%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i';

/**
* Vimeo regex
* @var array
*/
private $vimeoRegex = [
'%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)',
"?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$%im",
];

/**
* @param array $gallerySet
* @param array $videoSet
*
* @return array
*/
public function prepareMediaGallery(array $gallerySet)
public function prepareMediaGallery(array $gallerySet, array $videoSet = [])
{
$galleryPerProduct = [];

foreach ($gallerySet as $mediaImage) {
$linkFieldId = $mediaImage['row_id'];
$linkFieldId = $mediaImage['row_id'];
$image['typ'] = 'image';
$image = [
'typ' => 'image',
Expand All @@ -32,12 +49,45 @@ public function prepareMediaGallery(array $gallerySet)
'pos' => (int)($this->getValue('position', $mediaImage)),
];

$valueId = $mediaImage['value_id'];

if (isset($videoSet[$valueId])) {
$image['vid'] = $this->prepareVideoData($videoSet[$valueId]);
}

$galleryPerProduct[$linkFieldId][] = $image;
}

return $galleryPerProduct;
}

/**
* @param array $video
*
* @return array
*/
private function prepareVideoData(array $video)
{
$vimeoRegex = implode('', $this->vimeoRegex);
$id = null;
$type = null;
$reg = [];
$url = $video['url'];

if (preg_match($this->youtubeRegex, $url, $reg)) {
$id = $reg[1];
$type = 'youtube';
} elseif (preg_match($vimeoRegex, $video['url'], $reg)) {
$id = $reg[3];
$type = 'vimeo';
}

$video['video_id'] = $id;
$video['type'] = $type;

return $video;
}

/**
* @param string $fieldKey
* @param array $image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Divante\VsbridgeIndexerCatalog\Model\ConfigSettings;
use Divante\VsbridgeIndexerCatalog\Model\SlugGenerator;
use Divante\VsbridgeIndexerCatalog\Model\ResourceModel\Category\AttributeDataProvider;
use Divante\VsbridgeIndexerCatalog\Model\ResourceModel\Category\ProductCount as ProductCountResourceModel;

/**
* Class AttributeData
Expand Down Expand Up @@ -47,6 +48,11 @@ class AttributeData
*/
private $childrenResourceModel;

/**
* @var ProductCountResourceModel
*/
private $productCountResource;

/**
* @var \Divante\VsbridgeIndexerCore\Indexer\DataFilter
*/
Expand All @@ -57,6 +63,11 @@ class AttributeData
*/
private $childrenRowAttributes = [];

/**
* @var array
*/
private $childrenProductCount = [];

/**
* @var ConfigSettings
*/
Expand All @@ -80,13 +91,15 @@ class AttributeData
public function __construct(
AttributeDataProvider $attributeResource,
CategoryChildrenResource $childrenResource,
ProductCountResourceModel $productCountResource,
SlugGenerator\Proxy $catalogHelper,
ConfigSettings $configSettings,
CategoryChildAttributes $categoryChildAttributes,
DataFilter $dataFilter
) {
$this->settings = $configSettings;
$this->slugGenerator = $catalogHelper;
$this->productCountResource = $productCountResource;
$this->attributeResourceModel = $attributeResource;
$this->childrenResourceModel = $childrenResource;
$this->dataFilter = $dataFilter;
Expand All @@ -105,12 +118,17 @@ public function addData(array $indexData, $storeId)
/**
* TODO add option to load only specific categories
*/
$attributes = $this->attributeResourceModel->loadAttributesData($storeId, array_keys($indexData));

$categoryIds = array_keys($indexData);
$attributes = $this->attributeResourceModel->loadAttributesData($storeId, $categoryIds);
$productCount = $this->productCountResource->loadProductCount($categoryIds);

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

$indexData[$entityId] = $categoryData;
}

Expand All @@ -126,6 +144,9 @@ public function addData(array $indexData, $storeId)
$this->childAttributes->getRequiredAttributes()
);

$this->childrenProductCount = $this->productCountResource->loadProductCount(
array_keys($groupedChildrenById)
);
$indexData[$categoryId] = $this->addChildrenData($categoryData, $groupedChildrenById);
}

Expand Down Expand Up @@ -168,7 +189,7 @@ private function groupChildrenById(array $children)

/**
* @param array $categories
* @param $rootId
* @param int $rootId
*
* @return array
*/
Expand All @@ -188,6 +209,7 @@ private function plotTree(array $categories, $rootId)
$categoryData = array_merge($categoryData, $this->childrenRowAttributes[$categoryId]);
}

$categoryData['product_count'] = $this->childrenProductCount[$categoryId];
$categoryData = $this->prepareCategory($categoryData);
$categoryData['children_data'] = $this->plotTree($categories, $categoryId);
$categoryData['children_count'] = count($categoryData['children_data']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function addData(array $indexData, $storeId)

/**
* @param array $indexData
* @param $storeId
* @param int $storeId
*
* @return array
* @throws \Exception
Expand Down Expand Up @@ -299,7 +299,7 @@ private function hasPrice(array $product)
}

/**
* @param $storeId
* @param int $storeId
* @param array $allChildren
* @param array $requiredAttributes
*
Expand Down Expand Up @@ -345,19 +345,19 @@ private function loadChildrenRawAttributesInBatches($storeId, array $allChildren

/**
* @param array $documents
* @param $size
* @param int $batchSize
*
* @return \Generator
*/
private function getChildrenInBatches(array $documents, $size)
private function getChildrenInBatches(array $documents, $batchSize)
{
$i = 0;
$batch = [];

foreach ($documents as $documentName => $documentValue) {
$batch[$documentName] = $documentValue;

if (++$i == $size) {
if (++$i == $batchSize) {
yield $batch;
$i = 0;
$batch = [];
Expand Down
Loading

0 comments on commit 2e6983e

Please sign in to comment.