「最終価格」(すべてのカタログルールと特別価格を考慮に入れて)をMagento管理者の製品グリッドに追加するにはどうすればよいですか?
UPDATE 10/12/2012多数のカスタマイズでv1.1.8を使用しているので、v.1.1.8を新規インストールし、製品グリッドの_prepareCollection()にaddFinalPrice()を追加しましたが、今ではすべてgetは、製品の管理管理者の半空白の画面です。何か案は?
最終的な価格はウェブサイトと顧客グループによって異なります。これらの価格のどれを表示する必要があるかを説明するビジネス要件はありますか? 通常、製品グリッドのデータは店舗に依存するためです。
単純なケースでは、価格インデックス テーブルを製品のコレクションに追加し、そこからのデータを表示できます (製品コレクションでは既にメソッドが存在しますaddPriceData
)。(また、考えられるすべてのケースを確実にカバーするために、顧客グループ スイッチャーを実装することもできます)
以下のリンクの例で、製品グリッドに新しい列を追加する方法 http://www.magentocommerce.com/boards/viewthread/68993
製品グリッドをオーバーライドする簡単な例
ステップ1モジュールのconfig.xmlでグリッドをオーバーライドします
<config>
...
<global>
...
<blocks>
...
<adminhtml>
<rewrite>
<catalog_product_grid>Test_Catalog_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid>
</rewrite>
</adminhtml>
...
</blocks>
...
</global>
...
</config>
ステップ 2 ブロックを実装する
class Test_Catalog_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
/**
* get customer group id
*
* @return int
*/
protected function _getCustomerGroupId()
{
$customerGroupId = (int) $this->getRequest()->getParam('customer_group_id', 0);
return $customerGroupId;
}
/**
* prepare collection
*
* @return Test_Catalog_Block_Adminhtml_Catalog_Product_Grid
*/
protected function _prepareCollection()
{
$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id');
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
$collection->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left');
}
if ($store->getId()) {
$collection->addPriceData($this->_getCustomerGroupId(), $this->_getStore()->getWebsiteId());
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
$collection->addStoreFilter($store);
$collection->joinAttribute(
'name',
'catalog_product/name',
'entity_id',
null,
'inner',
$adminStore
);
$collection->joinAttribute(
'custom_name',
'catalog_product/name',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'status',
'catalog_product/status',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'visibility',
'catalog_product/visibility',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'price',
'catalog_product/price',
'entity_id',
null,
'left',
$store->getId()
);
}
else {
$collection->addAttributeToSelect('price');
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
}
$this->setCollection($collection);
Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
$this->getCollection()->addWebsiteNamesToResult();
return $this;
}
/**
* Prepare columns
*
* @return Mage_Adminhtml_Block_Widget_Grid
*/
protected function _prepareColumns()
{
$this->addColumnAfter('final_price',
array(
'header'=> Mage::helper('catalog')->__('Final Price'),
'type' => 'price',
'currency_code' => $this->_getStore()->getBaseCurrency()->getCode(),
'index' => 'final_price',
), 'price');
return parent::_prepareColumns();
}
}
現在、ストアを選択すると価格が表示されますが、「すべてのストア ビュー」の場合、このデータは利用できません
$collection->addPriceData()
役に立ちます