0

私の目的は単純です。私は引用と呼ばれるモジュールを持っています。引用が「チェックアウト」されたときにis_active列を変更することで、カートが作成されるたびにMagentoに新しい引用レコードを作成させることができました。そのため、それぞれが顧客に関連するたくさんの見積もりがあり、それぞれが見積もりに関連する sales/order_item 行があります。バックエンドに、すべての引用のグリッドを表示するページがあります。引用をクリックすると、編集ページに 2 つのタブが表示されます。1 つには、引用の詳細を表示する Form.php があります。(顧客名、日付など)、その見積もりの​​すべてのアイテムのグリッドを含む別のタブがあります。それはとても簡単に思えます:

$this->addTab("items_section", array(
  "label" => Mage::helper("quote")->__("Quote Items"),
  "title" => Mage::helper("quote")->__("Quote Items"),
  "content" => $this->getLayout()->createBlock("quote/adminhtml_quotes_edit_tab_cart")->toHtml(),
));

次に、カートブロックにこれがあります:

protected function _prepareCollection()
{
    $collection = Mage::getModel('sales/order_item')->getCollection();
    print_r($collection);
    $this->setCollection($collection);

    return parent::_prepareCollection();
}

最初にここで解決しなければならない問題があるため、(order_id によって) 正しいコレクションをロードすることにも興味がprint_rありません。見つかったレコードがグリッドに表示されます。典型的なMagentoのやり方では、エラーなどはありません。モデルが必要に応じてデータベースにクエリを実行することになっていることは理解していますが、それは起こっていないようです。Mage::core ファイルを読む時が来たと思いますが、このような単純な作業が非常に複雑であることに対する私の欲求不満を想像できるので、ここで何が起こっているのかを知っている人が私を助けてくれれば幸いです. 前もって感謝します。

4

2 に答える 2

0

私たちのヘッド開発者は、私がそれを機能させるのを手伝ってくれました。理由はまだわかりませんが、これはうまくいったようです

 protected function _prepareCollection()
{
    $quoteId = $this->getRequest()->getParam('id');

    $quote = Mage::getModel('sales/quote')->getCollection()->addFieldToFilter('entity_id', $quoteId);
    if ($quote->getFirstItem()->getId()) {
        $collection = $quote->getFirstItem()->getItemsCollection(false);
    }
$this->setCollection($collection);

    return parent::_prepareCollection();
}
于 2013-03-18T16:30:19.753 に答える
0

I may be wrong, but you can't setCollection() on a quote with sales order items. It has to be populated with sales/quote model items.

I don't know what the scope of $this is in _prepareCollection() but i'm assuming since its on the cart block, its dealing with a quote.

Just a hint, you might instead of print_r($collection), try doing this...

echo "<pre>";
foreach ($collection as $item) {
    var_dump($item->debug());
}

It supplies pretty much just the important info instead of the database structure. You can also check your item type and make sure you are using the correct model for your setCollection method. You can also throw a break; in there if you want to just get the first item etc. Debugging magento objects can be tedious, and i've found that this helps.

于 2013-03-18T14:27:03.373 に答える