Browsing articles in "Magento admin"
Sep 2, 2014
kalpesh

Magento set session cookie lifetime to 1 day

Is your Magento shopping cart kicking out all the items after 24 minutes? Are you frustrated because your customer’s cart items are getting flushed every few hours even though you have correct setting in Magento? Do you want to increase your shopping cart sessions to last for 1 day (or anything you wish)?

Here are the things to look for to increase/decrease Magento’s session cookie lifetime.

In your php.ini file:

1
session.gc_maxlifetime 86400

If you have not changed this, it should be by default 1440 i.e. 24 minutes. Change it to 86400 for one day session lifetime

In your Magento admin:

1
2
System -> Configuration -> Checkout -> Shopping Cart
Quote Lifetime (days) -> 1
1
2
System -> Configuration -> Web -> Session Cookie Management
Cookie Lifetime -> 86400

Make sure to check if you are in correct website/store if using multi-website/multi-store Magento setup. You can change the scope by changing the website/store from the upper left Store Switcher drop down in System -> Configuration screen.

If you are changing php.ini value, make sure you reload apache to reflect the changes.

Aug 13, 2013
kalpesh

Magento convert attribute type from TEXT to DROPDOWN

Magento convert attribute type from TEXT (varchar) to DROPDOWN / SELECT (int) in Backend.
Magento doesn’t have this in-built so we will have to do it in our own way. We will convert our existing attribute which is in TEXT type, to DROPDOWN (select). Let’s say our attribute code is “vendor”, you will need to replace it with your own attribute code in all the code below.

WARNING: All the coupon codes that uses this attribute for discounts/promotions will GO AWAY! Please note down all the coupon code Conditions and Actions (which uses this attribute) before converting the attribute.

Step 1.) Backup your database.

1
mysqldump -u mysqluser -p mysqldbname > mysqldbname_backup.sql

Step 2.) Export all the values of the attribute you want to convert in a CSV file. For that, create a file vendor.php (your_attribute.php) in your magento root with following code inside it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
require "app/Mage.php";
umask(0);
Mage::app();

$collection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('sku')
                        ->addAttributeToSelect('vendor'); //replace vendor with your attribute code

$data = $collection->getData();

foreach ($data as $product) { 
    echo $product['entity_id'] . "," . $product['vendor']."\n";
}

After saving the above code, run it from command line:

1
php vendor.php > vendor.csv

You should now have all the attribute’s data with product ID in the vendor.csv (your_attribute.csv) file.

Step 3.) Now get all the unique values you have in the attribute’s data, which we will be filling them as options of select dropdown.
Run following mysql command to get all the unique values and copy them in a new file:

1
select distinct value from catalog_product_entity_varchar where attribute_id in (select attribute_id from eav_attribute where attribute_code='vendor'); //replace vendor with your own attribute code

After this step, we have all the attribute’s data in CSV file, and all the UNIQUE attribute values.
Continue reading »

Aug 11, 2013
kalpesh

Magento how to remove order

First of all, removing live orders is not recommended. But if you are sure you want to remove orders (test orders?) then you can do so by custom script below. Get the order increment id(s) of the order you wish to delete from Magento. Remember, once order is deleted you can’t get any related information of that order.

Create a test PHP file in your Magento project root with below code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
require 'app/Mage.php';
Mage::app('admin')->setUseSessionInUrl(false);                                                                                      

$orderIncrementIDs = array('100000001','100000002'); //your order increment ids to delete, beware!
$rmvd = array();

foreach($orderIncrementIDs as $ordID){
    try{
        Mage::getModel('sales/order')->loadByIncrementId($ordID)->delete();
        $rmvd[] = $ordID;
    } catch(Exception $e){
        echo 'Error: '.$e->getMessage().'<br />';
    }
}
echo "Following Orders Removed!<br />" . implode(", ",$rmvd);

and run the file to delete the order(s).
Continue reading »

Jul 21, 2013
kalpesh

Magento redirect from observer

Redirection in observer doesn’t work normally as it do in Blocks, templates and controllers. Also there is no standard code to redirect from observer that works in every situation.

You will need an argument to achieve redirect when using below code:

1
2
3
4
public function observingMethod(Varien_Event_Observer $observer)
{
    $observer->getRequest()->setParam('return_url',$urlToRedirect);
}

Note that $observer object should have getRequest() method to make above code work. You may need to use $observer->getEvent()->getFront()->getRequest() otherwise, or simply var_dump/Mage::log $observer to get better idea what methods the object have.

Or you can use below code which is not recommended: Continue reading »

Jul 19, 2013
kalpesh

Magento products not showing in categories

If your Magento products are not showing up in frontend category pages, that can be because one or more of the below points are not done correctly.

The products must have following set correctly to appear in the category pages in frontend. You can check all the below things in Manage Products screen of any individual product.
Status must be Enabled (under General tab)
Visiblility should be Catalog OR Catalog, Search (under General tab)
– Stock Qty (quantity) should be greater than Qty for Item’s Status to Become Out of Stock (under Inventory tab)
Stock Availability must be IN STOCK
Category should be assigned (under Categories tab)
Website must be assigned (under Websites tab)

Clear the cache, re-index the indexes related to product (Product prices, Product flat data and Category products) and everything should work as expected.

This post is written to address the following issue:
magento products not displaying in categories
magento products not showing in categories
magento items not showing in categories
magento products not showing up in categories
magento products not showing under categories
magento products not displaying on category page
magento product images not showing in category
magento configurable product not showing in category
magento new product not showing in category

If you are unable to see Product Images in frontend category pages, check this blog post to resolve it: http://ka.lpe.sh/2013/02/26/magento-cant-see-product-images-in-category-page/

Pages:«1234567...12»

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications