What is an area?

Hello friends,

I have got the error “a:3:{i:0;s:20:“Area code is not set”;i:1;s:4345:”#0" while updating configurable products programatically, so i solved this error

$productFactory = $objectManager->create("\Magento\Catalog\Model\ProductFactory");

// this needs to be set to avoid exception:
// Magento\Framework\Exception\SessionException with message 'Area code not set: Area code must be set before starting a session.'
// I don't know why ...
$appState = $objectManager->get("Magento\Framework\App\State")
$appState->setAreaCode("de")

$product = $productFactory->create()

$product->setName("FooBar")
$product->setName("123")
$product->setAttributeSetId(15)

$product->save()

But what is meaning of area code means what its role ??

An area means a web service’s area.

Magento uses areas to efficiently make web service calls, loading only the dependent code for that area. Examples of areas include the storefront (frontend), Magento Admin (adminhtml, the administration interface), and the WebAPI framework (webapi_rest).
http://devdocs.magento.com/guides/v2.0/architecture/areas/areas.html


The purpose of areas is efficiency.
If you are invoking a REST web service call, for example, rather than load up all the code related to generating user HTML pages, there is a separate area (such as /rest) which loads code that knows only how to answer the REST call (and not generate HTML pages using layouts).
Each area can have completely different code on how to process URLs and requests.
http://devdocs.magento.com/guides/v2.0/architecture/modules/mod_and_areas.html

The Magento 2 core uses the following area codes:

  • admin
  • adminhtml
  • catalog
  • crontab
  • doc
  • frontend
  • global
  • setup
  • webapi_rest
  • webapi_soap

The official documentation mentions only 3 of them (may be because it is outdated, or for another reason):

http://devdocs.magento.com/guides/v2.0/architecture/modules/mod_and_areas.html
http://devdocs.magento.com/guides/v2.0/architecture/areas/areas.html

1 Like

A post was split to a new topic: What area code should I set to update or create a configurable product programatically?

github.com/AdobeDocs/commerce-php/blob/cf2534a3/src/pages/development/build/dependency-injection-file.md#areas-and-application-entry-points