想要从产品集合中删除 (((price_table_price.value)*1) <


Want to remove (((price_table_price.value)*1) < from the product collection

我对Magento很陌生。(事实上,这是我的第一个任务)。如果您能在这方面帮助我,我将非常高兴。

我正在使用Magento

示例数据库,Magento版本是1.3.2。

本地 PC 网址 : http://magento.local/electronics/cell-phones.html?price=4,100

等级 : Mage_Catalog_Block_Product_List

protected function _getProductCollection()
{
    if (is_null($this->_productCollection)) {
        $layer = Mage::getSingleton('catalog/layer');
        /* @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();
        $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
        if ($origCategory) {
            $layer->setCurrentCategory($origCategory);
        }
    }        
    return $this->_productCollection;
}

我需要从>_productCollection$this中删除((price_table_price.value)*1) <400)。无法弄清楚如何以及何时将其添加到产品系列中。请帮忙

!!

谢谢!!!!

由于没有人帮助我,我自己想出了答案。

首先,我将说明我的任务是什么。

假设我有一个产品在 100-200 价格范围内有 10 个,在 500-600 中有 12 个,X 类别的 10000-20000 中有 1 个产品。使用magento的默认价格范围,它显示为两个范围,即0-10000和10000-200000,这对客户没有多大用处。

我必须将范围设为 100-200,500-600 和 1000<</p>

我将在这里发布我的所有代码。

当我关注其他帖子进行自定义范围时,他们中的大多数只考虑显示分层导航。但是在这里,我已经考虑在单击最终范围(即1000<)时显示产品

请注意,LMage是本地>LMage文件夹,我也是Magento;)的新蜜蜂。

如果您找到更好的方法,请在此处发布。

class LMage_CatalogIndex_Model_Mysql4_Price extends Mage_CatalogIndex_Model_Mysql4_Price {
  public function getCount($range, $attribute, $entitySelect) {
    $select = clone $entitySelect;
    $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->join(array('price_table' => $this->getMainTable()), 'price_table.entity_id=e.entity_id', array());
    $response = new Varien_Object();
    $response->setAdditionalCalculations(array());
    if ($attribute->getAttributeCode() == 'price') {
        $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
        $args = array(
            'select' => $select,
            'table' => 'price_table',
            'store_id' => $this->getStoreId(),
            'response_object' => $response,
        );
        Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
    }

    $fields = array('count' => 'COUNT(DISTINCT price_table.entity_id)', 'range' => "FLOOR(((price_table.value" . implode('', $response->getAdditionalCalculations()) . ")*{$this->getRate()})/{$range})+1");
    $select->from('', $fields)
            ->group('range')
            ->where('price_table.website_id = ?', $this->getWebsiteId())
            ->where('price_table.attribute_id = ?', $attribute->getId());

    $result = $this->_getReadAdapter()->fetchAll($select);
    $counts = array();
    foreach ($result as $row) {
        if ($row['range'] >= 11) {
            $counts[11] = isset($counts[11])?$row['count']+$counts[11]:$row['count'];
        } else {
            $counts[$row['range']] = $row['count'];
        }
    }

    return $counts;
 }
 public function applyFilterToCollection($collection, $attribute, $range, $index, $tableName = 'price_table') {
    /**
     * Distinct required for removing duplicates in case when we have grouped products
     * which contain multiple rows for one product id
     */
    $collection->getSelect()->distinct(true);
    $tableName = $tableName . '_' . $attribute->getAttributeCode();
    $collection->getSelect()->joinLeft(
            array($tableName => $this->getMainTable()), $tableName . '.entity_id=e.entity_id', array()
    );
    $response = new Varien_Object();
    $response->setAdditionalCalculations(array());
    $collection->getSelect()
            ->where($tableName . '.website_id = ?', $this->getWebsiteId())
            ->where($tableName . '.attribute_id = ?', $attribute->getId());
    if ($attribute->getAttributeCode() == 'price') {
        $collection->getSelect()->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId());
        $args = array(
            'select' => $collection->getSelect(),
            'table' => $tableName,
            'store_id' => $this->getStoreId(),
            'response_object' => $response,
        );
        Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
    }
    $collection->getSelect()->where("(({$tableName}.value" . implode('', $response->getAdditionalCalculations()) . ")*{$this->getRate()}) >= ?", ($index - 1) * $range);
    if($index<=10){
        $collection->getSelect()->where("(({$tableName}.value" . implode('', $response->getAdditionalCalculations()) . ")*{$this->getRate()}) < ?", $index * $range);
    }
    return $this;
}
public function getCategoryProductPrices($attribute = null, $entitySelect) {
    $select = clone $entitySelect;
    $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);
    $response = new Varien_Object();
    $response->setAdditionalCalculations(array());
    $select->join(array('price_table' => $this->getMainTable()), 'price_table.entity_id=e.entity_id', array());
    if ($attribute->getAttributeCode() == 'price') {
        $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
        $args = array(
            'select' => $select,
            'table' => 'price_table',
            'store_id' => $this->getStoreId(),
            'response_object' => $response,
        );
        Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
    }
    $select
            ->from('', "(price_table.value" . implode('', $response->getAdditionalCalculations()) . ")")
            ->where('price_table.website_id = ?', $this->getWebsiteId())
            ->where('price_table.attribute_id = ?', $attribute->getId());
    return $this->_getReadAdapter()->fetchAll($select);
}
}

