2015-10-30

How to add external js to magento

Add to your layout:
<reference name="head">
   <block type="core/text" name="my.external.js">
      <action method="setText">
        <text>
           <![CDATA[<script type="text/javascript" src="https://domain.com/my_file.js"></script>]]>
        </text>
      </action>
   </block>
</reference>

2015-10-29

How to show global messages in own controller/block

Add to your controller:
$this->_initLayoutMessages('customer/session');
after loadLayout():
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->renderLayout();
Then in phtml:
<?= $this->getMessagesBlock()->toHtml() ?>

2015-10-15

How to create table in magento installation script

$installer = $this;

$installer->startSetup();

$table = $installer->getConnection()
    ->newTable($installer->getTable('wmpayment/webmoney_response'))
    ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'identity' => true,
        'unsigned' => true,
        'nullable' => false,
        'primary'  => true,
    ), 'Id')
    ->addColumn('id_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'unsigned' => true,
        'nullable' => false
    ), 'Id order')
    ->addColumn('response', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ), 'Response in json format')
    ->addIndex('id_order', 'id_order');
$installer->getConnection()->createTable($table);

How to get magento config value

$value = Mage::getStoreConfig('path/to/config');

2015-10-06

Change magento configuration programmatically

$configModel = Mage::getModel('core/config');
$configModel->saveConfig('path/to/config', 'new value');

2015-08-19

How to use regex route rewrite in zf1

Just add construction like this to your config file:
resources.router.routes.exhange.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.exhange.route = "([a-zA-Z0-9]+)-to-([a-zA-Z0-9]+).html"
resources.router.routes.exhange.defaults.module = default
resources.router.routes.exhange.defaults.controller = index
resources.router.routes.exhange.defaults.action = exchange
resources.router.routes.exhange.map.1 = "from"
resources.router.routes.exhange.map.2 = "to"
Then you will be able to use links like: /one-to-two.html, where $_GET['from'] will be "one" and $_GET['to'] - "two".

2015-07-15

How to compare float numbers in php

/**
 * Return true if $a equals to $b
 *
 * @param float $a
 * @param float $b
 *
 * @return bool
 */
function isEqualFloat($a, $b)
{
    $epsilon = 0.00001;

    if (abs($a - $b) < $epsilon) {
        return true;
    }

    return false;
}

2015-04-03

How to create table in bootstrap

Add this code:
$this->bootstrap('db');
$db = $this->getResource('db');
Zend_Registry::set('db', $db);
after
parent::__construct($application);
in your bootstrap constructor.
And then you can create table:
$tableAuthSession = new Application_Model_DbTable_AuthSession();

2015-03-24

How to group WHERE clause in zf1

$db = $this->getAdapter();
$select = $db->select();
$select->from($this->_name);

$select->where('ip = ?', '120.0.0.1');
$select->orWhere('login = ?', 'test');

$subQuery = $select->getPart(Zend_Db_Select::WHERE);
$select->reset(Zend_Db_Select::WHERE);
$select->where(implode(' ', $subQuery));
$select->where('created_at = ?', date('Y-m-d'));

$res = $select->query()->fetchAll();
This will create sql with WHERE clause like as: "((ip = '127.0.0.1') OR (login = 'test')) AND (created_at = '2015-03-24')"

2015-02-23

Get helper from template (.phtml) in magento 2.0

Let's imagine that you have a helper app/code/SliRx/News/Helper/Date.php.
You can get the helper from template (.phtml file) like this:
$helper = $this->helper('SliRx\News\Helper\Date');

2015-02-22

Changing page layout in magento 2.0

You can change page layout by adding:
$layout = '2columns-left';
$this->pageConfig->setPageLayout($layout);
to your block's constructor.

2015-02-13

Magento google tag manager gtm

Google Tag Manager integration

With Google Tag Manager you can manage your Analytics events, Adwords conversion tracking, remarketing, etc. in one place. This module allows you to integrate Google Tag Manager to your site.
All you need is insert your container id to configuration of this extension.

 

You can get Google Tag Manager Integration GTM for magento here

 

Where to configure the extension?

System > Configuration > Google Tag Manager > Configuration.

Extension features:

  • Support multi-store
  • Support transactions (ecommerce tracking)
  • Support remarketing

Transaction features:

  • Support all product types
  • You can specify a name of your shop for each store
Remarketing allows you to show ads to your past site visitors and customize those ads based on the section of your site people visited. With dynamic remarketing, you can take this a step further, and show your site visitors an ad with the specific product they viewed on your site.