Skip to content

Instantly share code, notes, and snippets.

View michaelhoang's full-sized avatar

Michael Hoang michaelhoang

View GitHub Profile
@michaelhoang
michaelhoang / prototype-fire.js
Last active August 29, 2015 14:04
Magento fire event prototype in product configurable selection
// Fire event 'change' prototype manual
var element = $(selectorId);
// Create html event
var evt = document.createEvent("HTMLEvents");
evt.initEvent('change', true, true);
// Set value configurable product
element.value = xxx;
// Fire event
element.dispatchEvent(evt);
@michaelhoang
michaelhoang / sub-words.php
Created August 3, 2014 14:34
Sub words with length
<?php
// Sub words with length
function truncate( $text, $length = 100, $more = null ) {
if ( null === $more )
$more = ' ...';
$text = strip_tags( $text );
$text = substr($text, 0, $length - strlen($more) + 1);
$words_array = preg_split("/[\s]+/", $text);
array_pop( $words_array );
@michaelhoang
michaelhoang / magento-modules
Last active August 29, 2015 14:05
Magento Necessary Modules
0. Magneto Debug
http://connect20.magentocommerce.com/community/MagnetoDebug
1. Attribute Splash Pages
http://connect20.magentocommerce.com/community/Fishpigs_Attribute_Splash_Page
2. Multiple Select In Layered Navigation (Filters)
http://connect20.magentocommerce.com/community/Mana_Filters
3. Instagram Extension
@michaelhoang
michaelhoang / wp.conf
Created October 23, 2014 10:33
Virtual Host In Linux
<VirtualHost *:80>
ServerName wp.local
DocumentRoot "/var/www/wp"
<Directory "/var/www/wp">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
## Must have
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/wp/$1
@michaelhoang
michaelhoang / vagrant-vhost-nginx
Last active August 29, 2015 14:09
Vhost in Nginx
#Add new vhost in Nginx
server {
listen *:80;
server_name example.local www.example.local;
index index.html index.htm index.php;
access_log /var/log/nginx/example.local.access.log;
error_log /var/log/nginx/example.local.error.log;
@michaelhoang
michaelhoang / vagrant-vhost-apache
Created November 11, 2014 01:56
Vagrant Vhost Apache
#Vhost in Apache 2
<VirtualHost *:80>
ServerName netshirt.local
## Vhost docroot
DocumentRoot "/var/www/netshirt"
## Directories, there should at least be a declaration for /var/www/netshirt
<Directory "/var/www/netshirt">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
@michaelhoang
michaelhoang / attribute.php
Last active August 29, 2015 14:19
All about attributes
// Get attribute object by code
Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'color');
// Get entity type object by code
Mage::getModel('eav/entity_type')->loadByCode('catalog_product');
// ===========================================================
public function joinEavTablesIntoCollection($collection, $mainTableForeignKey, $eavType)
{
$entityType = Mage::getModel('eav/entity_type')->loadByCode($eavType);
$attributes = $entityType->getAttributeCollection();
@michaelhoang
michaelhoang / magento-url.php
Created April 25, 2015 04:19
Magento Url Utilities
// Get new url base current url
$url = Mage::getUrl('/*/*', array(
'_use_rewrite' => true,
'_query' => array(
'param1' => 'param1',
'param2' => 'param2',
'param3' => 'param3',
),
));
// Get current url
@michaelhoang
michaelhoang / product.php
Last active August 29, 2015 14:20
Magento Shell
// Change product attribute value
public function run()
{
// --edit 1-10,color,5
// $default = array(
// 'product_ids' => array(1, 10),
// 'attribute_code' => 'color',
// 'attribute_value' => 5
// );
if (isset($this->_args['edit'])) {
@michaelhoang
michaelhoang / category.php
Created April 27, 2015 07:55
Magento Category
public function categoryTravel($category, $level)
{
$result = new Varien_Data_Collection;
if (is_numeric($category)) {
$category = Mage::getModel('catalog/category')->load($category);
}
$this->_categoryTravel($result, $level, $category);
return $result;