class LMage_CatalogIndex_Model_Price extends Mage_CatalogIndex_Model_Price{
public function getCategoryProductPrices($attribute, $entityIdsFilter){
    return $this->_getResource()->getCategoryProductPrices($attribute, $entityIdsFilter);
}    
}

class LMage_Catalog_Model_Layer_Filter_Price extends Mage_Catalog_Model_Layer_Filter_Price {
public function getPriceRange() {
    $range = $this->getData('price_range');
    if (is_null($range)) {
        $productsprice = $this->getCategoryProductPricesArr();
        $maxPrice = $this->getMaxPriceInt();            
        $maxPrice = $this->getMaxPriceOfMaxOccurenceRange($productsprice, $maxPrice);
        $index = 1;
        do {
            $range = pow(10, (strlen(floor($maxPrice)) - $index));
            $items = $this->getRangeItemCounts($range);
            $index++;
        } while ($range > self::MIN_RANGE_POWER && count($items) < 1);            
        $this->setData('price_range', $range);
    }
    return $range;
}
public function getMaxPriceOfMaxOccurenceRange($productsprice, $maxPrice) {
    $rangeArr = array();
    $i = 1;
    $val = 0;
    do {
        $val = self::MIN_RANGE_POWER * $i - 1;
        $rangeArr[$val] = 0;
        $i *= 10;
    } while ($maxPrice > $val);
    foreach ($productsprice as $value) {            
        $rangeArr[pow(10, strlen(floor($value['value']))) - 1]+=1;
    }
    return array_search(max($rangeArr), $rangeArr);
}
public function getCategoryProductPricesArr() {
    $productsprice = $this->getData('products_price_arr');
    if (is_null($productsprice)) {
        $productsprice = Mage::getSingleton('catalogindex/price')->getCategoryProductPrices(
                $this->getAttributeModel(), $this->_getBaseCollectionSql()
        );
        $this->setData('products_price_arr', $productsprice);
    }
    return $productsprice;
}
/**
 * Prepare text of item label
 *
 * @param   int $range
 * @param   float $value
 * @return  string
 */
protected function _renderItemLabel($range, $value) {
    $store = Mage::app()->getStore();
    if ($value > 10) {
        $fromPrice = $store->formatPrice(($value - 1) * $range);
        //$toPrice = $store->formatPrice($value * $range);
        return Mage::helper('catalog')->__('%s < ', $fromPrice);
    }
    $fromPrice = $store->formatPrice(($value - 1) * $range);
    $toPrice = $store->formatPrice($value * $range);        
    return Mage::helper('catalog')->__('%s - %s', $fromPrice, $toPrice);
}