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 / git_find_large_files_in_history.md
Created April 26, 2017 06:21
Git. Find/identify large files/commits in Git history

Find/identify large files/commits in Git history

The Base Code

This bash one-liner displays all blob objects in the repository, with the largest ones last.
This will generate computer-friendly output.

    git rev-list --objects --all \
 | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
@evgv
evgv / mage_validate_upoaded_files.md
Last active April 20, 2017 12:10
Magento. Validate uploaded files.

Validate uploaded files

In example below customer must(not required) upload agreement file what must be less then 10Mb and only .jpeg, .jpg, .png or .pdf format.

Full overwrited customer AccountController.php

<?php
/**
 * Customer account controller
@evgv
evgv / mage_update_attribute_via_upgrade_script.md
Last active April 28, 2020 09:03
Magento. Update attribute via install/upgrade script.

Update attribute via install/upgrade script

In example below I upgraded is_visible_on_front and used_in_product_listing from false to true for two attributes namely flavor and unit_count. These attributes are product attributes and refer to Mage_Catalog_Model_Product::ENTITY or catalog_product. For update attribute params we are need the: entity id of attribute, id of attribute, field name what we wont to change, new field value and sort order. Function what we will use is updateAttribute from class Mage_Eav_Model_Entity_Setup.

Install/upgrade script in my case this is the mysql4-upgrade-1.1.4-1.1.5.php

    /* @var $installer Mage_Catalog_Model_Resource_Setup */
@evgv
evgv / mage_update_stock_status_of_products_via_direct_sql.markdown
Last active April 13, 2017 13:06
Magento. Update stock status of products via direct SQL

Update stock status of products via direct SQL

In this case set out_of_stock to all products what is_in_stock (stock item status) and discontinued (code of yes/no attribute) via direct sql for speed up it and do without load product collection. This is good example for use direct SQL queries(select/update) using Varien_Db_Adapter_Interface.

Code of class below:

  <?php
@evgv
evgv / mage_update_content_of_meta_robots_tag.markdown
Last active January 5, 2019 01:55
Magento. Update content of meta robots tag

Update content of meta robots tag

Declare observer into config.xml

    
    <frontend>
        <events>
            <controller_action_layout_generate_xml_before>
                <observers>
@evgv
evgv / js_check_if_jquery_has_function.md
Last active April 21, 2017 07:47
Js. Check if jQuery has function.

Check if jQuery has function

For example we are check elevateZoom function.

    if ( !! jQuery.prototype.elevateZoom ) { 
        // has
    } else {
        // hasn't
 }
@evgv
evgv / mysql_password_validation_plugin.md
Last active March 29, 2017 20:32
MySQL. Password validation plugin

Passowrd validation plugin

MySQL 5.7+ by default haves a Password validation system. In case if you don't want to go strictly with the policy and need to assign your own then just set new validate rules.

First you login with mysql -u root -p and check the current policy rules by typing the command:

SHOW VARIABLES LIKE 'validate_password%';
@evgv
evgv / mage_disallow_all_routes_for_not_logged_users.markdown
Created March 27, 2017 07:06
Magento. Disallow all routes except `customer/*/*` for not logged users

Disallow all routes except customer/*/* for not logged users

Redirect to customer/account/login from any not customer/*/* routes. Well suited for use to close the store from not logged users/customers.

Register observer for event controller_action_predispatch

    <frontend>
        <events>
            <controller_action_predispatch>
                <observers>
@evgv
evgv / mage_add_related_products_tab_to_aw_blog_posts.md
Last active August 28, 2017 18:25
Magento. Add related products tab to AW_Blog posts.
@evgv
evgv / mage_show_address_fields_in_register.md
Created March 21, 2017 13:57
Magento. Show address fields in register

Show address fields in register

Create local.xml file (if it does not exist already) in [your_package]/[your_theme]/layout/ folder and add following code:

    <customer_account_create>
        <reference name="customer_form_register">
            <action method="setData"><key>show_address_fields</key><value>1</value></action>