Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6997101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:14:29+00:00 2026-05-27T20:14:29+00:00

Similar questions here didn’t helped me with my problem, so I’ll just ask by

  • 0

Similar questions here didn’t helped me with my problem, so I’ll just ask by myself.

I’ve got a php file which creates an attribute (Drop-Down) and a php file which creates options for it.

Now I want to create a php file which generates me a simple product for magento with one or more attributes (which were created before)

Here’s my piece of code to generate the data for it:

$code = "\$newProductData = array(  
          " . ((!empty($name)) ? "'name' => '$name', " : "") . "
          " . ((!empty($websites)) ? "'websites' => '$websites[0]', " : "") . "
          " . ((!empty($description)) ? "'description' => '$description', " : "") . "
          " . ((!empty($description_short)) ? "'description_short' => '$description_short', " : "") . "
          " . ((!empty($price)) ? "'price' => '$price', " : "") . "
          " . ((!empty($type)) ? "'type' => '$type', " : "") . "
          " . ((!empty($status)) ? "'status' => '$status', " : "") . "
          " . ((!empty($weight)) ? "'weight' => '$weight', " : "") . "
          " . ((!empty($tax_class_id)) ? "'tax_class_id' => '$tax_class_id', " : "") . "
          " . ((!empty($categories)) ? "'categories' => '$categories', " : "") . "
          " . ((!empty($manufacturer)) ? "'manufacturer' => '$manufacturer', " : "") . "
          " . ((!empty($color)) ? "'color' => '$color', " : "") . "
          " . ((!empty($url_key)) ? "'url_key' => '$url_key', " : "") . "
          " . ((!empty($url_path)) ? "'url_path' => '$url_path', " : "") . "
          " . ((!empty($visibility)) ? "'visibility' => '$visibility', " : "") . "
          " . ((!empty($news_from_date)) ? "'news_from_date' => '$news_from_date', " : "") . "
          " . ((!empty($news_to_date)) ? "'news_to_date' => '$news_to_date', " : "") . "
          " . ((!empty($special_price)) ? "'special_price' => '$special_price', " : "") . "
          " . ((!empty($special_from_date)) ? "'special_from_date' => '$special_from_date', " : "") . "
          " . ((!empty($special_to_date)) ? "'special_to_date' => '$special_to_date', " : "") . "
          " . ((!empty($meta_title)) ? "'meta_title' => '$meta_title', " : "") . "
          " . ((!empty($meta_keyword)) ? "'meta_keyword' => '$meta_keyword', " : "") . "
          " . ((!empty($meta_description)) ? "'meta_description' => '$meta_description', " : "") . "
          " . ((!empty($enable_googlecheckout)) ? "'enable_googlecheckout' => '$enable_googlecheckout', " : "") . "
          " . ((!empty($custom_design)) ? "'custom_design' => '$custom_design', " : "") . "
          " . ((!empty($custom_design_from)) ? "'custom_design_from' => '$custom_design_from', " : "") . "
          " . ((!empty($custom_design_to)) ? "'custom_design_to' => '$custom_design_to', " : "") . "
          " . ((!empty($custom_layout_update)) ? "'custom_layout_update' => '$custom_layout_update', " : "") . "
          " . ((!empty($page_layout)) ? "'page_layout' => '$page_layout', " : "") . "
          " . ((!empty($old_id)) ? "'old_id' => '$old_id', " : "") . "
          " . ((!empty($required_options)) ? "'required_options' => '$required_options', " : "") . "
          " . ((!empty($has_options)) ? "'has_options' => '$has_options', " : "") . "
          " . ((!empty($image_label)) ? "'image_label' => '$image_label', " : "") . "
          " . ((!empty($small_image_label)) ? "'small_image_label' => '$small_image_label', " : "") . "
          " . ((!empty($thumbnail_label)) ? "'thumbnail_label' => '$thumbnail_label', " : "") . "
          " . ((!empty($gift_message_available)) ? "'gift_message_available' => '$gift_message_available', " : "") . "
          " . ((!empty($cost)) ? "'cost' => '$cost', " : "") . "
          " . ((!empty($is_in_stock)) ? "'is_in_stock' => '$is_in_stock', " : "") . "
          " . ((!empty($qty)) ? "'qty' => '$qty', " : "") . "
          " . ((!empty($minimal_price)) ? "'minimal_price' => '$minimal_price', " : "") . "
          " . ((!empty($tier_price)) ? "'tier_price' => '$tier_price', " : "") . "
          " . ((!empty($options_container)) ? "'options_container' => '$options_container', " : "") . "
       );";

      /* evaluate code */
      eval($code);

      /* cause i dunno if i could simple add the attributes under the evaluated code, i'm merging  each attribute to main array with product data like productdata = (array)productdata + (array)attributeX */
     /* $attributes[$iteration] = "myattributename like custommanufacturer" */
     /* $attributeoptions[$iteration] = "myoptionname like customname" */
      while($iteration != $attr_count -1)
      {
        $iteration++;
        $attributeData = array($attributes[$iteration] => $attributeoptions[$iteration]);
        $newProductData = array_merge((array)$newProductData,(array)$attributeData);
      }
    if ($proxy->create($type, $set['set_id'], $sku, $newProductData)) 
      {
          $hp_bereich .= "\nsuccess=yes";
          $hp_bereich .= "\nwarning=";
          $hp_bereich .= "\nerrorcode=0";
          $hp_bereich .= "\nSKU=" .$sku;
      } 
      else 
      {
          $hp_bereich .= "\nsuccess=no";
          $hp_bereich .= "\nwarning=Error creating product see scriptblock";
          $hp_bereich .= "\nerrorcode=-2001";
          $hp_bereich .= "\nSKU=" .$sku;
      }

