Blog

Home / Blog

Import And Export Mysql Heavy Database

MySql
Exporting and Importing database through PhpMyadmin is only good if you have small database. But you want to import and export big database then it is not possible. Here I show you script which is easily import and export heavy mysql database. Import big mysql database [php] <?php $mysqlDatabaseName ='MyDBName'; $mysqlUserName ='username'; $mysqlPassword ='yourPassword'; $mysqlHostName ='localhost'; $mysqlImportFilename ='db.sql'; $command='mysql -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' < ' .$mysqlImportFilename; exec($command,$output=array(),$worked); switch($worked){ case 0: echo 'Import file <b>' .$mysqlImportFilename .'</b> successfully imported to database <b>' .$mysqlDatabaseName .'</b>'; break; case 1: echo 'Error during import. Please make sure the import file is saved in the same folder as this script and check your mysql details like username, password, host and database name.'; break; } ?> [/php] Export…
Read More

Magento get items in order

Magento
Here, I can show you how you can get information about all items in your magento shopping cart based on order id. How to get product details from order id or sometimes need to get product it, product sku, product name , category id, category name. So its easy to get product from order item based on order number. [php] <?php require 'app/Mage.php'; Mage::app(); $orderNumber = 100004544; $order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber); // get order total value $orderValue = number_format ($order->getGrandTotal(), 2, '.' , $thousands_sep = ''); // get order item collection $orderItems = $order->getItemsCollection(); foreach ($orderItems as $item){ $product_id = $item->product_id; $product_sku = $item->sku; $product_name = $item->getName(); $_product = Mage::getModel('catalog/product')->load($product_id); $cats = $_product->getCategoryIds(); $category_id = $cats[0]; // just grab the first id $category = Mage::getModel('catalog/category')->load($category_id); $category_name = $category->getName(); echo "orderNumber=".$orderNumber."<br/>"; echo…
Read More

Magento category product count

Magento
Many times we need to show product count per category in magento. So here I am showing to how many products (Product count) in that categories. First of all I get all categories based on category position with ascending order and then get product count for that category. It shows like below example: Laptops (4) Hard Drives (4) Root Catalog (5) Monitors (4) Shirts (19) Shoes (46) Get category and product count in magento [php] <?php $categories = Mage::getModel('catalog/category')->getCollection() ->addAttributeToSelect('name') ->addAttributeToSelect('url_key') ->addAttributeToSelect('my_attribute') ->addAttributeToSelect('position') ->addAttributeToSort('position', 'ASC') ->setLoadProductCount(true) ->addAttributeToFilter('is_active',array('eq'=>true)) ->load(); ?> <?php foreach($categories as $key=>$category): ?> <?php if($category->getName() != ''):?> <?php $prodCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category); // Magento product collection ?> <a href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?></a> (<?php echo $prodCollection->count() ?>)<br/> <?php endif;?> <?php endforeach; ?> [/php] [JWD-Magento-Development]
Read More

Remove all products,categories,customers,orders from magento

Magento
If you want to delete all products, categories, customers and orders or sample data from magento database using phpmyadmin then this is very help to you. Here I show you how you can delete all products from magento database as well as all categories,customers and orders. Delete all products from magento database Below code to delete all product and their related records from magento database. [sourcecode language="plain"] TRUNCATE TABLE `catalog_product_bundle_option`; TRUNCATE TABLE `catalog_product_bundle_option_value`; TRUNCATE TABLE `catalog_product_bundle_selection`; TRUNCATE TABLE `catalog_product_entity_datetime`; TRUNCATE TABLE `catalog_product_entity_decimal`; TRUNCATE TABLE `catalog_product_entity_gallery`; TRUNCATE TABLE `catalog_product_entity_int`; TRUNCATE TABLE `catalog_product_entity_media_gallery`; TRUNCATE TABLE `catalog_product_entity_media_gallery_value`; TRUNCATE TABLE `catalog_product_entity_text`; TRUNCATE TABLE `catalog_product_entity_tier_price`; TRUNCATE TABLE `catalog_product_entity_varchar`; TRUNCATE TABLE `catalog_product_link`; TRUNCATE TABLE `catalog_product_link_attribute`; TRUNCATE TABLE `catalog_product_link_attribute_decimal`; TRUNCATE TABLE `catalog_product_link_attribute_int`; TRUNCATE TABLE `catalog_product_link_attribute_varchar`; TRUNCATE TABLE `catalog_product_link_type`; TRUNCATE TABLE `catalog_product_option`; TRUNCATE TABLE `catalog_product_option_price`; TRUNCATE TABLE `catalog_product_option_title`;…
Read More

Recursive Delete Function

