2014-10-08 37 views
2

我需要sales_order_create表格显示的特殊价格,我已通过添加这样做:Magento sales_order_create grid - 可以添加if语句吗?

->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,如果不显示正常价格,则显示为bold。

IF special_price IS NOT 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

好问题。你是如何在收藏中添加特殊价格的?显示代码 – 2014-10-08 11:50:52

+0

嗨,我已经添加了整个_prepareCollection()函数到我原来的问题,我希望这是你的意思! – Lee 2014-10-08 11:59:33

回答

0

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

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

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

    Order B  nope    $5 
    .......................................... 

第一行尝试隐藏正常价格列,而第二行尝试隐藏特殊价格列。这绝对是一个模棱两可的情况。所以你不能简单地从多个属性中只显示一个属性,因为你正在处理一个集合。

希望你能找到我!

+0

这很有道理!我认为这会很棘手。没有办法添加单个列,并在该列中输入IF语句? – Lee 2014-10-08 12:17:22

+0

不..不存在我的知识。你试图实现的是不可能的 – 2014-10-08 12:24:51