Magento, PHP, Java, C#

How to debug static file resolution in Magento 2

I guess every Magento 2 developer will run into this common problem at some point. You want to replace a static content file from the core,  you copy it into your theme directory and make your changes, and in the end nothing happens, because Magento still serves the static file from the core. The first thing you can do in your development environment is to delete the deployed static content file.  If Magento 2 is in developer mode, you can just make a new request to the frontend and the file will be automatically redeployed. If it is still not working, this can become a serious problem. In the next steps I want to explain how to debug the static file resolution to track down the issue.

Continue reading

Automatically renew Let’s Encrypt SSL Certificate

Let’s Encrypt is a SSL certificate Authority that provides free SSL certificates, as well as a client that can be used to create and renew certificates. In most cases, if you are using LAMP or LEMP stacks the client provides all functionallity needed to enable HTTPS on your website. Up to now (2016-07-19), the automatic renewal function is the only important thing that is missing in the client. If you still want to autmatically renew your certificate, and not do this by hand every 90 days, you can use the following workaround.

Continue reading

Dependency Injection in Magento 2: Object Argument replacement vs. Class Preference

Dependency Injection

If you never heard about dependency injection in Magento 2 you should first take a look at the Magento 2 documentation about dependency injection. If you checked out the the documentation or already are familiar with dependency injection in Magento 2, you will know that there are two ways to inject objects to your constructors. Take the following code as example:

// Vendor\Namespace\Model\SomeClass
// ...
public function __construct(ExampleClass $object) {
    $this->object = $object;
// ...

If you want to inject “$object”, one approach is to use argument replacement, another one is to use class preference. I will shortly describe these two methods and than point out the big difference between them.

Continue reading

Magento2 xml validation on the fly

If you want your PhpStorm IDE to provide Magento2 xml validation on the fly, you now need to set up a misc.xml file in your .idea folder. In your misc.xml file you can configure how the URLs are mapped to the file locations of the Magento2 XSD files. Take the following xml as example:

<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Module/etc/module.xsd”>

The URL is “urn:magento:framework:Module/etc/module.xsd”. The place where PhpStorm is looking for a mapping to any file is the misc.xml file. Since you have not created one, or not inserted the mappings, it will not find the XSDs and on the fly validation won’t work.

Magento2 xml validation

There are different ways to let your IDE validate Magento2 XML files on the fly. If you have not installed the Magento2 PhpStorm Plugin already, I would recommend to use the bin/magento command line tool.

Continue reading

Magento2 module – simple example

In this post will cover the topic of how to create a simple Magento2 module. Aim of this article is to create a simple module with minimal configuration of controller, block and template. Therefore we have to do go through the following points:

  • Create the modules file structure
  • Configure the module
  • Create register.php
  • Define a frontname
  • Setup a controller
  • Create a block
  • Create a template

The aim of the module is to request a certain URL that calls a controller action and renders a template file with it’s own block class.

You can download the module on Github, or follow the instructions in this post to create your own.

Continue reading

Android Studio: Build unsigned APK file

If you created your project with Android Studio you just have to compile it, and an APK file is automatically generated in ProjectName/ProjectName/build/apk/

If you moved a project from a different IDE to Android Studio, this is more tricky because the APK file will not be in your apk folder. In this case, I would recommend you to just recompile it in Android Studio. There are many ways how to do this, but in this post I will describe the probably most commen way, the build with Gradle.

Build unsigned APK with Gradle

Nowadays one of the easiest way is to build your APK file with Gradle. There are a few steps you have to do:

  1. Go to Edit – Configurations
  2. Click “add” symbol
  3. Select Gradle
  4. Choose your module as Grade project
  5. Add the command assemble to Tasks
  6. Recompile your Project

Continue reading

© 2021 bpoiss

Theme by Anders NorénUp ↑