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.

asked Apr 11, 2017 at 10:22

1 Answer 1

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>
answered Apr 11, 2017 at 11:11
5
  • please check edit part in question Commented Apr 11, 2017 at 12:01
  • your form is being submitted twice Commented Apr 11, 2017 at 12:10
  • please tell how i can fix the issue ? Commented Apr 11, 2017 at 12:11
  • onSubmit="return false;" add this to form tag Commented Apr 11, 2017 at 12:20
  • sorry buddy, still 2 products only creating...... Commented Apr 11, 2017 at 12:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.