我创建了自己的产品类型并希望对价格进行索引,但这仅在我从索引管理运行重新索引后才会发生。
我添加了一个索引器(我的产品类似于一个分组的)。文件看起来像这样
<?php
class Mymodule_Model_Resource_Product_Indexer_Price_Mymodule extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Default {
/*
/**
* Reindex temporary (price result data) for all products
*
* @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped
*/
public function reindexAll() {
$this->useIdxTable(true);
$this->beginTransaction();
try {
$this->_prepareMymodulePriceData();
$this->commit();
} catch (Exception $e) {
$this->rollBack();
throw $e;
}
return $this;
}
/**
* Reindex temporary (price result data) for defined product(s)
*
* @param int|array $entityIds
* @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped
*/
public function reindexEntity($entityIds) {
$this->_prepareMymoduleData($entityIds);
return $this;
}
/**
* Calculate minimal and maximal prices for Grouped products
* Use calculated price for relation products
*
* @param int|array $entityIds the parent entity ids limitation
* @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped
*/
protected function _prepareMymodulePriceData($entityIds = null) {
$write = $this->_getWriteAdapter();
$table = $this->getIdxTable();
$select = $write->select()
->from(array('e' => $this->getTable('catalog/product')), 'entity_id')
->joinLeft(
array('l' => $this->getTable('catalog/product_link')), 'e.entity_id = l.product_id AND l.link_type_id=' . Mymodule_Model_Product_Type_Link::LINK_TYPE_Mymodule, array())
->join(
array('cg' => $this->getTable('customer/customer_group')), '', array('customer_group_id'));
$this->_addWebsiteJoinToSelect($select, true);
$this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id');
$maxCheckSql = $write->getCheckSql('le.required_options = 0', 'i.max_price', 0);
$select->columns('website_id', 'cw')
->joinLeft(
array('le' => $this->getTable('catalog/product')), 'le.entity_id = l.linked_product_id', array())
->joinLeft(
array('i' => $table), 'i.entity_id = l.linked_product_id AND i.website_id = cw.website_id'
. ' AND i.customer_group_id = cg.customer_group_id', array(
'tax_class_id' => $this->_getReadAdapter()
->getCheckSql('MIN(i.tax_class_id) IS NULL', '0', 'MIN(i.tax_class_id)'),
'price' => new Zend_Db_Expr('NULL'),
'final_price' => new Zend_Db_Expr('NULL'),
'min_price' => new Zend_Db_Expr('SUM(' . $maxCheckSql . ')'),
'max_price' => new Zend_Db_Expr('SUM(' . $maxCheckSql . ')'),
'tier_price' => new Zend_Db_Expr('NULL')
))
->group(array('e.entity_id', 'cg.customer_group_id', 'cw.website_id'))
->where('e.type_id=?', $this->getTypeId());
if (!is_null($entityIds)) {
$select->where('l.product_id IN(?)', $entityIds);
}
/**
* Add additional external limitation
*/
Mage::dispatchEvent('catalog_product_prepare_index_select', array(
'select' => $select,
'entity_field' => new Zend_Db_Expr('e.entity_id'),
'website_field' => new Zend_Db_Expr('cw.website_id'),
'store_field' => new Zend_Db_Expr('cs.store_id')
));
$query = $select->insertFromSelect($table);
$write->query($query);
return $this;
}
}
我的配置如下所示:
<product>
<type>
<Mymoduletranslate="label" module="Mymodule">
<label>Mymodule</label>
<model>Mymodule/product_type_Mymodule</model>
<price_model>Mymodule/product_price</price_model>
<composite>1</composite>
<index_priority>15</index_priority>
<allow_product_types>
<simple/>
<virtual/>
</allow_product_types>
<price_indexer>Mymodule/product_indexer_price_Mymodule</price_indexer>
</Mymodule>
</type>
</product>
当我记录该文件时,它也会在我保存产品时运行。我的猜测是我错过了一些重要的部分来使整个事情正常工作:(
欢迎对此提供任何帮助。