1

we are hiding the pop up once we click on login "button", but we want to hide only if the login is successfull. [ if user enter correct email id & password ]

Login Form

<form action="<?php echo $this->getUrl('example/amasty/createSimpleProductAndRedirect.....>

<label>Email Address</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" />
<label>password</label>
<input type="password" name="login[password]"  id="pass" />

<button onclick="hideWindow()" id="send2"><?php echo $this->__('Login') ?></button>

controllers

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');
        }
            // echo $login['product_id'];die;
            // 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());


                    $customerId = Mage::getSingleton('customer/session')->getCustomerId();
                    $product->setCreatedByCustomerId($customerId);

                    if ($doSave)
                        $product->save();
                    // To save inside my_designs

                    return $product;                   

                }
                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. <a href="%s">Click here</a> to resend confirmation email.', 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();
                    /
                }
            // } else {
            //     $result['error'] = Mage::helper('customer')->__('Login and password are required.');
            // }
        // }

        Mage::unregister('isSecureArea');
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

        // code for guest end
    }

enter image description here

1 Answer 1

0

You need to use ajax call on button click and check in call that if customer is got logged in. You can manage the popup display as per the ajax response from controller.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.