What are exactly those sections ?
A section is a piece of customer data grouped together. Each section is represented by key that is used to access and manage data and data itself.
Magento loads sections by AJAX request to
/customer/section/load/ and caches loaded data in the browser local storage under the key
mage-cache-storage. Magento tracks when some section is changed and load updated section automatically.
How do you define a section ?
A section defined in
di.xml file by adding a new section into sections pool
<argument name="sectionSourceMap" xsi:type="array">
<item name="cart" xsi:type="string">Magento\Checkout\CustomerData\Cart</item>
<item name="directory-data" xsi:type="string">Magento\Checkout\CustomerData\DirectoryData</item>
So here two new sections are registered
Magento\Customer\CustomerData\SectionSourceInterface and provides actual data as result of
How are the section updates triggered ?
Magento assumes that customer's private data is changed when a customer sends some state modification request (
DELETE). To minimize the load on server, developers should specify which action (or request) updates which customer data section in
Action name is an action key pattern. When a user calls to action that matches specified pattern Magento will detect that corresponding section is outdated and loads it again. If action name is
* that means that section will be updated on each POST and PUT request. If section tag is missed then all section will be updated.
So conceptually this is wrong to update mini cart when you rich cart page. At this point, mini cart (or cart section) already should be updated.
You can find more information about Customer Data here
To understand when and how sections are updated let's see implementation.
Key to understanding are files
At the end of last one of the two events handlers are registered for
PUT request, the handlers will be invoked. Both handlers have similar logic: with help of
Magento_Customer/js/section-config check should be any section updated or not. If some section should be updated then
customerData.invalidate(sections) is called. And later all invalidated sections are loaded from a server.
So how does
Magento_Customer/js/section-config know which section should be removed and on which action? The answer is in
/* @noEscape */ echo $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode([
'*' => ['Magento_Customer/js/section-config' => [
'sections' => $block->getSections(),
'clientSideSections' => $block->getClientSideSections(),
'baseUrls' => array_unique([
$block->getUrl(null, ['_secure' => true]),
$block->getUrl(null, ['_secure' => false]),
In such way, a server passes merged sections configuration to a browser.
So assuming all of that, section may be updated only by POST or PUT form submitting or AJAX request
In addition, there are only two notes:
- all described here is internal implementation and may be changed, so you may safely use only sections.xml and expect section updates when specified POST or PUT or DELETE actions are triggered.
- if you sure, that you really need update some section you can always do something like this: