Skip to content

Instantly share code, notes, and snippets.

View dinhkhanh's full-sized avatar

Trần Đình Khánh dinhkhanh

View GitHub Profile
@dinhkhanh
dinhkhanh / catalog.patch
Created June 18, 2014 14:11
Always include catalog in product url
Index: app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php
===================================================================
--- app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php (revision 2102)
+++ app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php (working copy)
@@ -553,7 +553,11 @@
->from($this->getTable('core/url_rewrite'), array('product_id', 'request_path'))
->where('store_id=?', Mage::app()->getStore()->getId())
->where('is_system=?', 1)
- ->where('category_id=? OR category_id is NULL', $this->_urlRewriteCategory)
+// excluding this clause to facilitate one URL per product, and one that includes the category
@dinhkhanh
dinhkhanh / magento-add-newest-sort-option.sql
Last active August 29, 2015 14:09
Magento - Add Newset sort option
UPDATE `catalog_eav_attribute`
SET `used_for_sort_by` = 1
WHERE `attribute_id` = (SELECT `attribute_id` FROM `eav_attribute` WHERE `entity_type_id` = (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_model` = "catalog/product") AND `attribute_code` = "created_at");
UPDATE `eav_attribute`
SET `frontend_label` = "Newest"
WHERE `entity_type_id` = (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_model` = "catalog/product" AND `attribute_code` = "created_at");
@dinhkhanh
dinhkhanh / magento-delete-order-phpmyadmin.sql
Created December 30, 2014 14:49
Magento delete order phpmyadmin
SET @increamentID = 'XXXXXXXXX';
SET FOREIGN_KEY_CHECKS = 1;
DELETE FROM sales_flat_order
WHERE increment_id = @increamentID;
DELETE FROM sales_flat_quote
WHERE reserved_order_id = @increamentID;
static NSString * BCP47LanguageCodeFromISO681LanguageCode(NSString *ISO681LanguageCode) {
if ([ISO681LanguageCode isEqualToString:@"ar"]) {
return @"ar-SA";
} else if ([ISO681LanguageCode hasPrefix:@"cs"]) {
return @"cs-CZ";
} else if ([ISO681LanguageCode hasPrefix:@"da"]) {
return @"da-DK";
} else if ([ISO681LanguageCode hasPrefix:@"de"]) {
return @"de-DE";
} else if ([ISO681LanguageCode hasPrefix:@"el"]) {
@dinhkhanh
dinhkhanh / update_attributes_source_model.php
Last active August 29, 2015 14:16
Magento: Update attributes source_model
<?php
require_once "app/Mage.php";
Mage::app();
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $installer->getEntityTypeId('catalog_product');
// replace <my_attribute_code> with your attribute code
$idAttribute = $installer->getAttribute($entityTypeId, '<your_attribute_code_here>', 'attribute_id');
$installer->updateAttribute($entityTypeId, $idAttribute, array(
@dinhkhanh
dinhkhanh / magento-manully-add-handle-in-controller.php
Created March 25, 2015 08:51
Magento - Manually add handle in controller
<?php
/**
1. If you add your handle before you call $this->loadLayout() from a controller it’s too soon
2. If you add your handle after you call $this->loadLayout() it’s too late
So, if you really need to add a handle to a controller, you need to replace the call to $this->loadLayout() with:
**/
$update = $this->getLayout()->getUpdate();
$update->addHandle('default');
$this->addActionLayoutHandles();
@dinhkhanh
dinhkhanh / magento-get-customer-data.php
Created March 28, 2015 10:29
Magento get Customer's data
<?php
// Check if any customer is logged in or not
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
// Load the customer's data
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->getPrefix();
$customer->getName(); // Full Name
SET FOREIGN_KEY_CHECKS=0;
-- Customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
@dinhkhanh
dinhkhanh / magent-remove-decimal-in-price-if-needed.php
Created May 22, 2015 09:44
Magento Remove decimal in price if needed
<?php
/**
* File: /app/code/core/Mage/Directory/Model/Currency.php
* Function: formatTxt
* Do: Add this before return;
*/
if (($price - intval($price)) == 0) {
$options['precision'] = 0;
}
@dinhkhanh
dinhkhanh / magento-cache-shell.php
Created May 26, 2015 16:09
Magento Cache Shell
<?php
/**
* Author: Nathan Wu
* Date: Nov 19, 2012
* Time: 12:54:29 AM
*
* Mage_Shell script that interfaces with the Magento cache.
*
*
* @category JoomlaCreator