Skip to content

Commit

Permalink
Add price group in request
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreGauthier committed Nov 14, 2024
1 parent 7ffe489 commit a8e6e53
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 133 deletions.
82 changes: 82 additions & 0 deletions src/Decorator/SavePriceFilterUnit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future.
*
* @package Gally
* @author Gally Team <elasticsuite@smile.fr>
* @copyright 2024-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
*/

declare(strict_types=1);

namespace Gally\OroPlugin\Decorator;

use Gally\OroPlugin\Search\SearchRegistry;
use Oro\Bundle\FilterBundle\Datasource\FilterDatasourceAdapterInterface;
use Oro\Bundle\FilterBundle\Filter\FilterInterface;
use Oro\Bundle\SearchBundle\Datagrid\Filter\SearchNumberFilter;

class SavePriceFilterUnit implements FilterInterface
{
public function __construct(
private SearchNumberFilter $decorated,
private SearchRegistry $searchRegistry,
) {
}

public function init($name, array $params)
{
$this->decorated->init($name, $params);
}

public function getName()
{
return $this->decorated->getName();
}

public function getForm()
{
return $this->decorated->getForm();
}

public function getMetadata()
{
return $this->decorated->getMetadata();
}

public function resolveOptions()
{
return $this->decorated->resolveOptions();
}

public function apply(FilterDatasourceAdapterInterface $ds, $data): void
{
if (isset($data['unit'])) {
$this->searchRegistry->setPriceFilterUnit($data['unit']);
}
$this->decorated->apply($ds, $data);
}

public function prepareData(array $data): array
{
return $this->decorated->prepareData($data);
}

public function setFilterState($state): void
{
$this->decorated->setFilterState($state);
}

public function getFilterState()
{
return $this->decorated->getFilterState();
}

public function reset(): void
{
$this->decorated->reset();
}
}
32 changes: 23 additions & 9 deletions src/Indexer/Normalizer/PriceDataNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Gally\OroPlugin\Indexer\Normalizer;

use Gally\OroPlugin\Resolver\PriceGroupResolver;
use Oro\Bundle\ConfigBundle\Config\ConfigManager;
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
use Oro\Bundle\FeatureToggleBundle\Checker\FeatureChecker;
Expand All @@ -24,6 +25,7 @@
use Oro\Bundle\PricingBundle\Placeholder\CPLIdPlaceholder;
use Oro\Bundle\PricingBundle\Placeholder\CurrencyPlaceholder;
use Oro\Bundle\PricingBundle\Placeholder\PriceListIdPlaceholder;
use Oro\Bundle\PricingBundle\Placeholder\UnitPlaceholder;
use Oro\Bundle\PricingBundle\Provider\WebsiteCurrencyProvider;
use Oro\Bundle\ProductBundle\Entity\Product;
use Oro\Bundle\WebsiteBundle\Entity\Website;
Expand All @@ -39,6 +41,7 @@ public function __construct(
private ConfigManager $configManager,
private FeatureChecker $featureChecker,
private WebsiteCurrencyProvider $currencyProvider,
private PriceGroupResolver $priceGroupResolver,
) {
}

