Thursday 24 December 2015

How to implement mail system in your custom magento module


First Add new Template in Magento Admin > System > Transactional Email > Add New Template.
For Customer Registration load default registration Template from Local, modify as requirement then save it.

Use below code in your save function of module controller where you need.




$customer = Mage::getModel('customer/customer')->load($customer_id);

$templateId = 9; /* get template ID from magento admin > System > tramsactional Emails */
$sender = Array('name' => Mage::getStoreConfig('trans_email/ident_sales/name'),
'email' => Mage::getStoreConfig('trans_email/ident_sales/email'));

$password = '123Q3!34'; /* generate random password */
$email = $customer->getEmail();
$customer_name = $customer->getFirstname().' '.$customer->getLastname();

$emailName = $customer->getFirstname();
$vars = Array('customer_name'=>ucfirst($customer->getFirstname().' '.$customer->getLastname()),'customer_password'=>$password, 'customer_email'=>$customer->getEmail(),);
/* Note : variables should be  same as in Template */

$storeId = Mage::app()->getStore()->getId();
$translate = Mage::getSingleton('core/translate');

$mail = Mage::getModel('core/email_template');

$mail->addBcc($BCCMail);
$mail->sendTransactional($templateId, $sender, $email, $emailName, $vars, $storeId);

Saturday 5 December 2015

Resources to install Magento 2

Resource :

  • Apache 2.2 or 2.4
  • PHP 5.6.x or 5.5.x (PHP 5.4 is not supported)
  • MySQL 5.6.x
  • Cron must be enable in server
  • Must enable server rewrites in Apache web server


server permissions :

UNIX systems require root privileges to install and configure software like a web server, PHP, and so on. If you need to install this software, make sure you have root access.

You should not install the Magento software in the web server docroot as the root user because the web server might not be able to interact with those files.

You’ll also need root privileges to create the Magento file system owner and add that owner to the web server’s group. You’ll use the Magento file system owner to run any commands from the command line and to set up the Magento cron job, which schedules tasks for you.


Note : I recommend changing the default Admin URL from admin to something else

How to disable “save address book” in checkout process?

Go to file "checkout/onepage/billing.phtml" Remove bellow code at line 30

and remove if condition at line 38
Also Remove below code at Line 173 :

Note : Must have a backup of billing.phtml before editing.

Thursday 3 December 2015

How to validate my radio button fields using magento?

If you are using magento form validation add class(magento-checkbox-validation) in your radio inputs(of same group):
class="magento-checkbox-validation" OR use "validate-one-required" on
 the last radio/checkbox in the group


And if you are writing your custom script then add this function in script :

 function validateRadioIsSelected()
{
 var options = $$('input.Classname');
    for( i in options ) {
        if( options[i].checked == true ) {
            return true;
        }
    }
    return false;
}

if above function return true, it means your radio is selected

Saturday 21 November 2015

To get product collection by category ID in Magento

Open your PHTML file of active template and use this code :
$categoryIds = array(Mage::registry('current_category')->getId());//category id


$_productCollection = Mage::getModel('catalog/product')
 ->getCollection()
 ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
 ->addAttributeToSelect('*')
 ->addAttributeToFilter('status','1')
 ->addAttributeToFilter('category_id', array('in' => $categoryIds));
?>
if(!$_productCollection->count()): 
     foreach ($_productCollection as $_product): 
       $product =  Mage::getModel('catalog/product')->load($_product->getId());
            $_product->getName() ;
    endforeach;
 endif; 

For all products of your current store :


$collection = Mage::getModel('catalog/product')->getCollection()->addStoreFilter($store_id); // default store Id is 1

   $collection ->setPageSize(6);

Note : if you want to get Products outside the magento, just call app/Mage.php file in your file, and use above codes.