0

私はMagentoを初めて使用します。(実際、これは私の最初の仕事です)。これについてお役に立てれば幸いです。

私は magento サンプル データベースを使用しており、Magento のバージョンは 1.3.2 です。

ローカル PC URL : 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;
}

$this->_productCollection から (((price_table_price.value)*1) < 400) を削除する必要があります。これがいつ、どのように製品コレクションに追加されたのかわかりません。助けてください!!!

ありがとう!!!!

4

1 に答える 1

0

誰も助けてくれなかったので、自分で答えを見つけました。

最初に、私のタスクが何であったかを述べます。

X カテゴリの 100 ~ 200 の価格帯に 10 個の製品、500 ~ 600 の製品に 12 個、10000 ~ 20000 の製品に 1 個の製品があるとします。Magento のデフォルトの価格帯では、0 ~ 10000 と 10000 ~ 200000 の 2 つの範囲が表示されますが、これは顧客にとってあまり役に立ちません。

範囲を 100 ~ 200、500 ~ 600、および 1000< にする必要がありました

すべてのコードをここに投稿します。

範囲をカスタマイズするために他の投稿に従うと、それらのほとんどは階層化されたナビゲーションの表示のみを考慮しています。しかし、ここでは、最終的な範囲 (つまり 1000<) をクリックしたときに製品を表示することを検討しました。

LMage は local->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);
}
于 2012-05-31T02:44:24.963 に答える