Skip to content

Instantly share code, notes, and snippets.

View michaelhoang's full-sized avatar

Michael Hoang michaelhoang

View GitHub Profile
@michaelhoang
michaelhoang / convert-quote-to-order.php
Last active September 8, 2015 03:00
Magento Add Pagination Pager in block
<?php
// Reference: app/code/core/Mage/Sales/Model/Service/Quote.php:134
// Set customer info to quote
// $store = Mage::getSingleton('core/store')->load($this->getArg('store_id'));
// $quote = Mage::getModel('sales/quote')->setStore($store)->load($this->getArg('quote_id'));
$convert = Mage::getModel('sales/convert_quote');
$isVirtual = $quote->isVirtual();
// Set shipping method
@michaelhoang
michaelhoang / command-generate-image.php
Last active September 21, 2020 19:31
All about Prestashop
<?php
$timer_start = microtime(true);
if (!defined('_PS_ADMIN_DIR_'))
define('_PS_ADMIN_DIR_', getcwd());
if (!defined('PS_ADMIN_DIR'))
define('PS_ADMIN_DIR', _PS_ADMIN_DIR_);
require(_PS_ADMIN_DIR_ . '/../config/config.inc.php');
require(_PS_ADMIN_DIR_ . '/functions.php');
@michaelhoang
michaelhoang / debug.php
Last active August 29, 2015 14:27
Debug: log infomation to file
<?php
final class Debug
{
public static function log($message, $file = 'system.log')
{
try {
$logDir = 'log';
$logFile = $logDir . '/' . $file;
if (!is_dir($logDir)) {
@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;
@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 / 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 / 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 / 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 / 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 / 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