本文整理汇总了PHP中Mage_Catalog_Model_Resource_Product_Collection::setFlag方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Resource_Product_Collection::setFlag方法的具体用法?PHP Mage_Catalog_Model_Resource_Product_Collection::setFlag怎么用?PHP Mage_Catalog_Model_Resource_Product_Collection::setFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Resource_Product_Collection
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Resource_Product_Collection::setFlag方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sort
/**
* @param Mage_Catalog_Model_Resource_Product_Collection $productCollection
* @return mixed
*/
public function sort(Mage_Catalog_Model_Resource_Product_Collection $productCollection)
{
//Pass a small validation
if (!$this->_getHelper()->isCategorySortingEnable() || $productCollection->getFlag(self::MARKETO_SORTED)) {
return $productCollection;
}
$categoriesList = $this->_getPesonalizeCalculator()->getScoreCategoryParams(HooshMarketing_Marketo_Model_Personalize_Calculator::CATEGORY_ID_AND_SCORE);
//get List of categories with key -> Category_id and value - Score
if (!count($categoriesList)) {
//if we havn`t score categories do nothing
return $productCollection;
}
uasort($categoriesList, function ($f, $s) {
return $f > $s ? 1 : -1;
//sort by descending
});
//Sort categories in order to show top scored categories first
$categoriesList = array_keys($categoriesList);
// get only category ids
try {
$productCategoryTable = $this->_getCoreResource()->getTableName("catalog_category_product");
$productCollection->getSelect()->joinLeft(array("marketo_category_table" => $productCategoryTable), "marketo_category_table.product_id = e.entity_id", array("top_category_id" => "marketo_category_table.category_id"))->group("entity_id")->order("FIELD(top_category_id, " . implode(',', $categoriesList) . ") DESC");
//order by top
$productCollection->setFlag(self::MARKETO_SORTED, true);
//to set order only one time
} catch (Exception $e) {
Mage::logException($e);
}
return $productCollection;
}