Now here’s the problem:
Product creating : done perfectly
Attribute will be shown on Admin-Panel inside of the Product (Drop-Down with selected Option for it): nope.

Could anyone help me with this problem?

I must create a product from scratch (with few information) including attributes which will be created by the user who’s controlling/filling the php-file with information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:14:29+00:00Added an answer on May 27, 2026 at 8:14 pm

    Firstly, and most importantly, do not use eval. It’s too risky and could allow code injection, if just one of those many variables wasn’t properly validated it could contain attacking code. There is a reason many web hosts disable it completely. In this case there is no benefit to eval, it achieves nothing you cannot do otherwise.


    To make a simple product is very simple indeed.

    Mage::getModel('catalog/product')
        ->setTypeId('simple')
        ->setWebsiteIds($websites)
        ->setName($name)
        ->setDescription($description)
        ->setDescriptionShort($description_short)
        // etc...
        ->save();
    

    The setters are magic methods so you can use any attribute name you like. If the value passed is null the attribute is unset so it is safe to call all those setters unconditionally. If you are building those variables from an array – perhaps using extract() – then it is quicker to use the array directly:

    Mage::getModel('catalog/product')
        ->setTypeId('simple')
        ->addData($array)
        ->save();
    

    If you want to learn how an existing product stores it’s attributes use something like the following:

    $product = Mage::getModel('catalog/product')->load($productId);
    print_r($product->debug());
    

    This is a good debugging technique and reveals a lot. Do this to find how the drop-down attributes are stored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen some similar questions about this around here but I didn't see anything
I have seen similar questions here but I just can't understand them. I am
I saw similar questions here, but I couldn't find solution to my problem. I
Though there are lot of similar questions already asked here, I didn't find the
I've recently encountered a problem, and despite coming across similar questions here alreadt, none
i found few similar questions here but from answers i didn't get the whole
I've posted similar question here , but it was closed because I didn't explained
I've searched a bit and didn't see any similar question, so here goes. How
I've looked at similar questions here but I haven't found one particular to my
I've read similar questions here but I'm still a little confused. MyCollection extends ArrayList<MyClass>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.