Showing posts with label Magento. Show all posts
Showing posts with label Magento. Show all posts

Wednesday, May 29, 2013

How to reset magento Admin user, role and resources permission to all?

scenario 1: All resource permissions were set to none for the admin role
Solution:
Step 1: Get current admin role details
SELECT * FROM admin_role WHERE role_name = 'Administrators' 
/*Administrators - is  Your admin role name*/
Step 2: Remove Existing permissions for the Admin role
/*clean all permission rules*/
DELETE admin_rule
 FROM admin_rule, admin_role
WHERE 
 admin_role.role_name = 'Administrators' /* Your admin role name*/
 AND admin_rule.role_id = admin_role.role_id
Step 3: Update Permission rule for the admin role
INSERT INTO admin_rule (role_id, resource_id, assert_id, role_type, permission)
VALUES ('1','all', '0', 'G', 'allow')
scenario 2: Admin was assignd to a wron role
Solution:
Step 1: Load your user information
    
  SELECT ar.*, au.*
  FROM admin_user AS au
  INNER JOIN admin_role AS ar ON (au.user_id = ar.user_id)
  WHERE au.username = 'username'
Step 2: Load Role information
SELECT * FROM admin_role WHERE role_type = 'G'
Step 3:Update your user for the proper role
UPDATE admin_role SET parent_id = [put selected role_id here] WHERE user_id = [your USER id]

Tuesday, May 21, 2013

How to post data using curl / Zend_Http_Client

using curl
$data = array("name" => "Hagrid", "age" => "36");     
$jsonData = json_encode($data);
$handle = curl_init();
$url = 'http://magento.com/customer/account/login';
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
using Zend_Http_Client
// new HTTP request to some HTTP address
$client = new Zend_Http_Client($url);
// set some parameters
$client->setParameterPost('data', $jsonData);
// POST request
$client->request(Zend_Http_Client::POST);

Tuesday, April 30, 2013

How to get store configuration data from Magento System Configuration?

$configData = Mage::getStoreConfig(
                   'sectionName/groupName/fieldName',
                   Mage::app()->getStore()
               ); 

Wednesday, April 17, 2013

How to create custom page in my account magento page

In your module's config file include your custom layout files using layout updates.

    
 
            
                
                    preferredlocation.xml
                
            
        
   

In your custom layout file include the below script(preferredlocation.xml).
 
  
    
        Preferred Locationpreferredlocation/edit
    
  
    
      
         
          
              
    
 

Display my account navigation links in my account sidebar

In your custom layout file include the below script.
 
  
    
        Preferred Locationpreferredlocation/edit
    
  
    
      
         
          
              
    
 

Thursday, October 11, 2012

Can not login to magento admin and frontend

Im using centos. I had a problem, Magento frontend and admin login doesn’t work and loops back to login with no message. This happens because of session cookie problem. I solved this problem by installing ntp

In your shell type the below command to install ntp

    # yum install ntp

Turn on ntp service

    # chkconfig ntpd on

Synchronize system clock with 0.pool.ntp.org server:

    # ntpdate pool.ntp.org

Start the NTP service:

    # /etc/init.d/ntpd start
 
Now check whether this has solved the cookie problem. If not try the following. comment the below lines in "/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php".

if (!$cookieParams['httponly']) {
 unset($cookieParams['httponly']);
 if (!$cookieParams['secure']) {
  unset($cookieParams['secure']);
  if (!$cookieParams['domain']) {
   unset($cookieParams['domain']);
  }
 }
}

if (isset($cookieParams['domain'])) {
 $cookieParams['domain'] = $cookie->getDomain();
}

Wednesday, April 11, 2012

Thursday, March 8, 2012

How to get special price end date in magento?

Here is the code to get special price end date in magento.
$this->formatDate($product->getSpecialToDate())

How to get special price or offer price in magento?

Here is the code to get special price in magento.
$price = $_product->getPrice();
$specialprice = $_product->getFinalPrice();
if($specialprice != $price)
{
 //your stuff here
 echo $specialprice;
}

Default toggle text in input text box magento

In common web design form we may noticed some help text inside the text field. The help text automatically removed when the user clicks on the input field. It has the benefit of putting the help precisely where the user's looking. Something like this:



Here is the code. Enjoy coding:)

Wednesday, February 1, 2012

Show category description using category id

$ca = $category->load($category_id);
$ca->getProductCollection()->addCategoryFilter($ca)->addAttributeToSelect('*');
echo $ca->getDescription();

Monday, October 17, 2011

"Image type and information need to be specified for each store view" Product Image upload problem in magento 1.6


Solution:

Install magento dull image uploader / No flash image uploader extension (Here). This will help to import images.

That’s all, go to admin panel in Magento admin panel and upload and import product successfully.

How to get products available stock quantity in magento?

Here is the code to get produts stock quantity. Place this code in your view.phtml file.
echo $qtyStock = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();

Thursday, October 6, 2011

How to remove validation on zip code in magento checkout page?

Login to your your magento admin panel then go to System -> Configuration->General. From Country option tab you can see there is an option "Postal code is optional for the following countries" Select the country which you want to Optional/Not validate . then click on save config to save your settings.



That's it you are done.

Tips to use home page url, custom page url and pass query string in Magento CMS Page

