Sunday 26 July 2015

Steps to Install a Magento Security Patch

This tutorial requires you to have SSH access to your server.

Security patch? Whats that!

Every time there is a major leak discovered in Magento, the company releases a patch that fixes the issue. The patch is a small .sh file that you can upload to your server, and execute with a SSH command, we’ll get to that later. The reason why Magento releases these patches is that they can be applied very quickly. We have upgraded some very big Magento stores and it’s a long process that takes a lot of time. Especially if the Magento store has a lot extensions that might not be compatible with a newer version of the CMS. Patches save time, they only fix whats broken and nothing else.

How to install a Magento patch

Installing a patch is very simple. First, you have to go to the Magento downloads page to download the correct patch for your Magento version. After the download has finished you’ll have a compressed folder. Unzip the folder and you should see a .sh file. Log in to your FTP client and connect to your host. Upload the .sh file in the root folder of your Magento installation.
The second step is also the last step (we told you, patches are a very quick solution ;)). Log in to your server via SSH, and navigate to the root folder where your Magento installation is located. In the root folder, execute the following SSH command:
Thats all there is to it. If you have executed this command correctly, the following message wil be displayed:

Friday 17 July 2015

Import Customer Group Price for Product using CSV in Magento

Hi,

Please use the below Github link to Download the Extension and install to your Magento site.

Once after installing, you will see the import option System > Import/Export > Import - Custom.

https://github.com/ryaan-anthony/import-group-prices 

Wednesday 15 July 2015

Add Custom Product Field in Opencart

In this tutorial we are going to learn how to add custom product field in opencart. Sometimes, due to specific requirement of the project, we need add new product fields which can be – product types, product information, custom description etc., that we want to display. So lets create a new product field called"custom_desc".

 Note : Following changes are tested in Opencart Versions : 2.0.1.1 and 2.0.3.1 


To accomplish our goal we need to make the changes at two levels
    - Database level
    - Files level


 Note: Before making any changes directly at any levels , its recommended to take a Backup of database and files.

(1) Database Level




In order to add the new field you can manually add it via phpmyadmin interface or by running the sql command given below. 



ALTER TABLE `oc_product` ADD `custom_desc` VARCHAR(200) NULL ;


here "oc_" is table prefix , it might possible that you have the different one than i have used here. In that case simply change it with your prefix or if you don't used any prefix then simply remove it. 


According to your requirements you can alter the query to add any kind of custom product field. So the above statement will add a new product field called "custom_desc" in your product table.


(2) Files Level


Now we need to make the changes required at files (coding) level. First of all we need to alter the insert and update queries for the product information.


Open your admin/model/catalog/product.php file and add the below line of code after the sort_order field in the addProduct($data) function's insert query. (approx line no : 6)


custom_desc = '" . $this->db->escape($data['custom_desc']) . "'

after adding the above code, the complete insert query will be like this:
$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', custom_desc = '" . $this->db->escape($data['custom_desc']) . "', date_added = NOW()");


Now search for the editProduct($product_id, $data) function and add the same code in update query  (approx line no : 131) after the sort_order field,


custom_desc = '" . $this->db->escape($data['custom_desc']) . "'


after adding the above code, the complete update query will be like this:
$this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', custom_desc = '" . $this->db->escape($data['custom_desc']) . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");


Now open admin/controller/catalog/product.php  file and search for the following line in the getForm()function.(approx line no : 584)    


$data['entry_sort_order'] = $this->language->get('entry_sort_order');


and add the below line just after that,
$data['entry_custom_desc'] = $this->language->get('entry_custom_desc');


If you want to provide help text for your field on mouse hover then search for the below code (approx line no : 601) ,


$data['help_isbn'] = $this->language->get('help_isbn');


and add the below code just after that,
$data['help_custom_desc'] = $this->language->get('help_custom_desc');



Next search for this code, in the same function, (approx line no : 806)

if (isset($this->request->post['isbn'])) {
 $data['isbn'] = $this->request->post['isbn'];
} elseif (!empty($product_info)) {
 $data['isbn'] = $product_info['isbn'];
} else {
 $data['isbn'] = '';
}


and add the below code just after that,


if (isset($this->request->post['custom_desc'])) {
 $data['custom_desc'] = $this->request->post['custom_desc'];
} elseif (!empty($product_info)) {
 $data['custom_desc'] = $product_info['custom_desc'];
} else {
 $data['custom_desc'] = '';
}


Now open admin/view/template/catalog/product_form.tpl file, search for the below line: (approx line no : 97)
<div class="tab-pane" id="tab-data">


and add the following code block just after the image block in order to add our custom field.

<div class="form-group">
     <label class="col-sm-2 control-label" for="input-custom_desc">
         <span data-toggle="tooltip" title="<?php echo $help_custom_desc; ?>"><?php echo $entry_custom_desc; ?></span>
     </label>
     <div class="col-sm-10">
        <input type="text" name="custom_desc" value="<?php echo $custom_desc; ?>" placeholder="<?php echo $entry_custom_desc; ?>" id="input-custom_desc" class="form-control" />
     </div>
</div>



Now open admin/language/english/catalog/product.php   file and add the following lines,


// in Entry section
$_['entry_custom_desc']      = 'Custom Description';
  
  and 
  
// in Help section
$_['help_custom_desc']       = 'This is Custom Description Field';



Thats it..!! you have successfully added your custom product field in admin section. Go to admin panel and add/edit any product you will find new custom desc field will be added.


 Note :  This newly added field will be shown in the Data tab of the product page of admin panel.

Tuesday 19 May 2015

Create a simple Magento payment module

Here is small example which will explain how to create a simple Magento payment module.
I hope that you know how to create magento module and I will skip this step.
First of all, you have to create in etc folder config.xml file with next content:
< ?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<test_mycheckout>
<version>1.0.0</version>
</test_mycheckout>
</modules>
 
<global>
<models>
<mycheckout>
<class>Test_Mycheckout_Model</class>
</mycheckout>
</models>
<helpers>
<mycheckout>
<class>Test_Mycheckout_Helper</class>
</mycheckout>
 
</helpers>
<blocks>
<mycheckout>
<class>Test_Mycheckout_Block</class>
</mycheckout>
</blocks>
</global>
 
<default>
<payment>
<mycheckout>
<model>mycheckout/standard</model>// very important thing, here you select the model for your payment method
<active>1</active>
<order_status>pending</order_status>
<title>CUSTOM CARD</title>
<payment_action>sale</payment_action>
<submit_url>https://someurl.com</submit_url>
<merchant_id>Insert merchant id</merchant_id>
<allowspecific>0</allowspecific>
<sort_order>1</sort_order>
</mycheckout>
</payment>
</default>
 
<frontend>
<routers>
<mycheckout>
<use>standard</use>
<args>
<module>Test_Mycheckout</module>
<frontname>customcard</frontname>
</args>
</mycheckout>
</routers>
</frontend>
</config>
Next step: you have to create system.xml file also in etc folder with next content:
< ?xml version="1.0"?>
<config>
<sections>
<payment>
<groups>
<mycheckout translate="label comment" module="paypal">
<label>Custom CARD MyCheckOut</label>
<frontend_type>text</frontend_type>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</active>
<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
 
</title>
<order_status translate="label">
<label>New Order Status</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status</source_model>
<sort_order>50</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</order_status>
<submit_url>
<label>Gateway URL</label>
<frontend_type>text</frontend_type>
<sort_order>58</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</submit_url>
<merchant_id>
<label>Merchant ID</label>
<frontend_type>text</frontend_type>
<sort_order>59</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</merchant_id>
<allowspecific translate="label">
<label>Payment Applicable From</label>
<frontend_type>select</frontend_type>
<sort_order>60</sort_order>
<source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</allowspecific>
<specificcountry translate="label">
<label>Countries Payment Applicable From</label>
<frontend_type>multiselect</frontend_type>
<sort_order>70</sort_order>
<source_model>adminhtml/system_config_source_country</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<depends><allowspecific>1</allowspecific></depends>
</specificcountry>
<sort_order translate="label">
<label>Sort Order</label>
<frontend_type>text</frontend_type>
</sort_order><sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
 
</fields>
</mycheckout>
</groups>
</payment>
 
</sections>
</config>
In this system.xml file we create options for this payment method. These options you will see in admin section under payment method, also if you need additional options you can add them.
Last step: is creating model in folder model with file-name standard.php. This model is defined in config.xml file. Here is example:
< ?php
 
class Test_Mycheckout_Model_Standard extends Mage_Payment_Model_Method_Abstract
{
 
protected $_code = 'mycheckout';
 
protected $_isInitializeNeeded      = true;
protected $_canUseInternal          = false;
protected $_canUseForMultishipping  = false;
 
/**
* Return Order place redirect url
*
* @return string
*/
public function getOrderPlaceRedirectUrl()
{
//when you click on place order you will be redirected on this url, if you don't want this action remove this method
return Mage::getUrl('customcard/standard/redirect', array('_secure' => true));
}
 
}
If your method redirect when customer click on checkout button place order you have to create (customcard/standard/redirect) standard controller with method redirectAction and etc. This page will create html form which will send POST data to payment gateway. All data which you need for creating this form you can get from Magento model $session = Mage::getSingleton(‘checkout/session’); and etc.
When you finish everything you will get next option in admin section: