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

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.

  • I thought when we pass : example/amasty/createSimpleProductAndRedirect , than thats going to be enough..... thanks a lot..... – Baby in Magento Apr 11 '17 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.

  • thanks , I will dig deeper on this & come back to you.... – Baby in Magento Apr 11 '17 at 6:14
  • updated question, when you get free time, please check once..... – Baby in Magento Apr 11 '17 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. – Marius Apr 11 '17 at 6:32
  • oh sorry, i will check it..... – Baby in Magento Apr 11 '17 at 6:33

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.