【问题标题】:In Magento, how do I populate a new column in sales_order_grid with data from sales_flat_order?在 Magento 中,如何使用 sales_flat_order 中的数据填充 sales_order_grid 中的新列?
【发布时间】:2015-10-02 22:31:38
【问题描述】:

我正在按照 Ivan 的教程 (Adding order attribute to the orders grid in Magento 1.4.1) 向 sales_order_grid 表(运输说明文本)添加一个额外的列,它可以正常工作,只是它不会将 sales_flat_order 中的旧数据带到 sales_order_grid 中的新列。

我的 SQL 安装脚本正确添加了该列,因为我使用的字段名称与 sales_flat_order 中的字段名称相同,所以我认为我不需要观察者,但是将所有现有运输描述数据导入到 shipping_description 字段中的代码没有运行。

我做错了什么?

我的 SQL 安装脚本:

<?php
/**
 * Setup scripts, add new column and fulfills
 * its values to existing rows
 *
 */
/* @var $this Mage_Sales_Model_Mysql4_Setup */
$this->startSetup();

// Add column to grid table
$this->getConnection()->addColumn(
    $this->getTable('sales/order_grid'),
    'shipping_description',
    "varchar(255) not null default ''"
);

// Add key to table for this field,
// it will improve the speed of searching & sorting by the field
$this->getConnection()->addKey(
    $this->getTable('sales/order_grid'),
    'shipping_description',
    'shipping_description'
);


// fill existing rows with data
$select = $this->getConnection()->select();
$select->join(
    array('order'=>$this->getTable('sales/order')),
    $this->getConnection()->quoteInto('order.entity_id = order_grid.entity_id',''),
    array('shipping_description' => 'shipping_description')
);

$this->getConnection()->query(
    $select->crossUpdateFromSelect(
        array('order_grid' => $this->getTable('sales/order_grid'))
    )
);

$this->endSetup();

我正在使用 Magento 1.5.1 社区版!

感谢您的帮助!

【问题讨论】:

    标签: magento


    【解决方案1】:

    这应该可行:

    $select = $this->getConnection()->select();
    $select->join(
        array('order_shipping'=>$this->getTable('sales/order')),//alias=>table_name
        $this->getConnection()->quoteInto(
            'order_shipping.entity_id = order_grid.entity_id',
            Mage_Sales_Model_Quote_Address::TYPE_SHIPPING
        ),//join clause
        array('shipping_description' => 'shipping_description')//fields to get
    );
    $this->getConnection()->query(
        $select->crossUpdateFromSelect(
            array('order_grid' => $this->getTable('sales/order_grid'))
        )
    );
    

    如果你愿意,看看我的extension :)
    高温

    【讨论】:

    • 完美!我在尝试将我的扩展程序放在一起时查看了您的扩展程序,并且在 Ivan 的帖子和您的扩展程序之间我是如此接近 - 只是在填充数据时弄错了 :-) 我一定会在以后也开源我的超级简单版本.谢谢!
    • 实际上我在销售订单网格中需要一个字段仓库我在 sales_flat_order 和 sales_flat_order_grid 表中创建了列名仓库并创建了属性:带有值的仓库 //workout $this->addColumn('warehouse', array( 'header' => Mage::helper('sales')->__('Warehouse'), 'index' => 'warehouse', 'type' => 'options', 'width' => '70px', 'options' => Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'warehouse'), ));仍然无法正常工作,我需要遵循什么步骤吗?
    • 销售订单网格上显示的列名,不显示值,主要是下订单后我需要手动更改仓库值,最初名称应该显示为“选择订单”我的属性:
    • 你能帮我做什么吗?
    • @Rathinam 如果您正在寻求帮助,您应该提出自己的问题
    猜你喜欢
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 2020-02-04
    • 2016-05-24
    • 2020-08-30
    • 1970-01-01
    相关资源
    最近更新 更多