コード例 #1
0
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter Filter
  * @return array
  */
 public function getCount($filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $select->reset(Zend_Db_Select::GROUP);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode());
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     $conditions = join(' AND ', $conditions);
     $fromParts = $select->getPart(Zend_Db_Select::FROM);
     if (isset($fromParts[$tableAlias])) {
         $conditionArray = explode(' AND ', $fromParts[$tableAlias]['joinCondition']);
         unset($conditionArray[count($conditionArray) - 1]);
         $conditions = implode(' AND ', $conditionArray);
         unset($fromParts[$tableAlias]);
         $select->setPart(Zend_Db_Select::FROM, $fromParts);
     }
     $select->join(array($tableAlias => $this->getMainTable()), $conditions, array('value', 'count' => new Zend_Db_Expr("COUNT(distinct {$tableAlias}.entity_id)")))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
コード例 #2
0
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     // Removed below as this was causing wrong counts
     // Not sure if this will break other functionality
     // $select->reset(Zend_Db_Select::WHERE);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode());
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     $from = $select->getPart('from');
     if (array_key_exists($tableAlias, $from)) {
         $select->reset(Zend_Db_Select::FROM);
         unset($from[$tableAlias]);
         $select->setPart(Zend_Db_Select::FROM, $from);
     }
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => new Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
コード例 #3
0
ファイル: Attribute.php プロジェクト: keyur-iksula/mongogento
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter The current catalog filter
  *
  * @return array
  */
 public function getCount($filter)
 {
     $catalogResource = Mage::getResourceModel("catalog/product");
     $attribute = $filter->getAttributeModel();
     /**
      * For legacy SQL based attributes, Magento based the query on "catalog/product_index_eav", let him do
      */
     if (in_array($attribute->getAttributeCode(), $catalogResource->getSqlAttributesCodes())) {
         return parent::getCount($filter);
     }
     /**
      * Since we have MongoDB, nothing is stored on eav index table for other attributes
      * Let's build the query with an aggregation
      *
      * @see http://docs.mongodb.org/manual/reference/operator/aggregation/
      */
     $collection = clone $filter->getLayer()->getProductCollection();
     /** @var Smile_MongoCore_Model_Resource_Connection_Adapter $adapter */
     $adapter = Mage::getSingleton('mongocore/resource_connection_adapter');
     $queryBuilder = $adapter->getQueryBuilder();
     $collectionName = Mage::getResourceModel('catalog/product')->getEntityTable();
     $docCollection = $adapter->getCollection($collectionName);
     /** Build a condition to have all products which have the specified attribute as "notnull" AND not an empty string */
     $scopedAttributeName = 'attr_' . $filter->getStoreId() . '.' . $attribute->getAttributeCode();
     $globalAttributeName = 'attr_' . Mage_Core_Model_App::ADMIN_STORE_ID . '.' . $attribute->getAttributeCode();
     $filterCascade = array('$or' => array(array('$and' => array(array($scopedAttributeName => array('$exists' => 1)))), array('$and' => array(array($scopedAttributeName => array('$exists' => 0)), array($globalAttributeName => array('$exists' => 1))))));
     $documentFilter = $filterCascade;
     $documentFilter['$or'][0]['$and'][] = array($scopedAttributeName => array('$' . "ne" => 'null'));
     $documentFilter['$or'][0]['$and'][] = array($scopedAttributeName => array('$' . "ne" => ''));
     $documentFilter['$or'][1]['$and'][] = array($globalAttributeName => array('$' . "ne" => 'null'));
     $documentFilter['$or'][1]['$and'][] = array($globalAttributeName => array('$' . "ne" => ''));
     /** First, the matching, current product ids, and our calculated document filter **/
     $match = array('$and' => array($queryBuilder->getIdsFilter($collection->getAllIds()), $documentFilter));
     /** And then, the grouping, by attribute values, and calculating a sum */
     $group = array("_id" => array("{$scopedAttributeName}" => '$' . $scopedAttributeName, "{$globalAttributeName}" => '$' . $globalAttributeName), "total" => array('$sum' => 1));
     /** Building aggregation pipeline based on match and group previously built */
     $pipeline = array(array('$match' => $match), array('$group' => $group));
     $aggregation = $docCollection->aggregate($pipeline);
     /**
      * Now parse the aggregation result
      * Goal is to obtain an array like this :
      *
      * <attribute option id> => <total number of occurences>
      */
     $aggregationResult = array();
     if ($aggregation['ok'] == 1 && isset($aggregation["result"])) {
         foreach ($aggregation["result"] as $aggregate) {
             if (isset($aggregate["_id"]) && isset($aggregate['total'])) {
                 $option = null;
                 foreach ($aggregate["_id"] as $value) {
                     $option = $value;
                 }
                 if (!is_null($option)) {
                     $aggregationResult[$option] = $aggregate['total'];
                 }
             }
         }
     }
     return ksort($aggregationResult);
 }
コード例 #4
0
 /**
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     // Redefining join type to allow multiple attribute values on currently filtered attribute
     $fromPart = $select->getPart(Zend_Db_Select::FROM);
     foreach ($fromPart as $key => &$part) {
         if ($key == $filter->getAttributeModel()->getAttributeCode() . '_idx') {
             $part['joinType'] = Zend_Db_Select::LEFT_JOIN;
         }
     }
     unset($part);
     $select->reset(Zend_Db_Select::FROM);
     $select->setPart(Zend_Db_Select::FROM, $fromPart);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = sprintf('%s_index', $attribute->getAttributeCode());
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => new Zend_Db_Expr("COUNT(DISTINCT {$tableAlias}.entity_id)")))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
コード例 #5
0
ファイル: Category.php プロジェクト: xiaoguizhidao/devfashion
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     /** @var $layer EcommerceTeam_Sln_Model_Layer */
     $layer = $filter->getLayer();
     $connection = $this->_getReadAdapter();
     $select = $layer->getSelectWithoutFilter('cat');
     if (!$select) {
         $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     }
     $where = array();
     $catIds = array();
     if ($this->_categories) {
         $catIds = $this->_categories;
     } else {
         $categories = $layer->getCurrentCategory()->getChildrenCategories();
         foreach ($categories as $category) {
             $catIds[] = $category->getEntityId();
         }
     }
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $select->reset(Zend_Db_Select::GROUP);
     $select->join(array('child_cat_index' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')), 'child_cat_index.category_id IN (' . implode(',', $catIds) . ') AND child_cat_index.product_id = e.entity_id', array('value' => 'category_id'));
     $fields = array('count' => 'COUNT(DISTINCT child_cat_index.product_id)');
     $select->columns($fields);
     $select->group('child_cat_index.category_id');
     return $connection->fetchPairs($select);
 }
コード例 #6
0
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     $categories = $filter->getLayer()->getCurrentCategory()->getAllChildren(true);
     $connection = $this->_getReadAdapter();
     $base_select = $filter->getLayer()->getBaseSelect();
     if (isset($base_select['cat'])) {
         $select = $base_select['cat'];
     } else {
         $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     }
     $where = array();
     $catIds = array();
     foreach ($categories as $category) {
         $catIds[] = $category;
     }
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $select->reset(Zend_Db_Select::GROUP);
     $select->join(array('child_cat_index' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')), 'child_cat_index.category_id IN (' . implode(',', $catIds) . ') AND child_cat_index.product_id = e.entity_id', array('value' => 'category_id'));
     $fields = array('count' => 'COUNT(DISTINCT child_cat_index.product_id)');
     $select->columns($fields);
     $select->group('child_cat_index.category_id');
     return $connection->fetchPairs($select);
 }
コード例 #7
0
ファイル: Stock.php プロジェクト: vstorm83/ausport
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     $connection = $this->_getReadAdapter();
     $base_select = $filter->getLayer()->getBaseSelect();
     if (isset($base_select['stock_status'])) {
         $select = $base_select['stock_status'];
     } else {
         $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     }
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $sql = $connection->fetchAll($select);
     $productCollection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
     $product_ids = array();
     foreach ($sql as $item) {
         $product_ids[] = $item['entity_id'];
     }
     $collection = $productCollection->addAttributeToFilter('entity_id', array('in' => $product_ids));
     $collection->joinField('is_in_stock', 'cataloginventory/stock_item', 'is_in_stock', 'product_id=entity_id');
     $stockCount = array('instock' => 0, 'outofstock' => 0);
     foreach ($collection as $product) {
         if ((int) $product->getIsInStock() > 0) {
             $stockCount['instock']++;
         } else {
             $stockCount['outofstock']++;
         }
     }
     return $stockCount;
 }
コード例 #8
0
ファイル: AttributeTest.php プロジェクト: relue/magento2
 public function testGetItems()
 {
     $items = $this->_model->getItems();
     $this->assertInternalType('array', $items);
     $this->assertEquals(1, count($items));
     /** @var $item Mage_Catalog_Model_Layer_Filter_Item */
     $item = $items[0];
     $this->assertInstanceOf('Mage_Catalog_Model_Layer_Filter_Item', $item);
     $this->assertSame($this->_model, $item->getFilter());
     $this->assertEquals('Option Label', $item->getLabel());
     $this->assertEquals($this->_attributeOptionId, $item->getValue());
     $this->assertEquals(1, $item->getCount());
 }
 protected function _getBaseCollectionSql()
 {
     $alias = 'attr_index_' . $this->getAttributeModel()->getId();
     // Varien_Db_Select
     $baseSelect = clone parent::_getBaseCollectionSql();
     // 1) remove from conditions
     $oldWhere = $baseSelect->getPart(Varien_Db_Select::WHERE);
     $newWhere = array();
     foreach ($oldWhere as $cond) {
         if (!strpos($cond, $alias)) {
             $newWhere[] = $cond;
         }
     }
     if ($newWhere && substr($newWhere[0], 0, 3) == 'AND') {
         $newWhere[0] = substr($newWhere[0], 3);
     }
     $baseSelect->setPart(Varien_Db_Select::WHERE, $newWhere);
     // 2) remove from joins
     $oldFrom = $baseSelect->getPart(Varien_Db_Select::FROM);
     $newFrom = array();
     foreach ($oldFrom as $name => $val) {
         if ($name != $alias) {
             $newFrom[$name] = $val;
         }
     }
     //it assumes we have at least one table
     $baseSelect->setPart(Varien_Db_Select::FROM, $newFrom);
     return $baseSelect;
 }
コード例 #10
0
ファイル: Attribute.php プロジェクト: protechhelp/gamamba
 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
 {
     if (Mage::getStoreConfig('mageworx_seo/seosuite/disable_layered_rewrites')) {
         return parent::apply($request, $filterBlock);
     }
     $text = $request->getParam($this->_requestVar);
     if (is_array($text)) {
         return $this;
     }
     $filter = $this->_getOptionId($text);
     if ($filter && $text) {
         $layeredNavigationCanonical = $this->getAttributeModel()->getLayeredNavigationCanonical();
         if ($layeredNavigationCanonical == 1) {
             $layerCanonicalFilter = Mage::registry('layer_canonical_filter');
             if (!$layerCanonicalFilter) {
                 $layerCanonicalFilter = array();
             }
             $attributeCode = $this->getAttributeModel()->getAttributeCode();
             $layerCanonicalFilter[$attributeCode] = $text;
             //$layeredNavigationCanonical;
             Mage::unregister('layer_canonical_filter');
             Mage::register('layer_canonical_filter', $layerCanonicalFilter);
         }
         if (method_exists($this, '_getResource')) {
             $this->_getResource()->applyFilterToCollection($this, $filter);
         } else {
             Mage::getSingleton('catalogindex/attribute')->applyFilterToCollection($this->getLayer()->getProductCollection(), $this->getAttributeModel(), $filter);
         }
         $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
         $this->_items = array();
     }
     return $this;
 }
コード例 #11
0
ファイル: Attribute.php プロジェクト: santhosh400/ecart
 /**
  * Get data array for building attribute filter items
  *
  * @return array
  */
 protected function _getItemsData()
 {
     if (!Mage::helper('catalin_seo')->isEnabled()) {
         return parent::_getItemsData();
     }
     $attribute = $this->getAttributeModel();
     $this->_requestVar = $attribute->getAttributeCode();
     $key = $this->getLayer()->getStateKey() . '_' . $this->_requestVar;
     $data = $this->getLayer()->getAggregator()->getCacheData($key);
     if ($data === null) {
         $attrUrlKeyModel = Mage::getResourceModel('catalin_seo/attribute_urlkey');
         $options = $attribute->getFrontend()->getSelectOptions();
         $optionsCount = $this->_getResource()->getCount($this);
         $data = array();
         foreach ($options as $option) {
             if (is_array($option['value'])) {
                 continue;
             }
             if (Mage::helper('core/string')->strlen($option['value'])) {
                 // Check filter type
                 if ($this->_getIsFilterableAttribute($attribute) == self::OPTIONS_ONLY_WITH_RESULTS) {
                     if (!empty($optionsCount[$option['value']])) {
                         $data[] = array('label' => $option['label'], 'value' => $attrUrlKeyModel->getUrlKey($attribute->getId(), $option['value']), 'count' => $optionsCount[$option['value']]);
                     }
                 } else {
                     $data[] = array('label' => $option['label'], 'value' => $attrUrlKeyModel->getUrlKey($attribute->getId(), $option['value']), 'count' => isset($optionsCount[$option['value']]) ? $optionsCount[$option['value']] : 0);
                 }
             }
         }
         $tags = array(Mage_Eav_Model_Entity_Attribute::CACHE_TAG . ':' . $attribute->getId());
         $tags = $this->getLayer()->getStateTags($tags);
         $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags);
     }
     return $data;
 }
