product loop : order by promo or newness
This commit is contained in:
@@ -143,7 +143,7 @@ class Product extends BaseLoop
|
|||||||
);
|
);
|
||||||
|
|
||||||
$attributeNonStrictMatch = $this->getAttribute_non_strict_match();
|
$attributeNonStrictMatch = $this->getAttribute_non_strict_match();
|
||||||
$usedAttributeNonStrictMatchList = array();
|
$isPSELeftJoinList = array();
|
||||||
|
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
|
||||||
@@ -179,12 +179,12 @@ class Product extends BaseLoop
|
|||||||
$new = $this->getNew();
|
$new = $this->getNew();
|
||||||
|
|
||||||
if ($new === true) {
|
if ($new === true) {
|
||||||
$usedAttributeNonStrictMatchList[] = 'new';
|
$isPSELeftJoinList[] = 'is_new';
|
||||||
$search->joinProductSaleElements('is_new', Criteria::LEFT_JOIN)
|
$search->joinProductSaleElements('is_new', Criteria::LEFT_JOIN)
|
||||||
->where('`is_new`.NEWNESS' . Criteria::EQUAL . '1')
|
->where('`is_new`.NEWNESS' . Criteria::EQUAL . '1')
|
||||||
->where('NOT ISNULL(`is_new`.ID)');
|
->where('NOT ISNULL(`is_new`.ID)');
|
||||||
} else if($new === false) {
|
} else if($new === false) {
|
||||||
$usedAttributeNonStrictMatchList[] = 'new';
|
$isPSELeftJoinList[] = 'is_new';
|
||||||
$search->joinProductSaleElements('is_new', Criteria::LEFT_JOIN)
|
$search->joinProductSaleElements('is_new', Criteria::LEFT_JOIN)
|
||||||
->where('`is_new`.NEWNESS' . Criteria::EQUAL . '0')
|
->where('`is_new`.NEWNESS' . Criteria::EQUAL . '0')
|
||||||
->where('NOT ISNULL(`is_new`.ID)');
|
->where('NOT ISNULL(`is_new`.ID)');
|
||||||
@@ -193,12 +193,12 @@ class Product extends BaseLoop
|
|||||||
$promo = $this->getPromo();
|
$promo = $this->getPromo();
|
||||||
|
|
||||||
if ($promo === true) {
|
if ($promo === true) {
|
||||||
$usedAttributeNonStrictMatchList[] = 'promo';
|
$isPSELeftJoinList[] = 'is_promo';
|
||||||
$search->joinProductSaleElements('is_promo', Criteria::LEFT_JOIN)
|
$search->joinProductSaleElements('is_promo', Criteria::LEFT_JOIN)
|
||||||
->where('`is_promo`.PROMO' . Criteria::EQUAL . '1')
|
->where('`is_promo`.PROMO' . Criteria::EQUAL . '1')
|
||||||
->where('NOT ISNULL(`is_promo`.ID)');
|
->where('NOT ISNULL(`is_promo`.ID)');
|
||||||
} else if($promo === false) {
|
} else if($promo === false) {
|
||||||
$usedAttributeNonStrictMatchList[] = 'promo';
|
$isPSELeftJoinList[] = 'is_promo';
|
||||||
$search->joinProductSaleElements('is_promo', Criteria::LEFT_JOIN)
|
$search->joinProductSaleElements('is_promo', Criteria::LEFT_JOIN)
|
||||||
->where('`is_promo`.PROMO' . Criteria::EQUAL . '0')
|
->where('`is_promo`.PROMO' . Criteria::EQUAL . '0')
|
||||||
->where('NOT ISNULL(`is_promo`.ID)');
|
->where('NOT ISNULL(`is_promo`.ID)');
|
||||||
@@ -207,7 +207,7 @@ class Product extends BaseLoop
|
|||||||
$min_stock = $this->getMin_stock();
|
$min_stock = $this->getMin_stock();
|
||||||
|
|
||||||
if (null != $min_stock) {
|
if (null != $min_stock) {
|
||||||
$usedAttributeNonStrictMatchList[] = 'min_stock';
|
$isPSELeftJoinList[] = 'is_min_stock';
|
||||||
$search->joinProductSaleElements('is_min_stock', Criteria::LEFT_JOIN)
|
$search->joinProductSaleElements('is_min_stock', Criteria::LEFT_JOIN)
|
||||||
->where('`is_min_stock`.QUANTITY' . Criteria::GREATER_THAN . '?', $min_stock, \PDO::PARAM_INT)
|
->where('`is_min_stock`.QUANTITY' . Criteria::GREATER_THAN . '?', $min_stock, \PDO::PARAM_INT)
|
||||||
->where('NOT ISNULL(`is_min_stock`.ID)');
|
->where('NOT ISNULL(`is_min_stock`.ID)');
|
||||||
@@ -216,7 +216,7 @@ class Product extends BaseLoop
|
|||||||
$min_weight = $this->getMin_weight();
|
$min_weight = $this->getMin_weight();
|
||||||
|
|
||||||
if (null != $min_weight) {
|
if (null != $min_weight) {
|
||||||
$usedAttributeNonStrictMatchList[] = 'min_weight';
|
$isPSELeftJoinList[] = 'is_min_weight';
|
||||||
$search->joinProductSaleElements('is_min_weight', Criteria::LEFT_JOIN)
|
$search->joinProductSaleElements('is_min_weight', Criteria::LEFT_JOIN)
|
||||||
->where('`is_min_weight`.WEIGHT' . Criteria::GREATER_THAN . '?', $min_weight, \PDO::PARAM_STR)
|
->where('`is_min_weight`.WEIGHT' . Criteria::GREATER_THAN . '?', $min_weight, \PDO::PARAM_STR)
|
||||||
->where('NOT ISNULL(`is_min_weight`.ID)');
|
->where('NOT ISNULL(`is_min_weight`.ID)');
|
||||||
@@ -225,7 +225,7 @@ class Product extends BaseLoop
|
|||||||
$max_weight = $this->getMax_weight();
|
$max_weight = $this->getMax_weight();
|
||||||
|
|
||||||
if (null != $max_weight) {
|
if (null != $max_weight) {
|
||||||
$usedAttributeNonStrictMatchList[] = 'max_weight';
|
$isPSELeftJoinList[] = 'is_max_weight';
|
||||||
$search->joinProductSaleElements('is_max_weight', Criteria::LEFT_JOIN)
|
$search->joinProductSaleElements('is_max_weight', Criteria::LEFT_JOIN)
|
||||||
->where('`is_max_weight`.WEIGHT' . Criteria::LESS_THAN . '?', $max_weight, \PDO::PARAM_STR)
|
->where('`is_max_weight`.WEIGHT' . Criteria::LESS_THAN . '?', $max_weight, \PDO::PARAM_STR)
|
||||||
->where('NOT ISNULL(`is_max_weight`.ID)');
|
->where('NOT ISNULL(`is_max_weight`.ID)');
|
||||||
@@ -234,7 +234,7 @@ class Product extends BaseLoop
|
|||||||
$min_price = $this->getMin_price();
|
$min_price = $this->getMin_price();
|
||||||
|
|
||||||
if(null !== $min_price) {
|
if(null !== $min_price) {
|
||||||
|
$isPSELeftJoinList[] = 'is_min_price';
|
||||||
$minPriceJoin = new Join();
|
$minPriceJoin = new Join();
|
||||||
$minPriceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'min_price_pse', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'is_min_price');
|
$minPriceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'min_price_pse', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'is_min_price');
|
||||||
$minPriceJoin->setJoinType(Criteria::LEFT_JOIN);
|
$minPriceJoin->setJoinType(Criteria::LEFT_JOIN);
|
||||||
@@ -253,7 +253,7 @@ class Product extends BaseLoop
|
|||||||
$max_price = $this->getMax_price();
|
$max_price = $this->getMax_price();
|
||||||
|
|
||||||
if(null !== $max_price) {
|
if(null !== $max_price) {
|
||||||
|
$isPSELeftJoinList[] = 'is_max_price';
|
||||||
$minPriceJoin = new Join();
|
$minPriceJoin = new Join();
|
||||||
$minPriceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'max_price_pse', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'is_max_price');
|
$minPriceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'max_price_pse', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'is_max_price');
|
||||||
$minPriceJoin->setJoinType(Criteria::LEFT_JOIN);
|
$minPriceJoin->setJoinType(Criteria::LEFT_JOIN);
|
||||||
@@ -271,18 +271,40 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
if( $attributeNonStrictMatch != '*' ) {
|
if( $attributeNonStrictMatch != '*' ) {
|
||||||
if($attributeNonStrictMatch == 'none') {
|
if($attributeNonStrictMatch == 'none') {
|
||||||
$actuallyUsedAttributeNonStrictMatchList = $usedAttributeNonStrictMatchList;
|
$actuallyUsedAttributeNonStrictMatchList = $isPSELeftJoinList;
|
||||||
} else {
|
} else {
|
||||||
$actuallyUsedAttributeNonStrictMatchList = array_values(array_intersect($usedAttributeNonStrictMatchList, $attributeNonStrictMatch));
|
$actuallyUsedAttributeNonStrictMatchList = array_values(array_intersect($isPSELeftJoinList, $attributeNonStrictMatch));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($actuallyUsedAttributeNonStrictMatchList as $key => $actuallyUsedAttributeNonStrictMatch) {
|
foreach($actuallyUsedAttributeNonStrictMatchList as $key => $actuallyUsedAttributeNonStrictMatch) {
|
||||||
if($key == 0)
|
if($key == 0)
|
||||||
continue;
|
continue;
|
||||||
$search->where('`is_' . $actuallyUsedAttributeNonStrictMatch . '`.ID=' . '`is_' . $actuallyUsedAttributeNonStrictMatchList[$key-1] . '`.ID');
|
$search->where('`' . $actuallyUsedAttributeNonStrictMatch . '`.ID=' . '`' . $actuallyUsedAttributeNonStrictMatchList[$key-1] . '`.ID');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* for ordering and outputs, the product will be :
|
||||||
|
* - new if at least one the criteria matching PSE is new
|
||||||
|
* - in promo if at least one the criteria matching PSE is in promo
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(count($isPSELeftJoinList) == 0) {
|
||||||
|
//
|
||||||
|
$isPSELeftJoinList[] = "global";
|
||||||
|
$search->joinProductSaleElements('global', Criteria::LEFT_JOIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
$booleanMatchesPromoList = array();
|
||||||
|
$booleanMatchesNewnessList = array();
|
||||||
|
foreach($isPSELeftJoinList as $isPSELeftJoin) {
|
||||||
|
$booleanMatchesPromoList[] = '`' . $isPSELeftJoin . '`.PROMO';
|
||||||
|
$booleanMatchesNewnessList[] = '`' . $isPSELeftJoin . '`.NEWNESS';
|
||||||
|
}
|
||||||
|
$search->withColumn('MAX(' . implode(' OR ', $booleanMatchesPromoList) . ')', 'main_product_is_promo');
|
||||||
|
$search->withColumn('MAX(' . implode(' OR ', $booleanMatchesNewnessList) . ')', 'main_product_is_new');
|
||||||
|
|
||||||
|
|
||||||
$current = $this->getCurrent();
|
$current = $this->getCurrent();
|
||||||
|
|
||||||
if ($current === true) {
|
if ($current === true) {
|
||||||
@@ -404,12 +426,12 @@ class Product extends BaseLoop
|
|||||||
case "alpha_reverse":
|
case "alpha_reverse":
|
||||||
$search->addDescendingOrderByColumn(\Thelia\Model\Map\ProductI18nTableMap::TITLE);
|
$search->addDescendingOrderByColumn(\Thelia\Model\Map\ProductI18nTableMap::TITLE);
|
||||||
break;
|
break;
|
||||||
/*case "min_price":
|
case "min_price":
|
||||||
$search->orderBy('real_price', Criteria::ASC);
|
$search->addAscendingOrderByColumn('real_price', Criteria::ASC);
|
||||||
break;
|
break;
|
||||||
case "max_price":
|
case "max_price":
|
||||||
$search->orderBy('real_price', Criteria::DESC);
|
$search->addDescendingOrderByColumn('real_price');
|
||||||
break;*/
|
break;
|
||||||
case "manual":
|
case "manual":
|
||||||
if(null === $category || count($category) != 1)
|
if(null === $category || count($category) != 1)
|
||||||
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
|
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
|
||||||
@@ -423,12 +445,12 @@ class Product extends BaseLoop
|
|||||||
case "ref":
|
case "ref":
|
||||||
$search->orderByRef(Criteria::ASC);
|
$search->orderByRef(Criteria::ASC);
|
||||||
break;
|
break;
|
||||||
/*case "promo":
|
case "promo":
|
||||||
$search->orderByPromo(Criteria::DESC);
|
$search->addDescendingOrderByColumn('main_product_is_promo');
|
||||||
break;
|
break;
|
||||||
case "new":
|
case "new":
|
||||||
$search->orderByNewness(Criteria::DESC);
|
$search->addDescendingOrderByColumn('main_product_is_new');
|
||||||
break;*/
|
break;
|
||||||
case "given_id":
|
case "given_id":
|
||||||
if(null === $id)
|
if(null === $id)
|
||||||
throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
|
throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
||||||
{/loop*}
|
{/loop*}
|
||||||
|
|
||||||
|
{*loop name="product" type="product" promo="0" min_stock="4" order="promo,min_price"}
|
||||||
|
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
||||||
|
{/loop*}
|
||||||
|
|
||||||
{loop name="product" type="product" order="promo,min_price"}
|
{loop name="product" type="product" order="promo,min_price"}
|
||||||
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
||||||
{/loop}
|
{/loop}
|
||||||
Reference in New Issue
Block a user