first commit
This commit is contained in:
39
bundles/KupShop/CatalogBundle/Query/ProductsTypes.php
Normal file
39
bundles/KupShop/CatalogBundle/Query/ProductsTypes.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace KupShop\CatalogBundle\Query;
|
||||
|
||||
use Query\Operator;
|
||||
use Query\Operator as Op;
|
||||
use Query\QueryBuilder;
|
||||
|
||||
class ProductsTypes
|
||||
{
|
||||
public static function joinAlsoBought($id_products, $limit = null)
|
||||
{
|
||||
return function (QueryBuilder $qb) use ($id_products, $limit) {
|
||||
$ordersWithProductsQb = sqlQueryBuilder()->select('id_order')->from('order_items')
|
||||
->where('total_price > 0')
|
||||
->andWhere(Operator::inIntArray($id_products, 'id_product'))
|
||||
->orderBy('id', 'DESC')
|
||||
// TODO: TMP "fix" to speed-up cart rendering during black-friday, REVERT ME!
|
||||
->setMaxResults(10);
|
||||
|
||||
$alsoBoughtProductsQb = sqlQueryBuilder()
|
||||
->select('oi.id_product', 'COUNT(oi.id_product) cnt')
|
||||
->from('order_items', 'oi')
|
||||
->join('oi', 'ordersWithProducts', 'oil', 'oil.id_order = oi.id_order')
|
||||
->andWhere(Op::not(Op::inIntArray($id_products, 'oi.id_product')))
|
||||
->andWhere('oi.total_price > 0') // excluding gifts & returns
|
||||
->groupBy('oi.id_product')
|
||||
->orderBy('cnt', 'DESC');
|
||||
|
||||
if ($limit) {
|
||||
$alsoBoughtProductsQb->setMaxResults($limit);
|
||||
}
|
||||
|
||||
$qb->withExpression('ordersWithProducts', $ordersWithProductsQb)
|
||||
->withExpression('alsoBoughtProducts', $alsoBoughtProductsQb)
|
||||
->join('p', 'alsoBoughtProducts', 'ic', 'ic.id_product = p.id');
|
||||
};
|
||||
}
|
||||
}
|
||||
33
bundles/KupShop/CatalogBundle/Query/RelatedProducts.php
Normal file
33
bundles/KupShop/CatalogBundle/Query/RelatedProducts.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace KupShop\CatalogBundle\Query;
|
||||
|
||||
use Query\Operator;
|
||||
use Query\QueryBuilder;
|
||||
|
||||
class RelatedProducts
|
||||
{
|
||||
public static function relatedProductsSubQuery(array $productIds, ?array $related_type = null)
|
||||
{
|
||||
$related_qb = sqlQueryBuilder()->select('*')
|
||||
->from('products_related')
|
||||
->andWhere(Operator::inIntArray($productIds, 'id_top_product'));
|
||||
|
||||
if ($related_type) {
|
||||
$related_qb->andWhere(Operator::inIntArray($related_type, 'type'));
|
||||
}
|
||||
|
||||
return $related_qb;
|
||||
}
|
||||
|
||||
public static function relatedProductsSpec(array $productIds, ?array $related_type = null, string $alias = 'pr'): callable
|
||||
{
|
||||
return function (QueryBuilder $qb) use ($productIds, $related_type, $alias) {
|
||||
$related_qb = self::relatedProductsSubQuery($productIds, $related_type);
|
||||
|
||||
$qb->joinSubQuery('p', $related_qb, $alias, "{$alias}.id_rel_product = p.id")
|
||||
->addSelect("{$alias}.*")
|
||||
->orderBy("{$alias}.position", 'ASC');
|
||||
};
|
||||
}
|
||||
}
|
||||
23
bundles/KupShop/CatalogBundle/Query/Search.php
Normal file
23
bundles/KupShop/CatalogBundle/Query/Search.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace KupShop\CatalogBundle\Query;
|
||||
|
||||
class Search
|
||||
{
|
||||
public static function searchFields($search_term, $fields, $operator = 'AND')
|
||||
{
|
||||
return function (\Query\QueryBuilder $qb) use ($search_term, $fields, $operator) {
|
||||
$search = get_search_query($search_term, $fields, $operator);
|
||||
|
||||
if ($search['order']) {
|
||||
$ordering = $qb->getQueryPart('orderBy');
|
||||
$qb->orderBySql($search['order']);
|
||||
$qb->add('orderBy', $ordering, true);
|
||||
}
|
||||
|
||||
$qb->addParameters($search['data']);
|
||||
|
||||
return $search['where'];
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user