一个得到添加属性(下拉条)brandss,某一特定值下的所有产品的例子
2011-01-25 00:34
555 查看
<?php
class MyCompany_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_Abstract
{
public function getFeaturedProducts(){
$ids = $this->_getFeaturedProductsIds();
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->getSelect()->where('e.entity_id in (?)', $ids);
$collection->addAttributeToSelect('*');
$productList = $collection->load();
return $productList;
}
public function _getFeaturedProductsIds(){
// instantiate database connection object
$categoryId = $this->getRequest()->getParam('id', false);
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');
$categoryProductTable = $resource->getTableName('catalog/category_product');
//$productEntityIntTable = $resource->getTableName('catalog/product_entity_int'); // doesn't work
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix().'catalog_product_entity_int';
$eavAttributeTable = $resource->getTableName('eav/attribute');
$eavAttributeTable1 = $resource->getTableName('eav/attribute_option_value');
// Query database for featured product
$select = $read->select()
->from(array('cp'=>$categoryProductTable))
->join(array('pei'=>$productEntityIntTable),'pei.entity_id=cp.product_id', array())
->joinNatural(array('ea'=>$eavAttributeTable))
->join(array('ea1'=>$eavAttributeTable1),'pei.value=ea1.option_id',array())
->where('cp.category_id=?', $categoryId)
// ->where('pei.value=1')
->where('ea1.value="brand1"')
->where('ea.attribute_code="brandss"');
$rows = $read->fetchAll($select);
$ids = array();
foreach($rows AS $row) {
$ids[] = $row['product_id'];
}
$ret = implode(',', $ids);
return $ids;
}
}
?>
class MyCompany_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_Abstract
{
public function getFeaturedProducts(){
$ids = $this->_getFeaturedProductsIds();
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->getSelect()->where('e.entity_id in (?)', $ids);
$collection->addAttributeToSelect('*');
$productList = $collection->load();
return $productList;
}
public function _getFeaturedProductsIds(){
// instantiate database connection object
$categoryId = $this->getRequest()->getParam('id', false);
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');
$categoryProductTable = $resource->getTableName('catalog/category_product');
//$productEntityIntTable = $resource->getTableName('catalog/product_entity_int'); // doesn't work
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix().'catalog_product_entity_int';
$eavAttributeTable = $resource->getTableName('eav/attribute');
$eavAttributeTable1 = $resource->getTableName('eav/attribute_option_value');
// Query database for featured product
$select = $read->select()
->from(array('cp'=>$categoryProductTable))
->join(array('pei'=>$productEntityIntTable),'pei.entity_id=cp.product_id', array())
->joinNatural(array('ea'=>$eavAttributeTable))
->join(array('ea1'=>$eavAttributeTable1),'pei.value=ea1.option_id',array())
->where('cp.category_id=?', $categoryId)
// ->where('pei.value=1')
->where('ea1.value="brand1"')
->where('ea.attribute_code="brandss"');
$rows = $read->fetchAll($select);
$ids = array();
foreach($rows AS $row) {
$ids[] = $row['product_id'];
}
$ret = implode(',', $ids);
return $ids;
}
}
?>
相关文章推荐
- 得到一个div下 特定ID的所有标签
- 得到页面所有的form内对象数值——————为一个控件加一个客户端属性
- 把数据库中的所有记录以一个特定格式的字符显示出来的一个例子
- 请使用sun 内省api得到某一个bean的所有属性,并操作bean的其中一个属性(给属性赋值,以及得到属性的值
- Flex中如何通过prompt属性在ComboBox控件中添加一个提示项(prompt)的例子
- 复制数据库中的表格 新建一个新的表 所有属性。再添加属性
- 如何在PowerShell中得到一个对象的所有属性名和方法名呢?
- (四十六)一个属性动画的经典例子(让TextView中的数值从某一个值变成0再变到另一个值)
- 如何在QML应用中得到一个Item的所有属性,信号及方法
- 如何遍历一个实例的所有属性,得到属性的名称和值
- 如何遍历一个实例的所有属性,得到属性的名称和值
- 遍历一个实例的所有属性,得到属性的名称和值
- Bigcommerce: 给模板添加一个自定义的产品属性,使用$GLOBALS全局变量调用
- 如何遍历一个实例的所有属性,得到属性的名称和值
- 1.请使用sun 内省api得到某一个bean的所有属性,并操作bean的其中一个属性(给属性赋值,以及得到属性的值) 。
- 一个记录集,如何得到该记录集中某一字段所有是重复记录的记录集
- Flex中如何利用titleIcon属性给Panel容器标题部添加一个ICON图标的例子
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- 一个使用GridView显示数据,并且可以进行添加、修改、删除操作的例子
- asp.net 得到一个文件夹下的所有文件夹及子文件夹名,得到所有文件名,文件大小,文件夹大小