Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating products with custom options in Magento Programming

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 302
    Comment on it

    we can create products with custom options by programming in Magento follow the steps :

    1. Create a form to submit all mandatory details to create a products
    2. Post all details to form controller to save product

      public function saveproductAction()
       { 
       $param            =   $this->getRequest()->getPost();
          $categoryId        =   $_REQUEST['catId'];
          $productName   =   $_REQUEST['ProductName'];
          $productDesc   =   $_REQUEST['productDesc'];
          $productPrice  =   $_REQUEST['productPrice'];
          $productQty        =   $_REQUEST['productQty'];
          $options       =   array();
          $option            =   array();
          for($i=0;$i";
              $options[$j]['title'] = $param['choicetitle'][$i][$j]['title'];
              $options[$j]['price'] = $param['choicetitle'][$i][$j]['price'];
              $options[$j]['price_type']    = 'fixed';
              $options[$j]['sort_order']    = '1';
              }
      
          $option[$i]['title']      = $param['choicetitle'][$i]['choice'];//adding no of choices
          $option[$i]['type']       = $param['choicetype'][$i]['type'];
          $option[$i]['is_require'] = 0;
          $option[$i]['sort_order'] = $i;
          $option[$i]['values']     = $options;
          }
          $newproduct    = new Mage_Catalog_Model_Product();
              $newproduct->setTypeId('simple');
              $newproduct->setWeight(10);
              $newproduct->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
              $newproduct->setStatus(1);
              $newproduct->setSku($productName.time());
              $newproduct->setTaxClassId(2);
              $newproduct->setCategoryIds($categoryId);
              $newproduct->setWebsiteIDs(array(1));
              //$newproduct->setStoreIDs(array(1));
              $newproduct->setStockData(array(
              'is_in_stock' => 1,
              'qty' =>$productQty,
              'manage_stock' => 1
              ));
              $newproduct->setAttributeSetId(4);
              $newproduct->setName($productName);
              $newproduct->setDescription($productDesc);
              $newproduct->setShortDescription($productDesc);
              $newproduct->setPrice($productPrice);
              $newproduct->setProductOptions($option);
              $newproduct->setCanSaveCustomOptions(true);
              try{
              $newproduct->save();
              //echo "Success";
              $this->_redirect('manager/account/dashboardedit/');
              }
              catch (Exception $e){
              echo $e->getMessage();
            }
      
       }
      

      By using this code we can add SELECT, CHECKBOX, RADIO type options to product

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: