Skip to content

Commit

Permalink
Revert "Fixes #2380 is_discount tiers price support (2.8.x)"
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayet authored Dec 17, 2021
1 parent 16b8d5d commit 8f501ae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
* @category Smile
* @package Smile\ElasticsuiteCatalogRule
* @author Romain Ruaud <romain.ruaud@smile.fr>
* @copyright 2021 Smile
* @copyright 2020 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\SpecialAttribute;

use Smile\ElasticsuiteCatalogRule\Api\Rule\Condition\Product\SpecialAttributeInterface;
use Smile\ElasticsuiteCore\Search\Request\QueryInterface;

/**
* Special "is_discount" attribute class.
Expand All @@ -30,31 +29,14 @@ class IsDiscount implements SpecialAttributeInterface
*/
private $booleanSource;

/**
* @var \Magento\Customer\Model\Session
*/
private $customerSession;

/**
* @var \Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory
*/
private $queryFactory;

/**
* IsDiscount constructor.
*
* @param \Magento\Config\Model\Config\Source\Yesno $booleanSource Boolean Source.
* @param \Magento\Customer\Model\Session $customerSession Customer session.
* @param \Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory $queryFactory Query factory.
* @param \Magento\Config\Model\Config\Source\Yesno $booleanSource Boolean Source
*/
public function __construct(
\Magento\Config\Model\Config\Source\Yesno $booleanSource,
\Magento\Customer\Model\Session $customerSession,
\Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory $queryFactory
) {
$this->booleanSource = $booleanSource;
$this->customerSession = $customerSession;
$this->queryFactory = $queryFactory;
public function __construct(\Magento\Config\Model\Config\Source\Yesno $booleanSource)
{
$this->booleanSource = $booleanSource;
}

/**
Expand All @@ -70,31 +52,8 @@ public function getAttributeCode()
*/
public function getSearchQuery()
{
/*
* Query cannot be computed directly with the attribute code and value (price.is_discount = true).
* The customer group needs to be taken into account because the discounted price could be a tiers price.
*/
return $this->queryFactory->create(
QueryInterface::TYPE_NESTED,
[
'path' => 'price',
'query' => $this->queryFactory->create(
QueryInterface::TYPE_BOOL,
[
'must' => [
$this->queryFactory->create(
QueryInterface::TYPE_TERM,
['field' => 'price.customer_group_id', 'value' => $this->customerSession->getCustomerGroupId()]
),
$this->queryFactory->create(
QueryInterface::TYPE_TERM,
['field' => 'price.is_discount', 'value' => true]
),
],
]
)
]
);
// Query can be computed directly with the attribute code and value. (price.is_discount = true).
return null;
}

/**
Expand Down
9 changes: 1 addition & 8 deletions src/module-elasticsuite-catalog-rule/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @category Smile
* @package Smile\ElasticsuiteCatalogRule
* @author Romain Ruaud <romain.ruaud@smile.fr>
* @copyright 2021 Smile
* @copyright 2020 Smile
* @license Open Software License ("OSL") v. 3.0
*/
-->
Expand All @@ -29,11 +29,4 @@
</type>

<preference for="Smile\ElasticsuiteCatalogRule\Api\Data\ConditionInterface" type="Smile\ElasticsuiteCatalogRule\Model\Data\Condition"/>

<!-- Session proxies -->
<type name="Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\SpecialAttribute\IsDiscount">
<arguments>
<argument name="customerSession" xsi:type="object">Magento\Customer\Model\Session\Proxy</argument>
</arguments>
</type>
</config>
19 changes: 5 additions & 14 deletions src/module-elasticsuite-virtual-category/Helper/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @category Smile
* @package Smile\ElasticsuiteVirtualCategory
* @author Romain Ruaud <romain.ruaud@smile.fr>
* @copyright 2021 Smile
* @copyright 2020 Smile
* @license Open Software License ("OSL") v. 3.0
*/

Expand All @@ -30,23 +30,14 @@ class Rule
*/
private $cache;

/**
* @var \Magento\Customer\Model\Session
*/
private $customerSession;

/**
* Provider constructor.
*
* @param \Magento\Framework\App\CacheInterface $cache Cache.
* @param \Magento\Customer\Model\Session $customerSession Customer session.
* @param \Magento\Framework\App\CacheInterface $cache Cache
*/
public function __construct(
\Magento\Framework\App\CacheInterface $cache,
\Magento\Customer\Model\Session $customerSession
) {
public function __construct(\Magento\Framework\App\CacheInterface $cache)
{
$this->cache = $cache;
$this->customerSession = $customerSession;
}

/**
Expand All @@ -61,7 +52,7 @@ public function __construct(
public function loadUsingCache(CategoryInterface $category, $callback)
{
\Magento\Framework\Profiler::start('ES:Virtual Rule ' . $callback);
$cacheKey = implode('|', [$callback, $category->getStoreId(), $category->getId(), $this->customerSession->getCustomerGroupId()]);
$cacheKey = implode('|', [$callback, $category->getStoreId(), $category->getId()]);

$data = $this->cache->load($cacheKey);

Expand Down
9 changes: 1 addition & 8 deletions src/module-elasticsuite-virtual-category/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @category Smile
* @package Smile\ElasticsuiteVirtualCategory
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2021 Smile
* @copyright 2020 Smile
* @license Open Software License ("OSL") v. 3.0
*/
-->
Expand Down Expand Up @@ -205,11 +205,4 @@
<preference for="Smile\ElasticsuiteCatalog\Model\Category\Filter\Provider" type="Smile\ElasticsuiteVirtualCategory\Model\Category\Filter\Provider"/>

<preference for="Smile\ElasticsuiteVirtualCategory\Api\Data\VirtualRuleInterface" type="Smile\ElasticsuiteVirtualCategory\Model\Rule"/>

<!-- Session proxies -->
<type name="Smile\ElasticsuiteVirtualCategory\Helper\Rule">
<arguments>
<argument name="customerSession" xsi:type="object">Magento\Customer\Model\Session\Proxy</argument>
</arguments>
</type>
</config>

0 comments on commit 8f501ae

Please sign in to comment.