本文整理汇总了PHP中Mage_Eav_Model_Entity_Collection_Abstract::addAttributeToFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Eav_Model_Entity_Collection_Abstract::addAttributeToFilter方法的具体用法?PHP Mage_Eav_Model_Entity_Collection_Abstract::addAttributeToFilter怎么用?PHP Mage_Eav_Model_Entity_Collection_Abstract::addAttributeToFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Eav_Model_Entity_Collection_Abstract
的用法示例。
在下文中一共展示了Mage_Eav_Model_Entity_Collection_Abstract::addAttributeToFilter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getGiveawayCollection
/**
* Retrieve loaded Giveaway Product Collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
protected function _getGiveawayCollection()
{
if (is_null($this->_productCollection)) {
$oProduct = Mage::getModel('catalog/product');
/* @var $oCollection Mage_Catalog_Model_Resource_Product_Collection */
$this->_productCollection = $oProduct->getResourceCollection();
$oSitewardsGiveawayHelper = Mage::helper('sitewards_giveaway');
$sGiveawayAttributeCode = $oSitewardsGiveawayHelper->getGiveawayIdentifierName();
$this->_productCollection->addAttributeToFilter($sGiveawayAttributeCode, true);
$this->_productCollection->addAttributeToSelect('*');
}
return $this->_productCollection;
}
示例2: _prepareEntityCollection
/**
* Apply filter to collection and add not skipped attributes to select.
*
* @param Mage_Eav_Model_Entity_Collection_Abstract $collection
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
protected function _prepareEntityCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection)
{
if (!isset($this->_parameters[Mage_ImportExport_Model_Export::FILTER_ELEMENT_GROUP]) || !is_array($this->_parameters[Mage_ImportExport_Model_Export::FILTER_ELEMENT_GROUP])) {
$exportFilter = array();
} else {
$exportFilter = $this->_parameters[Mage_ImportExport_Model_Export::FILTER_ELEMENT_GROUP];
}
$exportAttrCodes = $this->_getExportAttrCodes();
foreach ($this->filterAttributeCollection($this->getAttributeCollection()) as $attribute) {
$attrCode = $attribute->getAttributeCode();
// filter applying
if (isset($exportFilter[$attrCode])) {
$attrFilterType = Mage_ImportExport_Model_Export::getAttributeFilterType($attribute);
if ($attrCode == 'sku') {
$collection->addAttributeToFilter($attrCode, array('in' => $exportFilter[$attrCode]));
} elseif (Mage_ImportExport_Model_Export::FILTER_TYPE_SELECT == $attrFilterType) {
if (is_scalar($exportFilter[$attrCode]) && trim($exportFilter[$attrCode])) {
$collection->addAttributeToFilter($attrCode, array('eq' => $exportFilter[$attrCode]));
}
} elseif (Mage_ImportExport_Model_Export::FILTER_TYPE_INPUT == $attrFilterType) {
if (is_scalar($exportFilter[$attrCode]) && trim($exportFilter[$attrCode])) {
$collection->addAttributeToFilter($attrCode, array('like' => "%{$exportFilter[$attrCode]}%"));
}
} elseif (Mage_ImportExport_Model_Export::FILTER_TYPE_DATE == $attrFilterType) {
if (is_array($exportFilter[$attrCode]) && count($exportFilter[$attrCode]) == 2) {
$from = array_shift($exportFilter[$attrCode]);
$to = array_shift($exportFilter[$attrCode]);
if (is_scalar($from) && !empty($from)) {
$date = Mage::app()->getLocale()->date($from, null, null, false)->toString('MM/dd/YYYY');
$collection->addAttributeToFilter($attrCode, array('from' => $date, 'date' => true));
}
if (is_scalar($to) && !empty($to)) {
$date = Mage::app()->getLocale()->date($to, null, null, false)->toString('MM/dd/YYYY');
$collection->addAttributeToFilter($attrCode, array('to' => $date, 'date' => true));
}
}
} elseif (Mage_ImportExport_Model_Export::FILTER_TYPE_NUMBER == $attrFilterType) {
if (is_array($exportFilter[$attrCode]) && count($exportFilter[$attrCode]) == 2) {
$from = array_shift($exportFilter[$attrCode]);
$to = array_shift($exportFilter[$attrCode]);
if (is_numeric($from)) {
$collection->addAttributeToFilter($attrCode, array('from' => $from));
}
if (is_numeric($to)) {
$collection->addAttributeToFilter($attrCode, array('to' => $to));
}
}
}
}
if (in_array($attrCode, $exportAttrCodes)) {
$collection->addAttributeToSelect($attrCode);
}
}
return $collection;
}
示例3: _getProductCollection
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()->setPage(1, 1)->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
}
}
$this->_productCollection = $layer->getProductCollection();
$dateToday = date('m/d/y');
$dateToday = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d') + 1, date('y'));
$dateTomorrow = date('m/d/y', $tomorrow);
$this->_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $dateToday))->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $dateTomorrow), 1 => array('is' => new Zend_Db_Expr('null')))), 'left');
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}
return $this->_productCollection;
}
示例4: _getProductCollection
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()->setPage(1, 1)->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
$this->addModelTags($category);
}
}
$this->_productCollection = $layer->getProductCollection();
$current_cat = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$path = $current_cat->getPath();
$ids = explode('/', $path);
$topParent = 0;
if (isset($ids[2])) {
$topParent = $ids[2];
}
if ($topParent == '16') {
$userid = Mage::getSingleton('customer/session')->getId();
$user_id = $userid ? $userid : 0;
$this->_productCollection->addAttributeToFilter('customer_id', $user_id);
}
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}
return $this->_productCollection;
}
示例5: _getVendorCollection
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
protected function _getVendorCollection()
{
if (is_null($this->_vendorCollection)) {
$vendorIds = array();
$model = Mage::getModel('csmarketplace/vshop')->getCollection()->addFieldToFilter('shop_disable', array('eq' => Ced_CsMarketplace_Model_Vshop::DISABLED));
if (count($model) > 0) {
foreach ($model as $row) {
$vendorIds[] = $row->getVendorId();
}
}
$this->_vendorCollection = Mage::getModel('csmarketplace/vendor')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('status', array('eq' => Ced_CsMarketplace_Model_Vendor::VENDOR_APPROVED_STATUS));
if (($countryId = $this->getRequest()->getParam('country_id')) && $this->getRequest()->getParam('country_id') != '') {
$this->_vendorCollection->addAttributeToFilter('country_id', $countryId);
}
if (($postCode = $this->getRequest()->getParam('estimate_postcode')) && $this->getRequest()->getParam('estimate_postcode') != '') {
$this->_vendorCollection->addAttributeToFilter('zip_code', $postCode);
}
if (($region = $this->getRequest()->getParam('region')) && $this->getRequest()->getParam('region') != '') {
$this->_vendorCollection->addAttributeToFilter('region', $region);
}
if (($region_id = $this->getRequest()->getParam('region_id')) && $this->getRequest()->getParam('region_id') != '') {
$this->_vendorCollection->addAttributeToFilter('region_id', $region_id);
}
$char = $this->getRequest()->getParam('char');
if (strlen($char)) {
$this->_vendorCollection->addAttributeToFilter('public_name', array('like' => '%' . $char . '%'));
}
if (count($vendorIds) > 0) {
$this->_vendorCollection = $this->_vendorCollection->addAttributeToFilter('entity_id', array('nin' => $vendorIds));
}
if (!Mage::helper('csmarketplace')->isSharingEnabled()) {
$this->_vendorCollection->addAttributeToFilter('website_id', array('eq' => Mage::app()->getStore()->getWebsiteId()));
}
$this->prepareSortableFields();
}
/*echo $this->_vendorCollection->getSelect();die;*/
return $this->_vendorCollection;
}
示例6: addStoreAttributeToFilter
/**
* Add store_id attribute to filter of EAV-collection
*
* @param Mage_Eav_Model_Entity_Collection_Abstract $collection
*/
public function addStoreAttributeToFilter($collection)
{
$collection->addAttributeToFilter('store_id', array('in' => $this->_role->getStoreIds()));
}
示例7: addVisibleInSearchFilterToCollection
public function addVisibleInSearchFilterToCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection)
{
$collection->addAttributeToFilter('visibility', array('in' => $this->getVisibleInSearchIds()));
return $this;
}
示例8: addSaleableFilterToCollection
public function addSaleableFilterToCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection)
{
$collection->addAttributeToFilter('status', array('in' => $this->getSaleableStatusIds()));
return $this;
}
示例9: _getProductCollections
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
protected function _getProductCollections($page_id)
{
if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()->setPage(1, 1)->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
$this->addModelTags($category);
}
}
/* @var $layer Mage_Catalog_Model_Layer */
/* @var $layer Mage_Catalog_Model_Layer */
$this->_productCollection = $layer->getProductCollection();
//Mage::getSingleton('core/session', array('name' => 'frontend'));
$condition = new Zend_Db_Expr("special_price < price");
$this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->addMinimalPrice()->addStoreFilter()->setPageSize(20)->addAttributeToFilter('upcomingproduct', 0);
//->load();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($this->_productCollection);
$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);
$this->_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $tomorrowDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left');
$this->_productCollection->addAttributeToFilter('special_price', array('neq' => 'null'));
//$this->_productCollection->addFieldToFilter('special_price', array('lt' => 'price'));
if ($this->getRequest()->getParam('cat_id') != null) {
//echo "hdjkdjdksjdks";
$categoryId = $this->getRequest()->getParam('cat_id');
$category = Mage::getModel('catalog/category')->load($categoryId);
$this->_productCollection->addCategoryFilter($category);
}
$select = $this->_productCollection->getSelect();
$currentUrl = $this->helper('core/url')->getCurrentUrl();
$str = "sale";
$str1 = "superdeals";
if (strpos($currentUrl, $str) == true) {
$select->where('price_index.final_price < price_index.price');
} elseif (strpos($currentUrl, $str1) == true) {
$select->where('price_index.final_price < price_index.price AND (100 - (price_index.final_price/price_index.price) * 100) > 20');
} else {
$select->where('price_index.final_price < price_index.price');
}
//exit;
//print_r($collection);
//$this->_productCollection = $layer->getProductCollections();
//print_r($this->_productCollection);
}
return $this->_productCollection;
}