refactor product loop, removing some duplicated lines
This commit is contained in:
@@ -496,18 +496,9 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL
|
|||||||
$default_category_id = $product->getDefaultCategoryId();
|
$default_category_id = $product->getDefaultCategoryId();
|
||||||
|
|
||||||
$loopResultRow
|
$loopResultRow
|
||||||
->set("ID" , $product->getId())
|
->set("WEIGHT" , $product->getVirtualColumn('weight'))
|
||||||
->set("REF" , $product->getRef())
|
->set("QUANTITY" , $product->getVirtualColumn('quantity'))
|
||||||
->set("IS_TRANSLATED" , $product->getVirtualColumn('IS_TRANSLATED'))
|
->set("EAN_CODE" , $product->getVirtualColumn('ean_code'))
|
||||||
->set("LOCALE" , $this->locale)
|
|
||||||
->set("TITLE" , $product->getVirtualColumn('i18n_TITLE'))
|
|
||||||
->set("CHAPO" , $product->getVirtualColumn('i18n_CHAPO'))
|
|
||||||
->set("DESCRIPTION" , $product->getVirtualColumn('i18n_DESCRIPTION'))
|
|
||||||
->set("POSTSCRIPTUM" , $product->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
|
||||||
->set("URL" , $product->getUrl($this->locale))
|
|
||||||
->set("META_TITLE" , $product->getVirtualColumn('i18n_META_TITLE'))
|
|
||||||
->set("META_DESCRIPTION" , $product->getVirtualColumn('i18n_META_DESCRIPTION'))
|
|
||||||
->set("META_KEYWORDS" , $product->getVirtualColumn('i18n_META_KEYWORDS'))
|
|
||||||
->set("BEST_PRICE" , $product->getVirtualColumn('is_promo') ? $promoPrice : $price)
|
->set("BEST_PRICE" , $product->getVirtualColumn('is_promo') ? $promoPrice : $price)
|
||||||
->set("BEST_PRICE_TAX" , $taxedPrice - $product->getVirtualColumn('is_promo') ? $taxedPromoPrice - $promoPrice : $taxedPrice - $price)
|
->set("BEST_PRICE_TAX" , $taxedPrice - $product->getVirtualColumn('is_promo') ? $taxedPromoPrice - $promoPrice : $taxedPrice - $price)
|
||||||
->set("BEST_TAXED_PRICE" , $product->getVirtualColumn('is_promo') ? $taxedPromoPrice : $taxedPrice)
|
->set("BEST_TAXED_PRICE" , $product->getVirtualColumn('is_promo') ? $taxedPromoPrice : $taxedPrice)
|
||||||
@@ -517,47 +508,13 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL
|
|||||||
->set("PROMO_PRICE" , $promoPrice)
|
->set("PROMO_PRICE" , $promoPrice)
|
||||||
->set("PROMO_PRICE_TAX" , $taxedPromoPrice - $promoPrice)
|
->set("PROMO_PRICE_TAX" , $taxedPromoPrice - $promoPrice)
|
||||||
->set("TAXED_PROMO_PRICE" , $taxedPromoPrice)
|
->set("TAXED_PROMO_PRICE" , $taxedPromoPrice)
|
||||||
->set("PRODUCT_SALE_ELEMENT" , $product->getVirtualColumn('pse_id'))
|
|
||||||
->set("WEIGHT" , $product->getVirtualColumn('weight'))
|
|
||||||
->set("QUANTITY" , $product->getVirtualColumn('quantity'))
|
|
||||||
->set("EAN_CODE" , $product->getVirtualColumn('ean_code'))
|
|
||||||
->set("IS_PROMO" , $product->getVirtualColumn('is_promo'))
|
->set("IS_PROMO" , $product->getVirtualColumn('is_promo'))
|
||||||
->set("IS_NEW" , $product->getVirtualColumn('is_new'))
|
->set("IS_NEW" , $product->getVirtualColumn('is_new'))
|
||||||
->set("POSITION" , $product->getPosition())
|
|
||||||
->set("VISIBLE" , $product->getVisible() ? "1" : "0")
|
|
||||||
->set("TEMPLATE" , $product->getTemplateId())
|
|
||||||
->set("DEFAULT_CATEGORY" , $default_category_id)
|
|
||||||
->set("TAX_RULE_ID" , $product->getTaxRuleId())
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
if ($this->getBackend_context() || $this->getWithPrevNextInfo()) {
|
|
||||||
// Find previous and next category
|
|
||||||
$previous = ProductQuery::create()
|
|
||||||
->joinProductCategory()
|
|
||||||
->where('ProductCategory.category_id = ?', $default_category_id)
|
|
||||||
->filterByPosition($product->getPosition(), Criteria::LESS_THAN)
|
|
||||||
->orderByPosition(Criteria::DESC)
|
|
||||||
->findOne()
|
|
||||||
;
|
|
||||||
|
|
||||||
$next = ProductQuery::create()
|
$loopResult->addRow($this->associateValues($loopResultRow, $product, $default_category_id));
|
||||||
->joinProductCategory()
|
|
||||||
->where('ProductCategory.category_id = ?', $default_category_id)
|
|
||||||
->filterByPosition($product->getPosition(), Criteria::GREATER_THAN)
|
|
||||||
->orderByPosition(Criteria::ASC)
|
|
||||||
->findOne()
|
|
||||||
;
|
|
||||||
|
|
||||||
$loopResultRow
|
|
||||||
->set("HAS_PREVIOUS" , $previous != null ? 1 : 0)
|
|
||||||
->set("HAS_NEXT" , $next != null ? 1 : 0)
|
|
||||||
->set("PREVIOUS" , $previous != null ? $previous->getId() : -1)
|
|
||||||
->set("NEXT" , $next != null ? $next->getId() : -1)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
@@ -1011,6 +968,23 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL
|
|||||||
// Find previous and next product, in the default category.
|
// Find previous and next product, in the default category.
|
||||||
$default_category_id = $product->getDefaultCategoryId();
|
$default_category_id = $product->getDefaultCategoryId();
|
||||||
|
|
||||||
|
$loopResultRow
|
||||||
|
->set("BEST_PRICE" , $price)
|
||||||
|
->set("BEST_PRICE_TAX" , $taxedPrice - $price)
|
||||||
|
->set("BEST_TAXED_PRICE" , $taxedPrice)
|
||||||
|
->set("IS_PROMO" , $product->getVirtualColumn('is_promo'))
|
||||||
|
->set("IS_NEW" , $product->getVirtualColumn('is_new'))
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
$loopResult->addRow($this->associateValues($loopResultRow, $product, $default_category_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $loopResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function associateValues($loopResultRow, $product, $default_category_id)
|
||||||
|
{
|
||||||
$loopResultRow
|
$loopResultRow
|
||||||
->set("ID" , $product->getId())
|
->set("ID" , $product->getId())
|
||||||
->set("REF" , $product->getRef())
|
->set("REF" , $product->getRef())
|
||||||
@@ -1024,11 +998,7 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL
|
|||||||
->set("META_TITLE" , $product->getVirtualColumn('i18n_META_TITLE'))
|
->set("META_TITLE" , $product->getVirtualColumn('i18n_META_TITLE'))
|
||||||
->set("META_DESCRIPTION" , $product->getVirtualColumn('i18n_META_DESCRIPTION'))
|
->set("META_DESCRIPTION" , $product->getVirtualColumn('i18n_META_DESCRIPTION'))
|
||||||
->set("META_KEYWORDS" , $product->getVirtualColumn('i18n_META_KEYWORDS'))
|
->set("META_KEYWORDS" , $product->getVirtualColumn('i18n_META_KEYWORDS'))
|
||||||
->set("BEST_PRICE" , $price)
|
->set("PRODUCT_SALE_ELEMENT" , $product->getVirtualColumn('pse_id'))
|
||||||
->set("BEST_PRICE_TAX" , $taxedPrice - $price)
|
|
||||||
->set("BEST_TAXED_PRICE" , $taxedPrice)
|
|
||||||
->set("IS_PROMO" , $product->getVirtualColumn('main_product_is_promo'))
|
|
||||||
->set("IS_NEW" , $product->getVirtualColumn('main_product_is_new'))
|
|
||||||
->set("POSITION" , $product->getPosition())
|
->set("POSITION" , $product->getPosition())
|
||||||
->set("VISIBLE" , $product->getVisible() ? "1" : "0")
|
->set("VISIBLE" , $product->getVisible() ? "1" : "0")
|
||||||
->set("TEMPLATE" , $product->getTemplateId())
|
->set("TEMPLATE" , $product->getTemplateId())
|
||||||
@@ -1064,10 +1034,7 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
return $loopResultRow;
|
||||||
}
|
|
||||||
|
|
||||||
return $loopResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function manageFeatureAv(&$search, $feature_availability)
|
protected function manageFeatureAv(&$search, $feature_availability)
|
||||||
|
|||||||
Reference in New Issue
Block a user