douluoyou9876 2013-03-21 20:18
浏览 23
已采纳

从Magento集合中提取数据。 我将它分解为一个数组,但试图调用它打破了页面

I'm working on a script that will give a Magento user directions after selecting warehouse pickup (a plugin option). I already have the rest built. I'm simply missing one variable I need to call on success.phtml (the warehouse ID). The variable is tied to orders via stock_id.

This produces an array: I'm using $order successfully to pull the rest of the info I need for the script.

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getItemsCollection();

A shortened version of this array: can be printed with print_r($items->getData());

Array
(
    [0] => Array
        (
            [item_id] => 223
            [stock_id] => 15
            [base_discount_refunded] => 
        )

)

When I try to pull the data that I want out:

echo $items[0]['stock_id']; //the page breaks here and stops the page abruptly... 

the page breaks and any logic that should take place after is ignored. What would cause this? I tried braking variables I'm calling in other similar arrays. None of my tests have replicated the page breaking. Why is this specific one breaking the page instead of returning 15?

  • 写回答

2条回答 默认 最新

  • dsxfa26482 2013-03-21 20:40
    关注

    You might try enumerating $items using var_export in your page, instead of print_r so you can see them as they truly exist:

    foreach ($items as $item)
    {
       var_export($item->debug());
    }
    

    This will provide you with the results. Items is an object populated with more objects, not an array and should be treated as such. Try using

    $itemId = $item->getStockId();
    

    or

    $itemId = $item->getData('stock_id');
    

    Both accomplish the same thing.

    FYI.. the debug() function shows relevant info and its built into magento for use with all mage objects.

    EDIT: Try this:

    echo $items[0]->getData('stock_id');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?