【问题标题】:Magento: Order Items on separate rows in Sales Order GridMagento:在销售订单网格中的不同行上订购商品
【发布时间】:2023-04-06 12:30:01
【问题描述】:

我正在运行 Magento Community 1.6.2

我正在尝试编辑我的销售订单网格,以便单个项目(属于多个项目订单的一部分)出现在各自的行中。

我添加到 Grip.php 中的 prepareCollection 函数(首先要操作这些列)如下:

     protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass())
        ->join(
            'sales/order_item',
            '`sales/order_item`.order_id=`main_table`.entity_id',
            array(
                'skus'  => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR "<br>")'),
                'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR "<br>")'),
                'quantities' => new Zend_Db_Expr('group_concat(`sales/order_item`.qty_ordered SEPARATOR "<br>")'),
                )
            );
            $collection->getSelect()->group('entity_id');

        $this->setCollection($collection);
    return parent::_prepareCollection();
}

我已使用以下内容添加了列:

    $this->addColumn('skus', array(
        'header'    => Mage::helper('Sales')->__('SKUs'),
       'width'     => '120px',
        'index'     => 'skus',
       'type'        => 'text',

      ));


     $this->addColumn('names', array(
       'header'    => Mage::helper('Sales')->__('Item Names'),
       'width'     => '320px',
       'index'     => 'names',
       'type'        => 'text',
    )); 

      $this->addColumn('quantities', array(
        'header'    => Mage::helper('Sales')->__('Quantities'),
        'width'     => '100px',
        'index'     => 'quantities',
        'type'        => 'text',

    )); 

目前,在函数中,我只是简单地输入了&lt;br&gt;,以便在查看订单网格时呈现单独的线条。这不足以满足我的需求。我计划使用从该网格导出的 CSV,并且绝对必须将逐项列出的订单组件放在单独的行上。

感谢您的帮助!

【问题讨论】:

  • 你解决了吗?

标签: mysql magento zend-db magento-1.6


【解决方案1】:

我真的不知道是否可以在不创建法师销售订单项目网格的情况下完成您的要求。

以下是你问我的上一篇文章中的有效内容......也许它们会对你有所帮助:

$collection->getSelect()->join('catalog_product_index_eav', '`catalog_product_index_eav`.`entity_id` = `main_table`.`product_id` AND `catalog_product_index_eav`.`attribute_id` = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = "brand")', array('attribute_id'));
$collection->getSelect()->join('eav_attribute_option_value', '`eav_attribute_option_value`.`option_id` = `catalog_product_index_eav`.`value`', array('brand' => 'value'));

【讨论】:

    【解决方案2】:

    我修改了 sku 数组定义,而不是创建“数量”。

    $collection = Mage::getResourceModel($this->_getCollectionClass())
        ->join(
        'sales/order_item',
        '`sales/order_item`.order_id=`main_table`.entity_id',
            array(
                'skus'  => new Zend_Db_Expr('group_concat( `sales/order_item`.sku, "(", floor(`sales/order_item`.qty_ordered), ")" SEPARATOR ", ")'),
            ));
    

    我相信您可以使用 floor(sales/order_item.qty_ordered) 将您的“数量”定义转换为整数。

    订单网格结果中的 SKU 列类似于: MBA001(2), MOF004(1)

    【讨论】:

      猜你喜欢
      • 2012-11-25
      • 1970-01-01
      • 2015-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多