I want to configure Magium to work with my site using configurable classes
The key to working with Magium is knowing that almost everything is done for you. But that only works if you are using the default theme with the usernames and passwords that are in my database.
Fear not, however. Magium is designed to do 90% of what you need and configure the other 8% and override the remaining 2%. We will focus only on configuration in this post.
Note, also, that this is referring to magium/magento and magium/magento2
Theme configuration files and identities (and perhaps a few others) rely on the
AbstractConfigurableElement class. This class provides 3 different means of overriding configuration.
ClassConfigurationReader is the most typically used reader. It uses file inclusion to reconfigure itself. It sounds complicated, but it’s not.
Step 1 – Determine the fully qualified name of your class
If it is a theme configuration it could be
Magium\Magento\Themes\Magento19\ThemeConfiguration or, perhaps,
Magium\Magento2\Themes\Magento2\ThemeConfiguration. If it us a customer entity it could be
Magium\Magento\Identities\Customer. In particular, the theme configuration will be different for your site than for the test Magento site that I used to build Magium against. Your base URL will be different, your navigation instructions will be different, your checkout button might be different, etc. Those are the kinds of things you will want to override.
Step 2 – Create a mapped file
This mapped file will be included when the class is instantiated by the dependency injection container. You can kind of think of it like a .phtml file for classes.
The mapping is based off of a directory called
configuration followed by the directories corresponding to the class’ namespace with the class name .php appended. For example, with the file
Magium\Magento\Themes\Magento19\ThemeConfiguration, the filename, relative to the root of your project, would be
Step 3 – Write in your overrides
Since the configuration file will be included in the class, you can refer to the
$this context. For example, to change the base URL for your site your file would look like the following:
<?php /* @var $this \Magium\Magento\Themes\Magento19\ThemeConfiguration */ $this->baseUrl = 'http://my-site.loc/';
The comment is there to help your IDE with code completion.
Step 4 – Run your test
The file should automatically get picked up if the test references it in any way. If it is not referencing that file you can through an
exit() call, set a breakpoint, or something similar. If you need to debug why it is not working then you should set a breakpoint in the
Magium\Util\Configuration\ClassConfigurationReader class in the