once guest user click on button "create",
1) we are creating product programatically and
2) displaying pop up form to enter email id , password and login button.
once click on login button, we are creating new product and assiging that to customer [ as guest will become customer after login ]
what i want to know is once guest user click on "create" button, as we create product programtically, can we keep that product in session or in somewhere and once guest click on login button, can we assign that product to customer ?
is this possible to achieve ?
protected function _createProduct($type, $doSave = true, $originalProduct, $newImagePath = "")
{
Mage::register('isSecureArea',true);
$session = Mage::getSingleton('customer/session');
$result = array(
'success' => false
);
$login ="";
$productId ="";
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
$productId = $this->getRequest()->getPost('product_id');
}
// if (!empty($login['username']) && !empty($login['password'])) {
try {
if(isset($login) && (is_array($login) && !empty($login)) || ($login!="")){
$session->login($login['username'], $login['password']);
$result['redirect'] = $this->_getRefererUrl() ? $this->_getRefererUrl() : Mage::getUrl('customer/account', array(
'_secure' => true
));
$result['success'] = true;
$customerId = Mage::getSingleton('customer/session')->getCustomerId();
}
else{
$customerId = "";
}
$product->setName($originalProduct->getName());
//images
$images = array(
'image' => 'image.png'
);
foreach ($images as $imageType => $imageFileName) {
if ($newImagePath != "") {
$dir = Mage::getBaseDir('media') . DS . 'custom_product_preview/quote/';
$path = $dir . $newImagePath;
} else {
$dir = Mage::getBaseDir('media') . DS . 'example/amasty/';
$path = $dir . $imageFileName;
}
//echo $path."<br>";
if (file_exists($path)) {
try {
if ($imageType == 'image' && $newImagePath) {
Mage::getSingleton('checkout/session')->setNewImagePath($path);
}
$product->addImageToMediaGallery($path, $imageType, false);
}
catch (Exception $e) {
echo $e->getMessage();
}
} else {
echo "Can not find image by path: `{$path}`<br/>";
}
}
//$customerId = Mage::getSingleton('customer/session')->getCustomerId();
// $product->setCreatedByCustomerId($customerId);
$newImagePath = Mage::getSingleton('checkout/session')->getNewImagePath();
if ($doSave)
$product->save();
// To save inside my_designs table
$data = array(
'title' => fav1_id,
'product_id' => $product->getId(),
'customer_id' => $customerId,
'store_id' => 1,
'created_at' => $emaildate,
'value' => $newImagePath
);
$model = Mage::getModel('example/mydesign')->setData($data);
try {
$fav1_id = $model->save()->getId();
//echo "Custom Design saved successfully";
}
catch (Exception $e) {
echo $e->getMessage();
}
// To save inside my_designs end
return $product;
// code for guest
}
catch (Mage_Core_Exception $e) {
switch ($e->getCode()) {
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
$message = Mage::helper('customer')->__('This account is not confirmed.', Mage::helper('customer')->getEmailConfirmationUrl($login['username']));
break;
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
$message = $e->getMessage();
break;
default:
$message = $e->getMessage();
}
$result['error'] = $message;
$session->setUsername($login['username']);
}
catch (Exception $e) {
$result = "ERROR :".$e->getMesage();
}
Mage::unregister('isSecureArea');
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}