-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
馃摝 introduce new bundle product-image-grouping-product-page-search (#89)
- Loading branch information
0 parents
commit ec58b34
Showing
21 changed files
with
708 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
continous-integration: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php-versions: [ "8.0", "8.1", "8.2" ] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup PHP, with composer and extensions | ||
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
extensions: mbstring, dom, fileinfo, pgsql, json | ||
coverage: xdebug #optional | ||
- name: Get composer cache directory | ||
id: composercache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
- name: Cache composer dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composercache.outputs.dir }} | ||
# Use composer.json for key, if composer.lock is not committed. | ||
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: Install dependencies and run ci tasks | ||
run: make install ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.idea | ||
|
||
.DS_Store | ||
|
||
vendor | ||
composer.lock | ||
|
||
src/Generated | ||
src/Orm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2023-present FOND OF GmbH | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.PHONY: install | ||
install: | ||
composer install | ||
|
||
.PHONY: phpcs | ||
phpcs: | ||
./vendor/bin/phpcs --standard=./vendor/spryker/code-sniffer/Spryker/ruleset.xml ./src/FondOfImpala/* ./tests/* | ||
|
||
.PHONY: phpcbf | ||
phpcbf: | ||
./vendor/bin/phpcbf --standard=./vendor/spryker/code-sniffer/Spryker/ruleset.xml ./src/FondOfImpala/* ./tests/* | ||
|
||
.PHONY: phpstan | ||
phpstan: | ||
./vendor/bin/phpstan --memory-limit=-1 analyse ./src/FondOfImpala | ||
|
||
.PHONY: codeception | ||
codeception: | ||
./vendor/bin/codecept run --env standalone | ||
|
||
.PHONY: ci | ||
ci: phpcs codeception phpstan | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -Rf composer.lock | ||
rm -Rf ./vendor | ||
find ./tests/_output/ -not -name .gitignore -delete | ||
rm -Rf src/Generated/* | ||
rm -Rf src/Orm/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Product Image Grouping Product Page Search | ||
[![CI](https://github.com/fond-of-impala/product-image-grouping-product-page-search/actions/workflows/main.yml/badge.svg)](https://github.com/fond-of-impala/product-image-grouping-product-page-search/actions/workflows/main.yml) | ||
[![license](https://img.shields.io/github/license/fond-of-impala/product-image-grouping-product-page-search.svg)](https://packagist.org/packages/fond-of-impala/product-image-grouping-product-page-search) | ||
|
||
This package will group the image sets by name. Example: | ||
|
||
``` | ||
"groupedImages": { | ||
"setName1": { | ||
"images": [ | ||
{ | ||
"externalUrlSmall": "https:\/\/...", | ||
"externalUrlLarge": "https:\/\/...", | ||
"sortOrder": 5 | ||
}, | ||
{ | ||
"externalUrlSmall": "https:\/\/...", | ||
"externalUrlLarge": "https:\/\/...", | ||
"sortOrder": 10 | ||
}, | ||
{ | ||
"externalUrlSmall": "https:\/\/...", | ||
"externalUrlLarge": "https:\/\/...", | ||
"sortOrder": 15 | ||
} | ||
] | ||
}, | ||
"setName2": { | ||
"images": [ | ||
{ | ||
"externalUrlSmall": "https:\/\/...", | ||
"externalUrlLarge": "https:\/\/...", | ||
"sortOrder": 0 | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Installation | ||
|
||
``` | ||
composer require fond-of-impala/product-image-grouping-product-page-search | ||
``` | ||
|
||
## Usage | ||
|
||
In src/Pyz/Client/Catalog/CatalogDependencyProvider.php replace | ||
|
||
`use Spryker\Client\Catalog\Plugin\Elasticsearch\ResultFormatter\RawCatalogSearchResultFormatterPlugin;` | ||
|
||
with | ||
|
||
`use FondOfImpala\Client\ProductImageGroupingProductPageSearch\Plugin\Search\RawCatalogSearchResultFormatterPlugin` | ||
|
||
|
||
In src/Pyz/Zed/ProductPageSearch/ProductPageSearchDependencyProvider.php | ||
|
||
add `$dataExpanderPlugins[ProductImageGroupingProductPageSearchConfig::PLUGIN_PRODUCT_IMAGE_GROUPED_PAGE_DATA] = new ProductImageGroupedPageDataLoaderExpanderPlugin();` | ||
|
||
after | ||
|
||
`$dataExpanderPlugins[ProductPageSearchConfig::PLUGIN_PRODUCT_IMAGE_PAGE_DATA] = new ProductImagePageDataLoaderExpanderPlugin();` | ||
``` | ||
/** | ||
* @return array<\Spryker\Zed\ProductPageSearch\Dependency\Plugin\ProductPageDataExpanderInterface> | ||
*/ | ||
protected function getDataExpanderPlugins(): array | ||
{ | ||
$dataExpanderPlugins = []; | ||
... | ||
$dataExpanderPlugins[ProductPageSearchConfig::PLUGIN_PRODUCT_IMAGE_PAGE_DATA] = new ProductImagePageDataLoaderExpanderPlugin(); | ||
$dataExpanderPlugins[ProductImageGroupingProductPageSearchConfig::PLUGIN_PRODUCT_IMAGE_GROUPED_PAGE_DATA] = new ProductImageGroupedPageDataLoaderExpanderPlugin(); | ||
... | ||
return $dataExpanderPlugins; | ||
} | ||
``` | ||
|
||
add | ||
|
||
`new ProductImageGroupMapExpanderPlugin(),` | ||
|
||
after | ||
|
||
`new ProductImageMapExpanderPlugin(),` | ||
|
||
``` | ||
/** | ||
* @return array<\Spryker\Zed\ProductPageSearchExtension\Dependency\Plugin\ProductAbstractMapExpanderPluginInterface> | ||
*/ | ||
protected function getProductAbstractMapExpanderPlugins(): array | ||
{ | ||
return [ | ||
... | ||
new ProductImageMapExpanderPlugin(), | ||
new ProductImageGroupMapExpanderPlugin(), | ||
... | ||
]; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace: fond-of-impala/product-image-grouping-product-page-search | ||
|
||
suites: | ||
unit: | ||
path: . | ||
|
||
settings: | ||
shuffle: true | ||
lint: true | ||
|
||
bootstrap: _bootstrap.php | ||
|
||
paths: | ||
tests: tests | ||
output: tests/_output | ||
support: tests/_support | ||
data: tests/_data | ||
|
||
coverage: | ||
enabled: true | ||
include: | ||
- src/*.php | ||
|
||
modules: | ||
enabled: | ||
- \FondOfCodeception\Module\Spryker | ||
config: | ||
\FondOfCodeception\Module\Spryker: | ||
generate_transfer: false | ||
generate_map_classes: false | ||
generate_propel_classes: false | ||
generate_ide_auto_completion: false | ||
|
||
env: | ||
standalone: | ||
modules: | ||
config: | ||
\FondOfCodeception\Module\Spryker: | ||
generate_transfer: true | ||
generate_map_classes: true | ||
generate_propel_classes: true | ||
generate_ide_auto_completion: true | ||
supported_source_identifiers: | ||
- page | ||
monorepo: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "fond-of-impala/product-image-grouping-product-page-search", | ||
"description": "Product Image Grouping Product Page Search module.", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Julian Hyatt", | ||
"email": "dev@jzit.de" | ||
} | ||
], | ||
"require": { | ||
"php": ">=8.0", | ||
"spryker/catalog": "^3.0.0 || ^4.0.0 || ^5.0.0", | ||
"spryker/product-page-search": "^3.24.0", | ||
"spryker/product-page-search-extension": "^1.4.0" | ||
}, | ||
"require-dev": { | ||
"fond-of-codeception/spryker": "*", | ||
"spryker/code-sniffer": "*", | ||
"spryker-sdk/phpstan-spryker": "*" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"autoload": { | ||
"psr-4": { | ||
"FondOfImpala\\": "src/FondOfImpala/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"FondOfImpala\\": "tests/FondOfImpala/", | ||
"Generated\\": "src/Generated/", | ||
"Orm\\": "src/Orm/" | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
parameters: | ||
level: 5 | ||
reportUnmatchedIgnoredErrors: false | ||
scanDirectories: | ||
- src/Orm/Zed |
52 changes: 52 additions & 0 deletions
52
...uctImageGroupingProductPageSearch/Plugin/Search/RawCatalogSearchResultFormatterPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace FondOfImpala\Client\ProductImageGroupingProductPageSearch\Plugin\Search; | ||
|
||
use Elastica\ResultSet; | ||
use FondOfImpala\Zed\ProductImageGroupingProductPageSearch\Communication\Plugin\ProductPageSearch\ProductImageGroupMapExpanderPlugin; | ||
use Generated\Shared\Transfer\RestCatalogSearchProductImageTransfer; | ||
use Spryker\Client\Catalog\Plugin\Elasticsearch\ResultFormatter\RawCatalogSearchResultFormatterPlugin as SprykerRawCatalogSearchResultFormatterPlugin; | ||
|
||
class RawCatalogSearchResultFormatterPlugin extends SprykerRawCatalogSearchResultFormatterPlugin | ||
{ | ||
/** | ||
* @param \Elastica\ResultSet $searchResult | ||
* @param array $requestParameters | ||
* | ||
* @return mixed | ||
*/ | ||
public function formatSearchResult(ResultSet $searchResult, array $requestParameters = []) | ||
{ | ||
$rawData = parent::formatSearchResult($searchResult, $requestParameters); | ||
foreach ($rawData as $index => $rawProduct) { | ||
$rawData[$index] = $this->prepareImageData($rawProduct); | ||
} | ||
|
||
return $rawData; | ||
} | ||
|
||
/** | ||
* @param array $product | ||
* | ||
* @return array | ||
*/ | ||
protected function prepareImageData(array $product): array | ||
{ | ||
if (!array_key_exists(ProductImageGroupMapExpanderPlugin::KEY, $product)) { | ||
return $product; | ||
} | ||
|
||
$groupedImages = []; | ||
foreach ($product[ProductImageGroupMapExpanderPlugin::KEY] as $key => $images) { | ||
$key = lcfirst(str_replace('_', '', ucwords($key, '_'))); | ||
|
||
foreach ($images as $image) { | ||
$groupedImages[$key]['images'][] = (new RestCatalogSearchProductImageTransfer())->fromArray($image, true)->toArray(); | ||
} | ||
} | ||
|
||
$product[ProductImageGroupMapExpanderPlugin::KEY] = $groupedImages; | ||
|
||
return $product; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...red/ProductImageGroupingProductPageSearch/ProductImageGroupingProductPageSearchConfig.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace FondOfImpala\Shared\ProductImageGroupingProductPageSearch; | ||
|
||
use Spryker\Shared\Kernel\AbstractSharedConfig; | ||
|
||
class ProductImageGroupingProductPageSearchConfig extends AbstractSharedConfig | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public const PLUGIN_PRODUCT_IMAGE_GROUPED_PAGE_DATA = 'PLUGIN_PRODUCT_IMAGE_GROUPED_PAGE_DATA'; | ||
} |
21 changes: 21 additions & 0 deletions
21
...roupingProductPageSearch/Transfer/product_image_grouping_product_page_search.transfer.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0"?> | ||
<transfers xmlns="spryker:transfer-01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="spryker:transfer-01 https://static.spryker.com/transfer-01.xsd"> | ||
|
||
<transfer name="RestCatalogSearchAbstractProducts"> | ||
<property name="groupedImages" type="RestCatalogSearchGroupedProductImages[]" associative="true" singular="groupedImage"/> | ||
</transfer> | ||
|
||
<transfer name="RestCatalogSearchGroupedProductImages"> | ||
<property name="images" type="RestCatalogSearchProductImage[]" associative="true" singular="images"/> | ||
</transfer> | ||
|
||
<transfer name="RestCatalogSearchProductImage"> | ||
<property name="sortOrder" type="int"/> | ||
</transfer> | ||
|
||
<transfer name="ProductPageSearch"> | ||
<property name="groupedProductImages" associative="true" type="array" singular="groupedProductImage"/> | ||
</transfer> | ||
|
||
</transfers> |
Oops, something went wrong.