1

Once guest user click on button we are creating Product Programtically but issue is every time we click on button its creating 2 products instead of one.

form

 <form action="<?php echo $this->getUrl('example/amasty/createSimpleProductAndRedirect', 
 array('_secure'=>(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']==='on'),
 'id' => Mage::registry('current_product')->getId())) ?>" id="ajaxlogin-login-form">

controllers

protected function _createProduct($type, $doSave=true, $originalProduct, $newImagePath="") 
{       
        $product = Mage::getModel('catalog/product');

        $product->setName($originalProduct->getName()); 
        $product->setDescription('what ever you need here');

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

        if ($doSave)
            $product->save();

        return $product;
    }

full form code : http://pasted.co/d5b63b52

Edit

Once i removed this code from "form" : id="ajaxlogin-login-form , than its creating only one product, but after that once guest click on "save design" button, it will redirect to another page.

3

Replace below code

<script type="text/javascript">
            //<![CDATA[
            var ajaxLoginForm = new VarienForm('ajaxlogin-login-form', true);
            jQuery("#ajaxlogin-login-form").submit(function(e) {
    e.preventDefault();
    if (ajaxLoginForm.validator.validate()) {
        jQuery.ajax({
            type: "POST",
            url: jQuery('#ajaxlogin-login-form').attr('action'),
        }).done(function(result) {
            alert(result);
        }).fail(function() {
            alert('There is some error saving your design.');
        });
    }
});
            //]]>
        </script>

With this

    <script type="text/javascript">
                //<![CDATA[
                var ajaxLoginForm = new VarienForm('ajaxlogin-login-form', true);
                jQuery("#ajaxlogin-login-form").submit(function(e) {
        e.preventDefault();
        if (ajaxLoginForm.validator.validate()) {
            jQuery.ajax({
                type: "POST",
                url: jQuery('#ajaxlogin-login-form').attr('action'),
            }).done(function(result) {
                alert(result);
            }).fail(function() {
                alert('There is some error saving your design.');
            });
        }
return false;
    });
                //]]>
            </script>
  • please check edit part in question – Baby in Magento Apr 11 '17 at 12:01
  • your form is being submitted twice – Nalin Savaliya Apr 11 '17 at 12:10
  • please tell how i can fix the issue ? – Baby in Magento Apr 11 '17 at 12:11
  • onSubmit="return false;" add this to form tag – Nalin Savaliya Apr 11 '17 at 12:20
  • sorry buddy, still 2 products only creating...... – Baby in Magento Apr 11 '17 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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