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.
1 Answer 1
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 questionBaby in Magento– Baby in Magento2017年04月11日 12:01:19 +00:00Commented Apr 11, 2017 at 12:01 -
your form is being submitted twiceNalin Savaliya– Nalin Savaliya2017年04月11日 12:10:58 +00:00Commented Apr 11, 2017 at 12:10
-
please tell how i can fix the issue ?Baby in Magento– Baby in Magento2017年04月11日 12:11:24 +00:00Commented Apr 11, 2017 at 12:11
-
onSubmit="return false;"add this to form tagNalin Savaliya– Nalin Savaliya2017年04月11日 12:20:22 +00:00Commented Apr 11, 2017 at 12:20 -
sorry buddy, still 2 products only creating......Baby in Magento– Baby in Magento2017年04月11日 12:22:29 +00:00Commented Apr 11, 2017 at 12:22