Questions tagged [best-practice]

Denotes questions related to best-practices in Magento.

Filter by
Sorted by
Tagged with
2 votes
1 answer
34 views

Where do static library initializations go?

Suppose that I have a library located in: lib/Acme/ This library has to be statically initialized (once!) through the following call: AcmeBootstrap::init($data); $data in the above call is ...
Luke A. Leber's user avatar
3 votes
1 answer
2k views

Check if model column exists before saving in database

I want to insert a column into my db table, but only if it does not exist, yet. So I thought I'd check if the model with the specified email exists, and if not I perform save() method. Here is what I ...
xhallix's user avatar
  • 692
0 votes
0 answers
88 views

Magento Workflow Wizards, Some Sage Advice Please? [duplicate]

My question is really simple. What are your goto recommendations for working with Magento, be it local workflow or debug methods, what works best, when, what can I learn from your best practices? I'...
mprototype's user avatar
10 votes
2 answers
802 views

How To Properly Disable a (Model) Rewrite

There is a third-party extension which rewrites a specific Magento core class. It should not matter if it is a block, helper or model, but in this case it is a model. Now I encounter that this rewrite ...
Simon's user avatar
  • 5,685
6 votes
2 answers
483 views

Mage_Catalog_Model_Product_TYPE::TYPE_CONFIGURABLE vs 'configurable'

I'm working on an heavy customised magento version. Cancelling an order returned this fatal error: Mage_Catalog_Model_Product_TYPE not found on this line code: if($parent->getTypeId() == ...
apedic's user avatar
  • 923
0 votes
2 answers
417 views

Rich Snippets inside or outside of the template?

I recently added rich snippets to the product detail page for simple and configurable. But now I'm asking myself if it was right to add the meta datas at the end of the templates. How do you solved ...
Timo.Klement's user avatar
1 vote
2 answers
199 views

Workflow for Magento Database

I am planning on a Magento Workflow for staging and live enviroment. I want to use git for the filesystem. The workflow here is sorted already. But how to manage Database modifications? While on ...
Bernhard Prange's user avatar
1 vote
1 answer
400 views

What are some code optimization tips? [closed]

What do you guys suggest to modify in Magento core to speed it up, without breaking anything? Like disabling modules via xml files or modifying checkout to remove observers.
Vygantas's user avatar
  • 373
22 votes
6 answers
18k views

What is helper in Magento?

What is helper in Magento? In what cases should one use and not use helpers?
Supersonic's user avatar
1 vote
3 answers
3k views

Magento 2 - Accessing a helper without using constructor injection

Is there a clean way to initiate and access a custom helper without using the constructor? Currently I instantiate the custom helper using the constructor of the model as shown here as the accepted ...
rofavadeka's user avatar
3 votes
3 answers
5k views

Why use createBlock() and setTemplate() methods over creating a block via .xml file in /layout subdir?

I've seen examples in extensions and in core where blocks are created through PHP code, e.g. in a controller action: $block = $this->getLayout()->createBlock("company_module/..."); Or a block ...
fris's user avatar
  • 894
10 votes
5 answers
2k views

Where do I put .php, .js, .html, .css files from a 3rd party lib that interfaces with an extension I develop?

Let's say I want to develop a Magento extension that interfaces to, say, an Open Source charting package or an image gallery or whatever that is NOT part of the extension itself. When downloaded (...
fris's user avatar
  • 894
2 votes
2 answers
4k views

How to specify absolute external paths (e.g. CDN) using "addJS" in .xml in /layout (sub)directory?

It appears ABSOLUTE filespecs to external files work for CSS (addLinkRel) but not JS (addJs). The sytem always prepends the site domain+path when using addJs. <layout version="1.0.0"> <...
fris's user avatar
  • 894
6 votes
1 answer
159 views

How does an extension display info and warning messages in a theme-agnostic way?

Not looking to display form validation errors, but more global messages like "Hurry quick -- offer ends in 4 hours" or "Currently there are 3 users online". The question is not about how to generate ...
fris's user avatar
  • 894
7 votes
2 answers
94 views

Is it best practice for a Block function to call a ResourceModel function?

Is it appropriate for a Block class to retrieve data through a function in a ResourceModel class, rather than a Model class? Or should the Block call the Model which then passes the call to the ...
fris's user avatar
  • 894
6 votes
1 answer
153 views

Usage of superfluous (and potentially dangerous) standard code in installer scripts

I always thought it's some kind of epidemic plague that users behave in a high risk manner introducing $installer->startSetup() and $installer->stopSetup() calls in installer scripts. Many of ...
hakre's user avatar
  • 2,821
0 votes
1 answer
752 views

