0

If Registered user click on button, we are creating Product Programatically. but when guest user click on button , its creating product with empty product name

button :

<button onclick="return setproductlogin(\'<?php echo 
Mage::registry("current_product")->getId()?>\',
event);setrequestlogin();" 
id="submit-editorApply-{{rand}}" >SAVE DESIGN</button>

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;
 }

I tried below code, but didt worked for me

if($_category instanceof Mage_Catalog_Model_Category && $_category->getId()):
 $product->setName($originalProduct->getName()); 
 endif;

full controllers : https://pastebin.com/Gn6iMwug

Edit

when Registered user upload image or text and click on "Save Design" button in link , than Product creating with "Product Name".

enter image description here

When Guest user upload image or text and click on "Save Design" button in link , it will ask to login, once Guest login/register , Product is creating with empty Product name

enter image description here

After clicking save design, it redirect to another page :

enter image description here

asked Apr 11, 2017 at 5:49
2
  • Can you add your login popup phtml code? Commented Apr 11, 2017 at 6:46
  • @JaiminSutariya please check : pastebin.com/GR5eyFwK Commented Apr 11, 2017 at 6:48

2 Answers 2

1

This will only resolve your product Name issue.
Update your form action code to below.

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

The product is being created without name is because you are not passing variable id which is required in your createSimpleProductAndRedirect function.

answered Apr 11, 2017 at 6:54
1
  • I thought when we pass : example/amasty/createSimpleProductAndRedirect , than thats going to be enough..... thanks a lot..... Commented Apr 11, 2017 at 7:01
1

I looked through your code and this is normal behavior.

Your $_category variable is never assigned.
This means that the condition $_category instanceof Mage_Catalog_Model_Category will always return false.
Because of that, your line $product->setName($originalProduct->getName()); will never get executed and you end up with a product without a name.
I'm not sure what you are trying to do, because you code looks fuzzy, but I'm sure that's why the problem appears.

answered Apr 11, 2017 at 6:09
4
  • thanks , I will dig deeper on this & come back to you.... Commented Apr 11, 2017 at 6:14
  • updated question, when you get free time, please check once..... Commented Apr 11, 2017 at 6:30
  • you added nothing relevant. I already told you what the problem is. Enable your error reporting and you will see your coding errors on the screen. This is basic PHP. You are using a variable that is not initialized. Commented Apr 11, 2017 at 6:32
  • oh sorry, i will check it..... Commented Apr 11, 2017 at 6:33

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.