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_environment_emulation.md
Last active November 22, 2016 09:16
Magento. Environment emulation.

Environment emulation

  // init app emulation model
  $appEmulation = Mage::getSingleton('core/app_emulation'); 
  
  // Start environment emulation of the specified store
  $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($store_id); 
@evgv
evgv / mage_create_block.md
Last active March 14, 2017 10:36
Magento. Create block.
    /**
     * First way (1) use layout for block create
     */
    $block = Mage::app()->getLayout()->createBlock('customermenu/page_html_header_menu')
                                     ->setTemplate('customermenu/page/html/header/menu.phtml')
                                     ->toHtml();
                                     
    /**
     * First way (2) use layout for block create
@evgv
evgv / mage_array_group_to_json.markdown
Last active November 23, 2016 13:23
Magento. Create group JSON array from collection.

Create group JSON array from collection.

  /**
   * Crete group JSON array from collection object.
   * Can set fields that will be added to JSON array grouped by field.
   * 
   * @param Varien_Object $collection
 * @param array $groupFileds
@evgv
evgv / sql_cli_db_import.md
Created April 7, 2016 15:12
SQL. Cli db import.
  // Import sql file
  mysql -h HOST --port=3307 -p -u  USER DATABASE < FILE
  
  // example
  mysql -h localhost --port=3307 -p -u root main < main_dump.sql
  
  
 // Import archive
@evgv
evgv / jquery_trim_any_spaces_from_input.md
Last active July 6, 2016 06:40
jQuery. You can set any selector for field instead #email and you get realtime trim spacel from input, I'm use it for email fields.
  $(function(){
    $('#email').bind('input', function(){
      $(this).val(function(_, v){
       return v.replace(/\s+/g, '');
      });
    });
  });
 
@evgv
evgv / mage_redirect_to_parent_category_from_empty_category.md
Created April 27, 2016 07:01
Magento. Observer method for redirect from empty category to parent.
    /**
     * Redirect from empty category to parent
     * Observe event - core_block_abstract_to_html_before
     * 
     * @param Varien_Event_Observer $observer
     */
    public function redirectToParentCategory(Varien_Event_Observer $observer)
    {
        Varien_Profiler::start(__METHOD__);
@evgv
evgv / mage_redirect_to_product_category_from_disabled_product.md
Last active April 27, 2016 07:15
Magento. Observer method for redirect from disabled product to last product category.
    
    /**
     * Redirect from disabled product to product last category
     * Obseve event - controller_action_predispatch_catalog_product_view
     * 
     * @param Varien_Event_Observer $observer
     */
    public function catalogProductViewPredispatch(Varien_Event_Observer $observer)
 {
@evgv
evgv / mage_set_custom_layout_by_customer_group.md
Created May 20, 2016 12:08
Mage. Set custom layout by customer group.
  protected $_customer_groups = array('NOT_LOGGED_IN', 'Genaral', 'Wholesale', 'Retail');

    /**
     * Get current customer group and update handle depend from current group
     * Observe event "controller_action_layout_load_before"
     * 
     * @param Varien_Event_Observer $observer
     */
 public function setTemplate(Varien_Event_Observer $observer) 
@evgv
evgv / mage_sql_restore_admin_password.md
Created June 9, 2016 13:39
Magento. SQL query for restore admin password.
UPDATE admin_user SET password = CONCAT (MD5 ('sGnewpass'), ': sG') WHERE username = 'AdminUsername'; 
@evgv
evgv / mage_get_module_controller_action_name.md
Last active July 15, 2016 09:27
Mage. Get module, controller and action name.

###In template (*.phtml)

/**
 * get Controller name
 */
$this->getRequest()->getControllerName();
 
/**