Skip to content

Instantly share code, notes, and snippets.

View mukundthanki's full-sized avatar

Mukund Thanki mukundthanki

View GitHub Profile
@mukundthanki
mukundthanki / gist:3985015
Created October 31, 2012 05:32
Limit Words To String( title, content, anything )
<?php
function string_limit_words($string, $word_limit){
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
//Usage
//Suppose for wordpress content/excerpt length
@mukundthanki
mukundthanki / col-left.phtml
Last active September 23, 2019 14:09
Magento: How to get current category in magento
<?php
// Using singleton
$_category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
// Using Model
$_category = Mage::getModel('catalog/layer')->getCurrentCategory();
// Using Registry
$_category = Mage::registry('current_category');
?>
@mukundthanki
mukundthanki / view.phtml
Last active October 12, 2015 06:28
Magento: Using Helper Classes in Magento
<?php
// Get resized Image on list page.( Mage_Catalog_Block_Product_List )
echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(149);
// Get attribute
$_helper = $this->helper('catalog/output');
echo $_helper->productAttribute($_product, $_product->getName() , 'name');
?>
@mukundthanki
mukundthanki / My Magento Code.php
Last active May 31, 2018 09:24 — forked from claudiu-marginean/My Magento Code.php
Magento: Code Snippets
<block type="cms/block" name="block_name">
<action method="setBlockId"><id>block_code</id></action>
</block>
{{block type="cms/block" block_id="block_code"}}
{{block type="catalog/product_list" category_id="79" template="catalog/product/list_random.phtml"}}
@mukundthanki
mukundthanki / list.phtml
Last active December 14, 2015 04:28
Magento: Load products from selected categories in magento
<?php
$categories = array(8,22);
$collection = mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status',1)
->joinField('category_id',
'catalog/category_product',
'category_id',
'product_id=entity_id',
null,
@mukundthanki
mukundthanki / template.phtml
Last active December 14, 2015 04:29
Magento: Load selected categories in magento
<?php
$categories = Mage::getModel('catalog/category')->getCollection();
$categories->addAttributeToSelect('*');
$categories->addAttributeToFilter('is_active', 1);
$categories->addAttributeToFilter('entity_id', array('in' => array(3,4,5,6,7)));// Loading selected categories by passing array
$categories->load();
// Normal list of categories
if($categories){
echo "<ul>";
@mukundthanki
mukundthanki / google-map-v3.js
Last active December 14, 2015 23:48
Google map v3
// JavaScript Document
function initialize() {
var myOptions = {
zoom: 10,
center: new google.maps.LatLng(0, 0),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(
document.getElementById("map_canvas"),
@mukundthanki
mukundthanki / functions.php
Last active March 26, 2018 06:27
WordPress: Insert multiple files and attach them to post from front-end.
<?php
# Upload multiple files and attach them to post using single function
// Files Uploader attach to shop
if ($_FILES) {
$files = $_FILES['shop-imgs'];
foreach ($files['name'] as $key => $value) {
if ($files['name'][$key]) {
$file = array(
'name' => $files['name'][$key],
@mukundthanki
mukundthanki / install-magento-using-terminal
Last active December 24, 2015 01:29 — forked from tonyoconnell/gist:2351492
Install Magento 1.8.1.0 with sample data via ssh
mkdir mage_test
cd mage_test
wget http://www.magentocommerce.com/downloads/assets/1.8.1.0/magento-1.8.1.0.tar.gz
wget http://www.magentocommerce.com/downloads/assets/1.6.1.0/magento-sample-data-1.6.1.0.tar.gz
tar -zxvf magento-1.8.1.0.tar.gz
tar -zxvf magento-sample-data-1.6.1.0.tar.gz
mv magento-sample-data-1.6.1.0/media/* magento/media/
mv magento-sample-data-1.6.1.0/magento_sample_data_for_1.6.1.0.sql magento/data.sql
mv magento/* magento/.htaccess .
chmod o+w var var/.htaccess app/etc
# one-liner for generating this: mysqldump --no-data -uroot magento1600 | nawk '{if(match($0, /CREATE TABLE `(.*)`/, matchesT)) { the_table = matchesT[1]; } if(match($0, /(CONSTRAINT .*),?/, matchesK) && the_table) { the_key = gensub(/,?$/, "", matchesK[1]); the_key = gensub(/^ */, "", the_key); print "ALTER TABLE `" the_table "` ADD", the_key ";"; }}'
ALTER TABLE `admin_rule` ADD CONSTRAINT `FK_ADMIN_RULE_ROLE_ID_ADMIN_ROLE_ROLE_ID` FOREIGN KEY (`role_id`) REFERENCES `admin_role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `api_rule` ADD CONSTRAINT `FK_API_RULE_ROLE_ID_API_ROLE_ROLE_ID` FOREIGN KEY (`role_id`) REFERENCES `api_role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `api_session` ADD CONSTRAINT `FK_API_SESSION_USER_ID_API_USER_USER_ID` FOREIGN KEY (`user_id`) REFERENCES `api_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `catalog_category_entity_datetime` ADD CONSTRAINT `FK_CAT_CTGR_ENTT_DTIME_ATTR_ID_EAV_ATTR_ATTR_ID` FOREIGN KEY (`attribute_id