コード例 #12
0
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = $attribute->getAttributeCode() . '_idx';
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => "COUNT({$tableAlias}.entity_id)"))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
コード例 #13
0
 protected function _getItemsData()
 {
     $items = parent::_getItemsData();
     $templateArr = $this->getSortingTemplate();
     if (!$templateArr) {
         return $items;
     }
     // Do sorting
     rsort($templateArr);
     $foundMatch = false;
     $result = array();
     foreach ($items as $item) {
         foreach ($templateArr as $t) {
             if ($t == $item['label']) {
                 $foundMatch = true;
                 array_unshift($result, $item);
             }
         }
         if (!$foundMatch) {
             array_push($result, $item);
         }
         $foundMatch = false;
     }
     return $result;
 }
コード例 #14
0
 /**
  * In case we could not find a fitting dataset in database we generate a new one from given filter and option_id.
  * The current store's normalized and lowercased option label is used as speaking url segment for the current url.
  *
  * The process checks, whether the given option_id value belongs to the given filter's attribute model and whether
  * the attribute model is filterable (though this should work anyways as only filterable attributes can be used to
  * create attribute filters).
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter The given attribute Filter.
  * @param int $optionId The wanted option id.
  * @param int $storeId Id of the currently active store
  * @return Flagbit_FilterUrls_Model_Rewrite|false On success Self, otherwise false.
  */
 public function generateNewRewrite($filter, $optionId, $storeId)
 {
     if (empty($filter) || !(int) $optionId) {
         return FALSE;
     }
     // load option from option_id
     $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setStoreFilter($storeId, true);
     // normally this should be done using the setIdFilter option of the collection. Unfortunately this results in an
     // error in Magento version 1.6.2.0
     $optionCollection->getSelect()->where('`main_table`.`option_id` = ?', $optionId);
     $option = $optionCollection->getFirstItem();
     // get all currently filterable attributes
     $category = Mage::registry('current_category');
     $filterableAttributes = Mage::getSingleton('filterurls/catalog_layer')->setCurrentCategory($category)->getFilterableAttributes()->getItems();
     // failure, if current attribute not filterable or the option does not belong to the given attribute model
     if (!in_array($option['attribute_id'], array_keys($filterableAttributes)) || $filterableAttributes[$option['attribute_id']]->getAttributeCode() != $filter->getAttributeModel()->getAttributeCode()) {
         return FALSE;
     }
     // get normalized and lowercased version of the options label
     $label = mb_strtolower(Mage::helper('filterurls')->normalize($option->getValue()));
     // try to load the label, try to avoid duplication of rewrite strings by simple alternations
     $rewrite = Mage::getModel('filterurls/rewrite')->loadByRewriteString($label);
     $addition = 0;
     while ($rewrite->getId()) {
         $rewrite = Mage::getModel('filterurls/rewrite')->loadByRewriteString($label . '_' . ++$addition);
     }
     if ($addition) {
         $label .= '_' . $addition;
     }
     //set data, save to database and return new values
     $this->setAttributeCode($filter->getAttributeModel()->getAttributeCode())->setOptionId($optionId)->setRewrite($label)->setStoreId($storeId)->save();
     return $this;
 }
