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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化