Category Archives: Tutorials

Magento 2 Tutotorials and Tips

Magento 2 adding custom option programmatically

Magento 2 have import custom options is excellent, but some time you want to more have more control for custom options product, here is the script to add custom options to the added simple product in magento 2

This is a very basic to add a custom option to a product, hopefully it’s can help you to do some extra stuff for Magento 2 product updates.

Create class autocomplete with get in object manager Magento2 for phpstorm

In Magento 2, in order to create a new object, you have to call get or create method through object manager. But the instance after create is recognize by the IDE, so this is a little bit reduce productivity since you can’t hind methods and properties of the new objects.

Here is the guide to help Phpstorm recognize object create by using PhpStorm Advanced Metadata feature, with this update Phpstorm can understand a object created by magento 2 object manager or a block create by layout object

1. Create a new file: .phpstorm.meta.php at your Phpstorm project root
2. Update .phpstorm.meta.php with  content:

3. Save the file and restart Phpstorm. Let’s try to create some object or create some block in a controller assumed that have construct that assign object manager and layout:

Now you can save your time and enjoy type hinting with Phpstorm and Magento 2 of instance create by object manager now đŸ˜‰

If you want to create new rule for PhpStorm Advanced Metadata, please take a look at PhpStorm Advanced Metadata for more information.

How to add external js/css/link in magento2

Magento are handle script and css load in head section by layout xml, almost source are loaded from the local, but if some time we want to add external script or css link to our store, external script/source can be 3rd party or external CDN services, here is the guide to do it.

Add this element inside head section of your layout update, you can add in xml layout files or in backend layout update settings, we can add external script/css/link:

Just Simple add the src_type=”url” attribute to the element you want to external.

Maybe loading external script/source can affect your site speed so add async attribute is a good idea, just add async=”true” to the element you want to async loading

If you are a developer you can dig into the code that handle render head block at: