Magento sales_order_create网格-可以添加if语句


Magento sales_order_create grid - possible to add an if statement?

我需要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()函数。

这是有效的,现在有一个价格栏和一个特殊价格栏。

我的问题是,是否可以将这两列与if语句或类似的语句组合在一起?

理想情况下,我想要一个价格列,如果有,用粗体显示special_price,如果没有,则显示正常价格。

如果special_price不为空,则special_prce ELSE price<lt;

希望我已经说清楚了!

编辑:根据要求,这里是完整的_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();
}

想法很好。但据我所知,这根本不可能。这是因为special_price和正常价格是两个不同的属性。_prepareColumn()所做的是,它只需为使用addColumn在该方法中指定的每个属性创建一列。

现在假设您有两个订单。设为Order AOrder B。对于订单A,我们有特价,对于订单B,我们没有特殊产品。现在,如果我们试图单独显示这些列,它将破坏网格列表。即

    NAME       SPECIAL PRICE    NORMAL PRICE
    .........................................
     Order A       $10              nope
     Order B       nope              $5
   ..........................................

第一行试图隐藏正常价格列,而第二行试图隐藏特殊价格列。这绝对是一个模糊的情况。因此,您不能简单地显示多个属性中的一个属性,因为您正在处理一个集合。

希望你能抓住我!