Wednesday, August 22, 2012
Magento : Allow tags (iframe, embed) in CMS editor
Add following code in file: js/mage/adminhtml/wysiwyg/tiny_mce/setup.js
after line
after line
theme_advanced_resizing :true,
extended_valid_elements :'iframe[src|style|width|height|scrolling|marginwidth|marginheight|frameborder],style,script',
Labels:
Magento
Friday, August 17, 2012
Magento : Enablle specific payment method for specific IP address
Consider module as Bd_Testpament
Add a filed for Ip in system.xml with follwoing code
<config>
<sections>
<payment>
<groups>
<testpayment translate="label comment" module="testpayment">
<label>Test</label>
<comment>Test</comment>
<frontend_type>text</frontend_type>
<sort_order>256</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<allowed_ips translate="label">
<label>Allowed Ips</label>
<frontend_type>text</frontend_type>
<sort_order>130</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</allowed_ips>
</fields>
</secureebsoffer_standard>
</groups>
</payment>
</sections>
</config>
And edit __construct of model with following code
public function __construct()
{
parent::__construct();
$allowed_ips=Mage::getStoreConfig('payment/testpayment/allowed_ips');
if($allowed_ips !='')
{
if(!in_array($_SERVER['HTTP_X_FORWARDED_FOR'],explode(",",$allowed_ips)))
{
$this->_canUseCheckout=false;
}
}
else
{
$this->_canUseCheckout=false;
}
Add a filed for Ip in system.xml with follwoing code
<config>
<sections>
<payment>
<groups>
<testpayment translate="label comment" module="testpayment">
<label>Test</label>
<comment>Test</comment>
<frontend_type>text</frontend_type>
<sort_order>256</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<allowed_ips translate="label">
<label>Allowed Ips</label>
<frontend_type>text</frontend_type>
<sort_order>130</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</allowed_ips>
</fields>
</secureebsoffer_standard>
</groups>
</payment>
</sections>
</config>
And edit __construct of model with following code
public function __construct()
{
parent::__construct();
$allowed_ips=Mage::getStoreConfig('payment/testpayment/allowed_ips');
if($allowed_ips !='')
{
if(!in_array($_SERVER['HTTP_X_FORWARDED_FOR'],explode(",",$allowed_ips)))
{
$this->_canUseCheckout=false;
}
}
else
{
$this->_canUseCheckout=false;
}
Labels:
Magento
Wednesday, August 8, 2012
Magento : sharing the cart between stores
The first thing enable the Use SID on Frontend at
System→Configuration→Web→Session
Then replace following code in start() method of Mage_Core_Model_Session_Abstract_Varien
if (isset($_SESSION)) {
return $this;
}
with
if (isset($_SESSION) && !isset($_GET['SID'])) {
return $this;
}
System→Configuration→Web→Session
Then replace following code in start() method of Mage_Core_Model_Session_Abstract_Varien
if (isset($_SESSION)) {
return $this;
}
with
if (isset($_SESSION) && !isset($_GET['SID'])) {
return $this;
}
Labels:
Magento
Magento : MassDelete & Status action in admin grid
Consider Package: Bd, Module : Test & Model : Test
1.Override _prepareMassaction() method in Grid.php with following code
protected function _prepareMassaction()
{
$this->setMassactionIdField('test_id');
$this->getMassactionBlock()->setFormFieldName('test');
$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('test')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('test')->__('Are you sure?')
));
$statuses = Mage::getSingleton('test/status')->getOptionArray();
array_unshift($statuses, array('label'=>'', 'value'=>''));
$this->getMassactionBlock()->addItem('status', array(
'label'=> Mage::helper('test')->__('Change status'),
'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'status',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('test')->__('Status'),
'values' => $statuses
)
)
));
return $this;
}
2.Create two action in admin controller with following code
public function massDeleteAction() {
$testIds = $this->getRequest()->getParam('test');
if(!is_array($testIds)) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
} else {
try {
foreach ($testIds as $testId) {
$test = Mage::getModel('test/test')->load($testId);
$test->delete();
}
Mage::getSingleton('adminhtml/session')->addSuccess(
Mage::helper('adminhtml')->__(
'Total of %d record(s) were successfully deleted', count($testIds)
)
);
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
$this->_redirect('*/*/index');
}
public function massStatusAction()
{
$testIds = $this->getRequest()->getParam('test');
if(!is_array($testIds)) {
Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
} else {
try {
foreach ($testIds as $testId) {
$test = Mage::getSingleton('test/test')
->load($testId)
->setStatus($this->getRequest()->getParam('status'))
->setIsMassupdate(true)
->save();
}
$this->_getSession()->addSuccess(
$this->__('Total of %d record(s) were successfully updated', count($testIds))
);
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
}
$this->_redirect('*/*/index');
}
1.Override _prepareMassaction() method in Grid.php with following code
protected function _prepareMassaction()
{
$this->setMassactionIdField('test_id');
$this->getMassactionBlock()->setFormFieldName('test');
$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('test')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('test')->__('Are you sure?')
));
$statuses = Mage::getSingleton('test/status')->getOptionArray();
array_unshift($statuses, array('label'=>'', 'value'=>''));
$this->getMassactionBlock()->addItem('status', array(
'label'=> Mage::helper('test')->__('Change status'),
'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'status',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('test')->__('Status'),
'values' => $statuses
)
)
));
return $this;
}
2.Create two action in admin controller with following code
public function massDeleteAction() {
$testIds = $this->getRequest()->getParam('test');
if(!is_array($testIds)) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
} else {
try {
foreach ($testIds as $testId) {
$test = Mage::getModel('test/test')->load($testId);
$test->delete();
}
Mage::getSingleton('adminhtml/session')->addSuccess(
Mage::helper('adminhtml')->__(
'Total of %d record(s) were successfully deleted', count($testIds)
)
);
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
$this->_redirect('*/*/index');
}
public function massStatusAction()
{
$testIds = $this->getRequest()->getParam('test');
if(!is_array($testIds)) {
Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
} else {
try {
foreach ($testIds as $testId) {
$test = Mage::getSingleton('test/test')
->load($testId)
->setStatus($this->getRequest()->getParam('status'))
->setIsMassupdate(true)
->save();
}
$this->_getSession()->addSuccess(
$this->__('Total of %d record(s) were successfully updated', count($testIds))
);
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
}
$this->_redirect('*/*/index');
}
Labels:
Magento
Object Expected error in Internet Explorer
This error usually happens in the following scenario. An HTML file contains an inline JavaScript to load remote.js and call a function in remote.js
<script type="text/javascript">
//<![CDATA[
Event.observe(window, 'load', function() {
product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
});
//]]>
</script>
And in the file remote.js:
remoteFunction code.....
You would expect the output in this order:
Before loading remote.js
After loading remote.js
In remote function
IE gives an error message "Object Expected" because it calls the function remoteFunction() prematurely. It calls before loading the file remote.js, which contain the declaration of remoteFunction(). This is another unexpected behavior from IE. Fortunately, it can be corrected by adding the attribute defer="defer" to second script invocation. This will specifically prevent IE from executing in order to give a correct output. Other browsers are not affected by the change.
<script type="text/javascript">
//<![CDATA[
Event.observe(window, 'load', function() {
product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
});
//]]>
</script>
And in the file remote.js:
remoteFunction code.....
You would expect the output in this order:
Before loading remote.js
After loading remote.js
In remote function
IE gives an error message "Object Expected" because it calls the function remoteFunction() prematurely. It calls before loading the file remote.js, which contain the declaration of remoteFunction(). This is another unexpected behavior from IE. Fortunately, it can be corrected by adding the attribute defer="defer" to second script invocation. This will specifically prevent IE from executing in order to give a correct output. Other browsers are not affected by the change.
Labels:
Javascript
Tuesday, August 7, 2012
Magento: Tag Url Rewrite and Generate
Rewrite the tag/tag model and override the getTaggedProductsUrl() with the following code
public function getTaggedProductsUrl()
{
$fullTargetPath = Mage::getUrl('tag/product/list', array(
'tagId' => $this->getTagId(),
'_nosid' => true
));
$targetPath = substr($fullTargetPath, strlen(Mage::getBaseUrl()));
$rewriteUrl = Mage::getModel('core/url_rewrite')->loadByIdPath($targetPath);
if ($rewriteUrl->getId()) {
return $rewriteUrl->getRequestPath();
}
return $fullTargetPath;
}
public function getTaggedProductsUrl()
{
$fullTargetPath = Mage::getUrl('tag/product/list', array(
'tagId' => $this->getTagId(),
'_nosid' => true
));
$targetPath = substr($fullTargetPath, strlen(Mage::getBaseUrl()));
$rewriteUrl = Mage::getModel('core/url_rewrite')->loadByIdPath($targetPath);
if ($rewriteUrl->getId()) {
return $rewriteUrl->getRequestPath();
}
return $fullTargetPath;
}
Labels:
Magento
Subscribe to:
Comments (Atom)