title: Magento discount coupon code created on fly but not working properly
body: <p>Here is my code which create the coupon code on the fly:</p>
  
  <pre><code>$productId  = (int) $this-&gt;getRequest()-&gt;getParam('id'); 
          $discountprice=$_POST['product']['discountprice']; 
          $model = Mage::getModel('salesrule/rule');
          $couponCode=generateUniqueId(8);
          $model-&gt;setName($couponCode);
          $model-&gt;setCouponCode($couponCode);
          $model-&gt;setDescription('Discount coupon for Surger.');
          $model-&gt;setUsesPerCoupon(1);
          $model-&gt;setUsesPerCustomer(1);
          $model-&gt;setCustomerGroupIds('0,1');
          $model-&gt;setIsActive(1);
         // $model-&gt;setConditionsSerialized('a:6:{s:4:\"type\";s:32:\"salesrule/rule_condition_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
          //$model-&gt;setActionsSerialized('a:6:{s:4:\"type\";s:40:\"salesrule/rule_condition_product_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
          $model-&gt;setStopRulesProcessing(0);
          $model-&gt;setIsAdvanced(1);
          $model-&gt;setProductIds($productId);
          $model-&gt;setSortOrder(1);
          $model-&gt;setSimpleAction('by_percent');
          $model-&gt;setDiscountAmount($discountprice);
          $model-&gt;setDiscountStep(0);
          $model-&gt;setSimpleFreeShipping(0);
          $model-&gt;setTimesUsed(0);
          $model-&gt;setIsRss(0);
          $model-&gt;setWebsiteIds('1');
          $model-&gt;save();
  </code></pre>
  
  <p>but when I checkout particular product the discount apply automatically, my requirement is the discount must be apply after I enter the code in the Discount Codes box, also when I enter the code in Discount Codes it shows the code is not valid...</p>
  
  <p>Please help anyone. I am also trying my best to solve this; if I find any solution I'll put here.</p>