コード例 #15
0
ファイル: Attribute.php プロジェクト: vstorm83/ausport
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = $attribute->getAttributeCode() . '_idx';
     $base_select = $filter->getLayer()->getBaseSelect();
     if (isset($base_select[$attribute->getAttributeCode()])) {
         $select = $base_select[$attribute->getAttributeCode()];
     } else {
         $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     }
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $select->reset(Zend_Db_Select::GROUP);
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => "COUNT(DISTINCT {$tableAlias}.entity_id)"))->group("{$tableAlias}.value");
     $_collection = clone $filter->getLayer()->getProductCollection();
     $searched_entity_ids = $_collection->load()->getSearchedEntityIds();
     if ($searched_entity_ids && is_array($searched_entity_ids) && count($searched_entity_ids)) {
         $select->where('e.entity_id IN (?)', $searched_entity_ids);
     }
     return $connection->fetchPairs($select);
 }
コード例 #16
0
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter, $requestVar = null)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = sprintf('%s_idxcount', $attribute->getAttributeCode());
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     if (isset($requestVar)) {
         $options = $select->getPart('from');
         $select->reset(Zend_Db_Select::FROM);
         unset($options[$requestVar . '_idx']);
         $select->forFrom($options);
     }
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => new Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
コード例 #17
0
ファイル: Textfield.php プロジェクト: CherylMuniz/fashion
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     // reset columns, order and limitation conditions
     //
     $fromPart = $select->getPart(Zend_Db_Select::FROM);
     if (!empty($fromPart['cat_index']['joinCondition'])) {
         $fromPart['cat_index']['joinCondition'] = str_replace('cat_index.visibility IN(2, 4)', 'cat_index.visibility IN(2, 3, 4)', $fromPart['cat_index']['joinCondition']);
     }
     $select->setPart(Zend_Db_Select::FROM, $fromPart);
     //
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = $attribute->getAttributeCode() . '_idx';
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()));
     $select->join(array($tableAlias => $this->textfieldTable), join(' AND ', $conditions), array('value', 'count' => "COUNT({$tableAlias}.entity_id)"))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
