<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('default');
$resource = Mage::getConfig()->getNode('global/resources')->asArray();
echo '<pre>';
print_r($resource);
echo '</pre>';
$db_host = $resource['default_setup']['connection']['host'];
$db_user = $resource['default_setup']['connection']['username'];
$db_pass = $resource['default_setup']['connection']['password'];
$db_name = $resource['default_setup']['connection']['dbname'];
echo '<br />host : '.$db_host;
echo '<br />username : '.$db_user;
echo '<br />password : '.$db_pass;
echo '<br />dbname : '.$db_name;
?>
If you are searching for the professional web development, app development company in Vadodara then Cloudswift Solutions is the name on which you can trust. Visit our website for more information.
Tuesday, 6 November 2012
Magento - How to get all order details into table format?
<?php
require_once('app/Mage.php');
Mage::app('admin');
Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*');
//->addFieldToFilter('hpc_order_id', array('neq' => '',))
//->addFieldToFilter('hpc_order_from', array('eq' => 'ebay',)));
//->addFieldToFilter('status', 'complete')->load(); //pending,complete
//$collection->addAttributeToSort('created_at', 'desc');
$min_diff = '60';
$from_date = date("Y-m-d H:i:s", strtotime("-".$min_diff." minute"));
$to_date = date("Y-m-d H:i:s");
$collection->addAttributeToFilter('updated_at', array(
'from' => $from_date,
'to' => $to_date
));
/*
echo '<pre>';
print_r($collection);
echo '</pre>';
*/
echo "<br />supplement order start";
echo '<table border="1" style="1px solid #cccccc">';
echo '<tr>';
echo '<th>Order Id</th>';
echo '<th>Order Created at</th>';
echo '<th>Order Updated at</th>';
echo '<th>Order State</th>';
echo '<th>Order Status</th>';
echo '<th>HPC Order ID</th>';
echo '<th>HPC Order from</th>';
echo '</tr>';
foreach ($collection as $col) {
echo '<tr>';
echo "<td>".$col->getIncrementId()."</td>";
echo "<td>".$col->getCreatedAt()."</td>";
echo "<td>".$col->getUpdatedAt()."</td>";
echo "<td>".$col->getState()."</td>";
echo "<td>".$col->getStatus()."</td>";
echo "<td>".$col->getHpcOrderId()."</td>";
echo "<td>".$col->getHpcOrderFrom()."</td>";
echo '</tr>';
}
echo '</table>';
echo "<br />supplement order ends";
require_once('app/Mage.php');
Mage::app('admin');
Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*');
//->addFieldToFilter('hpc_order_id', array('neq' => '',))
//->addFieldToFilter('hpc_order_from', array('eq' => 'ebay',)));
//->addFieldToFilter('status', 'complete')->load(); //pending,complete
//$collection->addAttributeToSort('created_at', 'desc');
$min_diff = '60';
$from_date = date("Y-m-d H:i:s", strtotime("-".$min_diff." minute"));
$to_date = date("Y-m-d H:i:s");
$collection->addAttributeToFilter('updated_at', array(
'from' => $from_date,
'to' => $to_date
));
/*
echo '<pre>';
print_r($collection);
echo '</pre>';
*/
echo "<br />supplement order start";
echo '<table border="1" style="1px solid #cccccc">';
echo '<tr>';
echo '<th>Order Id</th>';
echo '<th>Order Created at</th>';
echo '<th>Order Updated at</th>';
echo '<th>Order State</th>';
echo '<th>Order Status</th>';
echo '<th>HPC Order ID</th>';
echo '<th>HPC Order from</th>';
echo '</tr>';
foreach ($collection as $col) {
echo '<tr>';
echo "<td>".$col->getIncrementId()."</td>";
echo "<td>".$col->getCreatedAt()."</td>";
echo "<td>".$col->getUpdatedAt()."</td>";
echo "<td>".$col->getState()."</td>";
echo "<td>".$col->getStatus()."</td>";
echo "<td>".$col->getHpcOrderId()."</td>";
echo "<td>".$col->getHpcOrderFrom()."</td>";
echo '</tr>';
}
echo '</table>';
echo "<br />supplement order ends";
Magento - Steps to moving magento from one server to other
Step 1:
clear the /var/cache and /var/session directory which is allow more space to you
then add your magento folder into zip/rar file and extract them on the target server.
Step 2:
once you finished with the copying then you should set the correct permissions for
magento files and folders
as
/var and contents should have permissions “777″
/media and contents should have permissions “777″
/app/etc and contents should have permissions “777″
Step 3:
Now important part is that set the new database connection settings in the
file /app/etc/local.xml
as
<resources>
<db>
<table_prefix><![CDATA[db_prefix]]></table_prefix>
</db>
<default_setup>
<connection>
<host><![CDATA[db_host]]></host>
<username><![CDATA[db_user]]></username>
<password><![CDATA[db_password]]></password>
<dbname><![CDATA[db_name]]></dbname>
<initstatements><![CDATA[SET NAMES utf8]]></initStatements>
<model><![CDATA[mysql4]]></model>
<type><![CDATA[pdo_mysql]]></type>
<pdotype><![CDATA[]]></pdoType>
<active>1</active>
</connection>
</default_setup>
</resources>
You need to replace db_prefix db_host db_user db_password etc.. with your values.
Step 4:
Now goto your Database admin panel like phpmyadmin and run the query below
UPDATE core_config_data SET VALUE="http://newhostsite.com/"
WHERE path="web/unsecure/base_url";
UPDATE core_config_data SET VALUE="http://newhostsite.com/"
WHERE path="web/unsecure/base_url";
Where “newhostsite.com” is a new server domain name.
clear the /var/cache and /var/session directory which is allow more space to you
then add your magento folder into zip/rar file and extract them on the target server.
Step 2:
once you finished with the copying then you should set the correct permissions for
magento files and folders
as
/var and contents should have permissions “777″
/media and contents should have permissions “777″
/app/etc and contents should have permissions “777″
Step 3:
Now important part is that set the new database connection settings in the
file /app/etc/local.xml
as
<resources>
<db>
<table_prefix><![CDATA[db_prefix]]></table_prefix>
</db>
<default_setup>
<connection>
<host><![CDATA[db_host]]></host>
<username><![CDATA[db_user]]></username>
<password><![CDATA[db_password]]></password>
<dbname><![CDATA[db_name]]></dbname>
<initstatements><![CDATA[SET NAMES utf8]]></initStatements>
<model><![CDATA[mysql4]]></model>
<type><![CDATA[pdo_mysql]]></type>
<pdotype><![CDATA[]]></pdoType>
<active>1</active>
</connection>
</default_setup>
</resources>
You need to replace db_prefix db_host db_user db_password etc.. with your values.
Step 4:
Now goto your Database admin panel like phpmyadmin and run the query below
UPDATE core_config_data SET VALUE="http://newhostsite.com/"
WHERE path="web/unsecure/base_url";
UPDATE core_config_data SET VALUE="http://newhostsite.com/"
WHERE path="web/unsecure/base_url";
Where “newhostsite.com” is a new server domain name.
Magento - Store Information
Get store data
Mage::app()->getStore();
Store Id
Mage::app()->getStore()->getStoreId();
Store code
Mage::app()->getStore()->getCode();
Website Id
Mage::app()->getStore()->getWebsiteId();
Store Name
Mage::app()->getStore()->getName();
Is Active
Mage::app()->getStore()->getIsActive();
Store Home Url
Mage::app()->getStore()->getHomeUrl();
Mage::app()->getStore();
Store Id
Mage::app()->getStore()->getStoreId();
Store code
Mage::app()->getStore()->getCode();
Website Id
Mage::app()->getStore()->getWebsiteId();
Store Name
Mage::app()->getStore()->getName();
Is Active
Mage::app()->getStore()->getIsActive();
Store Home Url
Mage::app()->getStore()->getHomeUrl();
Magento - Import Manufacturers
1> Create a file in the root of magento dir: manufacturer_import.php
2> Write the following code there:
<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('default');
$_manufacturers = file('manufacturers.txt');
$_attribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'manufacturer');
$manufacturers = array('value' => array(), 'order' => array(), 'delete' => array());
$i = 0;
foreach($_manufacturers as $_manufacturer){
$i++;
$manufacturers['value']['option_' . $i] = array($_manufacturer);
}
$_attribute->setOption($manufacturers);
try{
$_attribute->save();
echo 'Manufacturer successfully imported';
}catch(Exception $e){
echo 'Import Error::'.$e->getMessage();
}
?>
3> Note i have used manufacturers.txt in the root dir with the values of manufacturers in newline format. For example:
Dell
Toshiba
Sony
Fujitsu
Magento Set, Retrieve and Unset Session Variables
To set a Magento session variable:
$myValue = 'Hello World';
Mage::getSingleton('core/session')->setMyValue($myValue);
To Retrieve:
$myValue = '';
$myValue=Mage::getSingleton('core/session')->getMyValue();
To Unset:
Mage::getSingleton('core/session')->unsMyValue();
Note that ‘MyValue’ can be any text you want but ‘set’, ‘get’ and ‘uns’ prefixes are required.
$myValue = 'Hello World';
Mage::getSingleton('core/session')->setMyValue($myValue);
To Retrieve:
$myValue = '';
$myValue=Mage::getSingleton('core/session')->getMyValue();
To Unset:
Mage::getSingleton('core/session')->unsMyValue();
Note that ‘MyValue’ can be any text you want but ‘set’, ‘get’ and ‘uns’ prefixes are required.
Monday, 5 November 2012
Magento important tables
sales_flat_quote -> magento cart master table.
sales_flat_order -> magento order master table.
eav_attribute -> magento attribute master table.
catalog_product_entity -> product master table.
catalog_product_entity_varchar -> product master table values.
catalog_category_entity -> category master table.
catalog_category_entity_varchar -> category master table values.
core_resource -> plugin table.
newsletter_subscriber -> newsletter subscriber master table.
review -> review master table.
review_detail -> review detail table.
customer_entity -> customer main table
wishlist -> wishlist main table.
admin_user -> admin user master table.
cms_block -> cms block master table.
cms_page -> cms page master table.
sales_flat_order -> magento order master table.
eav_attribute -> magento attribute master table.
catalog_product_entity -> product master table.
catalog_product_entity_varchar -> product master table values.
catalog_category_entity -> category master table.
catalog_category_entity_varchar -> category master table values.
core_resource -> plugin table.
newsletter_subscriber -> newsletter subscriber master table.
review -> review master table.
review_detail -> review detail table.
customer_entity -> customer main table
wishlist -> wishlist main table.
admin_user -> admin user master table.
cms_block -> cms block master table.
cms_page -> cms page master table.
Saturday, 3 November 2012
Magento: How to delete test orders in magento
- Login to Admin Panel and go to Sales-->Orders.
- Note down your test order ids, for example: 100000001,100000002,100000003,100000111,100000112,100000199
- Now create a php file in magento root directory and name it: deleteOrders.php
- Now copy below code and paste it in your file:<?php
require 'app/Mage.php';
Mage::app('admin')->setUseSessionInUrl(false); //replace your own orders numbers here:
$test_order_ids=array(
'100000001',
'100000002',
'100000003',
'100000109',
'100000112',
'100000134'
);
foreach($test_order_ids as $id){
try{
Mage::getModel('sales/order')->loadByIncrementId($id)->delete();
echo "order #".$id." is removed".PHP_EOL;
}catch(Exception $e){
echo "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;
}
}
echo "complete."?> - Now go to your browsers address bar and run file from here like:[Your_Magento_Base_URL] /deleteOrders.php
- At the end, delete deleteOrders.php.
That's All.. Cheers :)
How to change the Magento Admin Panel Title?
If you want to change default title of Magento Admin, there is an easy solution:
Just open the main.xml file, which is located in app/design/adminhtml/default/default/layout folder.
Find line like below:
<action method="setTitle" translate="title"><title>Magento Admin</title></action>
and replace the words Magento Admin with the words you like to be in default title.
Hide Attributes which have no value in Magento
Open attribute.phtml, which is located in app/design/frontend/[your package]/[your theme]/template/catalog/product/view folder, and find code like this:
<?php foreach ($_additional as $_data): ?>
<tr>
<th><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
Now replace this by:
<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != ")) { ?>
<tr>
<th><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
<?php foreach ($_additional as $_data): ?>
<tr>
<th><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
Now replace this by:
<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != ")) { ?>
<tr>
<th><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
Magento: How to view Magento version
Create file versionTest.php parallel to index.php in root folder.
Now copy and paste following code in versionTest.php:
<?php
include_once(‘App/Mage.php’);
Mage::app();
echo Mage::getVersion();
?>
Now copy and paste following code in versionTest.php:
<?php
include_once(‘App/Mage.php’);
Mage::app();
echo Mage::getVersion();
?>
Magento - Reset the admin password
UPDATE admin_user SET password=CONCAT(MD5('admin123')) WHERE username='admin';
Script for to remove the cache - Magento
<?php require_once ("app/Mage.php"); umask(0); Mage::run(); Mage::app()->getCache()->clean(); exit("done"); ?>
can call that file with :http://yourdomainname/cache-clear.php
Magento Add Free Shipping promotions to the sidebar my cart block
app/design/frontend/base/default/template/checkout/cart/sidebar.phtml
replace the following code :
replace the following code :
<!--The section we want is around line 48-->
<p>
<?php if ($this->canApplyMsrp()): ?>
<span><?php echo $this->__('ORDER TOTAL WILL BE DISPLAYED BEFORE YOU SUBMIT THE ORDER'); ?></span>
<?php else: ?>
<span><?php echo $this->__('Cart Subtotal:') ?></span> <?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?>
<?php if ($_subtotalInclTax = $this->getSubtotalInclTax()): ?>
<br />(<?php echo Mage::helper('checkout')->formatPrice($_subtotalInclTax) ?> <?php echo Mage::helper('tax')->getIncExcText(true) ?>)
<?php endif; ?>
<?php endif; ?>
</p>
</div>
<?php endif ?>
<!--Here is our conditional statement, if more that $60 in cart, then $free_delivery is less than zero, and first message gets displayed -->
<?php $free_delivery=60-$this->getSubtotal();?>
<?php if ($free_delivery<0): ?>
<br /><p><b>Free UPS Ground delivery with this order!</b></p>
<!--Here is the second part, if less that $60 in cart, then $free_delivery message displays a teaser to add more stuff to cart-->
<?php else: ?>
<br /><p>Free UPS Ground delivery when spending $60 or more!
<!--Here is where the amount they need to spend is displayed-->
<br><b>Spend another <?php echo Mage::helper('checkout')->formatPrice($free_delivery) ?> to get free delivery with this order!</b></p>
<?php endif ?>
<?php if($_cartQty && $this->isPossibleOnepageCheckout()): ?>
Thursday, 1 November 2012
Show subcategory in a category page
If you're comfortable editing your theme, this code snippet will bring you a list of all sub-categories of the current category (from the session, so this should work anywhere in your theme). I typically use this in app/design/frontend/default/*theme_name*/template/catalog/category/view.phtml
<?php
$_category = $this->getCurrentCategory();
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper = Mage::helper('catalog/category');
?>
<ul>
<?foreach ($collection as $cat):?>
<?php if($_category->getIsActive()):?>
<?php
$cur_category = Mage::getModel('catalog/category')->load($cat->getId());
$_img = $cur_category->getImageUrl();
?>
<li>
<a href="<?php echo $helper->getCategoryUrl($cat);?>">
<img src="<?php echo $_img?>" title="$cat->getName()"/>
<cite><?php echo $cat->getName();?></cite>
</a>
</li>
<?php endif?>
<?php endforeach;?>
</ul>
Delete all product from cart
I have add a function in the app\code\core\Mage\Checkout\controllers\CartController.php
if you call this it will delete all item in the cart.
the url should be http://www.yoursite.com/index.php/checkout/cart/deleteall/
public function deleteallAction()
{
$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item)
{
$itemId = $item->getItemId();
$cartHelper->getCart()->removeItem($itemId)->save();
}
$this->_redirectReferer(Mage::getUrl('*/*'));
}if you call this it will delete all item in the cart.
the url should be http://www.yoursite.com/index.php/checkout/cart/deleteall/
Subscribe to:
Posts (Atom)