我需要sales_order_create网格来显示特价,我已经这样做了:
->addAttributeToSelect('special_price')
到_prepareCollection()函数,然后添加:
$this->addColumn('special_price', array(
'header' => Mage::helper('sales')->__('Special Price'),
'column_css_class' => 'price',
'align' => 'center',
'type' => 'currency',
'currency_code' => $this->getStore()->getCurrentCurrencyCode(),
'rate' => $this->getStore()->getBaseCurrency()->getRate($this->getStore()->getCurrentCurrencyCode()),
'index' => 'special_price',
'renderer' => 'adminhtml/sales_order_create_search_grid_renderer_price',
));
到_prepareColumns()函数。
这样做,现在有一个价格列和一个special_price列。
我的问题是,是否可以将2列与if语句或类似的东西结合起来?
理想情况下,我想要一个价格列,如果有,则以粗体显示special_price,如果没有,则显示正常价格。
如果special_price不是NULL,那么special_price ELSE价格<<那种事情
希望我已经说清楚了!
编辑:根据要求,这是完整的_prepareCollection()函数:
(我添加的唯一一行是 - > addAttributeToSelect('special_price'))
protected function _prepareCollection()
{
$attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
/* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
$collection = Mage::getModel('catalog/product')->getCollection();
$collection
->setStore($this->getStore())
->addAttributeToSelect($attributes)
->addAttributeToSelect('product_size')
->addAttributeToSelect('special_price')
->addAttributeToSelect('sku')
->addStoreFilter()
->addAttributeToFilter('type_id', array_keys(
Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()
))
->addAttributeToSelect('gift_message_available');
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
$this->setCollection($collection);
return parent::_prepareCollection();
}
答案 0 :(得分:0)
想法很好。但根据我的理解,我认为这根本不可能。这是因为special_price
和正常价格是两个不同的属性。 _prepareColumn()
的作用是,它只是为使用addColumn
在该方法中指定的每个属性创建一列。
现在假设您有两个订单。设为Order A
和Order B
。对于订单A,我们有特价,对于订单B,我们没有特殊产品。现在,如果我们试图单独显示这些列,它将分解网格列表。即
NAME SPECIAL PRICE NORMAL PRICE
.........................................
Order A $10 nope
Order B nope $5
..........................................
第一行尝试隐藏正常价格列,而第二行尝试隐藏特殊价格列。这绝对是一个模糊的情况。因此,您不能只显示多个属性中的一个属性,因为您正在处理集合。
希望你能帮到我!