コード例 #18
0
 /**
  * Get data array for building attribute filter items
  * Override to replace label by attribute option image
  *
  * @return array
  * @version 1.7.0.2
  */
 protected function _getItemsData()
 {
     if (!Mage::getStoreConfig('mtattribute/general/show3')) {
         return parent::_getItemsData();
     }
     $attribute = $this->getAttributeModel();
     $this->_requestVar = $attribute->getAttributeCode();
     $key = $this->getLayer()->getStateKey() . '_' . $this->_requestVar;
     $data = $this->getLayer()->getAggregator()->getCacheData($key);
     if ($data === null) {
         $options = $attribute->getFrontend()->getSelectOptions();
         $optionsCount = $this->_getResource()->getCount($this);
         $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter($attribute->getAttributeId())->setStoreFilter()->load();
         $width = Mage::getStoreConfig('mtattribute/general/width3');
         $width = $width ? $width : 30;
         $thumbs = array();
         foreach ($optionCollection as $opt) {
             if ($opt->getThumb()) {
                 $thumbs[$attribute->getAttributeId()][$opt->getOptionId()] = sprintf('<img src="%s" width="%d" title="%s" style="margin-bottom: 2px;border: 2px solid #ccc"/>', $opt->getThumb(), $width, $opt->getValue());
             }
         }
         $data = array();
         foreach ($options as $option) {
             if (is_array($option['value'])) {
                 continue;
             }
             if (Mage::helper('core/string')->strlen($option['value'])) {
                 // Check filter type
                 if ($this->_getIsFilterableAttribute($attribute) == self::OPTIONS_ONLY_WITH_RESULTS) {
                     if (!empty($optionsCount[$option['value']])) {
                         $data[] = array('label' => isset($thumbs[$attribute->getAttributeId()][$option['value']]) ? $thumbs[$attribute->getAttributeId()][$option['value']] : $option['label'], 'value' => $option['value'], 'count' => $optionsCount[$option['value']]);
                     }
                 } else {
                     $data[] = array('label' => $option['label'], 'value' => $option['value'], 'count' => isset($optionsCount[$option['value']]) ? $optionsCount[$option['value']] : 0);
                 }
             }
         }
         $tags = array(Mage_Eav_Model_Entity_Attribute::CACHE_TAG . ':' . $attribute->getId());
         $tags = $this->getLayer()->getStateTags($tags);
         $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags);
     }
     return $data;
 }
コード例 #19
0
ファイル: Vendor.php プロジェクト: shashankkanungo/magento
 /**
  * Construct attribute filter
  *
  */
 public function __construct()
 {
     parent::__construct();
     $this->_requestVar = 'attribute';
 }
コード例 #20
0
 /**
  * Define options separator
  */
 public function __construct()
 {
     parent::__construct();
     $this->_optionsSeparator = Bubble_Layer_Helper_Data::OPTIONS_SEPARATOR;
 }
コード例 #21
0
ファイル: Abstract.php プロジェクト: jpbender/mage_virtual
 /**
  * Retrieve filter items count
  *
  * @return int
  */
 public function getItemsCount()
 {
     return $this->_filter->getItemsCount();
 }
コード例 #22
0
ファイル: Attribute.php プロジェクト: jpbender/mage_virtual
 /**
  * Apply attribute filter to solr query
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @param int $value
  */
 public function applyFilterToCollection($filter, $value)
 {
     if (empty($value)) {
         $value = array();
     } else {
         if (!is_array($value)) {
             $value = array($value);
         }
     }
     $productCollection = $this->getLayer()->getProductCollection();
     $attribute = $filter->getAttributeModel();
     $param = Mage::helper('enterprise_search')->getSearchParam($productCollection, $attribute, $value);
     $productCollection->addSearchQfFilter($param);
     return $this;
 }
コード例 #23
0
ファイル: Request.php プロジェクト: AleksNesh/pandora
 /**
  * 
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCountAttribute($filter)
 {
     $ret = array();
     if (empty($filter)) {
         return $ret;
     }
     $attribute = $filter->getAttributeModel();
     if (empty($attribute)) {
         return $ret;
     }
     $label = 'attribute_' . $attribute->getId();
     if (!$this->checkAttributesCountLabel($label)) {
         $vals = array();
         $res = $this->getSearchResult();
         if (!empty($res['facets'])) {
             foreach ($res['facets'] as $facet) {
                 if ($facet['attribute'] == $label) {
                     if (!empty($facet['buckets'])) {
                         foreach ($facet['buckets'] as $bucket) {
                             if ($bucket['count'] > 0) {
                                 $vals[$bucket['value']] = $bucket['count'];
                             }
                         }
                     }
                 }
             }
         }
         $this->setAttributesCountLabel($vals, $label);
     }
     return $this->getAttributesCountLabel($label);
 }
 protected function _getBaseCollectionSql()
 {
     $alias = $this->_getAttributeTableAlias();
     $baseSelect = clone parent::_getBaseCollectionSql();
     $oldWhere = $baseSelect->getPart(Varien_Db_Select::WHERE);
     $newWhere = array();
     foreach ($oldWhere as $cond) {
         if (!strpos($cond, $alias)) {
             $newWhere[] = $cond;
         }
     }
     if ($newWhere && substr($newWhere[0], 0, 3) == 'AND') {
         $newWhere[0] = substr($newWhere[0], 3);
     }
     $baseSelect->setPart(Varien_Db_Select::WHERE, $newWhere);
     $oldFrom = $baseSelect->getPart(Varien_Db_Select::FROM);
     $newFrom = array();
     foreach ($oldFrom as $name => $val) {
         if ($name != $alias) {
             $newFrom[$name] = $val;
         }
     }
     $baseSelect->setPart(Varien_Db_Select::FROM, $newFrom);
     return $baseSelect;
 }
コード例 #25
0
ファイル: Attribute.php プロジェクト: jokusafet/MagentoSource
 /**
  * Apply attribute filter to solr query
  *
  * @param   Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @param   int $value
  *
  * @return  Celebros_Conversionpro_Model_Catalog_Layer_Filter_Attribute
  */
 public function applyFilterToCollection($filter, $value)
 {
     if (empty($value) || isset($value['from']) && empty($value['from']) && isset($value['to']) && empty($value['to'])) {
         $value = array();
     }
     if (!is_array($value)) {
         $value = array($value);
     }
     $collection = Mage::helper('conversionpro')->getCurrentLayer()->getProductCollection();
     $engine = Mage::getResourceSingleton('conversionpro/fulltext_engine');
     $fieldName = $engine->getSearchEngineFieldName($filter->getAttributeModel(), 'nav');
     foreach ($value as $answerId) {
         $collection->addFqFilter(array($fieldName => $answerId));
     }
     return $this;
 }
