Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento资源模型不工作_Magento - Fatal编程技术网

Magento资源模型不工作

Magento资源模型不工作,magento,Magento,我有以下代码: $recipients = Mage::getResourceModel('crm/crm_collection'); $recipients->getSelect() ->joinInner(array( 'link' => $recipients->getTable('crm/bulkMailLink'),

我有以下代码:

$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);
然后记录代码生成的select语句:

$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);
Mage::log("DEBUG: ".((string)$recipients->getSelect()));
上面生成了一个在phpmyadmin中完美执行的工作sql查询,并返回我期望的结果

$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);
然后我记录$recipients的计数

$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);
Mage::log("Loading recipients for queue: {$recipients->count()}");
这就是代码停止的地方。实际上,它甚至不会记录消息。如果我注释掉上面的日志代码并尝试

$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);
foreach ($recipients as $crm)
{
    var_dump($crm);
    die();
}
它不会进入foreach。解析器将在foreach之前停止

$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);
最糟糕的是没有打印错误消息。我被卡住了

$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);
谢谢

无论是
count()
还是
foreach
操作都会触发集合实际
load()
,这意味着执行查询,获取结果集,并尝试在集合的模型类实例上将每个结果设置为
\u data
。实现该项后,collection类将尝试通过
addItem()
将其添加到其内部存储器中

$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);
我怀疑您的集合显式抛出异常,因为结果集中存在重复的主键;有关逻辑,请参见。暂时将其注释掉以进行测试

$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);

要解决此问题,请更改您的查询或在您的集合类中本地重写
addItem()

先生,您是个天才!非常感谢你。
$recipients = Mage::getResourceModel('crm/crm_collection');
            $recipients->getSelect()
                    ->joinInner(array(
                        'link' => $recipients->getTable('crm/bulkMailLink'),
                    ), "link.crm_id = e.entity_id", array(
                        'link_id' => 'link.id',
                    ))
                    ->where("link.queue_id = ? AND link.sent_at IS NULL", $queue->getId());
            $recipients->addAttributeToSelect('title');
            $recipients->addAttributeToSelect('first_name');
            $recipients->addAttributeToSelect('chinese_name');
            $recipients->addAttributeToSelect('last_name');
            $recipients->addAttributeToSelect('email1');
            $recipients->addAttributeToFilter('email1', array('neq'=>''));
            $recipients->setPageSize(100);
            $recipients->setCurPage(1);