Expand All @@ -64,7 +67,10 @@ public function normalize(
): void {
if (Product::class === $entityClass) {
$prices = [];
$minimalPrices = $fieldsValues['minimal_price.CPL_ID_CURRENCY'] ?? [];
$minimalPrices = array_merge(
$fieldsValues['minimal_price.CPL_ID_CURRENCY'] ?? [],
$fieldsValues['minimal_price.CPL_ID_CURRENCY_UNIT'] ?? [],
);
foreach ($this->toArray($minimalPrices) as $value) {
$value = $value['value'];
$placeholders = [];
Expand All @@ -74,15 +80,23 @@ public function normalize(
$value = $value->getValue();
}

if ($this->defaultCurrency !== $placeholders[CurrencyPlaceholder::NAME]) {
continue;
$priceListId = $placeholders[CPLIdPlaceholder::NAME] ?: $placeholders[PriceListIdPlaceholder::NAME];
$prices[] = [
'price' => (float) $value,
'group_id' => $this->priceGroupResolver->getGroupId(
isset($placeholders[CPLIdPlaceholder::NAME]),
$priceListId,
$placeholders[CurrencyPlaceholder::NAME],
$placeholders[UnitPlaceholder::NAME] ?? null
),
];

if ($this->defaultPriceList->getId() === $priceListId
&& $this->defaultCurrency === $placeholders[CurrencyPlaceholder::NAME]
&& !isset($placeholders[UnitPlaceholder::NAME])
) {
array_unshift($prices, ['price' => (float) $value, 'group_id' => 0]);
}

$groupId = $placeholders[CPLIdPlaceholder::NAME] ?: $placeholders[PriceListIdPlaceholder::NAME];
$groupId = $this->defaultPriceList->getId() === $groupId
? 0
: (($placeholders[CPLIdPlaceholder::NAME] ? 'cpl_' : 'pl_') . $groupId);
$prices[] = ['price' => (float) $value, 'group_id' => $groupId];
}

if (!empty($prices)) {
Expand Down
25 changes: 24 additions & 1 deletion src/Resolver/PriceGroupResolver.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future.
*
* @package Gally
* @author Gally Team <elasticsuite@smile.fr>
* @copyright 2024-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
*/

declare(strict_types=1);

namespace Gally\OroPlugin\Resolver;

class PriceGroupResolver
{

public function getGroupId(bool $isCPLUsed, int $priceListId, string $currency, ?string $unit): string
{
return implode(
'_',
array_filter([
$isCPLUsed ? 'cpl' : 'pl',
$priceListId,
$currency,
$unit,
])
);
}
}
116 changes: 0 additions & 116 deletions src/Resolver/QueryPlaceholderResolver.php

This file was deleted.

4 changes: 4 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ services:
- '@oro_website_search.placeholder.registry'

Gally\OroPlugin\Resolver\QueryPlaceholderResolver:
class: Oro\Bundle\WebsiteSearchBundle\Resolver\QueryPlaceholderResolver
public: false
arguments:
- '@Gally\OroPlugin\Placeholder\PlaceholderDecorator'

Gally\OroPlugin\Resolver\PriceGroupResolver:
public: false

oro_website_elastic_search.voter.elastic_search_engine_feature_voter:
class: Gally\OroPlugin\Voter\ElasticSearchEngineFeatureVoter
arguments:
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ services:
- '@oro_config.manager'
- '@oro_featuretoggle.checker.feature_checker'
- '@oro_pricing.provider.website_currency_provider'
- '@Gally\OroPlugin\Resolver\PriceGroupResolver'
tags:
- { name: gally.indexer_normalizer }

Expand Down
17 changes: 17 additions & 0 deletions src/Resources/config/services/search.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
services:
Gally\OroPlugin\Search\SearchRegistry: ~

Gally\OroPlugin\Decorator\SavePriceFilterUnit:
decorates: oro_pricing.filter.frontend_product_price
arguments:
- '@.inner'
- '@Gally\OroPlugin\Search\SearchRegistry'

Gally\OroPlugin\Search\ContextProvider:
arguments:
- '@oro_website.manager'
Expand All @@ -16,6 +22,9 @@ services:
arguments:
- '@Gally\OroPlugin\Search\ContextProvider'
- '@Gally\OroPlugin\Search\ExpressionVisitor'
- '@Gally\OroPlugin\Search\SearchRegistry'
- '@Gally\OroPlugin\Resolver\PriceGroupResolver'
- '@oro_website_search.placeholder.registry'

Gally\OroPlugin\Search\Filter\SelectFilter:
public: false
Expand Down Expand Up @@ -46,6 +55,14 @@ services:
tags:
- { name: 'oro_website_search.engine', engine_name: 'gally' }

Gally\OroPlugin\Search\CustomerPartialUpdateDriver:
arguments:
- '@oro_website_search.provider.placeholder_provider'
- '@oro_visibility.visibility.provider.product_visibility_provider'
- '@oro_entity.doctrine_helper'
tags:
- { name: 'oro_website_search.customer_partial_update_driver', engine_name: 'gally' }

Gally\OroPlugin\Search\Extension\GallyDataGridExtension:
arguments:
- '@oro_website_search.engine.parameters'
Expand Down
19 changes: 13 additions & 6 deletions src/Search/CustomerPartialUpdateDriver.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future.
*
* @package Gally
* @author Gally Team <elasticsuite@smile.fr>
* @copyright 2024-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
*/

declare(strict_types=1);

namespace Gally\OroPlugin\Search;

use Oro\Bundle\CustomerBundle\Entity\Customer;
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
use Oro\Bundle\SearchBundle\Query\Criteria\Criteria;
use Oro\Bundle\SearchBundle\Query\Query;
use Oro\Bundle\VisibilityBundle\Driver\AbstractCustomerPartialUpdateDriver;
use Oro\Bundle\VisibilityBundle\Entity\VisibilityResolved\BaseVisibilityResolved;
use Oro\Bundle\VisibilityBundle\Indexer\ProductVisibilityIndexer;
use Oro\Bundle\VisibilityBundle\Visibility\Provider\ProductVisibilityProvider;
use Oro\Bundle\WebsiteElasticSearchBundle\Manager\ElasticSearchPartialUpdateManager;
use Oro\Bundle\WebsiteSearchBundle\Provider\PlaceholderProvider;

/**
* Driver for the partial update of the customer visibility in the website search index
* Driver for the partial update of the customer visibility in the website search index.
*/
class CustomerPartialUpdateDriver extends AbstractCustomerPartialUpdateDriver
{
Expand Down
Loading

0 comments on commit a8e6e53

Please sign in to comment.