Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add style unique field #6

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# spryker-product-page-search-expander

[![PHP from Travis config](https://img.shields.io/travis/php-v/symfony/symfony.svg)](https://php.net/)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://packagist.org/packages/fond-of-spryker/product-page-search-expander)

## Installation

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ interface ProductPageSearchExpanderConstants

public const SIZE = 'size';

public const STYLE_UNIQUE = 'style_unique';

public const STYLE_KEY = 'style_key';

public const AVAILABLE = 'available';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace FondOfSpryker\Zed\ProductPageSearchExpander\Communication\Plugin\ProductPageSearch\Elasticsearch\ProductAbstractMap;

use FondOfSpryker\Shared\ProductPageSearchExpander\ProductPageSearchExpanderConstants;
use Generated\Shared\Transfer\LocaleTransfer;
use Generated\Shared\Transfer\PageMapTransfer;
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
use Spryker\Zed\ProductPageSearchExtension\Dependency\PageMapBuilderInterface;
use Spryker\Zed\ProductPageSearchExtension\Dependency\Plugin\ProductAbstractMapExpanderPluginInterface;

/**
* @method \FondOfSpryker\Zed\ProductPageSearchExpander\Communication\ProductPageSearchExpanderCommunicationFactory getFactory()
*/
class StyleUniqueMapExpanderPlugin extends AbstractPlugin implements ProductAbstractMapExpanderPluginInterface
{
/**
* Specification:
* - Expands and returns the provided PageMapTransfer objects data.
*
* @api
*
* @param \Generated\Shared\Transfer\PageMapTransfer $pageMapTransfer
* @param \Spryker\Zed\ProductPageSearchExtension\Dependency\PageMapBuilderInterface $pageMapBuilder
* @param array $productData
* @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer
*
* @return \Generated\Shared\Transfer\PageMapTransfer
*/
public function expandProductMap(
PageMapTransfer $pageMapTransfer,
PageMapBuilderInterface $pageMapBuilder,
array $productData,
LocaleTransfer $localeTransfer
): PageMapTransfer {
if (isset($productData[ProductPageSearchExpanderConstants::STYLE_UNIQUE])) {
$pageMapTransfer->setStyleKey($productData[ProductPageSearchExpanderConstants::STYLE_UNIQUE]);
}

return $pageMapTransfer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace FondOfSpryker\Zed\ProductPageSearchExpander\Communication\Plugin\ProductPageSearch\Elasticsearch\ProductPageData;

use FondOfSpryker\Shared\ProductPageSearchExpander\ProductPageSearchExpanderConstants;
use Generated\Shared\Transfer\ProductPageSearchTransfer;
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
use Spryker\Zed\ProductPageSearch\Dependency\Plugin\ProductPageDataExpanderInterface;

/**
* @method \FondOfSpryker\Zed\ProductPageSearchExpander\Communication\ProductPageSearchExpanderCommunicationFactory getFactory()
*/
class StyleUniqueDataExpanderPlugin extends AbstractPlugin implements ProductPageDataExpanderInterface
{
/**
* Specification:
* - Expands the provided ProductAbstractPageSearch transfer object's data by reference.
*
* @api
*
* @param array $productData
* @param \Generated\Shared\Transfer\ProductPageSearchTransfer $productAbstractPageSearchTransfer
*
* @return void
*/
public function expandProductPageData(
array $productData,
ProductPageSearchTransfer $productAbstractPageSearchTransfer
): void {
if (!isset($productData[ProductPageSearchExpanderConstants::PRODUCT_ATTRIBUTES])) {
return;
}

$productAttributes = json_decode($productData[ProductPageSearchExpanderConstants::PRODUCT_ATTRIBUTES], true);

if (array_key_exists(ProductPageSearchExpanderConstants::STYLE_UNIQUE, $productAttributes)) {
$productAbstractPageSearchTransfer->setStyleKey($productAttributes[ProductPageSearchExpanderConstants::STYLE_UNIQUE]);
}
}
}