Skip to content

Instantly share code, notes, and snippets.

View evgv's full-sized avatar
🏠
Working from home

Eugene Zubkov evgv

🏠
Working from home
View GitHub Profile
@evgv
evgv / mage_right_way_to_alter_table_via_upgrade_script.md
Created June 23, 2017 14:19
Magento. The right way to alter table (add column) via upgrade script

Right way to alter table (add column) via upgrade script

Add new text column(if it not existed) with name yt_id in table with alias aboutus/aboutus defined in config.xml

/* @var $installer Mage_Core_Model_Resource_Setup */
$installer    = $this;
$aboutusTable = $installer->getTable('aboutus/aboutus');
$connection   = $installer->getConnection();
@evgv
evgv / php_pattern_singleton.md
Last active September 27, 2017 07:12
PHP. Pattern: Singleton

Simple example of Singleton design pattern

A singleton class is a class that can have only one object (an instance of the class) at a time.

Lasy load Singleton

The instance is created when the static method is first invoked.

  
/**
* Lazy load Simple example of Singleton design pattern 
@evgv
evgv / mage_turn_on_reporting.md
Last active June 16, 2017 07:20
Magento. Turn on error reporting

Turn on error reporting

Hardcode method

Fast but not good.
Uncomment this line in index.php

    ini_set('display_errors', 1);
@evgv
evgv / mage2_foler_file_permissions.md
Last active September 20, 2024 07:57
Magento 2 folder/file permissions

Magento 2 folder/file permissions

  • The owner of the Magento file system: Must have full control (read/write/execute) of all files and directories.
  • Must not be the web server user; it should be a different user.
  • The web server user must have write access to the following files and directories: var app/etc pub
  • In addition, the web server's group must own the Magento file system so that the Magento user (who is in the group) can share access to files with the web server user. (This includes files created by the Magento Admin or other web-based utilities.)
We recommend setting the permissions as follows:
All directories have 770 permissions.
@evgv
evgv / own_post_server_.markdown
Last active June 14, 2017 08:20
Own post server

Own post server

Server

Ubuntu + Postfix

Spam

Postfix and [Spamassassin]

Interfeice

[Roundcube]

@evgv
evgv / mage_run_magento_code_externally.md
Created May 12, 2017 09:49
Magento. Run Magento code externally.

Run Magento code externally

Sometimes we are need to run Magento code externally ouside of platform.
This can be easily achieved with the following lines of code.

    
    require_once('app/Mage.php'); // Path to Mage class
    umask(0);
 Mage::app();
@evgv
evgv / mage_how_to_debug_blank_white_screen.md
Last active June 20, 2017 14:32
Magento. How to debug blank white screen

How to debug blank white screen

Use the following code in your index.php file

    
    ini_set('error_reporting', E_ERROR);
    register_shutdown_function(function() {
        $error = error_get_last();
 if( ! empty($error) ) {
@evgv
evgv / mage_load_media_images_of_a_product.md
Created May 3, 2017 18:59
Magento. Load media images of a product

Load media images of a product

Use Backend model of media_gallery attribute & afterload of product model

    
      $attribute = $product->getResource()->getAttribute('media_gallery');
       
      $backend = $attribute->getBackend();
 $backend->afterLoad($product);
@evgv
evgv / mage_modify_table_column.md
Created May 3, 2017 15:25
Magento. Modify table column

Modify table column

Change column type from int(11) to bigint(20) with modifyColumn() function from class Varien_Db_Adapter_Pdo_Mysql

$installer = $this;
$installer->startSetup();

$installer->getConnection()->modifyColumn($installer->getTable('webforms/results'), 'customer_ip', array('type' => Varien_Db_Ddl_Table::TYPE_BIGINT));    
@evgv
evgv / mage_display_custom_attribute_in_cart.md
Last active April 26, 2017 06:32
Magento. Display custom attribute in cart.

How to display custom attribute in cart

Get custom product attribute from quote item.

1. Load product by item and get atribute

Will reload all product data from the database. While this will work, bear in mind that every time you call load() Magento will execute a database query.

 // load product