コード例 #26
0
 /**
  * Apply attribute filter to solr query
  *
  * @param   Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @param   int $value
  *
  * @return  Enterprise_Search_Model_Catalog_Layer_Filter_Attribute
  */
 public function applyFilterToCollection($filter, $value)
 {
     if (empty($value) || isset($value['from']) && empty($value['from']) && isset($value['to']) && empty($value['to'])) {
         $value = array();
     }
     if (!is_array($value)) {
         $value = array($value);
     }
     $attribute = $filter->getAttributeModel();
     $options = $attribute->getSource()->getAllOptions();
     foreach ($value as &$valueText) {
         foreach ($options as $option) {
             if ($option['label'] == $valueText) {
                 $valueText = $option['value'];
             }
         }
     }
     $fieldName = Mage::getResourceSingleton('enterprise_search/engine')->getSearchEngineFieldName($attribute, 'nav');
     $this->getLayer()->getProductCollection()->addFqFilter(array($fieldName => $value));
     return $this;
 }
コード例 #27
0
 /**
  * Set request variable name which is used for apply filter
  *
  * @param   string $varName
  * @return  Mage_Catalog_Model_Layer_Filter_Abstract
  */
 public function setRequestVar($varName)
 {
     if (Mage::helper('catalin_seo')->isEnabled()) {
         $attrUrlKeyModel = Mage::getResourceModel('catalin_seo/attribute_urlkey');
         $varName = $attrUrlKeyModel->getUrlKey($varName);
     }
     return parent::setRequestVar($varName);
 }
コード例 #28
0
 /**
  * Create filter item object
  *
  * @param string $label Label of the filter value
  * @param mixed  $value Value of the filter
  * @param int    $count Number of result (default is 0)
  *
  * @return Mage_Catalog_Model_Layer_Filter_Item
  */
 protected function _createItem($label, $value, $count = 0)
 {
     $isSelected = false;
     if ($this->getIsMultipleSelect() && $value) {
         if (in_array($value, $this->_rawFilter)) {
             $isSelected = true;
         }
         $values = $this->_rawFilter;
         if (($key = array_search($value, $values)) !== false) {
             unset($values[$key]);
             $value = array_values($values);
         } else {
             if (!is_array($value)) {
                 $value = array($value);
             }
             $value = array_merge($values, $value);
         }
     }
     $item = parent::_createItem($label, $value, $count);
     $item->setSelected($isSelected);
     return $item;
 }
コード例 #29
0
 /**
  * Returns option label if attribute uses options.
  *
  * @param int $optionId
  * @return bool|int|string
  */
 protected function _getOptionText($optionId)
 {
     if ($this->getAttributeModel()->getFrontendInput() == 'text') {
         return $optionId;
         // not an option id
     }
     return parent::_getOptionText($optionId);
 }