Skip to content

Commit

Permalink
feat: add style unique field (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcecube authored Jun 19, 2024
1 parent cc3b5f7 commit 25eb7ba
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
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]);
}
}
}

0 comments on commit 25eb7ba

Please sign in to comment.