PHP
Sometimes we need to delete any particular directory or all files and sub directory in one specific directory. People who have computer repair training may need to do this from time to time. The following function is useful if you wish to clear out all files and folders in one particular directory. [php] <?php function DELETE_RECURSIVE_DIRS($dirname) { // recursive function to delete // all subdirectories and contents: if(is_dir($dirname))$dir_handle=opendir($dirname); while($file=readdir($dir_handle)) { if($file!="." && $file!="..") { if(!is_dir($dirname."/".$file))unlink ($dirname."/".$file); else DELETE_RECURSIVE_DIRS($dirname."/".$file); } } closedir($dir_handle); rmdir($dirname); return true; } ?> [/php] [JWD-Web-Development]
Read More

How to add SSL certificate magento

Magento
Here I can show how to install SSL certificate in Magento. Before we go to Magento SSL certificate this important to know all what is SSL and why we need this. What is SSL? SSL is an acronym for Secure Sockets Layer, an encryption technology that was created by Netscape. SSL creates an encrypted connection between your web server and your visitors' web browser allowing for private information to be transmitted without the problems of eavesdropping, data tampering, or message forgery. Once you have done the SSL install, you can access a site securely by changing the URL from http:// to https://. When an SSL certificate is installed on a website, you can be sure that the information you enter (credit card or any other information), is secured and only…
Read More

Add New Hook In Prestashop

Prestashop
PrestaShop hooks are great way to insert or add data at the most important places or actions of this great e-commerce platform. But may be some time you want to use custom hooks with my custom modules. So here I show you how to implement custom hook? How to create custom hook? Step 1: Register a new hook in FrontController.php open file \classes\FrontController.php and find below code [php] self::$smarty->assign(array( 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_TOP' => Module::hookExec('top'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn') )); [/php] Updated code For add new hook I add this line of code [php]'HOOK_Top_Center' => Module::hookExec('topCenter') // New Hook [/php] So you code look like below. [php] self::$smarty->assign(array( 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_TOP' => Module::hookExec('top'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_Top_Center' => Module::hookExec('topCenter') )); [/php] Step 2: All active hooks are hold in Prestashop…
Read More

Read xml data in php

PHP
PHP: Hypertext Preprocessor programming language, a popular dynamic web page scripting language, features the built-in SimpleXML extension, which simplifies reading and using XML in your PHP scripts. Read an RSS feed, XML office documents, or your own custom XML document. Here we use SimpleXML library, which is not only the best for converting string to XML object but is also built into PHP core so there is no need to install it. Once you have the URL of the XML feed that you are going to use, you need to have PHP load the contents of the feed into a string variable. Using file_get_contents, you could fetch the XML file like so: How to Read an XML File With PHP [php] <?php $xmlStr = file_get_contents('http://www.youdomain.com/feeds/news.xml'); $xmlObj = simplexml_load_string($xmlStr); $arrXml =…
Read More

Override Magento Admin Controller

Magento
When you use magento sometime need to customize some admin core functionality based on requirement. If you want to change core functionality of any controller so you need to override controller action with your controller action. Learning how to perform this action may be helpful to those who have computer forensics degrees. how to override magento admin controller action This example to show you override edit action from ProductController.php is located app/code/core/Mage/Adminhtml/controllers/Catalog Step 1: Create new module from app/etc/Justwebdevelopment_Overridecontroller.xml [sourcecode language="plain"] <?xml version="1.0"?> <config> <modules> <Justwebdevelopment_Overridecontroller> <active>true</active> <codePool>local</codePool> </Justwebdevelopment_Overridecontroller> </modules> </config> [/sourcecode] Step 2: Make config.xml from app/code/local/Justwebdevelopment/Overridecontroller/etc/config.xml [sourcecode language="plain"] <?xml version="1.0"?> <config> <modules> <Justwebdevelopment_Overridecontroller> <version>0.0.1</version> </Justwebdevelopment_Overridecontroller> </modules> <admin> <routers> <adminhtml> <args> <modules> <Justwebdevelopment_Overridecontroller before="Mage_Adminhtml">Justwebdevelopment_Overridecontroller</Justwebdevelopment_Overridecontroller> </modules> </args> </adminhtml> </routers> </admin> </config> [/sourcecode] Using above code you want to override any…
Read More

Move a WordPress One Domain to Another

Wordpress
In some cases user need to move wordpress to subdomain or move wordpress from subdomain to main domain. Students in basic computer classes can learn how to move wordpress to another domain. Here I want to show you how to move wordpress from one domain to another. move wordpress site from subdomain to main domain Please follow this step for moving your wordpress site. 1. Please take backup whole site with database.2. Compress, Download & Upload site files via FTP or SSH (Secure Shell).3. Open wp-config.php and edit with to set your new domain. [sourcecode language="plain"]define('WP_SITEURL', 'http://www.NEW-DOMAIN.com');<br> define('WP_HOME', 'http://www.NEW-DOMAIN.com');[/sourcecode] Put this code at top of the file. 4. Edit wp-config.php with your new Database settings (host, db, user, password) 5. For replace old URL with new URL from your database…
Read More