Magento: Add new column to Customer Grid in Admin

This article shows how you can add new column to customer grid in Magento 1.x admin. In this example, we will be adding a fetching the fax field value from customer’s billing address and showing in the customer grid in Magento admin. For this, you need to rewrite/override the Adminhtml’s customer_grid block class. Here is … Read more

Magento: Create Order Programmatically

This article show how you can create sales order programmatically through code in Magento 1.x. This code example also includes creating new customer if the customer email is not already registered. It also shows how you can save customer address to the newly created customer. This code has been tested for simple products. Here are … Read more

Magento: Create Customer Programmatically

This article shows how you can programmatically (through code) create customers in Magento 1.x. In this example code, you can find saving customer general information along with saving customer’s billing address and shipping address. Here are the steps followed in the code below: – The code first loads the customer by email. – If the … Read more

Magento: Get Customer Groups

This article shows how to get all customer groups name and id in Magento 1. To get all customer groups, we will be using Mage_Customer_Model_Resource_Group_Collection class. Here’s the code: $collection = Mage::getResourceModel('customer/group_collection'); $customerGroups = $collection->toOptionArray(); // adding a new element to the beginning of customerGroups array array_unshift($customerGroups, array('value'=>'', 'label'=>'Any')); Sample Output: print_r($customerGroups); Array ( [0] … Read more

Magento 2: Set Unset Get Session

This article shows how to create and destroy different types (Checkout, Customer, Catalog) of sessions in Magento 2. As you can see below, there are different types of session classes present in Magento 2. vendor/magento/module-catalog/Model/Session.php vendor/magento/module-newsletter/Model/Session.php vendor/magento/module-persistent/Model/Session.php vendor/magento/framework/Message/Session.php vendor/magento/module-customer/Model/Session.php vendor/magento/module-backend/Model/Session.php vendor/magento/module-checkout/Model/Session.php In below example code, I will be dealing with Catalog, Customer, and Checkout sessions. … Read more

Magento: Delete Customers Programmatically

Here is a quick code to delete customers programmatically in Magento. You can manually delete customers from customer admin grid. But, sometime you might need to do it automatically through code. Here is the full code to do so. This code can be saved in a new file in your Magento root folder and then … Read more

Magento: Clear / Delete Shopping Cart Items of Single or All Customers

Here is the code to delete all shopping cart items of currently logged in single customer: $cart = Mage::getSingleton('checkout/cart'); $quoteItems = Mage::getSingleton('checkout/session') ->getQuote() ->getItemsCollection(); foreach( $quoteItems as $item ){ $cart->removeItem( $item->getId() ); } $cart->save(); If you want to clear all shopping cart items of all customers then you can use the following code: $quoteCollection = … Read more