tag:blogger.com,1999:blog-78080833165892600852023-12-28T12:27:45.761+05:30Magento BlogMagento Tutorial, Magneto modules, Magento Banckend, Magento admin, Magento Frontend, Magento Interview Question, Jquery, CSS, Javascript, PHP, XHTMLAnonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.comBlogger127125tag:blogger.com,1999:blog-7808083316589260085.post-83383612080889991392014-03-13T15:52:00.000+05:302014-03-13T15:54:41.346+05:30How to add custom variables to new order E-mail in magento?<div dir="ltr" style="text-align: left;" trbidi="on"><p>You can add custom variable data or something related to product's attribute in any transactional email. You also can write your custom code according to the current order id and display the required result. If you want to use new module, you can create hope for creating new module I don't need to describe the steps here.</p><p>open your layout file.xml then write below xml there</p><code><sales_email_order_anything><br />
<block type="sales/order_email_items" name="anything" template="email/anyname.phtml"/> <br />
</sales_email_order_anything></code><br />
<p>In anyname.phtml file you can write <?php $_order = $this->getOrder(); ?> to get the order object.</p><p>Now go to order transactional email then write </p><code>{{layout handle="sales_email_order_anything" order=$order}}</code><br />
<p>Replace all anything/anyname to suitable text</p></div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com2Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764182 76.949115699999979 13.4667792 78.240009699999987tag:blogger.com,1999:blog-7808083316589260085.post-16096889390314599272013-12-06T15:16:00.000+05:302013-12-06T15:16:17.794+05:30How to use WYSIWYG editor TinyMCE in custom Admin Magento Module<div dir="ltr" style="text-align: left;" trbidi="on">It's so easy to enable by the below 3 steps<br />
1) Go to Yournamespace_Modulename_Block_Adminhtml_Modulename_Edit<br />
then copy and paste the below code<br />
<code>protected function _prepareLayout() {<br />
parent::_prepareLayout();<br />
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {<br />
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);<br />
}<br />
}</code><br />
<br />
2) In the same File inside public function __construct() function add the following condition<br />
<code>$this->_formScripts[] = "<br />
function toggleEditor() {<br />
if (tinyMCE.getInstanceById('show_content') == null) {<br />
tinyMCE.execCommand('mceAddControl', false, 'show_content');<br />
} else {<br />
tinyMCE.execCommand('mceRemoveControl', false, 'show_content');<br />
}<br />
} <br />
";</code><br />
If you already have the $this->_formScripts[] then insert function toggleEditor() and it's content to it.<br />
<br />
3) Now go to Yournamespace_Modulename_Block_Adminhtml_Modulename_Edit_Tab_Form<br />
<code>$fieldset->addField('description', 'editor', array(<br />
'name' => 'description',<br />
'label' => Mage::helper('show')->__('Description'),<br />
'title' => Mage::helper('show')->__('Description'), <br />
'wysiwyg' => true,<br />
'required' => false,<br />
));</code><br />
</div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-35806817995328931902013-10-29T15:32:00.000+05:302013-12-09T12:27:16.914+05:30How to add Diners Club credit card in magento<div dir="ltr" style="text-align: left;" trbidi="on"><p>Default Magento doesn't have this card in his payment gateway. If you want to add then follow the below steps, I have describe here in core file you need to override all core files before doing any changes</p><p>Go to app/code/core/Mage/Payemtn/etc/Config.xml then go to line number 56 you can find there are already some card has defined, you need to add your code there</p><code><payment> <!--(already defined)--><br />
<cc> <!--(already defined)--><br />
<types> <!--(already defined)--><br />
<DC><br />
<code>DC</code><br />
<name>Diners Club</name><br />
<order>80</order><br />
</DC><br />
</types> <!--(already defined)--><br />
</cc><!--(already defined)--><br />
</types><!--(already defined)--><br />
</code><br />
<p>You can copy paste this section in your custom module to add the Diners Club card else Copy from <DC> to </DC> and paste it after the </OT></p><p>Now you successfully added the card in to Credit card Dropdown.</p><p>Next you have to validate the card, Magento use two types of validation one Javascript validation another PHP validation You have to validate both way.</p><p>1) Javascript Validation<br />
Go to magento root directory then js/prototype/validation.js then go to end of the page you will find there already all card validation added, The code will be something like this</p><code>Validation.creditCartTypes = $H({<br />
'SS': [new RegExp('^((6759[0-9]{12})|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})|(6333[0-9]{12})|(6334[0-4]\d{11})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],<br />
'SO': [new RegExp('^(6334[5-9]([0-9]{11}|[0-9]{13,14}))|(6767([0-9]{12}|[0-9]{14,15}))$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],<br />
'SM': [new RegExp('(^(5[0678])[0-9]{11,18}$)|(^(6[^05])[0-9]{11,18}$)|(^(601)[^1][0-9]{9,16}$)|(^(6011)[0-9]{9,11}$)|(^(6011)[0-9]{13,16}$)|(^(65)[0-9]{11,13}$)|(^(65)[0-9]{15,18}$)|(^(49030)[2-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49033)[5-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49110)[1-2]([0-9]{10}$|[0-9]{12,13}$))|(^(49117)[4-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49118)[0-2]([0-9]{10}$|[0-9]{12,13}$))|(^(4936)([0-9]{12}$|[0-9]{14,15}$))'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],<br />
'VI': [new RegExp('^4[0-9]{12}([0-9]{3})?$'), new RegExp('^[0-9]{3}$'), true],<br />
'MC': [new RegExp('^5[1-5][0-9]{14}$'), new RegExp('^[0-9]{3}$'), true],<br />
'AE': [new RegExp('^3[47][0-9]{13}$'), new RegExp('^[0-9]{4}$'), true],<br />
'DI': [new RegExp('^6011[0-9]{12}$'), new RegExp('^[0-9]{3}$'), true],<br />
'JCB': [new RegExp('^(3[0-9]{15}|(2131|1800)[0-9]{11})$'), new RegExp('^[0-9]{4}$'), true],<br />
'OT': [false, new RegExp('^([0-9]{3}|[0-9]{4})?$'), false]<br />
});</code><br />
<p>then replace this function with the below content</p><code>Validation.creditCartTypes = $H({<br />
'SS': [new RegExp('^((6759[0-9]{12})|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})|(6333[0-9]{12})|(6334[0-4]\d{11})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],<br />
'SO': [new RegExp('^(6334[5-9]([0-9]{11}|[0-9]{13,14}))|(6767([0-9]{12}|[0-9]{14,15}))$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],<br />
'SM': [new RegExp('(^(5[0678])[0-9]{11,18}$)|(^(6[^05])[0-9]{11,18}$)|(^(601)[^1][0-9]{9,16}$)|(^(6011)[0-9]{9,11}$)|(^(6011)[0-9]{13,16}$)|(^(65)[0-9]{11,13}$)|(^(65)[0-9]{15,18}$)|(^(49030)[2-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49033)[5-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49110)[1-2]([0-9]{10}$|[0-9]{12,13}$))|(^(49117)[4-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49118)[0-2]([0-9]{10}$|[0-9]{12,13}$))|(^(4936)([0-9]{12}$|[0-9]{14,15}$))'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],<br />
'VI': [new RegExp('^4[0-9]{12}([0-9]{3})?$'), new RegExp('^[0-9]{3}$'), true],<br />
'MC': [new RegExp('^5[1-5][0-9]{14}$'), new RegExp('^[0-9]{3}$'), true],<br />
'AE': [new RegExp('^3[47][0-9]{13}$'), new RegExp('^[0-9]{4}$'), true],<br />
'DI': [new RegExp('^6011[0-9]{12}$'), new RegExp('^[0-9]{3}$'), true],<br />
'JCB': [new RegExp('^(3[0-9]{15}|(2131|1800)[0-9]{11})$'), new RegExp('^[0-9]{4}$'), true],<br />
'OT': [false, new RegExp('^([0-9]{3}|[0-9]{4})?$'), false],<br />
'DC': [new RegExp('^3(?:0[0-5]|[68][0-9])[0-9]{11}$'), new RegExp('^[0-9]{3}$'), true]<br />
});</code><br />
So this way you can do the javascript validation<br />
<p><p>If you don't want to edit the js core file then add the below script in to your form/cc.phtml or in your custom phtml file which is responsible for showing the payment Block</p><code><script type="text/javascript"><br />
Validation.creditCartTypes.set('DC', [new RegExp('^3(?:0[0-5]|[68][0-9])[0-9]{11}$'), new RegExp('^[0-9]{3}$'), true]);<br />
</script><br />
</code><br />
2) PHP validation<br />
Go to app/code/core/Mage/Payment/Model/Method/Cc.php<br />
there you can find the validation line number near about 111</p><code>$ccTypeRegExpList = array(<br />
//Solo, Switch or Maestro. International safe<br />
'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/', // Solo only<br />
'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',<br />
<br />
'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/', // Maestro / Solo<br />
'VI' => '/^4[0-9]{12}([0-9]{3})?$/', // Visa<br />
'MC' => '/^5[1-5][0-9]{14}$/', // Master Card<br />
'AE' => '/^3[47][0-9]{13}$/', // American Express<br />
'DI' => '/^6011[0-9]{12}$/', // Discovery<br />
'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/', // JCB<br />
);</code><br />
<p>replace the above code with the below code</p><code>$ccTypeRegExpList = array(<br />
//Solo, Switch or Maestro. International safe<br />
'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/', // Solo only<br />
'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',<br />
<br />
'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/', // Maestro / Solo<br />
'VI' => '/^4[0-9]{12}([0-9]{3})?$/', // Visa<br />
'MC' => '/^5[1-5][0-9]{14}$/', // Master Card<br />
'AE' => '/^3[47][0-9]{13}$/', // American Express<br />
'DI' => '/^6011[0-9]{12}$/', // Discovery<br />
'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/', // JCB<br />
'DC' => '/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/', //Diners Club<br />
);<br />
</code><br />
<p>Now go to Line number 183 there already a function which validate CVV number . The codes are</p><code>public function getVerificationRegEx()<br />
{<br />
$verificationExpList = array(<br />
'VI' => '/^[0-9]{3}$/', // Visa<br />
'MC' => '/^[0-9]{3}$/', // Master Card<br />
'AE' => '/^[0-9]{4}$/', // American Express<br />
'DI' => '/^[0-9]{3}$/', // Discovery<br />
'SS' => '/^[0-9]{3,4}$/',<br />
'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro<br />
'SO' => '/^[0-9]{3,4}$/', // Solo<br />
'OT' => '/^[0-9]{3,4}$/',<br />
'JCB' => '/^[0-9]{4}$/' //JCB<br />
);<br />
return $verificationExpList;<br />
}<br />
</code><br />
<p>Now replace this function with below function </p><code>public function getVerificationRegEx()<br />
{<br />
$verificationExpList = array(<br />
'VI' => '/^[0-9]{3}$/', // Visa<br />
'MC' => '/^[0-9]{3}$/', // Master Card<br />
'AE' => '/^[0-9]{4}$/', // American Express<br />
'DI' => '/^[0-9]{3}$/', // Discovery<br />
'SS' => '/^[0-9]{3,4}$/',<br />
'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro<br />
'SO' => '/^[0-9]{3,4}$/', // Solo<br />
'OT' => '/^[0-9]{3,4}$/',<br />
'JCB' => '/^[0-9]{4}$/', //JCB<br />
'DC' => '/^[0-9]{3}$/' // Diners Club<br />
);<br />
return $verificationExpList;<br />
} <br />
</code><br />
<p>That's All , Now magento will successfully validate your Diners club code. Instead of doing this changes in magento core files try to override the model class then change it in your custom module. </p></div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com1Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764182 76.949115699999979 13.4667792 78.240009699999987tag:blogger.com,1999:blog-7808083316589260085.post-88322114479414290492013-09-03T18:35:00.000+05:302013-09-19T17:48:14.462+05:30Create host in ubuntu<div dir="ltr" style="text-align: left;" trbidi="on"><p>To create host you need to have superuser permission. If you have then follow the below command line</p><code>sudo vi /etc/hosts<br />
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/yoursite<br />
sudo vi /etc/apache2/sites-available/yoursite<br />
</code><br />
Then edit the code<br />
<code><VirtualHost *:80><br />
ServerAdmin webmaster@localhost<br />
ServerName www.yourwebsite.dev<br />
DocumentRoot /var/www/yourwebsitefoldername<br />
<Directory /><br />
Options FollowSymLinks<br />
AllowOverride None<br />
</Directory><br />
<Directory /var/www/yourwebsitefoldername/><br />
Options Indexes FollowSymLinks MultiViews<br />
AllowOverride All<br />
Order allow,deny<br />
allow from all<br />
</Directory><br />
<br />
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/<br />
<Directory "/usr/lib/cgi-bin"><br />
AllowOverride None<br />
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch<br />
Order allow,deny<br />
Allow from all<br />
</Directory><br />
<br />
ErrorLog ${APACHE_LOG_DIR}/error.log<br />
<br />
# Possible values include: debug, info, notice, warn, error, crit,<br />
# alert, emerg.<br />
LogLevel warn<br />
<br />
CustomLog ${APACHE_LOG_DIR}/access.log combined<br />
<br />
Alias /doc/ "/usr/share/doc/"<br />
<Directory "/usr/share/doc/"><br />
Options Indexes MultiViews FollowSymLinks<br />
AllowOverride None<br />
Order deny,allow<br />
Deny from all<br />
Allow from 127.0.0.0/255.0.0.0 ::1/128<br />
</Directory><br />
<br />
</VirtualHost><br />
</code><br />
<br />
Then make the site available and restart the apache server<br />
<code>sudo a2ensite yoursite<br />
sudo service apache2 restart<br />
</code><br />
</div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764182 76.949115699999979 13.4667792 78.240009699999987tag:blogger.com,1999:blog-7808083316589260085.post-82063668712177726042013-04-05T17:23:00.001+05:302013-04-05T17:23:45.750+05:30Print array contents in log file of magento<div dir="ltr" style="text-align: left;" trbidi="on">In Magento You can print your log in Exception.log using <br />
<code>Mage::logException($e->getMessage());</code><br />
If you want to put the log to your custom log file, then you can use write below line<br />
<code>Mage::log('Your Query', Zend_Log::DEBUG, custom.log);</code><br />
But the problem is that , It will not print any Array data, If you want to print Array data in to log file then you can use any one of the below method<br />
<code>Mage::getModel('core/log_adapter', 'custom.log')->log($arrayvariable);<br />
or<br />
Mage::log('Your Data :'.print_r($arrayvariable, true), Zend_Log::DEBUG, 'custom.log');</code><br />
</div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0Bangalore, Karnataka, India12.9715987 77.59456269999998312.4764197 76.949115699999979 13.4667777 78.240009699999987tag:blogger.com,1999:blog-7808083316589260085.post-63710094409136095922012-12-11T15:33:00.002+05:302012-12-11T15:34:49.765+05:30How to create custom cron job in magento <div dir="ltr" style="text-align: left;" trbidi="on"><p>Magento default have a cron.php file located in the root directory. To set a cron in magento you have to create your own module first, and in the config.xml you have to declare the method which will fired and the time. Below is a dump of a etc/config.xml file of a custom cron module</p><code><?xml version="1.0"?><br />
<config><br />
<modules><br />
<Wl_Cronset><br />
<version>0.1.0</version><br />
</Wl_Cronset><br />
</modules><br />
<crontab><br />
<jobs><br />
<Wl_Cronset><br />
<schedule><br />
<cron_expr>01 00 * * *</cron_expr><br />
</schedule><br />
<run><br />
<model>cronset/expired::productExpired</model><br />
</run><br />
</Wl_Cronset><br />
</jobs><br />
</crontab> <br />
<global><br />
<models><br />
<cronset><br />
<class>Wl_Cronset_Model</class> <br />
</cronset> <br />
</models> <br />
</global><br />
</config><br />
</code><br />
<p>As per mentioned in this xml your cron will be fired every day @ night 00:01 min</p><p>Now you have to write your own functionality in your module Model file, Here my model file name is Expired and the function which will trigger is productExpired().<br />
</p><code><?php<br />
class Wl_Cronset_Model_Expired extends Mage_Core_Model_Abstract<br />
{<br />
public function productExpired()<br />
{<br />
// Your code goes here<br />
}<br />
}<br />
?><br />
</code><br />
<p>Now login to your server to call the magento root cron.php and set to be fired in every minute.</p></div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com1Bangalore, Karnataka, India12.9715987 77.594562712.724026199999999 77.2787057 13.2191712 77.910419699999991tag:blogger.com,1999:blog-7808083316589260085.post-38101071724384478442012-07-30T19:55:00.000+05:302012-07-30T19:55:16.563+05:30How to Add country and state Dropdown in magento admin<div dir="ltr" style="text-align: left;" trbidi="on">
<p>I din't able to create this in proper way like magento does but if you will have all the state of all country then I think this is the perfect solution. If you don't have all state for all country then this module is not solved your problem. If any one knows the correct way then please add the solution via comment. I am describing here How I exactly did.</p>
<p>Open your form which is in Yournamespace/Modulename/Block/Adminhtml/Modulename/Edit/Tab/Form.php then add below fields</p>
<code><pre>
$country = $fieldset->addField('country', 'select', array(
'name' => 'country',
'label' => 'Country',
'values' => Mage::getModel('adminhtml/system_config_source_country') ->toOptionArray(),
'onchange' => 'getstate(this)',
));
$fieldset->addField('state', 'select', array(
'name' => 'state',
'label' => 'State',
'values' => Mage::getModel('modulename/modulename')
->getstate('AU'),
));
/*
* Add Ajax to the Country select box html output
*/
$country->setAfterElementHtml("<script type=\"text/javascript\">
function getstate(selectElement){
var reloadurl = '". $this
->getUrl('modulename/adminhtml_modulename/state') . "country/' + selectElement.value;
new Ajax.Request(reloadurl, {
method: 'get',
onLoading: function (stateform) {
$('state').update('Searching...');
},
onComplete: function(stateform) {
$('state').update(stateform.responseText);
}
});
}
</script>");
</pre></code>
<p>Now Create State Action in modulenamecontroller.php file which will be like this</p>
<code><pre>
public function stateAction() {
$countrycode = $this->getRequest()->getParam('country');
$state = "<option value=''>Please Select</option>";
if ($countrycode != '') {
$statearray = Mage::getModel('directory/region')->getResourceCollection() ->addCountryFilter($countrycode)->load();
foreach ($statearray as $_state) {
$state .= "<option value='" . $_state->getCode() . "'>" . $_state->getDefaultName() . "</option>";
}
}
echo $state;
}
</pre></code>
<br /></div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com8Grant Rd, Sampangi Rama Nagar, Bangalore, Karnataka, India12.9715987 77.594562711.982661199999999 76.331135199999991 13.9605362 78.8579902tag:blogger.com,1999:blog-7808083316589260085.post-52217558685569955792012-07-30T19:37:00.000+05:302012-07-30T19:37:12.773+05:30Wysiwyg Editor not working in custom module created by Module creator<div dir="ltr" style="text-align: left;" trbidi="on">
<p>When you create a module using module creator then if you try to turn on the Wysiwyg editor of magento then you need to add some function in the Edit.php file which resides under Namespace/Modulename/Block/Adminhtml/Modulename/Edit.php</p>
<code><pre>
protected function _prepareLayout() {
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}</pre></code>
<p>Now turn on the Wysiwyg editor in your code which may be like below</p>
<code><pre>
$fieldset->addField('summary', 'editor', array(
'name' => 'summary',
'label' => Mage::helper('modulename')->__('Description'),
'title' => Mage::helper('modulename')->__('Description'),
'style' => 'height:100px;',
'wysiwyg' => true,
'required' => true,
));
</pre></code>
<br /></div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com1Bangalore, Karnataka, India12.9715987 77.594562710.9885162 75.0677072 14.9546812 80.1214182tag:blogger.com,1999:blog-7808083316589260085.post-2523323089099122302012-07-24T12:02:00.000+05:302012-07-24T12:03:28.963+05:30Join custom table to product collection in magento<div dir="ltr" style="text-align: left;" trbidi="on">
<p>For your custom module if you want to join your custom table data with Magento default product collection then you need to join tables with the entiry_id of the product and your product_id stored in your custom table. Here I have just used the resource model collection to join the table. I tried with getmodel feature of Magento don't know why it doesn't able to create the Product grid in the backend. So I used resource model and it worked. If you are only joining the table, not to generate the Product grid, then you can use getmodel instead of resource model.</p><code><pre>$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('name')
->addAttributeToSelect('sku')
->addAttributeToSelect('price')
->addAttributeToSelect('status')
->addAttributeToSelect('visibility')
->addAttributeToFilter('type_id', array('eq' => 'simple'))
->addFieldToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
->addAttributeToFilter('visibility', array('neq' => 1));
$collection->getSelect()->join(array('mep' => "mage_brand_product"), "e.entity_id = mep.product_id", array('mep.*'));</pre></code>
<br />
</div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com1Bangalore, Karnataka, India12.9715987 77.594562712.724026199999999 77.2787057 13.2191712 77.910419699999991tag:blogger.com,1999:blog-7808083316589260085.post-15741058167851829972012-05-17T12:30:00.000+05:302012-05-17T12:30:07.645+05:30addFiledToFilter Condition In Magento<div dir="ltr" style="text-align: left;" trbidi="on">
<p>As I already mentioned on the previous post that we only can give the condition of attribute name to filter the result. There is another method to filter result that you can use in your customer Module. Let you are having a customer module which is responsible to show some banner on the homepage. For that let you have some place to upload image and also have feature to give sort order and enable disable feature. Here in the below code I will show how to filter the result with addFieldtoFilter </p>
<div><code>
$banner = Mage::getModel('mymodulename/banner')->getCollection();<br/>
</code>
</div>
<p>Now I wish to show banner whose status are active. I already have a field name/column name 'status' in my custom table.</p>
<div><code>
$banner -> addFieldToFilter('status', array('eq' => 1));<br/>
</code></div>
<p>Now I will sort the result according to sort order in my table. I already have a field name 'sort_order' in my table. To sort according to that column I will write</p>
<div><code>
$banner -> setOrder('sort_order', 'DESC');<br/>
</code></div>
</div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com1Salt Lake City, Kolkata, West Bengal, India22.582808 88.41652622.5534835 88.377044 22.6121325 88.456008000000011tag:blogger.com,1999:blog-7808083316589260085.post-89774867845059201992012-05-17T12:10:00.000+05:302012-05-17T12:37:55.634+05:30addAttributeToFilter Condition In Magento<div dir="ltr" style="text-align: left;" trbidi="on">
<p>addAttributeToFilter Condition is used to Filter the collection query of magento . we can use to to filter the result of category collection, Product Collection, Customer collection, Order collection etc.</p>
<p>When you use this condition into the collection make sure your filterable option should be an attribute not should be a table column or fieldname.</p>
<p>Below is the example to fetch all products and using addAttributeToFilter to filter the result</p>
<div><code>
$collection = Mage::getModel('catalog/product')->getCollection();<br/>
</code>
</div>
<p>Below are all types of condition which you can use To Filter the result</p>
<div><code>
$collection -> addAttributeToFilter('status', array('eq' => 1));<br/>
$collection -> addAttributeToFilter('status', array('neq' => 0));<br/>
$collection -> addAttributeToFilter('id' , array('in' => array(1,2,3,4)));<br/>
$collection -> addAttributeToFilter('id' , array('nin' => array(5,6)));<br/>
$collection -> addAttributeToFilter('sku' , array('like' => "%a%"));<br/>
$collection -> addAttributeToFilter('sku' , array('nlike' => "test%"));<br/>
$collection -> addAttributeToFilter('weight', array('gt' => 10));<br/>
$collection -> addAttributeToFilter('weight', array('lt' => 1));<br/>
$collection -> addAttributeToFilter('name' , 'notnull');<br/>
$collection -> addAttributeToFilter('sort_description' , 'null');<br/>
</code></div>
</div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0Unnamed Rd, FE Block, Salt Lake City, Kolkata, West Bengal, India22.582808 88.41652622.5534855 88.377044 22.6121305 88.456008000000011tag:blogger.com,1999:blog-7808083316589260085.post-74814926334074305222012-03-28T12:02:00.001+05:302012-03-28T12:02:38.474+05:30How to refresh magento cache using magento php code<div dir="ltr" style="text-align: left;" trbidi="on">create a file in the root folder of your magento for example refreshcache.php and write the below code to refresh your magento cache without logging to Admin panel</div><code>require_once 'app/Mage.php';<br />
umask( 0 );<br />
Mage :: app( "default" );<br />
$ver = Mage :: getVersion();<br />
$userModel = Mage :: getModel( 'admin/user' );<br />
$userModel -> setUserId( 0 );<br />
Mage :: getSingleton( 'admin/session' ) -> setUser( $userModel );<br />
echo "Refreshing cache...\n";<br />
Mage :: app() -> cleanCache();<br />
$enable = array();<br />
foreach ( Mage :: helper( 'core' ) -> getCacheTypes() as $type => $label ) {<br />
$enable[$type] = 1;<br />
} <br />
Mage :: app() -> saveUseCache( $enable );<br />
echo "Cache refreshed";</code>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-70430167646417432022011-12-28T17:20:00.001+05:302011-12-28T17:20:13.212+05:30How to override catalogsearch model class in magento<div dir="ltr" style="text-align: left;" trbidi="on"><p>In magento if you wish to override some controller then definately you will get lots of site which will describe how to do that but for model class, you will have some result. So I think to share my knowledge here. I am going to override default catalog search Model of magento. For that I will create an module with name space name Mage and module name Searchby. I hope you people know how to create an module so I will show you how to override model class only</p><p>Go to config.xml of your custom module then write the below code to override the catalogsearch model class</p><p><code><?xml version="1.0" encoding="UTF-8"?><br />
<config><br />
<modules><br />
<Mage_Searchby><br />
<version>0.1.0</version><br />
</Mage_Searchby><br />
</modules><br />
<frontend><br />
<routers><br />
<searchby><br />
<use>standard</use><br />
<args><br />
<module>Mage_Searchby</module><br />
<frontName>searchby</frontName><br />
</args><br />
</searchby><br />
</routers> <br />
</frontend><br />
<global><br />
<models><br />
<catalogsearch><br />
<rewrite><br />
<layer>Mage_Searchby_Model_Layer</layer><br />
</rewrite><br />
</catalogsearch><br />
</models><br />
</global><br />
</config></code></p><p>Now create an Layer.php file inside <strong>yourmodulename/Model</strong> then write the below code</p><p><code><?php<br />
class Mage_Searchby_Model_Layer extends Mage_CatalogSearch_Model_Layer<br />
{<br />
public function prepareProductCollection($collection)<br />
{<br />
//Code to be executed<br />
}<br />
}?></code></p>That's all thanks<br />
</div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-69171991175641282572011-11-25T16:42:00.002+05:302011-11-25T16:42:43.056+05:30How to add search by category in magento mini search<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<p>There is no free extension in magento commerce which will help you to search your store with particular category. I tried from myself and able to do, I am sharing my exprerience here with.</p><p>First create the drop down list of all category in form.mini.phtml</p><p><code><select name="category" id="category_search_field"><br />
<option value="">-- Any Category --</option><br />
<?php foreach ($catalog->getStoreCategories() as $_category): ?><br />
<?php if($_category->hasChildren()): ?><br />
<option class="parent-cat" value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option><br />
<?php foreach ($_category->getChildren() as $subcategory):<br />
if($subcategory->getIsActive()) : ?><br />
<option value="<?php echo $subcategory->getId(); ?>"<?php echo ($this->getRequest()->getQuery('category') == $subcategory->getId() ? ' selected="selected"': "") ?>><?php echo $subcategory->getName(); ?></option><br />
<?php endif; endforeach; ?><br />
<?php elseif($_category->getIsActive()): ?><br />
<option value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option><br />
<?php endif; ?><br />
<?php endforeach ?><br />
</select></code></p><p>Now go to app/code/core/Mage/CatalogSearch/Helper and open the Data.php and add the below code</p><p><code>public function getStoreCategories()<br />
{<br />
$helper = Mage::helper('catalog/category');<br />
return $helper->getStoreCategories();<br />
}<br />
public function getSelectedCategory()<br />
{<br />
$catid = (int)addslashes($_REQUEST['category']); <br />
$cat="";<br />
if($catid>1)<br />
$cat = Mage::getModel('catalog/category')->load($catid); <br />
return $cat; <br />
}</code></p><p>Now go to app/code/core/Mage/CatalogSearch/Model and open the Layer.php</p><p>replace </p><p><code><em>public function prepareProductCollection($collection)<br />
{<br />
$collection<br />
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())<br />
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())<br />
->setStore(Mage::app()->getStore())<br />
->addMinimalPrice()<br />
->addFinalPrice()<br />
->addTaxPercents()<br />
->addStoreFilter()<br />
->addUrlRewrite();<br />
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);<br />
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);<br />
return $this;<br />
}</em></code></p><p>with</p><p><code>public function prepareProductCollection($collection)<br />
{<br />
if(Mage::helper('catalogsearch')->getSelectedCategory()!="")<br />
{<br />
$collection<br />
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())<br />
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())<br />
->setStore(Mage::app()->getStore())<br />
->addMinimalPrice()<br />
->addFinalPrice()<br />
->addTaxPercents()<br />
->addStoreFilter()<br />
->addCategoryFilter(Mage::helper('catalogsearch')->getSelectedCategory())<br />
->addUrlRewrite();<br />
}<br />
else<br />
{<br />
$collection<br />
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())<br />
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())<br />
->setStore(Mage::app()->getStore())<br />
->addMinimalPrice()<br />
->addFinalPrice()<br />
->addTaxPercents()<br />
->addStoreFilter() <br />
->addUrlRewrite();<br />
} <br />
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);<br />
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);</code></p><p>return $this;<br />
}</p><p>save and Enjoy.</p></div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com17tag:blogger.com,1999:blog-7808083316589260085.post-88452016158198382382011-11-17T11:46:00.000+05:302011-11-17T11:46:16.487+05:30cache is not generating in magento<div dir="ltr" style="text-align: left;" trbidi="on">Magento stores cache inside the cache folder which resides under <b>Var</b> folder of your root magento ,But if your cache folder or var folder have not correct file permisson that is 777 then magento will not be able to generate any cache. So change <b>Var</b> folder permission to 777 , you will see the effect. </div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com1tag:blogger.com,1999:blog-7808083316589260085.post-55977880469982265632011-10-31T19:45:00.001+05:302011-10-31T19:45:12.338+05:30How To Display Best Selling Products On Magento Store<div dir="ltr" style="text-align: left;" trbidi="on">To promote best selling products on your site Magento use so many way to show bestseller product, One of them I am going to show. Below code will fetch the all the list of all product which have already sell.<br />
</div><code><?php<br />
$_productCollection = Mage::getResourceModel('reports/product_collection')<br />
->addOrderedQty()<br />
->setOrder('ordered_qty', 'desc');<br />
?><br />
</code><br />
<p>This is the collection of all the product which already have sell.</p>Now use foreach loop to show some number of product and it details. I wish to show only the name of the product which has sell most. And I will show on the left sidebar of the page. <br />
<code><div class="block best-seller"><br />
<div class="right-title-bg"><h3>Best Selling Product</h3></div><br />
<div class="block-content"><br />
<ul class="best-selling-item"><br />
$count = 0;<br />
foreach($_productCollection as $product):<br />
$id = $product->getId();<br />
$prod = Mage::getModel('catalog/product')->load($id);?><br />
<li><a href="<?php echo $prod->getProductUrl();?>" title="<?php echo $prod->getName();?>"><?php echo $prod->getName();?></a></li><br />
<?php<br />
$count++ ;<br />
if($count==$totalPerPage)<br />
break;<br />
endforeach;<br />
?><br />
</ul><br />
</div><br />
</div><br />
</code><br />
<p>If you wish to show all the details of the product then you also can do that as you will get the product Id from $prod->getId(); and from product Id you can fetch each and every details of the product</p>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com1tag:blogger.com,1999:blog-7808083316589260085.post-55470649781261769052011-10-29T18:47:00.001+05:302011-10-29T18:48:01.474+05:30How to print product collection query in magento<div dir="ltr" style="text-align: left;" trbidi="on"><p>Let you have write a product collection with some attribute to select some product, but you are not getting proper result then you must need to print the sql query to see whether you have write the correct syntax in magento default collection. then write the below code to get the sql query .<br />
</p><code><?php <br />
$productcollection = Mage::getModel('catalog/product')->getCollection()<br />
->addAttributeToFilter('bestseller', array('eq' => 1))<br />
->addAttributeToSelect('*');<br />
echo $productcollection->getSelect()->assemble();<br />
?><br />
</code><br />
</div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-6343186342355028832011-09-27T15:20:00.004+05:302011-09-27T15:23:24.617+05:30How to delete all sales order in magento<div dir="ltr" style="text-align: left;" trbidi="on"><p>In <a href="http://www.magentocommerce.com/magento-connect">Magento Connect</a> you will find some extension which will delete all cancel order and Pending Order, But it never delete all processed order. To delete all orders following code snippet can be used.</p><code><?php<br />
require 'app/Mage.php';<br />
Mage::app('admin')->setUseSessionInUrl(false); <br />
$sales_orders = Mage::getModel('sales/order')->getCollection()->getData();<br />
foreach($sales_orders as $sales_order){<br />
$id = 0;<br />
$id = $sales_order['increment_id'];<br />
try{<br />
Mage::getModel('sales/order')->loadByIncrementId($id)->delete();<br />
echo "order #".$id." is removed".PHP_EOL;<br />
}catch(Exception $e){<br />
echo "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;<br />
}<br />
}<br />
echo "complete."<br />
?><br />
</code><br />
</div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-82589811740407730372011-09-26T11:42:00.001+05:302011-09-26T11:42:39.014+05:30How to use or mysql condition in $collection data of magento<div dir="ltr" style="text-align: left;" trbidi="on">Magento provide addAttributeToFilter to use and operator in $collection, But using of OR operator is little bit different . I was guess that there must be and OrAttributeToFilter , But I was wrong I think magento forgot to write this function, Lastly I found the solution to use mysql OR in magento . In addAttributeToFilter we have to write the condition in the form of array.<br />
<code>protected function _prepareCollection()<br />
{<br />
$collection = Mage::getModel('catalog/product')->getCollection();<br />
$collection->addAttributeToFilter(<br />
array(<br />
array('attribute'=>'category_ids','finset'=>2),<br />
array('attribute'=>'category_ids','finset'=>3)<br />
)<br />
);<br />
}<br />
</code><br />
<br />
<p>use your own attribute name and value to get the data</p></div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-18842507161161972302011-09-16T19:55:00.001+05:302011-09-16T19:55:51.738+05:30How to upload and read csv file in magento<div dir="ltr" style="text-align: left;" trbidi="on">To upload CSV file and to read that file line by line , Please write the below code in magento<br />
<code><br />
if(isset($_FILES['import_file']['name']) && $_FILES['import_file']['name'] != '')<br />
{<br />
$uploaderFile = new Varien_File_Uploader('import_file');<br />
$uploaderFile->setAllowedExtensions(array());<br />
$uploaderFile->setAllowRenameFiles(false);<br />
$uploaderFile->setFilesDispersion(false);<br />
$uploaderFilepath = Mage::getBaseDir('media') . DS . 'importcsv' . DS ;<br />
$uploaderFile->save($uploaderFilepath, $_FILES['import_file']['name'] );<br />
$file = <span class="Apple-tab-span" style="white-space: pre;"> </span>$_FILES['import_file']['name'];<br />
$filepath = $uploaderFilepath.$file;<br />
$i = 0;<br />
if(($handle = fopen("$filepath", "r")) !== FALSE) {<br />
while(($data = fgetcsv($handle, 1000, ",")) !== FALSE){ <span class="Apple-tab-span" style="white-space: pre;"> </span><br />
if($i>0 && count($data)>1){<br />
updateData($data);<br />
} <br />
$i++;<br />
}<br />
}<br />
else{<br />
Mage::getSingleton('adminhtml/session')->addError("There is some Error");<br />
$this->_redirect('*/*/index');<br />
}<br />
}<br />
function updateData($data)<br />
{<br />
//Write your code here and Update it to magento tables<br />
}<br />
<br />
</code></div>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-88304138198190423902011-08-30T12:53:00.006+05:302011-08-30T12:58:57.544+05:30How to get contact us email address in magento<p>Here’s the code to get Contacts email:</p>
<code>
<?php echo Mage::getStoreConfig('contacts/email/recipient_email');?>
</code>
<p>Or you can change it from <b>admin</b> -> <b>System</b>-> <b>Configuration</b>. From the left tab select Contacts then On the right side you will see Email Options Tab. From that tab you can see there is a field for send Emails To.Change th evalue to your require email address</p>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-84412670408925138782011-08-04T19:58:00.009+05:302011-08-04T20:16:22.208+05:30How to uncheck Radio button by jquery<script type="text/javascript">
$(document).ready(function(){
$("#btn").click(function(){
$('input[name="rd"][type="radio"]:checked').each(function(){
$(this).attr("checked", false);
});
});
});
</script>
<form action="" name="aa" method="post">
<input type="radio" name="rd" value="1"/>
<input type="radio" name="rd" value="2"/>
<input type="radio" name="rd" value="3"/>
<input type="button" id="btn" value=" Click here to Uncheck " />
</form>
<h3>Write the Below code to Unchecked Radio Button by Jquery</h3>
<p>
<pre><code><script type="text/javascript">
$(document).ready(function(){
$("#btn").click(function(){
$('input[name="rd"][type="radio"]:checked').each(function(){
$(this).attr("checked", false);
});
});
});
</script></code></pre>
</p>
<br/>
<p>
<pre><code>
<form action="" name="aa" method="post">
<input type="radio" name="rd" value="1"/>
<input type="radio" name="rd" value="2"/>
<input type="radio" name="rd" value="3"/>
<input type="button" id="btn" value="Click" />
</form>
</code></pre>
</p>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-31018459674804775372011-08-04T19:38:00.004+05:302011-08-04T20:23:29.393+05:30How to change value and fetch value of Minimum Order Amounts of free shipping in magento<p>
First of all to make Minimum Order Amounts of Free Shipping to <strong>[STORE VIEW]</strong> instead of <strong>[WEBSITE]</strong> then Go to <strong>app->code->core->Mage->Shipping->etc->System.xml</strong>
<br/>
then change the value of <strong><show_in_store></strong> to <strong>1</strong> under <strong>carriers -> groups -> freeshipping ->free_shipping_subtotal</strong>.
</p>
<p>Now to fetch the value of the Minimum Order Amount according to store view write the below code</p>
<code>
<?php echo Mage::getStoreConfig('carriers/freeshipping/free_shipping_subtotal'); ?>
</code>Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com0tag:blogger.com,1999:blog-7808083316589260085.post-2182719744907026012011-07-30T07:33:00.005+05:302011-07-30T07:47:32.704+05:30How to remove validation on zip code in magento checkout page<p>
In the World some of the country has no zip code like Ireland, But magento has default zip code validation to make that optional for specific country magento has added a new feature in admin panel. To make Zip code optional please follow the following steps.</p>
<p> Login to your your magento admin panel then go to System -> Configuration->General. From Country option tab you can see there is an option " <em>Postal code is optional for the following countries</em> " Select the country which you want to Optional/Not validate . then click on save config to save your settings. To be more clear on this please see the below screenshot.
</p>
<img src="http://1.bp.blogspot.com/-UT-W5o59RfY/TjNpGRZOmfI/AAAAAAAAAW4/JGwg_m2g6qk/s1600/zip-code-optional.gif" border="0" alt="" width="580" />Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com1tag:blogger.com,1999:blog-7808083316589260085.post-70658657691702112022011-07-17T11:46:00.006+05:302011-07-17T11:53:28.818+05:30How to change default quantity on Magento Product Page<p>By default magento shows zero in the place of quantity text field in product details page, if you wish to change then just login to your admin panel go to <b>System->Configuration->Catalog->inventory</b>.</p>
<p>There, add your minimal quantity from <b>Minimum Qty Allowed in Shopping Cart</b></p>
<p>See the below screenshot to make it more clear</p>
<img src="http://4.bp.blogspot.com/-vaeUW0LHu8s/TiJ_a31wwTI/AAAAAAAAAWw/-6icGEXA-8Y/s1600/change-minimum-quanity.gif" border="0" alt="" width="500" />Anonymoushttp://www.blogger.com/profile/00622300376257624773noreply@blogger.com7