Skip to content

Commit

Permalink
Start implementation of filters of features
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Apr 5, 2024
1 parent f5f7cdc commit f64c5d7
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder;

use Context;
use DbQuery;
use PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\Condition;
use PrestaShop\Module\PsxMarketingWithGoogle\Repository\LanguageRepository;

class FeatureQueryBuilder implements QueryBuilderInterface
{
/**
* @var Context
*/
protected $context;

/**
* @var LanguageRepository
*/
protected $languageRepository;

/**
* @var string
*/
protected $currentLanguageIsoCode;

public function __construct(
Context $context,
LanguageRepository $languageRepository
) {
$this->context = $context;
$this->languageRepository = $languageRepository;
$this->currentLanguageIsoCode = $this->languageRepository->getIsoById(
(int) $this->context->language->id
);
}

public function addWhereFromFilter(DbQuery $query, $filter): DbQuery
{
/*
Example of payload:
{
"attribute": "feature",
"condition": "in",
"values": [
{
"id": "6",
"key": "Brasserie",
"value": "BRASSERIE DES LEGENDES",
"language": "fr"
},
{
"id": "6",
"key": "Brasserie",
"value": "BRASSERY DES LEGENDES",
"language": "gb"
}
]
}
*/


switch ($filter['condition']) {
case Condition::IS:
// TODO
return $query;
case Condition::IS_NOT:
// TODO
return $query;
}

return $query;
}

public function addRelations(DbQuery $query): DbQuery
{
return $query
->leftJoin('feature_product', 'fp', 'fp.id_product = p.id_product')
->innerJoin('feature', 'f', 'fp.id_feature = f.id_feature')
->innerJoin('feature_shop', 'fs', 'fs.id_feature = f.id_feature')
->innerJoin('feature_lang', 'fl', 'fl.id_feature = f.id_feature')
->innerJoin('feature_value', 'fv', 'fv.id_feature = fp.id_feature')
->innerJoin('feature_value_lang', 'fvl', 'fvl.id_feature_value = fv.id_feature_value')
->where('fs.id_shop = ' . (int) $this->context->shop->id)
->where('fl.id_lang = ' . (int) $this->context->language->id);
}
}
3 changes: 3 additions & 0 deletions classes/ProductFilter/FilterApplication/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\BrandQueryBuilder;
use PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\CategoryQueryBuilder;
use PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\CustomAttributeQueryBuilder;
use PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\FeatureQueryBuilder;
use PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\OutOfStockQueryBuilder;
use PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\PriceQueryBuilder;
use PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\ProductIdQueryBuilder;
Expand All @@ -47,6 +48,7 @@ public function __construct(
BrandQueryBuilder $brandQueryBuilder,
CategoryQueryBuilder $categoryQueryBuilder,
CustomAttributeQueryBuilder $customAttributeQueryBuilder,
FeatureQueryBuilder $featureQueryBuilder,
OutOfStockQueryBuilder $outOfStockQueryBuilder,
PriceQueryBuilder $priceQueryBuilder,
ProductIdQueryBuilder $productIdQueryBuilder
Expand All @@ -56,6 +58,7 @@ public function __construct(
AttributeType::BRAND => $brandQueryBuilder,
AttributeType::CATEGORY => $categoryQueryBuilder,
AttributeType::CUSTOM_ATTRIBUTE => $customAttributeQueryBuilder,
AttributeType::FEATURE =>$featureQueryBuilder,
AttributeType::OUT_OF_STOCK => $outOfStockQueryBuilder,
AttributeType::PRICE => $priceQueryBuilder,
AttributeType::PRODUCT_ID => $productIdQueryBuilder,
Expand Down
8 changes: 8 additions & 0 deletions config/admin/product_filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ services:
class: PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\CustomAttributeQueryBuilder
public: true

PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\FeatureQueryBuilder:
class: PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\FeatureQueryBuilder
public: true
arguments:
- '@psxmarketingwithgoogle.context'
- '@PrestaShop\Module\PsxMarketingWithGoogle\Repository\LanguageRepository'

PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\OutOfStockQueryBuilder:
class: PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\OutOfStockQueryBuilder
public: true
Expand All @@ -67,6 +74,7 @@ services:
- '@PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\BrandQueryBuilder'
- '@PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\CategoryQueryBuilder'
- '@PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\CustomAttributeQueryBuilder'
- '@PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\FeatureQueryBuilder'
- '@PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\OutOfStockQueryBuilder'
- '@PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\PriceQueryBuilder'
- '@PrestaShop\Module\PsxMarketingWithGoogle\ProductFilter\FilterApplication\AttributeQueryBuilder\ProductIdQueryBuilder'
Expand Down

0 comments on commit f64c5d7

Please sign in to comment.