gpt4 book ai didi

magento - 在 Magento 的管理产品网格中添加最终价格?

转载 作者:行者123 更新时间:2023-12-01 05:28:22 24 4
gpt4 key购买 nike

如何将“最终价格”(考虑到所有目录规则和特价)添加到 Magento 管理员的产品网格中?

2012 年 10 月 12 日更新
我正在使用具有大量自定义的 v1.1.8,所以我刚刚重新安装了 v.1.1.8,并将 addFinalPrice() 添加到产品网格中的 _prepareCollection() 中,但现在我得到的只是一个半空白管理产品管理中的屏幕。有任何想法吗?

最佳答案

最终价格取决于网站和客户群,您是否有业务要求说明需要显示哪些价格?
因为通常情况下产品网格中的数据取决于商店。

在简单的情况下,您可以将价格索引表添加到产品集合中并从中显示数据(在产品集合中已经存在方法 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 步实现你的 block
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();
}
}

现在,如果您选择商店,您将能够看到价格,对于“所有商店 View ”,此数据不可用

关于magento - 在 Magento 的管理产品网格中添加最终价格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12732848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com