本文整理汇总了PHP中Mage_Catalog_Model_Resource_Product_Collection类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Resource_Product_Collection类的具体用法?PHP Mage_Catalog_Model_Resource_Product_Collection怎么用?PHP Mage_Catalog_Model_Resource_Product_Collection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Catalog_Model_Resource_Product_Collection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _process
/**
* @param Mage_Catalog_Model_Resource_Product_Collection $products
* @return bool
*/
protected function _process($products)
{
$processor = $this->_htmlProcessor;
$helper = $this->_getHelper();
foreach ($products as $product) {
$product->setData('url', $product->getProductUrl());
}
$items = $processor->query($helper->getCssSelector('related_product_link'));
if (count($items) === 0) {
return false;
}
$positions = array();
foreach ($items as $i => $item) {
/** @var $item DOMElement */
$url = $item->getAttribute('href');
$product = $products->getItemByColumnValue('url', $url);
if (!$product) {
continue;
}
if ($helper->isEnabledForProduct($product)) {
$positions[] = $i;
}
}
$processor->replace($helper->getCssSelector('related_product_price'), $this->_getHelper()->prepareReplacement(), $positions);
}
示例2: _filterPrice
/**
* Callback method for applying price filter.
* @param Mage_Catalog_Model_Resource_Product_Collection $_collection
* @param Mage_Adminhtml_Block_Widget_Grid_Column $_column
*/
public function _filterPrice($_collection, $_column)
{
$_field = $_column->getFilterIndex() ? $_column->getFilterIndex() : $_column->getIndex();
$_condition = $_column->getFilter()->getCondition();
if (!$_field || !is_array($_condition)) {
return;
}
if (!array_key_exists('type', $_condition) || !is_numeric($_condition['type'])) {
$_collection->addFieldToFilter($_field, $_condition);
} else {
$_storeId = (int) $this->getRequest()->getParam('store', 0);
$_store = Mage::app()->getStore($_storeId);
$_joinCondition = array('`e`.`entity_id` = `at_reservation_price`.`entity_id`', '`at_reservation_price`.`store_id` = ' . $_store->getId(), '`at_reservation_price`.`ptype` = ' . $_condition['type']);
if (array_key_exists('from', $_condition)) {
$_joinCondition[] = '`at_reservation_price`.`price` >= ' . $_condition['from'];
}
if (array_key_exists('to', $_condition)) {
$_joinCondition[] = '`at_reservation_price`.`price` <= ' . $_condition['to'];
}
$_joinCondition[] = '`at_reservation_price`.`date_from` = \'0000-00-00 00:00:00\' OR DATE(`at_reservation_price`.`date_from`) <= DATE(\'' . date('Y-m-d H:i:s', Mage::getModel('core/date')->gmtTimestamp(time())) . '\')';
$_joinCondition[] = '`at_reservation_price`.`date_to` = \'0000-00-00 00:00:00\' OR DATE(`at_reservation_price`.`date_to`) >= DATE(\'' . date('Y-m-d H:i:s', Mage::getModel('core/date')->gmtTimestamp(time())) . '\')';
$_collection->getSelect()->joinInner(array('at_reservation_price' => $_collection->getTable('payperrentals/reservationprices')), '(' . implode(') AND (', $_joinCondition) . ')', array('price_type' => 'at_reservation_price.ptype', 'reservation_price' => 'at_reservation_price.price', 'reservation_number' => 'at_reservation_price.numberof'));
/** TODO Check collection count calculation with group. I think need change join for use distinct */
$_collection->getSelect()->group('e.entity_id');
}
}
示例3: addIsInStockFilterToCollection
/**
* Add only is in stock products filter to product collection
*
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
*
* @return Mage_CatalogInventory_Model_Resource_Stock_Status
*/
public function addIsInStockFilterToCollection($collection)
{
$websiteId = Mage::app()->getStore($collection->getStoreId())->getWebsiteId();
$joinCondition = $this->_getReadAdapter()->quoteInto('e.entity_id = status_table_mli.product_id' . ' AND status_table_mli.store_id = ?', Mage::app()->getStore()->getId());
$collection->getSelect()->join(array('status_table_mli' => $this->getTable('demac_multilocationinventory/stock_status_index')), $joinCondition, array())->where('status_table_mli.is_in_stock=1');
return $this;
}
示例4: addExcludeProductFilter
/**
* Make collection not to load products that are in specified quote
*
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
* @param int $quoteId
* @return Mage_Checkout_Model_Resource_Cart
*/
public function addExcludeProductFilter($collection, $quoteId)
{
$adapter = $this->_getReadAdapter();
$exclusionSelect = $adapter->select()->from($this->getTable('sales/quote_item'), array('product_id'))->where('quote_id = ?', $quoteId);
$condition = $adapter->prepareSqlCondition('e.entity_id', array('nin' => $exclusionSelect));
$collection->getSelect()->where($condition);
return $this;
}
示例5: addCatalogInventoryToProductCollection
/**
* Add join for catalog in stock field to product collection
*
* @param Mage_Catalog_Model_Resource_Product_Collection $productCollection
* @return Mage_CatalogInventory_Model_Resource_Stock_Item
*/
public function addCatalogInventoryToProductCollection($productCollection)
{
$adapter = $this->_getReadAdapter();
$isManageStock = (int) Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
$stockExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 1', $isManageStock, 'cisi.manage_stock');
$stockExpr = $adapter->getCheckSql("({$stockExpr} = 1)", 'cisi.is_in_stock', '1');
$productCollection->joinTable(array('cisi' => 'cataloginventory/stock_item'), 'product_id=entity_id', array('is_saleable' => new Zend_Db_Expr($stockExpr), 'inventory_in_stock' => 'is_in_stock'), null, 'left');
return $this;
}
示例6: addMinimalPrices
public function addMinimalPrices(Mage_Catalog_Model_Resource_Product_Collection $collection)
{
$minimalPrices = $this->_getResource()->getMinimalPrices($collection->getLoadedIds());
foreach ($minimalPrices as $row) {
$item = $collection->getItemById($row['entity_id']);
if ($item) {
$item->setData('minimal_price', $row['value']);
$item->setData('minimal_tax_class_id', $row['tax_class_id']);
}
}
}
示例7: _beforeLoad
/**
* Add tax class id attribute to select and join price rules data if needed
*
* @return Mage_Catalog_Model_Resource_Product_Collection
*/
protected function _beforeLoad()
{
if (isset($this->_productLimitationFilters['category_id']) && is_array($this->_productLimitationFilters['category_id'])) {
$this->getSelect()->group('e.entity_id');
}
return parent::_beforeLoad();
}
示例8: apply
/**
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
* @param string $currDir
*
* @return $this
*/
public function apply($collection, $currDir)
{
if (!$this->isEnabled()) {
return $this;
}
$alias = 'price_index';
if (preg_match('/`([a-z0-9\\_]+)`\\.`final_price`/', $collection->getSelect()->__toString(), $m)) {
$alias = $m[1];
}
$price = Mage::getStoreConfig('amsorting/general/profit_price');
$attribute = Mage::getStoreConfig('amsorting/general/product_attribute');
$collection->joinAttribute('cost', Mage_Catalog_Model_Product::ENTITY . '/' . $attribute, 'entity_id', null, 'left', Mage::app()->getStore()->getId());
$collection->getSelect()->columns(array('profit' => "(`{$alias}`.`{$price}` - IF(`at_cost`.`value` IS NULL, 0, `at_cost`.`value`))"));
$collection->getSelect()->order("profit {$currDir}");
return $this;
}
示例9: 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;
}
示例10: _applyCategoryFilter
/**
* Apply filter by category id
*
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
*/
protected function _applyCategoryFilter(Mage_Catalog_Model_Resource_Product_Collection $collection)
{
$categoryId = $this->getRequest()->getParam('category_id');
if ($categoryId) {
$category = $this->_getCategoryById($categoryId);
if (!$category->getId()) {
$this->_critical('Category not found.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
$collection->addCategoryFilter($category);
}
}
示例11: apply
/**
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
* @param string $currDir
*
* @return $this
*/
public function apply($collection, $currDir)
{
if (!$this->isEnabled()) {
return $this;
}
$sorters = $this->getSorters();
if (Mage::getStoreConfig('amsorting/general/use_index')) {
foreach ($sorters as $sorter) {
$collection->joinField($sorter->getCode(), $sorter->getIndexTable(), $sorter->getCode(), 'id=entity_id', array('store_id' => Mage::app()->getStore()->getId()), 'left');
}
} else {
$select = $collection->getSelect();
$col = $select->getPart('columns');
foreach ($sorters as $sorter) {
$col[] = array('', $sorter->getColumnSelect(), $sorter->getCode());
}
$select->setPart('columns', $col);
}
$collection->getSelect()->order(new Zend_Db_Expr('(' . $sorters['dividend']->getCode() . '/' . $sorters['divider']->getCode() . ') ' . $currDir));
return $this;
}
示例12: getLinkCollection
/**
* Get link collection
*
* @return Mage_Catalog_Model_Resource_Product_Collection|null
*/
public function getLinkCollection()
{
if (is_null($this->_linkCollection)) {
$this->_linkCollection = $this->_getTargetLinkCollection();
if ($this->_linkCollection) {
// Perform rotation mode
$select = $this->_linkCollection->getSelect();
$rotationMode = $this->getTargetRuleHelper()->getRotationMode($this->getProductListType());
if ($rotationMode == Enterprise_TargetRule_Model_Rule::ROTATION_SHUFFLE) {
Mage::getResourceSingleton('enterprise_targetrule/index')->orderRand($select);
} else {
$select->order('link_attribute_position_int.value ASC');
}
}
}
return $this->_linkCollection;
}
示例13: testSetOrder
/**
* @dataProvider setOrderDataProvider
*/
public function testSetOrder($order, $expectedOrder)
{
$this->_collection->setOrder($order);
$this->_collection->load();
// perform real SQL query
$selectOrder = $this->_collection->getSelect()->getPart(Zend_Db_Select::ORDER);
foreach ($expectedOrder as $field) {
$orderBy = array_shift($selectOrder);
$this->assertArrayHasKey(0, $orderBy);
$this->assertTrue(false !== strpos($orderBy[0], $field), 'Ordering by same column more than once is restricted by multiple RDBMS requirements.');
}
}
示例14: addItem
/**
* Added exception handling to addItem, otherwise in some cases will throw an exception
*
* @param \Varien_Object $object
*/
public function addItem(\Varien_Object $object)
{
try {
return parent::addItem($object);
} catch (Exception $e) {
}
}
示例15: addAttributeToSort
public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
{
if ($attribute == 'best') {
$this->getSelect()->order("t2.position " . $dir);
return $this;
}
return parent::addAttributeToSort($attribute, $dir);
}