Anonymous said: Developing a 3rd party payment module, using getCheckoutRedirectUrl() to redirect when the payment method is selected. When the control comes back with the success response what should happen? I assume we should show the review section of the onepage checkout but, how? Is there a way to load the onepage checkout page directly opening a section? Hope its clear. Thanks!

You have to create a custom review and submit order page - see PayPal Express for example. Once the customer is redirected back to Magento, they show a special Express Checkout Review screen.

You can’t use the regular Onepage Checkout review step (unless you build that as a customization).


Anonymous said: do you have a dog?

Yup. It’s an imaginary dog; he’s been with me since I was 8 years old.


Anonymous said: is there is any option in magento 1.7 to change the payment method randomly on each time the customer checkout



Anonymous said: Can you explain, how work indexer in frontend ? Eg. how Magento get data in frontend ?

There are many possible indexers. Which one do you mean? Catalog flat data? URL rewrites? Product Prices? layered Navigation? Search Results?


Anonymous said: Hi, I read the «custom quote item» tutorial, but I'm not sure if that's what I'm looking for. All the products on my store have a price that depends on the client. We have to get this price by webservice and use it on the shopping cart when the client is logged in. The price is only shown on the product page (and following ones). How can I set a specific price for each product depending on the client? The price has to be consulted to the ERP. Thanks! @paugnu

I’d suggest fetching the price in an observer to the catalog_product_load_after and catalog_product_collection_load_after events and setting the returned value on the product.


Anonymous said: Hi, is it possible to make a tutorial about how to show different manufactures on different stores/sites with magento multi store? thanks

I don’t understand the question - what do you mean by “show different manufacturers”?


Renaming “Wishlist” to “Saved Products”

Ugly but fun: str_replace in controller_front_send_response_before. But better: create a module that adds an additional…

…translation file for every module that contains a string with “Wishlist” that is loaded after the original translations.

Use the xpath frontend/translate/modules/[Core_Module]/files/[yourmodule] with a value of Mage_[Module]_YourModule.csv

The basic idea is that you can have more then one translation file per module (loaded in order of module dependency).

CSV loaded later can overwrite or add to the modules translations from files loaded earlier.

All translation files are localized in app/locale/[locale]/, so you only add the files for the languages you choose to support.

The CSV content format is: “Original text with Wishlist”,”New Text with Saved Products”

That way you have a clean, theme independent, modularized replacement of Wishlist, kinda like a extension language pack.

Thanks to @Dan_The_Man for giving me the idea to tweet about this topic. 


Magento / Zend_DB SQL Profiling

Turn on profiler output in the configuration at System > Configuration > Developer > Debug > Profiler.

Switch on SQL profiling by adding the node <profiler>true</profiler> to the local.xml config into global/resources/default_setup/connection/

Alternatively you can call Mage::getSingleton(‘core/resource’)->getConnection(‘default_setup’)->getProfiler()->setEnabled(true); inline.

See Varien_Profiler::getSqlProfiler() on how to access detailed query information if the default display is too limited for you.

If you need profiling data from a page that redirects, you can log it using the event controller_front_send_response_after.


Setup Resource Classes

#tweetorial When declaring a setup resource in a config.xml global/resources/[module]_setup/setup at least a <module> node is required.

The <module> node links the setup resource to the module version, since Magento doesn’t remember from where the declaration is after merging

One other important node is global/resources/[module]_setup/setup/class. If omitted it defaults to Mage_Core_Model_Resource_Setup.

This class is used for executing the install and upgrade scripts. When do we need to specify a different class instead of the default?

Many modules extend the usual EAV attribute capabilities, e.g. catalog entity attributes have a is_configurable property.

To be able to specify a value for this property we need to use the catalog setup resource Mage_Catalog_Model_Resource_Setup.

So when you add attributes to an entity, be sure to use the setup class from the corresponding module (customer, catalog, sales, index,…)


eav/entity_setup addAttribute() vs. installEntities()

The difference of addAttribute() vs. installEntities() in setup scripts is today’s #tweetorial topic.
Both are used to manipulate the EAV configuration. Mage_Eav_Model_Entity_Setup::addAttribute() adds records to the eav_attribute table.
Mage_Eav_Model_Entity_Setup::installEntities() takes an array with an entity type definition including it’s attributes.
So installEntities() will add or update entries in eav_entity_type as well as use addAttribute() on each of the listed attributes.

You can use installEntities() to add more attributes to an existing entity, but in that case it’s just a wrapper for addAttribute().

