在一页中从两个模型获取数据-Magento [英] Get data from two models in one page - Magento

查看:95
本文介绍了在一页中从两个模型获取数据-Magento的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我解决以下两个问题吗?

Could someone help me with the following two questions?

  1. 如何在下面的查询中对Websiteid进行过滤?
  2. 是否可以在一个文件中从两个集合中获取数据?最后一个值"company"应该来自已被注释掉的客户地址模型.

<?php function getcustomers() 
{
  /* Magento's Mage.php path
   * Mage Enabler users may skip these lines
   */
  require_once ("app/Mage.php");
  umask(0);
  Mage::app("nl");
  /* Magento's Mage.php path */

  /* Get customer model, run a query */
  $collection = Mage::getModel('customer/customer')
  //$collection = Mage::getModel('customer/address')
    ->getCollection()
    ->addAttributeToSelect('*');

  $result = array();
  foreach ($collection as $customer) { $result[] = $customer->toArray();  }

  return $result; 
} 
?>

<html>
<head>
  <title>Customers</title>
  <style>    table {border-collapse: collapse;} 
  td {padding: 5px;   border:1px              solid             #000000;}
  </style>
</head>
<body>
<table>
<tr>
<td>ID</td>
<td>Lastname</td>
<td>Firstname</td>
<td>Email</td>
<td>Is Active?</td>
<td>Date Created</td>
<td>Date Updated</td>
<td>Website ID</td>
<td>Store ID</td>
<td>Zip Code</td>
</tr>
<?php
   $result = getcustomers();
   if(count($result) > 0)
   {
     foreach($result as $key => $value)
     {
       echo "<tr>";
       echo "<td>".$value['entity_id']."</td>";
       echo "<td>".$value['lastname']."</td>";
       echo "<td>".$value['firstname']."</td>";
       echo "<td>".$value['email']."</td>";
       echo "<td>";
       echo $value['is_active'] == 1 ? "Yes" : "No";
       echo "</td>";
       echo "<td>".$value['created_at']."</td>";
       echo "<td>".$value['updated_at']."</td>";
       echo "<td>".$value['website_id']."</td>";
       echo "<td>".$value['store_id']."</td>";
       echo "<td>".$value['zipcode']."</td>";
       echo "</tr>";
     }
   }
   else
   {
     echo "<tr><td colspan=\"7\">No records found</td></tr>";
   }
   ?>
   </table>
   </body>
   </html>

推荐答案

在这里,也许试试看?同样,我不确定这是否行得通,但我认为它的方向正确.

Here, maybe try this? Again I'm not sure if this will work, but I think its in the right direction.

<?php 

$collection1 = Mage::getModel('customer/customer')->getCollection();
$collection2 = Mage::getModel('customer/address')->getCollection();

$merged_ids = array_merge($collection1->getAllIds(), $collection2->getAllIds());

$merged_collection = Mage::getResourceModel('customer/customer_collection')
    ->addFieldToFilter('customer_id', $merged_ids)
    ->addAttributeToSelect('*')
    ->addStoreFilter();


?>

这篇关于在一页中从两个模型获取数据-Magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