Custom Magento2 System Configuration

Magento2 Specialist

In magento 2 series we already know how to create module and admin menu. If you miss previous article, read from here. Today We discuss about magento 2 system configuration. So lets start..

How to adding a system config file
As like magento 1, system configuration are stored inside system.xml file. Location of this file is

Adding a new Tab
The first thing we’re going to do is a add a custom “Tab” to the System Configuration. Tabs are left navigation in admin section Stores -> Configuration. Lets create our new tab “Hello World”. Inside system.xml file code should be following.

Adding A New Section
Now we create a new section of helloworld tab. Now code should be following

Adding Groups and Fields

Adding ACL
In magento 1 acl are stored inside adminhtml. But in magento 2 acl are stored acl.xml file and located

Don’t forget clearing magento…

View original post 17 more words

Advertisements

Magento2 Events Observers

Hey Magento folks, this article is based on Magento2 1.0.0 beta version. I will be briefly explaining the event observers in Magento2. Developers who have worked on Magento 1.x series are well aware the importance of events-observers in terms of developing custom functionality, and a way to avoid core code modification.

In Magento2 , it is nearly the same concept, just the aesthetics of using it has changed. So lets dive into it without any further ado.

Contrary to Magento 1.x, all event defintions fo into a seperate xml file i.e events.xml

So in your module folder, there could be three events file.

  1. etc/events.xml
  2. etc/frontend/events.xml
  3. etc/adminhtml/events.xml

So as you might have guessed first file is for global scope and then frontend , adminhtml respectively.

So late’s say, i need to observer event, checkout_cart_add_product_complete

i will create an events.xml

<?xml version=“1.0” encoding=“UTF-8”?>
<config xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:noNamespaceSchemaLocation=“../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd”>
    <event name=“checkout_cart_add_product_complete”>
        <observer name=“techbuzz_custom_checkout_cart_add_product_complete” instance=“Techbuzz\Custom\Observer\CompleteObserver”  />
    </event>
</config>
ok, so here the in events tag, name is given as the event name. In the observer tag we have
1. name  = name of the observer – which should be unique
2. instance = class name which will contain this observer
So, in my module i.e. Techbuzz\Custom\Observer
<?php
namespace ‘Techbuzz\Custom\Observer’
use Magento\Framework\Event\ObserverInterface;
class CompleteObserver implements ObserverInterface
{
/**
* @param \Magento\Framework\Event\Observer $observer
* @return void
*
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
//execute your code here
}
}

Okie, so going deep into, how the events are initialize

//file \Magento\Checkout\Controller\Cart\Add.php -113

$this->_eventManager->dispatch(
‘checkout_cart_add_product_complete’,
[‘product’ => $product, ‘request’ => $this->getRequest(), ‘response’ => $this->getResponse()]
);

Where event manager is a object of \Magento\Framework\Event\ManagerInterface

So in same way we could initialize and fire our own custom events.

You can find list of events fired throughout Magento2 here

Building Magento 2 Extension – lets begin…

Max Yekaterynenko

There are a tons of blogs and materials around Magento 2, including development experiments, and overall sharing of knowledge. Good reference is Alan’s blog – http://alankent.wordpress.com, where he post actual and interesting ideas, facts, news about Magento 2.

So, i want to join in the group of Magento evangelists, and share my own experience to build extension for Magento 2. Sounds funny, taking in account i am developing Magento 2, but i think it will be good exercise for me to spend some time in Magento 2 Extension developer’s skin. Right?! 🙂

So, lets do it together, the goal is to create new Magento 2 Extension, which will cover some important development practices and technics in new Magento 2 world. The extension will consists of several Modules, which will be posted here –  https://github.com/maksek/m2experience.

Let agreed on terminology will be used here, Extension is 1 or more modules which alter or extend Magento…

View original post 466 more words

Building Magento 2 Extension – lets begin…

Max Yekaterynenko

There are a tons of blogs and materials around Magento 2, including development experiments, and overall sharing of knowledge. Good reference is Alan’s blog – http://alankent.wordpress.com, where he post actual and interesting ideas, facts, news about Magento 2.

So, i want to join in the group of Magento evangelists, and share my own experience to build extension for Magento 2. Sounds funny, taking in account i am developing Magento 2, but i think it will be good exercise for me to spend some time in Magento 2 Extension developer’s skin. Right?! 🙂

So, lets do it together, the goal is to create new Magento 2 Extension, which will cover some important development practices and technics in new Magento 2 world. The extension will consists of several Modules, which will be posted here –  https://github.com/maksek/m2experience.

Let agreed on terminology will be used here, Extension is 1 or more modules which alter or extend Magento…

View original post 466 more words

Building Magento 2 Extension – ExtendedConfig

Max Yekaterynenko

As I promised, it is continuation for ExtendedConfig module. I will show how to add module configuration settings into Stores->Configuration page, with minimal amount of “coding” 🙂

Understanding Store Configuration

First step for every customization is to investigate functionality, which is going to be customized. Check how it works natively. So let’s open Stores->Configuration page and investigate it.

ExtendedConfig-configpage

On left side of the page there is navigation menu with tabs and sections. Tabs are not clickable, as they are just used for grouping sections. Sections are clickable and consist of groups. Every group consists of form fields. If navigate through different sections on the page, what user always see – is a form.

On screenshot – GENERAL (all capitals) is tab, General is section and Store Information is one group in the section, with several form fields. For navigation by the form we need to use Section->Group->Field path, later we will see example.

The Configuration page is rendered by Magento_Config module. It uses information from <system><config>

View original post 1,185 more words

Magento 2 branches, composer packages and sample data

Max Yekaterynenko

Right after Merchant Beta release, we changed our Continues Delivery approach. We decided to be completely open and do pushes immediately, as we are doing development, in public github. Yes, we still do coding in internal github[hidden by firewall and intranet], and then we do merge to public. It may looks like not ideal solution, but it works for all of us at the moment. Maybe in future we will move our development to public github, but it will be in future.

At the moment we have 2 ways to get Magento 2 code delivered to developers: github and composer packages. While i prefer github, our recommended way to use composer.

Github & Composer

In Magento 2 github we have 2 main branches:

Master branch – has stable official releases (currently 1.0.0-beta), recommended one. I don’t want go deep in stability term, but we do invest good amount of time & quality efforts to make…

View original post 411 more words

Magento create admin user programmatically

Santosh's Blog

Hello all,

Here is custom script to create admin user programmatically.

<?php
# Create New admin User programmatically.
require_once(‘./app/Mage.php’);
umask(0);
Mage::app();

try {
$user = Mage::getModel(‘admin/user’)
->setData(array(
‘username’  => ‘admin1’,
‘firstname’ => ‘Admin’,
‘lastname’    => ‘Admin’,
’email’     => ‘santosh@test.com’,
‘password’  =>’admin123′,
‘is_active’ => 1
))->save();

} catch (Exception $e) {
echo $e->getMessage();
exit;
}

//Assign Role Id
try {
$user->setRoleIds(array(1))  //Administrator role id is 1 ,Here you can assign other roles ids
->setRoleUserId($user->getUserId())
->saveRelations();

} catch (Exception $e) {
echo $e->getMessage();
exit;
}

echo “User created successfully”;

?>

Put the above content in a magento root folder in a file and  then browse the file.

You are done with creating new admin user.

Chears

View original post