I suggest you use installEntities() only to register new EAV entities. Use addAttribute() if all you are doing is creating attributes.

For creating all the required tables for new EAV entities have a look at the handy method createEntityTables() of the eav/entity_setup class
Example setup script using createEntityTables(), installEntities() and addAttribute(): https://gist.github.com/1349110


Action Level Controller Rewriting

Time to reactivate writing #tweetorials. Today a little information on controller rewrites (there are many ways to do this in Magento).

The official best practice to rewrite controllers is to use the config/[area]/routers/[route]/args/modules/ node. This is covered elsewhere.

Or see the code that evaluates this configuration at Mage_Core_Controller_Varien_Router_Standard::collectRoutes() (ref http://alanstorm.com/magento_dispatch_standard_router)

The information I want to share is that the controller is NOT only matched by it’s file name (e.g Sales/OrderController.php)

If the requested action isn’t implemented on a controller class, Magento will continue to look through the list of modules for a match.

So don’t extend the parent class you are rewriting unless you have to. This will let other modules rewrite other methods if needed.


Collection Filter Reference Classes

Since I’m travelling today, just a very short #tweetorial. One thing I find useful  to remember is a reference for collection filter details

In Magento 1.6 refer to Varien_Db_Adapter_Pdo_Mysql::prepareSqlCondition() for a listing of all possible filter types (e.g. eq, like, gteq, …)

In Magento 1.5 and older refer to Varien_Data_Collection_Db::_getConditionSql() for a filter type reference.


Magento Collection Ordering (or Sorting)

Today’s #tweetorial is about collection sorting. It can be confusing because we have five(!) options to choose from (4 tweets)

The available sorting methods are addOrder(), setOrder(), unshiftOrder(), addAttributeToSort() and getSelect()->order()

Only setOrder($field, $dir) is available regardless of collection type and system settings. I suggest you get used to using setOrder().

If you need to enforce an order, but an order is already set on the collection, use unshiftOrder($field, $dir) for flat table collections.

For EAV collections you need to do $col->getSelect()->reset(Zend_Db_Select::ORDER); And then use $col->setOrder($field, $dir);


Flat Table Collection OR Filters

Specifying an OR filter with a single attribute on a flat table collection is the same as on a EAV collection.

Eg: $col->addFieldToFilter(‘name’, array(array(‘like’ => ‘M%’), array(‘like’ => ‘%O’))); // get items whose name start with M OR end with O

To join multiple attributes in an OR condition the syntax is different from EAV collections (NOTE: this is BROKEN in Magento 1.6)

Eg: $col->addFieldToFilter(array(‘weight’, ‘name’), array(array(‘in’ => array(1,3)), array(‘like’ => ‘M%’)));

The first attribute is mapped to the first condition, the second attribute is mapped to the second condition, etc

Since this is broken in 1.6 we are left with the possibility to specify simple equality conditions for multiple attributes using addFilter()

Eg: $col->addFilter(‘weight’, 1, ‘or’)->addFilter(‘weight’, 2, ‘or’)->addFilter(‘sku’, ‘ABC’, ‘or’); // weight is 1 or 2 or sku is ABC

You can always use $collection->getSelect()->orWhere(…), too, but you have to watch out for cross RDBMS compatibility #SQL


EAV Collection OR Filters

The #tweetorial for the day will cover setting OR conditions on EAV collections. There are several cases we have to distinguish.

Note that FLAT TABLE collections use a different syntax! We will cover that tomorrow.

Also, when specifying OR conditions for the same attribute the syntax is different then if you want to use two different attributes.

Use $collection->load(true) to test and see the specified filter as SQL (I find it easier to understand that way).

For EAV collections use addAttributeToFilter() or addFieldToFilter(), but the first can take an optional third $joinType argument.

How To add an OR filter for ONE attribute on EAV collections: the attribute code is the first argument and the conditions are the second.

Eg: $col->addFieldToFilter(‘name’, array(array(‘like’ => ‘M%’), array(‘like’ => ‘%O’))); (get items whose name starts with M OR ends with O)

How To add an OR filter for DIFFERENT attributes on EAV collections: only pass one argument, an array of conditions with attributes.

Eg: $col->addFieldToFilter(array(array(‘attribute’ => ‘weight’, ‘in’ => array(1,3)), array(‘attribute’ => ‘name’, ‘like’ => ‘M%’)));

This gets all items whose weight is 1 or 3 OR whose name starts with M.