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_add_static_block_programmatically_with_setup_script.md
Created March 17, 2017 10:23
Magento. Add static block programmatically within setup script

Add static block programmatically within setup script

    /* @var $installer Mage_Core_Model_Resource_Setup */
    $installer = $this;

    /* @var $connection Varien_Db_Adapter_Pdo_Mysql */
    $connection = $installer->getConnection();
@evgv
evgv / mage_format_date.md
Created March 17, 2017 10:01
Magento. Format date.

Format date

    $now   = Mage::getModel('core/date')->gmtDate(); // 2017-03-17 09:59:10
    
    /* @var $helperCore Mage_Core_Helper_Data */
    $helperCore = Mage::helper('core');
    
 $full = $helperCore->formatDate(null, Mage_Core_Model_Locale::FORMAT_TYPE_FULL, true); // Friday, March 17, 2017 11:59:10 AM Europe/Helsinki
@evgv
evgv / mage_add_image_to_cms_page.md
Created March 17, 2017 08:24
Magento. Add image to cms page.

Add image to cms page

1. Add new fields to cms_page table

Add new mysql4-install-1.0.0 if you create new module or mysql4-upgrade-x.x.x-x.x.x if you add it to existed module.

    /* @var $installer Mage_Core_Model_Resource_Setup */
    $installer = $this;
@evgv
evgv / mage_add_new_column_to_existed_table.md
Created March 17, 2017 07:45
Magento. Add new column to existed table

Add new column to existed table

/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();

try {
 $installer->getConnection()
@evgv
evgv / Configurable.php
Last active February 26, 2017 17:55
Rewrite method getSelectedAttributesInfo() in class Mage_Catalog_Model_Product_Type_Configurable for add into configurable options array attribute store_label on cart page.
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
@evgv
evgv / Cookie.php
Last active February 26, 2017 17:26
Improved class for working with cookies.
@evgv
evgv / regexp.markdown
Last active September 14, 2017 07:38
Regular expressions.

Regular expressions

The list will be supplemented

Cut all from string exept numbers

    $string = 'jkwei fwoewego bo7  hp9gghwhl wekof we90fgweh wempgojwe90';

    echo preg_replace('/[^0-9]/', '', $string); // 799090
@evgv
evgv / mage_model_without_auto_increment_primary_key.markdown
Last active February 21, 2017 09:22
Magento. Database model without an auto_increment primary key

Magento database model without an auto_increment primary key

When you create a model in Magento that reads and writes data $model->load() and $model->save() to a database table, by default, Magento expects the primary key of the table to be an auto_increment field called id.

If you want to use a primary key that is not an auto_increment field then you need to set the _isPkAutoIncrement flag to false.

For example:

class {Vendor}_{Extension}_Model_Resource_{Model} extends Mage_Core_Model_Resource_Db_Abstract 
@evgv
evgv / redis_cli.md
Last active February 26, 2017 17:50
Redis. CLI

Redis CLI

The list will be supplemented

Open Redis CLI (for ubuntu/debian)

  
  redis-cli
  
@evgv
evgv / rss_feed_api.markdown
Last active February 26, 2017 17:47
RSS Feed API

RSS feed API

Previously, I used Google Feed API. But this API is officially deprecated and will stop working after December 15th, 2016. See deprecation policy in Google [Terms of Service][terms-of-service] for details.

For example I try to retrieve [Pinterest][pinterest] RSS feed of my pinned posts.

How to get Pinterest RSS link

https://pinterest.com/{usename}/feed.rss for my account link is https://pinterest.com/evgvzubkoff/feed.rss

RSS service

I'm chose a [RSStoJSON][rsstojson]