Multiple country-specific stores - how to set up global products

So I'm setting up a multi country/same domain store, with the stores living in /us/ and /au/ I want to have global products but localised prices. That is, I can build a product once that shows in ...
theschtickler's user avatar
2 votes
1 answer
1k views

Best practice for multi country magento store setup

this is my first magento build and just had some questions on the best method to set the store up. It's a single business but running out of 2 countries. These are the specifics: Products to be ...
theschtickler's user avatar
3 votes
1 answer
456 views

Rwd Child Theme Copy Sass Partials Or Create New Ones

I want to create an upgrade-safe child theme mypackage/mytheme of the default rwd/default theme. Magento's RWD dev guide says: To customize styles for an existing Magento theme, you should edit ...
Simon's user avatar
  • 5,685
7 votes
1 answer
535 views

Best practices for running and updating multiple separate stores

3 years ago I was a part of a company that ran magento webshops for many independent customers. What we experienced at the end was that if we wanted to do a change that affects all the shops (bug fix) ...
David Gulbrandsen's user avatar
4 votes
2 answers
11k views

Magento - Production and Test environment - Best practices [closed]

I know there are some posts related to this topic available, but I do think it covers my questions: I have now set up two environment: Staging and Production, as the shop is not live yet it is quite ...
David Gulbrandsen's user avatar
4 votes
1 answer
101 views

Writing unit tests: refactor the original vs deal with difficult code to test

Given that I am using EcomDev's PHPUnit framework to write unit tests for my Magento modules, sometimes I come across a controller action that has too much logic within it. It would mean mocking lots ...
scrowler's user avatar
  • 2,014
6 votes
2 answers
2k views

How to replace default Magento editor by Editor based on tinyMCE 4?

The default Magento Editor has become less effective, no HTML5 support with weak image upload and management, so i need to upgrade editor! I'm looking for an Editor providing strong enhancements with ...
user3622685's user avatar
0 votes
1 answer
1k views

How to quickly override/modify core block file?

I need to modify 1 line of code in: Mage/Catalog/Search/Block/Autocomplete.php $html .= '<li title="'.$this->escapeHtml($item['title']).'" class="'.$item['row_class'].'">' . '...
Alan's user avatar
  • 917
7 votes
2 answers
635 views

Strategy for rewriting classes

[TL:DR] I have Core_Class_A and Core_Class_B extends Core_Class_A. I need to rewrite both of them and add a common functionality. So I made this: Custom_Class_A extends Core_Class_A. The question ...
Marius's user avatar
  • 198k
1 vote
2 answers
687 views

What Is The Best Practice To Validate a Property of a Controller In an In another Controller Validation

Let me explain a demo situation. I need to allow only logged in customers to subscribe newsletter. So in newsletter controller, I am validating whether the user is guest or a valid customer. If the ...
Rajeev K Tomy's user avatar
2 votes
1 answer
222 views

Best practice to add export type by calling $this->addExportType() on order gird?

I want to call addExportType() to add my custom export type to sales order grid. I can do it two ways: Either rewrite the admin sales order grid :Mage_Adminhtml_Block_Sales_Order_Grid and add the ...
Paras Sood's user avatar
  • 2,530
2 votes
1 answer
888 views

Best practice to add a layout handle for my custom module?

I think I read somewhere that the best place to add a layout handle for a custom module was through the local.xml file in layouts folder. However, almost all modules that I have seen, never has one ...
Paras Sood's user avatar
  • 2,530
0 votes
3 answers
213 views

Facebook like button count inconsistancy due to automatic url rewriting

I was trying to add the facebook like button to my product pages but then I noticed that the like counter has different numbers depending on where the page was accessed from and the URL it has. ...
Jake's user avatar
  • 131
1 vote
2 answers
39 views

Should custom Magento code always be a module, regardless of size

As a Magento newbie, I'm still trying to learn the good and the bad when it comes to developing for Magento. I need to write a class, that in Yii I would just create a class in the 'vendors' ...
Ste's user avatar
  • 323
19 votes
2 answers
1k views

Magento 2 DI best practices

Let's say I'm building a Magento 2 extension that does....well...not important. Let's say it does super awesome stuff. But I want to make sure that this is build using the proper standards so other ...
Marius's user avatar
  • 198k
1 vote
1 answer
123 views

The correct way to modify core code - need clarification

I'm preparing my installation of 1.8 to upgrade to the latest. Over the past year I've had a few different developers assist me and even though I ask them not to modify core code, some do anyway. I'...
SR_Magento's user avatar
  • 5,209
7 votes
3 answers
8k views

Best Practice for staging/development site

I am new to magento and have been working a my first site and it is now ready to go live. I have been advised that once live to also build a staging or development site so that i can in the future ...
odd_duck's user avatar
  • 1,396
9 votes
3 answers
17k views

Best Practise to Add Custom Tab in Product Details (backend)

I would like to add an extra tab to the product details ( backend ) and I don't want to perform any override, if possible. What is the best way to accomplish this ?
Fra's user avatar
  • 6,955
2 votes
3 answers
829 views

Check/Audit Magento custom code

Is there a way ,or some steps which ensure any custom module/code written in Magento is adhering to all standard/best practices, without it breaking Magento in any case i.e upgrades,extension ...
huzefam's user avatar
  • 2,576
0 votes
2 answers
96 views

Is it safe to use one instance of a Model to load several different entities?

Are there side-effects, or issues with doing something like this: // Retrieve the Model once $model = Mage::getModel('some/model'; // Load several different instances foreach($idlist as $id) { $...
STW's user avatar
  • 2,047
0 votes
1 answer
54 views

What should be the steps to be followed before working on a multistore website?

I am going to work on a Magento multistore website. The site is already live , I need to setup a development environment and need to work on this development site. What should be the steps which I ...
Mukesh's user avatar
  • 1,428
1 vote
2 answers
145 views

Can DEBUG level messages be excluded from system.log?

I'm working on a large Magento installation setup by another developer. Logging is disabled in the live environment which struck me as odd. While testing the code with logging enabled locally it ...
STW's user avatar
  • 2,047
1 vote
1 answer
43 views

best practice for placing descriptions and landing pages

this is probably a question for the magento forums directly, but as they are such a spam-fest.. I'll try here :) I want to put at the top of each product category a large splash image and description ...
egg's user avatar
  • 499
15 votes
3 answers
23k views

Magento : Fastest way to update a product attribute

I'm looking for the fastest and reliable method for mass attribute update. Below are the methods am aware of but I don't know with which I should go. $store_id = 0; Mage::getSingleton('catalog/...
Deepak Mallah's user avatar
1 vote
1 answer
97 views

Keep the collection always fixed to certain number

I am using the following code to get five Best sellers collection. The number five is fixed here. // Array of Id's to retrieve from product collection $dataArray = array(2, 8 , 17, 3, 7); $...
Mr_Green's user avatar
  • 1,605
1 vote
1 answer
152 views

When overriding a community extension should I use the original namespace or my own?

We work with a large number of community extensions and frequently override their behavior with small extensions of my own. So far I've been using a naming convention of app/code/local/{MyCompany}_{...
STW's user avatar
  • 2,047
3 votes
1 answer
11k views

Best Way To Iterate Through Product Collection

Which of these methods is "easier" on the Magento platform, specifically the database? Method 1 uses a single call to the database to retrieve the collection, and then iterates over the result. Method ...
Jongosi's user avatar
  • 1,501
4 votes
1 answer
963 views

What are the best practices in Magento? [closed]

Can anyone suggest what are the best practices relevant to the followings. Magento coding standards. Magento naming conventions (including folder names, file names etc.) Folder structure which should ...
Sukeshini's user avatar
  • 9,935
3 votes
1 answer
113 views

Examples of well written modules

Can anyone point me in the direction (github or magento connect) of any well written modules in terms of code/architecture and not functionality? Preferably also using unit tests or magespec. It ...
Marty Wallace's user avatar
2 votes
1 answer
44 views

Non-volatile data store

I often find myself wanting to store a simple piece of information such as 'last exported id' or 'last import date' for retrieval at a later point in time. This is the kind of information that will ...
Peter O'Callaghan's user avatar
11 votes
4 answers
25k views

Best practice to join product attributes

I have a custom table with a product reference product_id. Now I would like to show product information (sku, name) in my backend grid, but I am unsure what is the best practice to do this? My best ...
Celldweller's user avatar
27 votes
4 answers
34k views

Efficient get product url from id

What is the most efficient way of getting a product url given just it's ID? In a few places in our code we have things such as Mage::getModel('catalog/product')->load($id)->getProductUrl() in ...
Peter O'Callaghan's user avatar
148 votes
5 answers
12k views

How to write a custom extension?

Because I had a lot of issues lately with free and commercial extension I've decided to ask this question and answer it with the steps I usually follow when writing an extension. Feel free to edit the ...
Marius's user avatar
  • 198k
45 votes
2 answers
22k views

What's the preferred way of throwing exceptions in Magento?

All of the following methods are used in Magento core so which one is the preferred (or the latest "best practice") way? Mage::throwException('Some Message') - 732 Usages throw new Exception('Some ...
Samuel Katz's user avatar