title: Using include method in PHP function in Magento
body: <p>Let's keep it simple so I have my code in <strong>View.phtml</strong> to display javascript element</p>
  
  <pre><code>    $Abowl = '&lt;p id="finalprice"&gt;&lt;/p&gt;';
      echo $Abowl; 
  </code></pre>
  
  <p>And now i want to pass this to another PHP name's <strong>DATA.php</strong>, I tried but it's not working</p>
  
  <pre><code> public function formatPrice($price)
  {
      include'view.phtml';
      return $this-&gt;getQuote()-&gt;getStore()-&gt;formatPrice($Abowl); 
  }
  </code></pre>
  
  <p><strong>UPDATE 1:</strong>
  I tried something like this : </p>
  
  <pre><code>public function formatPrice($price)
  {
      require_once(Mage::getBaseDir() . '\app\design\frontend\neighborhood\default\template\catalog\product\view.‌​phtml');
      return $this-&gt;getQuote()-&gt;getStore()-&gt;formatPrice($Abowl); //this is the source
  }
  </code></pre>
  
  <p><strong>UPDATE 2 :</strong> I had asked a question which said DATA.php do not accept any outsource variable in here : <a href="https://stackoverflow.com/questions/29247520/how-can-i-get-access-to-modify-this-price-function-in-magento/29248999#29248999">How can I get access to modify this price function in Magento</a>
  Does it affect me?</p>
  
  <p><strong>UPDATE 3</strong> : I have modified the function under <strong>\magento\js\varien\product.js</strong> in order to satisfy my client's requirement. It works fine, the discount will apply due to the users information from our database. 
  <img src="https://i.stack.imgur.com/ixGlF.jpg" alt="enter image description here"></p>
  
  <p>But when the customer add an item to cart, it only shows the original price which is $549.47 in this example.</p>
  
  <p><img src="https://i.stack.imgur.com/ML7S6.jpg" alt="enter image description here">  </p>
  
  <p>Therefore, i want to pass the javascript result to the DATA.php as well since It is contain the formatPrice function which apply to the shopping cart section</p>
  
  <p><strong>Here's part of my javascript codes(\magento\js\varien\product.js) which generate the discounted price:</strong></p>
  
  <pre><code>var subPrice = 0; //is the price inside the option
              var subPriceincludeTax = 0;
              var discountRate = discountRateUrl; //discount base on database
              var price = priceUrl;//get the product price
              var discountedPrice = price*discountRate; // price * ourdiscount
              //var discountedSubPrice = subPrice*((100-test)/100); // custom option addition price * ourdiscounted prices
              //console.log(discountedPrice); //display the prices as int
              //console.log(discountedSubPrice);
              //console.log(test);
              Object.values(this.customPrices).each(function(el){
                  if (el.excludeTax &amp;&amp; el.includeTax) {
                      subPrice += parseFloat(el.excludeTax); // use the var factor &amp;&amp; this will affect the price when changing option *important
                      subPriceincludeTax += parseFloat(el.includeTax);
  
                  } else {
                      subPrice += parseFloat(el.price);
                      subPriceincludeTax += parseFloat(el.price);
  
                  }
                  var finalprice = (subPrice*discountRate+discountedPrice);//checking if getting the php
                  var fomattedprice = finalprice.toFixed(2); //Convert a number into a string, keeping only two decimals
                  console.log(finalprice); //tester of the final prices
                  console.log(discountRate);//tester discount rate in string
                  document.getElementById("finalprice").innerHTML = "&lt;small&gt;Your price is &lt;/small&gt;"+ "$" + fomattedprice + "*" +"&lt;br/&gt;&lt;small&gt;&lt;em&gt;*Discount will be applied during check out&lt;/em&gt;&lt;/small&gt;";
            });
  </code></pre>
  
  <p>You can ignore these bunch of codes, i just want to know where should i pass my <code>document.getElementById("finalprice");</code> result in order to show the discounted price.</p>
  
  <p>The follow is my view.html for reference:</p>
  
  <pre><code>  &lt;?php 
          //SQL to identify ones email and discount
          $prices = Mage::helper('core')-&gt;currency($_product-&gt;getPrice(), $formatPrice, $html);
          echo $this-&gt;getChildHtml('product_type_data');
          if(Mage::getSingleton('customer/session')-&gt;isLoggedIn()) {
          $customerData = Mage::getSingleton('customer/session')-&gt;getCustomer();
  
          $conn = Mage::getModel('core/resource')-&gt;getConnection('core_read');
  
          //need to change this sql statment to other table, took up and sl.is_active = 1 for test only
          //it won't work by now because method is changed and not connecting to the right DB table
          $sql = 'select sl.discount_amount, scg.customer_group_id, sl.stop_rules_processing from salesrule sl
                  join salesrule_customer_group scg on scg.rule_id = sl.rule_id
                  join customer_entity ce on ce.group_id = scg.customer_group_id
                  where ce.email = "'.$customerData-&gt;getemail().'" 
                  order by sl.discount_amount desc';
          //and sl.is_active = 1
  
          //'select sl.discount_amount from salesrule sl 
                  //  join salesrule_customer_group scg on scg.rule_id = sl.rule_id
                  //  join customer_entity ce on ce.group_id = scg.customer_group_id
                  //  where ce.email = "'.$customerData-&gt;getemail().'";';
  
          $results = $conn-&gt;fetchAll($sql);
  
          $Abowl = '&lt;p id="finalprice"&gt;&lt;/p&gt;';
          echo $Abowl; //only applied when not logged in
  
          $discountRate = 1;
          foreach ($results as $result)
          {   
  
              $currentRate = $result['discount_amount'];
              //print_r($currentRate);
              $discountRate = $discountRate*(100 - $currentRate)/100;
  
              if($result['stop_rules_processing']==1){
                  break;
              }
  
          }
  
          }   ?&gt;
  </code></pre>