JQuery – Ajax request with jQuery
Perform an Ajax request with jQuery: jQuery.ajax({ url: ‘url_of_ajax_request’, success: function(response) { alert(‘Response from url is: ‘ + response) } }); Source: JQuery Ajax
Perform an Ajax request with jQuery: jQuery.ajax({ url: ‘url_of_ajax_request’, success: function(response) { alert(‘Response from url is: ‘ + response) } }); Source: JQuery Ajax
Magento get front controller name: Mage::app()->getFrontController()->getRequest()->getRouteName()
Get a parameter value: $paramValue = $this->getRequest()->getParam($paramName); Get all parameters and values: $allParams = $this->getRequest()->getParams();
Get subcategories of a main category: $_cat = Mage::getModel(‘catalog/category’)->load($cat_id); $_subcats = $_cat->getChildrenCategories(); foreach ($_subcats as $subcat) { echo “<h1>” . $subcat->getName() . “<h1>”; } Get subcategories Ids $subcat_ids = Mage::getResourceSingleton(‘catalog/category_tree’)->load()->getChildren($cat_id, false);
Hack to solve the “404 Not Found error” after magento installation: Replace in the original index.php: Mage::run(”); with Mage::run(‘default’); Instead of ‘default’ can be used the name of default store.
Small hack in file: app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php to correct image url from something like: <img src=”http://www.mysite.com//index.php/admin/cms_wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9Ii9jbGFzc2lmaWVkVUwuanBnIn19/key/f90eef374eaee0f5b76fc9783680c059/” /> into the correct image url. public function getImageHtmlDeclaration($filename, $asIs = false) { $fileurl = $this->getCurrentUrl() . $filename; $mediaPath = str_replace(Mage::getBaseUrl(‘media’), ”, $fileurl); $directive = sprintf(‘{{media url=”%s”}}’, $mediaPath); $directive = $fileurl; if ($asIs) { $html = sprintf(”, $directive); } else {
Add contact form to CMS Pages: {{block type=”core/template” name=”contactForm” form_action=”/contacts/index/post” template=”contacts/form.phtml”}}
Read all files and folders from a directory using scandir: $dir = “/temp”; $files = scandir($dir); print_r($files); Read all files and folders from a directory using opendir: $dir = “/temp/” if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo “Filename: ” . $file . “: filetype: ” .
Create user with mysql command: CREATE USER ‘username’@’localhost’ IDENTIFIED BY ‘password’; Add all privilleges to databases for user: GRANT ALL ON *.* TO ‘username’@’localhost’;
Export database into a file with shell command: mysqldump -u USERNAME -p PASSWORD database > filename.ext; Import database from a file with shell command: mysql -u USERNAME -p PASSWORD database < filename.ext;