我发现了客户登录事件的问题。我在magento之外有应用程序(flex app),并且有一个客户登录表单。我使用此代码登录客户:
require_once '../../app/Mage.php';
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session');
try {
$session->login ( $_REQUEST['username'], $_REQUEST['password'] );
$return .= '<userid>'.$session->getCustomer()->getId().'</userid>';
} catch (Exception $e) {
$return .= '<error>'.$e->getMessage().'</error>';
}
一切运作良好且客户已登录。问题是调度事件但是Mage :: Visitor和Mage :: Reports没有捕获事件,如果我从flex返回到产品视图页面它会获得MySQL “report_viewed_product_index”表中的错误。任何人都可以帮忙解决这个问题。
谢谢!
答案 0 :(得分:0)
解决了我的问题:How do I create a Magento session outside of Magento?
这是我做过的事情
require_once '../../app/Mage.php';
umask(0);
Mage::app($_REQUEST['store_id'])->init();
$core_session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session');
$return = '<user>';
$write = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_write' );
$url = Mage::getUrl ( '*/*/*', array ('_current' => true ) );
Mage::getSingleton ( 'core/session' )->setLastUrl ( $url );
$visitor_id = $_SESSION ['core'] ['visitor_data'] ['visitor_id'];
if (! empty ( $visitor_id )) {
Mage::getSingleton ( 'log/visitor' )->setId ( $visitor_id );
} else {
Mage::getSingleton ( 'customer/session' )->setWishlistItemCount ( 0 );
Mage::getSingleton ( 'catalog/session' )->setCatalogCompareItemsCount ( 0 );
$write->query ( "INSERT INTO log_url_info (url, referer) VALUES (?, ?)", array ($url, Mage::helper ( 'core/http' )->getHttpReferer ( true ) ) );
$url_id = $write->lastInsertId ();
$log_visitor = Mage::getSingleton ( 'log/visitor' )->initServerData ()->setFirstVisitAt ( now () )->setIsNewVisitor ( true )->setLastVisitAt ( now () )->setLastUrlId ( $url_id )->save ();
$write->query ( "INSERT INTO log_url (url_id, visitor_id, visit_time) VALUES (?, ?, ?)", array ($url_id, $log_visitor->getId (), now () ) );
$core_session->setVisitorData ( $log_visitor->getData () );
$visitor_id = $log_visitor->getId ();
}
try {
$session->login ( $_REQUEST['username_cl_mag'], $_REQUEST['password_cl_mag'] );
//$session->setCustomerAsLoggedIn($session->getCustomer());
//$customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
$customerId = $session->getCustomerId();
$eventModel = Mage::getModel('reports/event');
$eventModel->updateCustomerType($visitor_id, $customerId);
Mage::getModel('reports/product_index_compared')
->updateCustomerFromVisitor()
->calculate();
Mage::getModel('reports/product_index_viewed')
->updateCustomerFromVisitor()
->calculate();
$return .= '<userid>'.$session->getCustomerId().'</userid>';
} catch (Exception $e) {
$return .= '<error>'.$e->getMessage().'</error>';
}
print $return .= "</user>";