0
제품을 장바구니에 추가하기 전에 자동으로 사용자를 Magento에 로그인하기 위해 아래 코드를 사용하고 있습니다.Magento 자동 로그인이 때때로 실패 함
경우에 따라 아래 코드는 작동하지만 로그인이 "고집하지"않기 때문에 제품이 장바구니에 추가되지 않습니다. 세션이 문제인 것처럼 보입니다. 오랜 시간 동안 웹 서버를 재부팅하지 않으면 Magento는 생성 된 세션을 "잊어 버린 것"으로 보이며 제품이 장바구니에 아무 것도 추가하지 않기 때문에 아래 코드가 실패합니다. 나는 $ 세션 -> isLoggedIn()에 대한 호출을 추가하는 경우
// This call is actually in a class called Login_model, function called dual_login
// It is shown below.
$lm = new Login_model();
$ret = $lm ->dual_login($Username, $Password);
if ($ret['result'] = 'SUCCESS') {
$product_id = Mage::getModel("catalog/product") -> getIdBySku("$sku");
$product = Mage::getModel("catalog/product") -> load($product_id);
$session = Mage::getSingleton("core/session", array("name" => "frontend"));
$cart = Mage::helper("checkout/cart") -> getCart();
$cart -> addProduct($product, 1);
$session -> setLastAddedProductId($product -> getId());
$session -> setCartWasUpdated(true);
$cart -> save();
$cart_url = $site_url_https . "store/checkout/cart";
header("Location: " . $cart_url);
}
//
// dual_login code below
//
Mage::getSingleton('core/session', array('name'=>'frontend'));
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($Email);
$session = Mage::getSingleton('customer/session');
$session->login($Email,$Password);
$session->setCustomerAsLoggedIn($session->getCustomer());
//
// How can I determine here if the login was actually successful
// and the product can be added to the cart?
//
$ret['result'] = 'SUCCESS';
, 그것은 사실 반환하지만 제품이 여전히 장바구니에 추가되지 않습니다.
Magento에서이 작업을 수행 할 수있는 원인은 무엇이며 어떻게 테스트 할 수있어서 문제가 발생했는지 알 수 있습니까?
아, 알겠습니다. 그러나이 코드는 오랜 시간 동안 작업 해 왔으며 세션이 문제를 일으키는 문제는 경험하지 못했습니다. 웹 서버를 재부팅 할 때 문제가 해결되었습니다. 명백하게 Magento의 세션은 더럽혀지고 있었다. 나는 그것을 조사 할 것이다. – MB34