SHARE
TWEET

Untitled

a guest Jun 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <frontend>
  2. <routers>
  3.     <askstore>
  4.         <use>standard</use>
  5.         <args>
  6.             <module>AdiGh_askStore</module>
  7.             <frontName>estores</frontName>
  8.         </args>
  9.     </askstore>
  10. </routers>
  11. <layout>
  12.     <updates>
  13.         <askstore>
  14.             <file>estores.xml</file>
  15.         </askstore>
  16.     </updates>
  17. </layout>
  18.      
  19. class AdiGh_askStore_AjaxController extends Mage_Core_Controller_Front_Action
  20. {
  21.     public function indexAction()
  22.     {
  23.         $this->loadLayout();
  24.         $this->renderLayout();
  25.     }
  26. }
  27.      
  28. <layout version="0.1.0">
  29. <default>
  30.     <reference name="content">
  31.     </reference>
  32. </default>
  33. <askstore_index_index>
  34.     <reference name="content">
  35.         <block type="askstore/askstore" name="askstore" template="estores/estores.phtml" />
  36.     </reference>
  37. </askstore_index_index>
  38. <askstore_ajax_index>
  39.     <reference>
  40.         <block type="askstore/askstore" name="root" template="estores/estores.phtml" output="toHtml">
  41.     </block>
  42.     </reference>
  43. </askstore_ajax_index>
  44.      
  45. <?php
  46. $theIds = $this->getId();
  47. ?>
  48. <?php echo get_class($this)."<br />"; ?>
  49. <script type="text/javascript">
  50.     function showEmail(str)
  51.     {
  52.         if (str=="")
  53.         {
  54.             document.getElementById("response").innerHTML="";
  55.             return;
  56.         }
  57.         if (window.XMLHttpRequest)
  58.         {// code for IE7+, Firefox, Chrome, Opera, Safari
  59.             xmlhttp=new XMLHttpRequest();
  60.         }
  61.         else
  62.         {// code for IE6, IE5
  63.             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  64.         }
  65.         xmlhttp.onreadystatechange=function()
  66.         {
  67.             if (xmlhttp.readyState==4 && xmlhttp.status==200)
  68.             {
  69.                 document.getElementById("response").innerHTML=xmlhttp.responseText;
  70.             }
  71.         }
  72.         xmlhttp.open("GET","ajax/index/store/q="+str,true);
  73.         xmlhttp.send();
  74.     }
  75. </script>
  76. <form name='myForm'>
  77.     Choose Store:
  78.     <select name="store" id="store" onChange="showEmail(this.value);">
  79.         <option value="">Please select a store</option>
  80.         <?php foreach ($theIds as $i => $theId) : ?>
  81.             <?php
  82.                 $theNames = $this->getName();
  83.                 $theName = $theNames[$i];
  84.             ?>
  85.         <option value="<?php echo $theId; ?>"><?php echo $theName; ?></option>
  86.         <?php endforeach; ?>
  87.     </select>
  88. </form>
  89. <?php echo $this->theResponse() ?>
  90. <?php
  91.  
  92. ?>
  93.  
  94. Email: <div id="response"></div>
  95.      
  96. class AdiGh_askStore_Block_AskStore extends Mage_Core_Block_Template
  97. {
  98.  
  99. public function getId()
  100. {
  101.     $iduri='';
  102.     $collection = Mage::getModel('adigh_askstore/estores')->getCollection()->setOrder('id','asc');
  103.     foreach($collection as $data)
  104.     {
  105.         $iduri .= $data->getData('id') .',';
  106.     }
  107.     Mage::getSingleton('adminhtml/session')->addSuccess('Cool Ca marche !!');
  108.     return explode(',' , $iduri );
  109.  }
  110.  
  111. public function getName()
  112. {
  113.     $name='';
  114.     $collection = Mage::getModel('adigh_askstore/estores')->getCollection()->setOrder('id','asc');
  115.     foreach($collection as $data)
  116.     {
  117.         $name .= $data->getData('name') .',';
  118.     }
  119.     Mage::getSingleton('adminhtml/session')->addSuccess('Cool Ca marche !!');
  120.     return explode(',' , $name );
  121. }
  122.  
  123. public function getEmail()
  124. {
  125.     $email='';
  126.     $collection = Mage::getModel('adigh_askstore/estores')->getCollection()->setOrder('id','asc');
  127.     foreach($collection as $data)
  128.     {
  129.         $email .= $data->getData('email') .',';
  130.     }
  131.     Mage::getSingleton('adminhtml/session')->addSuccess('Cool Ca marche !!');
  132.     return explode(',' , $email );
  133. }
  134. public function theResponse() {
  135.  
  136.     $q = intval($_GET['q']);
  137.  
  138.  
  139.  
  140.     if($q==0)
  141.     {
  142.         echo "store is 0";
  143.     }
  144.     elseif ($q>0){
  145.         $read = Mage::getSingleton( 'core/resource' )->getConnection( 'core_read' ); // To read from the database
  146.         $productTable = Mage::getSingleton( 'core/resource' )->getTableName( 'adigh_askstore/estores' );
  147.  
  148.         $query = "SELECT * FROM " . $productTable . "WHERE id = '".$q."'";
  149.  
  150.         $result = $read->query($query);
  151.         while ( $row = $result->fetch() ) {
  152.             echo 'ID: ' . $row['id'] . '<br>';
  153.             echo 'ID: ' . $row['name'] . '<br>';
  154.             echo 'ID: ' . $row['email'] . '<br>';
  155.     }
  156.  
  157.  
  158.     }
  159.  
  160.     print_r($result);
  161.  
  162.  
  163.  
  164.  
  165. }
  166. }
  167.      
  168. public function storeAction()
  169. {
  170.     $this->getLayout()->getBlockSingleton('askstore/askstore')->theResponse();
  171. }
  172.      
  173. $this->loadLayout();
  174. //$this->renderLayout();   //this is reason for complete page loading
  175. //and for ajax call
  176. $layout = $this->getLayout();
  177. $block = $layout->getBlock('Block_name');
  178. $this->getResponse()->setBody($block->toHtml());
  179.      
  180. function submitAndReloadArea(area, url) {
  181.         if($(area)) {
  182.             var fields = $(area).select('select');
  183.             var data = Form.serializeElements(fields, true);
  184.             url = url + (url.match(new RegExp('\?')) ? '&isAjax=true' : '?isAjax=true');
  185.             new Ajax.Request(url, {
  186.                 parameters: $H(data),
  187.                 loaderArea: area,
  188.                 onSuccess: function(transport) {
  189.                     try {
  190.                         if (transport.responseText.isJSON()) {
  191.                             var response = transport.responseText.evalJSON()
  192.                             if (response.error) {
  193.                                 alert(response.message);
  194.                             }
  195.                             if(response.ajaxExpired && response.ajaxRedirect) {
  196.                                 setLocation(response.ajaxRedirect);
  197.                             }
  198.                         } else {
  199.                             $(area).update(transport.responseText);                                
  200.                         }
  201.                     }
  202.                     catch (e) {
  203.                         $(area).update(transport.responseText);
  204.                     }
  205.                 },
  206.                 onLoading: function() {
  207.  
  208.                             });
  209.                     },
  210.                 onComplete: function() {
  211.  
  212.                     }
  213.             });
  214.         }
  215.     }
  216.      
  217. public function reloadSomethinglsAction()
  218. {
  219. $html = $this->getLayout()->createBlock('mymodule/block','mymodule_alias',array('template' => 'template_folder/mytemplate.phtml'))
  220.             ->setSometing($something)->toHtml();
  221.  
  222.     $translate = Mage::getModel('core/translate_inline');
  223.     if ($translate->isAllowed()) {
  224.         $translate->processResponseBody($html);
  225.     }      
  226.     $this->getResponse()->setBody($html);
  227. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top