{{store url=""}} -> Used to get Store's home page URL.
Resulting in a URL like "http://yourstore.com/"

{{store url="contacts"}} -> Used to get contact us page URL.
Resulting in a URL like "http://yourstore.com/contacts/"

If you want to show custom URL Use direct_url
{{store direct_url="category/subcategory.html"}} -> Used to get custom URL.
Resulting in a URL like "http://yourstore.com/category/subcategory.html"

If you want to pass parameters in query string use _query
{{store direct_url="category/subcategory.html" _query="a=param_a&b=param_b"}} -> Used to Pass query string
Resulting in a URL like "http://yourstore.com/category/subcategory.html?a=param_a&b=param_b"

{{skin url='images/homepageimage.jpg'}} -> Used to get image url

Wednesday, October 5, 2011

How to prevent not logged in users from accessing magento site and force customer to login?

Step 1:
Create and put below content to the file named "redirect.phtml" and place under "/template/page/html/".
Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());  //save requested URL for later redirection
if(!Mage::getSingleton('customer/session')->isLoggedIn()) {  // if not logged in
    header("Status: 301");
    header('Location: '.$this->getUrl('customer/account/login')) ;  // send to the login page
    exit; 
} 
Step 2:
Edit "page.xml" and place the code

after

Step 3:
Edit the below files "template/page/"
1. 1column.phtml
2. 2columns-left.phtml
3. 2columns-right.phtml
4. 3columns.phtml

and Insert the following line at the start of all the files.
echo $this->getChildHtml('auth-redirect')
Step 4:
Now Add exceptions for home, login and cms page.
Edit your "layout/customer.xml"
Add below code
<remove name="auth-redirect" />
under
<customer_account_login>
Also If you want users to be able to create an account, another good one to make public might be place code under
<customer_account_create>
in "layout/customer.xml"
If you want to make the home (front) page public, add the "remove" code to the 

<cms_index_index>
That's it you are done.

Export Magento categories with ID using php script

Copy the code below into a new file "categorywithid.php" and place this file in your root folder
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
Mage::app();

$category = Mage::getModel ( 'catalog/category' );
$tree = $category->getTreeModel ();
$tree->load ();

$ids = $tree->getCollection ()->getAllIds ();

if ($ids) {
 $file = "var/export/catwithid.csv";
 file_put_contents($file,"catId, catName\n");
 foreach ( $ids as $id ) {
   $string = $id . ', ' .$category->load($id)->getName() . "\n";
  file_put_contents($file,$string,FILE_APPEND);
 }
}
Hit Your browser like www.YourDomain.com/categorywithid.php Thats it. You are done. Get the csv file under "var/export/catwithid.csv".

Mass Products Stock levels Update in Magento

Step 1:
Create a CSV with a minimum of 3 columns, the SKU, qty and is_in_stock.
Then save it to "/app/var/import/updateStockLevels.csv".
For instance, we will use,
"sku","qty","is_in_stock"
"prod1","100","1"

Step 2:
Copy the code below into a new file "updateStock.php" and place this file in your root folder
define('MAGENTO', realpath(dirname(__FILE__)));
 require_once MAGENTO . '/app/Mage.php';
 umask(0); $count = 0;
 Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
 
 $file = fopen(MAGENTO . '/var/import/updateStockLevels.csv', 'r');
 while (($line = fgetcsv($file)) !== FALSE) {
   if ($count == 0) {
   foreach ($line as $key=>$value) {
   $cols[$value] = $key;
   }
 }
 
 $count++;
 if ($count == 1) continue;
 
 #Convert the lines to cols
 if ($count > 0) {
   foreach($cols as $col=>$value) {
   unset(${$col});
   ${$col} = $line[$value];
   }
 }
 
 // Check if SKU exists
 $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
 if ( $product ) {
   $productId = $product->getId();
   $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
   $stockItemId = $stockItem->getId();
   $stock = array();
   if (!$stockItemId) {
     $stockItem->setData('product_id', $product->getId());
     $stockItem->setData('stock_id', 1);
     } else {
       $stock = $stockItem->getData();
   }
 
   foreach($cols as $col=>$value) {
   $stock[$col] = $line[$value];
   }
 
   foreach($stock as $field => $value) {
   $stockItem->setData($field, $value?$value:0);
   }
 
 $stockItem->save();
 unset($stockItem); unset($product);
 }
 echo "
Stock updated $sku"; 
}
 fclose($file);

Step 3:
Run the php script in  Your browser like "www.YourDomain.com/updateStock.php".
Thats it. You are done.

How to remove right column sidebar from product view page in Magento?

Edit your theme's "/layout/catalog.xml" file. Find the below lines.

  
      
        
      
You can set your template to 1column like this:
 
or use "<remove name="right"/>" code to remove right sidebar.


  
  
    
      
        
      
After making changes dont forget to refresh the cache. That's it. You are done.

How to remove the Discount Code / Coupon Code box in Magento My cart page?

Solution 1:
Edit your theme's "/layout/checkout.xml" file. Find and Comment the below lines.

Solution 2:
Add new local.xml file under your theme's layout folder.

   
      
   
 
Here, You no need to search for any template or layout file. This code will do the trick. After making changes dont forget to refresh the cache. That's it. You are done.