Archive for the ‘Magento 1.x’ Category

Magento add Js Script

Method 1. Adding to layout file <reference name="head"> <action method="addJs"><script>skin/frontend/base/default/js/yourextension/index/scriptname.js</script></action> </reference> Method 2. Adding to phtml file <?php echo $this->helper(’core/js’)->includeSkinScript(’js/yourextension/index/scriptname.js’) ?>

Sending email in Magento with attachment

$mail = new Zend_Mail(); $mail->setType(Zend_Mime::MULTIPART_RELATED); $mail->setBodyHtml('<p>This is Magento email sample with attachment</p>’); $mail->setFrom("sender@senderemail.com", "Sender title"); $mail->addTo(["recepient@recepientemail.com"]); $mail->setSubject("Email Subject"); $file = $mail->createAttachment(file_get_contents("/file/path/to/attachment.csv")); $file->type = ‘text/csv’; $file->disposition = Zend_Mime::DISPOSITION_INLINE; $file->encoding = Zend_Mime::ENCODING_BASE64; $file->filename = basename("/file/path/to/attachment.csv"); $mail->send();

Using {{widget}} tag in phtml same as in CMS Editor

$filter = new Mage_Widget_Model_Template_Filter(); $_widget = $filter->filter('{{widget type="cms/widget_page_link" template="cms/widget/link/link_block.phtml" page_id="2"}}’); echo $_widget;

Magento order calculation formula

orders.subtotal = ((orders.grand_total+IFNULL(orders.base_customer_balance_amount,0)) + ABS(orders.base_discount_amount))-orders.base_shipping_amount Explanation: Order items makes subtotal, then shipping cost is added to it. From that sum discount is extracted and customer balance (if any) extracted. Remaining amount is total due to pay (amount which really needs to be paid by customer) or grand_total

How-to generate magento extension package

1. Go to magento root folder and inside the var folder, create a new folder connect. 2. Login to admin panel in your browser. 3. From the admin panel, navigate to System > Magento Connect > Package extensions. 4. This will enable you to create extension package page.

Put magento into maintenance mode

Simply create empty file maintenance.flag in magento www folder

Update website base url

UPDATE core_config_data SET VALUE=’http://www.website.com/’ WHERE path=’web/unsecure/base_url’; UPDATE core_config_data SET VALUE=’http://www.website.com/’ WHERE path=’web/secure/base_url’;

Cms Block Stores

$blockCollection = Mage::getResourceModel(’cms/block_collection’); foreach($blockCollection as $block) { Zend_Debug::dump($block->getResource()->lookupStoreIds($block->getBlockId())); }

Redirecting in observer

$controller = $observer->getEvent()->getControllerAction(); $controller->getResponse()->setRedirect($redirectUrl); $controller->setFlag(”, Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); $controller->setFlag(”, Mage_Core_Controller_Varien_Action::FLAG_NO_POST_DISPATCH, true);

Reset customer password in db

UPDATE customer_entity_varchar SET VALUE = md5(’new_password’) WHERE entity_id=(SELECT entity_id FROM customer_entity WHERE email=’email@hostname.com’) AND attribute_id IN (SELECT attribute_id FROM eav_attribute WHERE attribute_code = ‘password_hash’ AND entity_type_id = 1);