Skip to main content

Posts

Showing posts from 2016

Magento - Functional Testing

We have checked on how to do unit testing in magento in previous post . That is not enough to test the magento website. If we can testing the magento home page, login page, etc. it would be great. Fortunately, we have a module that deals with this situation.

Magento - Unit Testing

Magento 2 comes with default unit testing in built. But, for magento 1, it is very difficult to perform unit testing. There is an extension EcomDev_PHPUnit, which can help us in performing unit tests in magento 1.

Magento 2 - Add to System Configuration

In magento 2, the system configuration has gone little changes. Now we can access the configuration from Stores > Settings > Configuration. Also, there is small changes in the system.xml file also. Now the system.xml file is inside etc/adminhtml/ folder. You can find the sample code in the git repo .

Magento 2 - Create Attributes in Setup

Sometimes in our module we require to create product or category attributes automatically on module install. Also, we might require to add extra fields to quote, sales order, invoice, creditmemo tables. We will go through how to do that in magento 2. You can find the sample code in the git repo .

Magento 2 - Add to Admin Menu

In magento 2, the admin menu has changed from top to left side. There is not much difference between the old way and the new way to add the menu. Just some file changes and way to write them. You can find the sample code in the git repo .

Magento 2 - Create a simple module

In magento 2, the creation of module has changed completely. We will go through how to create a module. Like earlier magento, we do not need to put our module files in different folders for code, theme, skin, etc. All, the codes related to the module should be inside one main folder. You can find the sample code in the git repo .

Magento - Apply only one Catalog Price Rule

In default magento, on click of "Apply rules" in catalog price rules (Promotions > Catalog Price Rules), it get the products for all the active rules and add the data in a separate table. If there are more than five active rules, then lots of data have to be created and the process takes a lot of time. If we have to create a new rule, the save and apply will re-calculate for all the active rules.

Magento - Get the attributes from attribute code

We always require the attribute data via attribute code. Below is the code to get the product attribute data from the attribute code. It can used to get the attribute data from the code, without always trying to load the attribute model. public function getAttribute($code) { $this->getAttributes(); if (isset($this->_attributes[$code])) { return $this->_attributes[$code]; } return null; } public function getAttributes() { if (is_null($this->_attributes)) { $this->_attributes = Mage::getResourceSingleton("catalog/product") ->loadAllAttributes() ->getAttributesByCode(); } return $this->_attributes; }

Modman for magento

Modman is the best way to arrange your magento code with custom modules. Keep your magento codes separate from the custom modules. It will help you to upgrade magento easily and also, upgrade you custom modules also.