【问题标题】:How to get invoice increment_id on order grid? (Magento 1.7)如何在订单网格上获取发票 increment_id? (Magento 1.7)
【发布时间】:2013-02-06 10:56:40
【问题描述】:

我正在尝试从 sales_flat_invoice 表中获取 increment_id 以显示在我的订单网格中。

我已经做到了,但它只会显示已开票的订单。

总结一下,我想要做的是创建一个包含发票的 increment_id 的列(如果订单已经开票 - 如果没有,它应该是空白的)。

使用的代码如下:

在 _prepareCollection() 中:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()
    ->join(
        array('address' => $collection->getTable("sales/order_address")),
        'main_table.entity_id = address.parent_id AND address.address_type = "shipping"',
        array('postcode')
    );
    //$collection->join('invoice', 'main_table.entity_id = invoice.order_id', 'increment_id as invoice_id');


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

在 _prepareColumns() 中:

    $this->addColumn('invoice_id', array(
        'header' => 'Faktureret',
        'index' => 'invoice_id',
        'width' => '70px',
        'type' => 'text',
    ));

谢谢,祝你有美好的一天!

【问题讨论】:

    标签: magento magento-1.7


    【解决方案1】:

    如果您想在销售订单网格中添加发票 ID,则可以在 prepareCollection() 函数中使用以下代码

    $collection->getSelect()->joinLeft('sales_flat_invoice', 'main_table.entity_id = sales_flat_invoice.order_id', 'increment_id as invoice_id');

    通过使用以下代码,您将能够从销售订单网格中的当前订单 ID 获取发票 ID。 在此之后添加列字段为

    $this->addColumn('invoice_id', 大批( 'header'=> $this->__('Invoice Id'), '对齐' =>'正确', '类型=' => '文本', 'index' => 'invoice_id', ) );

    更多关注我 http://www.webtechnologycodes.com

    【讨论】:

      【解决方案2】:

      您需要进行 LEFT JOIN。使用->joinLeft。 ->加入对->joinInner的引用

      【讨论】:

      • 感谢托拜厄斯!你拯救了我的一天;-)
      • 能否分享完整的代码?我也遇到了这个问题。但是当我使用时: $collection->joinLeft('invoice', 'main_table.entity_id = invoice.order_id', 'increment_id as invoice_id');它不起作用。
      • 那么你现在的状态是什么?您还没有收到足够的发票?
      【解决方案3】:

      从订单详细信息中获取发票详细信息。你可以使用

      $_orders = $this->getOrders(); $_invoices = $_order->getInvoiceCollection();

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-11
        • 2013-08-14
        相关资源
        最近更新 更多