質問

なぜ私は次のことをすることができないのですか:

            $this->getSelect()
        ->columns(
            array(
                'ordered_qty' => 'COUNT(DISTINCT main_table.entity_id)', 
                'invoiced_qty' => new Zend_Db_Expr('( select COUNT(OI.item_id) AS Ct from sales_flat_order_item AS OI WHERE OI.order_id=main_table.entity_id ) AS invoiced_qty')
                            )
                    );

サブクエリは、「フィールド名を決定できない」というエラーで失敗します

役に立ちましたか?

解決

あなたの質問には具体的な答えを提供するのに十分なコンテキストがないので、Magentoがメッセージで例外を投げている理由を説明します

フィールド名を決定できません

うまくいけば、それが問題を追跡するのに十分な情報を提供するでしょう。

在庫のマゼントシステムでは、 それだけ 「フィールド名を決定できない」と表示されるエラーが表示されます

#File: app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php
protected function _attributeToField($attribute)
{
    $field = false;
    if (is_string($attribute)) {
        $field = $attribute;
    } elseif ($attribute instanceof Mage_Eav_Model_Entity_Attribute) {
        $field = $attribute->getAttributeCode();
    }
    if (!$field) {
        Mage::throwException(Mage::helper('sales')->__('Cannot determine the field name.'));
    }
    return $field;
}

だから、場合 _attributeToField メソッドには属性値が渡されます

  1. 空の文字列

  2. 属性オブジェクト getAttributeCode falseを返します(またはPHPが偽りと見なされる多くの値の1つ)

  3. ではないもの Mage_Eav_Model_Entity_Attribute または文字列

次に、「フィールド名を決定できません」という例外がスローされます。

標準システムでは、Magentoがコレクションオブジェクトを呼び出すときにこの方法を呼び出します addAttributeToSelect, addAttributeToFilter, addAttributeToSort, 、 また addAttributeToSearchFilter 方法。

したがって、あなたのコードについて何かが無効な値をに引き起こします _attributeToField. 。これは、問題がサブクエリではないことを意味します。または、サブクエリが無効な値を渡すものを変更する可能性があります。

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top