Marius
Moderator
  • Member for 9 years
  • Last seen this week
How to write a custom extension?
Accepted answer
195 votes

Here is what I usually do: Always develop with error_reporting on. Always develop with isDeveloperMode set to true. Just add SetEnv MAGE_IS_DEVELOPER_MODE 1 to your httpd.conf file (or corresponding ...

View answer
Extending / Overriding JS in Magento 2
Accepted answer
112 votes

There is no more skin folder but you can still use themes. As a proof of concept I used you example with op-checkout-method.js and this this. Preconditions: Magento2-beta11 installed Default ...

View answer
How can I bootstrap Magento 2 in a test.php script?
Accepted answer
98 votes

Based on @Flyingmana's answer I did a little digging and come up with a solution. It seams to work for me. First my solution, then some explanations. I've created a file called test.php in the root of ...

View answer
Magento2 how to getRequest
Accepted answer
93 votes

If you are trying this from a controller that extends Magento\Framework\App\Action\Action you can get the request with $this->getRequest()->getPost(). If you are in a custom class, you need to ...

View answer
Difference between getSize() and count() on collection
Accepted answer
92 votes

Most (if not all) the collections extend Varien_Data_Collection_Db. Here are the 2 methods from this class public function getSize() { if (is_null($this->_totalRecords)) { $sql = $this-...

View answer
Magento 2 - How to get attribute options value of eav entity?
Accepted answer
69 votes

you can add to the constructor of your class an instance of \Magento\Eav\Model\Config like this: protected $eavConfig; public function __construct( ... \Magento\Eav\Model\Config $eavConfig, ...

View answer
How to Set, Retrieve and Unset Session Variables in Magento 2?
65 votes

In magento 2 there is no more core/session. There are these ones though (may be others also): \Magento\Backend\Model\Session \Magento\Catalog\Model\Session \Magento\Checkout\Model\Session \Magento\...

View answer
How indexing works in magento
65 votes

There are different kind of indexes in Magento. All of the indexers are there to make things run faster. I will cover here only a few of them. Flat Index There are 2 such indexes. One for ...

View answer
To use or not to use the ObjectManager directly?
59 votes

You should never use \Magento\Framework\App\ObjectManager::getInstance(). It defeats the purpose of dependency injection. We're back at Mage::getModel(). Object manager should be used only in ...

View answer
Add new field in magento(1.9) customer registration
Accepted answer
56 votes

You need to create a new extension to make it clean. Let's call the extension StackExchange_Customer. You will need the following files: app/etc/modules/StackExchange_Customer.xml - the declaration ...

View answer
Magento 2 Get Current Store Date Time
Accepted answer
53 votes

You need to inject in your class constructor an instance of \Magento\Framework\Stdlib\DateTime\DateTime and use that one. Something like this: protected $date; public function __construct( .... ...

View answer
How to create an new observer on the event catalog_product_save_before
Accepted answer
52 votes

You need to create a new module. Let's call it Easylife_Meta. app/etc/modules/Easylife_Meta.xml - the declaration file <?xml version="1.0"?> <config> <modules> <...

View answer
How to get attribute "option label/attribute text" having "attribute value" (option_id)?
Accepted answer
50 votes

In addition to your code put this: $product = Mage::getModel('catalog/product') ->setStoreId($store_id) ->setBrand($brand_value); // not loading the product - ...

View answer
Magento 2 - How to uninstall module?
Accepted answer
48 votes

it says in the documentation you linked, this: This command works only with modules defined as Composer packages. If you did not install the module via composer, it won't work. You can only ...

View answer
Most efficient way to get all ID's from a collection
Accepted answer
46 votes

Actually getAllIds is the best way of doing it. For example in the product collection resource model the method looks like this: public function getAllIds($limit = null, $offset = null) { $...

View answer
Depend and if/else in transaction emails in Magento 1
Accepted answer
43 votes

This is exactly the purpose of {{depend}} and {{if}}. The only difference between them is that {{if}} supports an {{else}} statement. {{depend}} is just as an {{if}} without an {{else}}. To see how ...

View answer
Magento2: what is the difference between referenceContainer and referenceBlock
Accepted answer
41 votes

basically containers are the equivalent of the core/text_list blocks in magento 1. "philosophically" they work the same, the only difference is that containers are predefined blocks that only support ...

View answer
Filtering results using LIKE
Accepted answer
41 votes

Give this a try and see if it fits: $collection->addAttributeToFilter('name', array( array('like' => '% '.$needle.' %'), //spaces on each side array('like' => '% '.$needle), //space ...

View answer
Magento 2: How to get current admin user detail?
Accepted answer
40 votes

you need to add this to the constructor of your class protected $authSession; public function __construct( .... \Magento\Backend\Model\Auth\Session $authSession, .... ) { .... $...

View answer
Adding a non-category link to the navigation links in magento 2
Accepted answer
39 votes

[EDIT] Apparently, in latest versions of M2 this does not work anymore. Thanks to Max for pointing this out. For later version you need to add a plugin for Magento\Theme\Block\Html\Topmenu instead of ...

View answer
Magento2 InstallSchema.php does not create the table specified
Accepted answer
39 votes

The installer won't run again if it was already executed. Removing the record from setup_module with module = 'MyVendor_Helpdesk' should make it run again.

View answer
Adding a CMS block via setup script
Accepted answer
38 votes

For this, I suggest using the data folder of one of your custom modules. Let's say that the module is currently at version 1.0.4. Create the file data/[module]_setup/data-upgrade-1.0.4-1.0.5.php with ...

View answer
Difference Between setData() and addData()
Accepted answer
37 votes

setData overrides the existing data and can receive as parameter either a pair key-value either an array. if you set as parameters a pair key-value then $_data[key] becomes value. If you set as ...

View answer
How to call helper method in .phtml file
Accepted answer
36 votes

You should not use helper calls directly in the template. Have your helper instance provided as a dependency to the block that renders the template and create a method in your block that calls the ...

View answer
Bulk update products to include new websites
Accepted answer
36 votes

Step 1 Build an array with your new website ids. $websiteIds = array(5,6,7); Step 2 Now get all the product ids. $productIds= Mage::getResourceModel('catalog/product_collection')->getAllIds()...

View answer
In Magento2 what is <script type="text/x-magento-init">?
Accepted answer
34 votes

General usage of "script type" When using <script type="...."> the browser interprets only what it knows (like text/javascript for example). Anything else is ignored. Basically using a custom ...

View answer
Magento 2 Templates: Use `$block` or `$this`?
Accepted answer
34 votes

In a template file, $block and $this->_currentBlock are the same thing. Take a look at the render method in the Php.php template engine. Before including the template file, this happens: $this-&...

View answer
Remove Shipping steps in Onepage Checkout
Accepted answer
33 votes

Here is what I've done. I removed the shipping step and used a default shipping method that I know is always going to be available. Not sure if this is what you need but you can at least use it as a ...

View answer
Magento : Fastest way to update a product attribute
Accepted answer
33 votes

The fastest way is to do direct selects and inserts/updates in the database, but that's not the safest. You can easily break stuff. I use the Mage::getSingleton('catalog/product_action')->...

View answer
How to create an EAV entity?
Accepted answer
32 votes

Part 1 For the purpose of this demo I'm going to create a module, let's name it Easylife_News that contains an entity named Article. The module comes with complete CRUD code for backend, including ...

View answer
1
2 3 4 5
131