Column Collation in Table

This doesn't work:

    ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array(
        'nullable'  => false,
        'collate'   => 'utf8mb4_unicode_ci' // doesn't work
        ), 'Name')

That's because it is ignored:

// lib\Varien\Db\Ddl\Table.php
public function addColumn($name, $type, $size = null, $options = array(), $comment = null)
{
//...
    $this->_columns[$upperName] = array(
        'COLUMN_NAME'       => $name,
        'COLUMN_TYPE'       => $type,
        'COLUMN_POSITION'   => $position,
        'DA...

validation.js

/*
* Really easy field validation with Prototype
* http://tetlaw.id.au/view/javascript/really-easy-field-validation
* Andrew Tetlaw
* Version 1.5.4.1 (2007-01-05)
*
* Copyright (c) 2007 Andrew Tetlaw
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software,...

Adminhtml JSON Response Body

HTML

public function visibleProductsAction()
{
    $this->getResponse()->setBody(
        $this->getLayout()->createBlock('module/adminhtml_block_type')->toHtml()
    );
}

Generic Block:

$block = $this->getLayout()->createBlock('adminhtml/template')
    ->setTemplate('system/autocomplete.phtml')
    ->assign('items', $items);

$this->getResponse()->setBody($block->toHtml());

Array

class Mage_Adminhtml_JsonController extends Mage_Adminhtml_Controller_Action
{
    /**
     * Return JSON-encoded array of count...

Modify Column in Table

Change Text Length

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

$table = $installer->getTable('sales/order_item');
// Using modifyColumn()
$installer->getConnection()->modifyColumn($table, 'product_options', 'MEDIUMTEXT');
// Using changeColumn()
$installer->getConnection()->changeColumn(
    $table,
    'product_options',
    'product_options',
    [
        'type' =>  Varien_Db_Ddl_...

Translation

DO NOT use inline translation. The inline translations are stored in the table core_translate. Backup the table, convert all entries to a file translate.csv. Then configure the following.

Set up translation in the theme

Backend > System > Configuration > set the Current Configuration Scope to the store of interest, then go to Design > Theme > Translation and set the name of the theme:

Image

Then create or save the file translate.csv in app\design\frontend\<PACKAGE>\visa\locale\en_GB.

FIle Download

Generate the URL:

    /**
     * For file and image field, get the file URL
     * 
     * @see Mage_Customer_Model_Attribute_Data_File
     * @return string
     */
    public function getFileUrl()
    {
        return $this->getUrl('extendedcustomer/account/viewfile', array(
            'file'      => Mage::helper('core')->urlEncode($this->getValue()),
        ));
    }

Controller:

class Scicom_ExtendedCustomer_AccountController extends Mage_Core_Controller_Front_Action
{
    /**
     * @see Mage_Adminhtml_CustomerCont...

_prepareLayout

Add css

protected function _prepareLayout()
{
    $this->getLayout()->getBlock('head')->addCss('course/form.css');
    $this->setTitle('Course Eligibility Result');
    return parent::_prepareLayout();
}

Set Child Block

protected function _prepareLayout()
{       
    parent::_prepareLayout();
    $this->setChild('setForm', $this->getLayout()->createBlock('extendedcustomer/adminhtml_attribute_set_main_formset'));
    return $this;
}

Add Button

protected function _prepareLayout()
{
    $this->_addButton('s...

When there is no payment methods on onepage checkout page

There are many reasons why a payment method is not listed or missing on the checkout page:

  1. admin > System > Configuration > Sales > Payment Methods >
    1. check that the payment methods are enabled
    2. check for min and max amount of the payment method
    3. check for applicable countries or any other configurable values which can prevent the method from being listed
  2. [3rd-party extension] admin > Customers > Customer Group > select a group > Group Payment Methods > check that the payment methods are selected for the customer gr...

Varien_Data_Form Fieldset Options

Wide field

Useful for long text.

$form = new Varien_Data_Form();

$fieldset = $form->addFieldset('base_fieldset', [
    'legend' => Mage::helper('im')->__('Comment'),
   // 'comment' => 'non-html text is rendered before other fields',
    'class' => 'fieldset-wide'
]);

        $fieldset->addField('comment', 'textarea', [
            'name'      => 'comment',  
            'required'  => true,
            'after_element_html' => "<script>$('comment').up('td').previous('td').remove();$('comment').up('td').colspan=2;</script>"
     ...

Warning: Invalid argument supplied for foreach() in lib/Zend/Locale/Format.php on line 853

PHP Version 7.4.7 OpenMage 1.9.4.5

if ($day !== false) {
    $parse[$day]   = 'd';
    if (!empty($options['locale']) && ($options['locale'] !== 'root') &&
        (!is_object($options['locale']) || ((string) $options['locale'] !== 'root'))) {
        // erase day string
            $daylist = Zend_Locale_Data::getList($options['locale'], 'day');
        foreach($daylist as $key => $name) {
            if (iconv_strpos($number, $name) !== false) {
                $number = str_replace($name, "EEEE", $number);
                break;
 ...

How to Set Date Format by Locale in Magento 1

Each locale has different date formats. The default settings are configured in xml files located in lib\Zend\Locale\Data. The locale is configured in backend

System > Configuration > General > Locale Options > Locale

For example, if we set the Locale to English (United Kingdom), which value is en_GB. To look up the default date formats, look at the file lib\Zend\Locale\Data\en_GB.xml:

<dateFormats>
    <dateFormatLength type="full">
        <dateFormat>
            <pattern>EEEE, d MMMM U</pattern>
        </dateFormat>
 ...

How to add TCPDF to Library to Magento 1

We can add a 3rd-party to library to Magento, for example TCPDF.

  1. Download the library and unzip.
  2. Place the unzip contents to /lib/Tcpdf/.
  3. For autoloading by Magento, we need to change the main application class name to Mage standard (separated by underscore): <folder-name>_<original-class-name>; for TCPDF, we edit the file Tcpdf.php: the original class name is class TCPDF, we change it to class Tcpdf_Tcpdf.
    1. class Tcpdf_Tcpdf
    2. class Tcpdf_Tcpdf2DBarcode
  4. No we can ins...

Link Top Menu Item to Product View

Top menu is configured in backend > Catalog > Manage Categories. The landing page can be set to product list, static block, or a combination of both. But what if we want to by pass the product listing and land on a product page? Here's the technique I use to do just that:

[vs code] Create a Couple of Blocks

/**
 * es Module
 *
 * @category   Celera
 * @package    Celera_Es
 * @copyright  Copyright (c) 2019 Ng Kiat Siong, Celera eShop, kiatsiong.ng@gmail.com  
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software...

Set custom URL to 'Add to Cart' in Backend Product Page

admin > product page > Design > Custom Layout Update:

<reference name="content">
    <block type="es/catalog_product_view_layoutUpdate_application" name="layoutupdate_application"/>
</reference>
<reference name="product.info">
    <action method="setCustomAddToCartUrl"><url>/controller/catalog_product/route</url></action>
</reference>
<reference name="head">
    <action method="addItem"><type>skin_js</type><name>js/aes.js</name>
    <action method="addJs"><script>dir/jsonp.js</script></action>
</action>
</reference>

Insert Vue.j...

Collection: addFieldToSelect vs select columns

collection->addFieldToSelect('col_name') will include the ID column in result. To return only columns of interest, use

$collection->getSelect()
    ->reset(Zend_Db_Select::COLUMNS)
    ->columns(['col_name']);

Example:

$collection->getSelect()
   ->reset(Zend_Db_Select::COLUMNS)
   ->columns(['entity_id' => 'mageproductid', 'value' => 'userid']);
$result = $collection->toArray();

$result output:

 array(2) {
  ["totalRecords"] => int(1565)
  ["items"] => array(1565) {
    [0] => array(2) {
      ["entity_id"]...