Skip to content

Instantly share code, notes, and snippets.

View 0-Sony's full-sized avatar

Phuong LÊ 0-Sony

View GitHub Profile
@0-Sony
0-Sony / Adminhtml_Model_Source_Category_Tree.php
Last active May 6, 2016 09:03
Get Category Tree Model for Adminhtml
<?php
class Namespace_Adminhtml_Model_Source_Category_Tree extends Mage_Core_Model_Abstract
{
/**
* @return array
* @throws Mage_Core_Exception
*/
public function toOptionArray()
{
@0-Sony
0-Sony / addColumnToFlatCustomProductAttributes.php
Last active August 12, 2016 13:00
Add new Column to Flat some product attributes in `sales_flat_order_item` Table
<?php
/** Location Namespace/Module/sql/namespace_module_setup **/
try {
/* @var $conn Varien_Db_Adapter_Interface */
/* @var $installer Mage_Sales_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
$installer->addAttribute('order_item', 'custom_attribute', array(
@0-Sony
0-Sony / Mage_Captcha_Model_Observer.php
Last active May 6, 2016 08:58
Fix bug Magento array_key_exists() error
<?php
//Replace this line Method@checkUserLogin && Method@checkUserLoginBackend
$login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
//By this one
$login = array_key_exists('username', array($loginParams)) ? $loginParams['username'] : null;
@0-Sony
0-Sony / .htaccess
Last active May 10, 2016 08:53
Htaccess configuration for a multi website
#Configuration
SetEnvIf Host ^mydomain\.com MAGE_RUN_CODE=base
SetEnvIf Host ^mydomain\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^foo\.mydomain\.com MAGE_RUN_CODE=mycustomwebsitecode1
SetEnvIf Host ^foo\.mydomain\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^mydomain2\.com MAGE_RUN_CODE=mycustomwebsitecode2
SetEnvIf Host ^mydomain2\.com MAGE_RUN_TYPE=website
@0-Sony
0-Sony / add_category_attribute.php
Created May 19, 2016 11:53
Add attributes for categories with installer
<?php
try {
/** @var Mage_Catalog_Model_Resource_Setup $installer */
$installer = $this;
$installer->startSetup();
$installer->addAttribute(
Mage_Catalog_Model_Category::ENTITY,
@0-Sony
0-Sony / pageType.php
Last active March 15, 2018 15:45
Magento : Generic Method to Get Page Type using for Tag
<?php
class Namespace_MyModule_myClass extends Mage_Core_Template
/**
* Get Page Type
* @return string
*/
public function getPageType()
{
$fullActionName = Mage::app()->getFrontController()->getAction()->getFullActionName();
@0-Sony
0-Sony / addOrUpdateProductPrice.php
Last active January 2, 2017 10:45
Magento 1 : Use Event to add product to cart and change the Quote Item Price.
<?php
Class MyNameSpace_MyModule_Model_Observer extends Mage_Checkout_Model_Observer_Abstract {
/**
* Add product to cart or update product price
*
* @event sales_quote_collect_totals_before
* @param Varien_Event_Observer $observer
**/
@0-Sony
0-Sony / customValidation.js
Last active December 17, 2016 00:46
Custom Validation[FR] Js for Magento
Validation.addAllThese([
['validate-zip-fr', 'Please enter a valid zip code. For example 75001.', function (v) {
return Validation.get('IsEmpty').test(v) || /(^\d{5}$)/.test(v);
}],
['validate-mobile-fr', 'Please enter a valid cellphone number. For example 0601020304.', function (v) {
return Validation.get('IsEmpty').test(v) || /(^[0][6-7]\d{8}$)/.test(v);
}],
['validate-fix-fr', 'Please enter a valid cellphone number. For example 0101020304.', function (v) {
return Validation.get('IsEmpty').test(v) || /(^[0]([1-5]|9)\d{8}$)/.test(v);
}],
@0-Sony
0-Sony / magento2_categoryInstaller.php
Last active June 19, 2024 17:20
Magento2: Create Category By Setup Install
<?php
namespace Namespace\Category\Setup;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Catalog\Api\Data\CategoryInterfaceFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
@0-Sony
0-Sony / ListProduct_SearchCriteriaBuilder.php
Last active March 13, 2020 19:00
Magento 2 : Example of using searchCriteriaBuiler
<?php
namespace MyNameSpace\Catalog\Block\Product
use Magento\Catalog\Model\ProductRepository;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\Search\FilterGroupBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\View\Element\Template;