Skip to content
Permalink
Browse files

Merge pull request #4721 from magento-performance/MC-19242

[Performance] Fix missing shims and phtml files with mage-init directives
  • Loading branch information
vzabaznov committed Sep 3, 2019
2 parents b31bb4f + a241517 commit db43c11c6830465b764ede32abb7262258e5f574
@@ -11,17 +11,14 @@
$id = $block->getContainerId() . random_int(0, PHP_INT_MAX);
$config = [
'Magento_Braintree/js/paypal/button' => [
'id' => $id,
'clientToken' => $block->getClientToken(),
'displayName' => $block->getMerchantName(),
'actionSuccess' => $block->getActionSuccess(),
'environment' => $block->getEnvironment()
]
'id' => $id,
'clientToken' => $block->getClientToken(),
'displayName' => $block->getMerchantName(),
'actionSuccess' => $block->getActionSuccess(),
'environment' => $block->getEnvironment()
];
?>
<div data-mage-init='<?= /* @noEscape */ json_encode($config); ?>'
<div data-mage-init='{"Magento_Braintree/js/paypal/button":<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($config) ?>}'
class="paypal checkout paypal-logo braintree-paypal-logo<?= /* @noEscape */ $block->getContainerId(); ?>-container">
<div data-currency="<?= /* @noEscape */ $block->getCurrency(); ?>"
data-locale="<?= /* @noEscape */ $block->getLocale(); ?>"
@@ -8,8 +8,14 @@
$viewModel = $block->getData('viewModel');
?>
<div class="breadcrumbs"></div>
<?php
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($viewModel->getJsonConfigurationHtmlEscaped());
$widgetOptions = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['breadcrumbs']);
?>
<script type="text/x-magento-init">
{
".breadcrumbs": <?= $viewModel->getJsonConfigurationHtmlEscaped() ?>
{
".breadcrumbs": {
"breadcrumbs": <?= /* @noEscape */ $widgetOptions ?>
}
}
</script>
@@ -15,7 +15,10 @@
// phpcs:disable PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket
?>
<?php if ($block->getCollection()->getSize()) :?>
<div class="toolbar toolbar-products" data-mage-init='<?= /* @noEscape */ $block->getWidgetOptionsJson() ?>'>
<?php $widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getWidgetOptionsJson());
$widgetOptions = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['productListToolbarForm']);
?>
<div class="toolbar toolbar-products" data-mage-init='{"productListToolbarForm":<?= /* @noEscape */ $widgetOptions ?>}'>
<?php if ($block->isExpanded()) :?>
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/viewmode.phtml')) ?>
<?php endif; ?>
@@ -7,14 +7,15 @@
/** @var \Magento\Customer\Block\CustomerData $block */
?>
<script type="text/x-magento-init">
<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode([
'*' => ['Magento_Customer/js/customer-data' => [
'sectionLoadUrl' => $block->getCustomerDataUrl('customer/section/load'),
'expirableSectionLifetime' => $block->getExpirableSectionLifetime(),
'expirableSectionNames' => $block->getExpirableSectionNames(),
'cookieLifeTime' => $block->getCookieLifeTime(),
'updateSessionUrl' => $block->getCustomerDataUrl('customer/account/updateSession'),
]],
]);
?>
{
"*": {
"Magento_Customer/js/customer-data": {
"sectionLoadUrl": "<?= $block->escapeJs($block->escapeUrl($block->getCustomerDataUrl('customer/section/load'))) ?>",
"expirableSectionLifetime": <?= (int)$block->getExpirableSectionLifetime() ?>,
"expirableSectionNames": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getExpirableSectionNames()) ?>,
"cookieLifeTime": "<?= $block->escapeJs($block->getCookieLifeTime()) ?>",
"updateSessionUrl": "<?= $block->escapeJs($block->escapeUrl($block->getCustomerDataUrl('customer/account/updateSession'))) ?>"
}
}
}
</script>
@@ -7,18 +7,19 @@
/* @var $block \Magento\Customer\Block\CustomerScopeData */
?>
<script type="text/x-magento-init">
<?= /* @noEscape */ $block->encodeConfiguration([
'*' => ['Magento_Customer/js/invalidation-processor' => [
'invalidationRules' => [
'website-rule' => [
'Magento_Customer/js/invalidation-rules/website-rule' => [
'scopeConfig' => [
'websiteId' => $block->getWebsiteId(),
]
]
]
]
]],
]);
?>
{
"*": {
"Magento_Customer/js/invalidation-processor": {
"invalidationRules": {
"website-rule": {
"Magento_Customer/js/invalidation-rules/website-rule": {
"scopeConfig": {
"websiteId": "<?= $block->escapeJs($block->getWebsiteId()) ?>"
}
}
}
}
}
}
}
</script>
@@ -7,15 +7,16 @@
/** @var \Magento\Customer\Block\SectionConfig $block */
?>
<script type="text/x-magento-init">
<?= /* @noEscape */ $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]),
]),
]],
]);
?>
{
"*": {
"Magento_Customer/js/section-config": {
"sections": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getSections()) ?>,
"clientSideSections": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getClientSideSections()) ?>,
"baseUrls": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode(array_unique([
$block->getUrl(null, ['_secure' => true]),
$block->getUrl(null, ['_secure' => false]),
])) ?>
}
}
}
</script>
@@ -59,7 +59,7 @@ $priceElementIdPrefix = $block->getPriceElementIdPrefix() ? $block->getPriceElem
$priceElementId = $priceElementIdPrefix . $productId . $block->getIdSuffix();
$popupId = 'msrp-popup-' . $productId . $block->getRandomString(20);
$data = ['addToCart' => [
$data = [
'origin'=> 'msrp',
'popupId' => '#' . $popupId,
'productName' => $block->escapeJs($block->escapeHtml($product->getName())),
@@ -72,11 +72,11 @@ $priceElementIdPrefix = $block->getPriceElementIdPrefix() ? $block->getPriceElem
'closeButtonId' => '#map-popup-close',
'addToCartUrl' => $addToCartUrl,
'paymentButtons' => '[data-label=or]'
]];
];
if ($block->getRequest()->getFullActionName() === 'catalog_product_view') {
$data['addToCart']['addToCartButton'] = '#product_addtocart_form [type=submit]';
$data['addToCartButton'] = '#product_addtocart_form [type=submit]';
} else {
$data['addToCart']['addToCartButton'] = sprintf(
$data['addToCartButton'] = sprintf(
'form:has(input[type="hidden"][name="product"][value="%s"]) button[type="submit"]',
(int) $productId . ',' .
sprintf(
@@ -91,7 +91,7 @@ $priceElementIdPrefix = $block->getPriceElementIdPrefix() ? $block->getPriceElem
id="<?= /* @noEscape */ ($popupId) ?>"
class="action map-show-info"
<?php //phpcs:disable ?>
data-mage-init='<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($data) ?>'>
data-mage-init='{"addToCart":<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($data) ?>}'>
<?php //phpcs:enable ?>
<?= $block->escapeHtml(__('Click for price')) ?>
</a>
@@ -8,30 +8,30 @@ use Magento\Paypal\Block\Express\InContext\Minicart\Button;
/** @var \Magento\Paypal\Block\Express\InContext\Component $block */
$configuration = [
'*' => [
'Magento_Paypal/js/in-context/express-checkout' => [
'id' => Button::PAYPAL_BUTTON_ID,
'path' => $block->getUrl(
'paypal/express/gettoken',
[
'_secure' => $block->getRequest()->isSecure()
]
),
'merchantId' => $block->getMerchantId(),
'button' => $block->isButtonContext(),
'clientConfig' => [
'locale' => $block->getLocale(),
'environment' => $block->getEnvironment(),
'button' => [
Button::PAYPAL_BUTTON_ID,
],
]
'id' => Button::PAYPAL_BUTTON_ID,
'path' => $block->getUrl(
'paypal/express/gettoken',
[
'_secure' => $block->getRequest()->isSecure()
]
),
'merchantId' => $block->getMerchantId(),
'button' => $block->isButtonContext(),
'clientConfig' => [
'locale' => $block->getLocale(),
'environment' => $block->getEnvironment(),
'button' => [
Button::PAYPAL_BUTTON_ID,
]
]
];
?>
<div style="display: none;" id="<?= /* @noEscape */ Button::PAYPAL_BUTTON_ID ?>"></div>
<script type="text/x-magento-init">
<?= /* @noEscape */ json_encode($configuration) ?>
{
"*": {
"Magento_Paypal/js/in-context/express-checkout": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($configuration) ?>
}
}
</script>
@@ -7,7 +7,9 @@
/**
* @var \Magento\Paypal\Block\Express\InContext\Minicart\SmartButton $block
*/
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getJsInitParams());
$widgetConfig = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['Magento_Paypal/js/in-context/button']);
?>
<div data-mage-init='<?= /* @noEscape */ $block->getJsInitParams() ?>'
<div data-mage-init='{"Magento_Paypal/js/in-context/button":<?= /* @noEscape */ $widgetConfig ?>}'
class="paypal checkout paypal-logo <?= $block->escapeHtml($block->getContainerId()) ?>-container">
</div>
</div>
@@ -5,7 +5,11 @@
*/
/**
* @var \Magento\Paypal\Block\Express\Shortcut $block
* @var \Magento\Paypal\Block\Express\InContext\SmartButton $block
*/
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getJsInitParams());
$widgetConfig = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode(
$widget['Magento_Paypal/js/in-context/product-express-checkout']
);
?>
<div data-mage-init='<?= /* @noEscape */ $block->getJsInitParams() ?>'></div>
<div data-mage-init='{"Magento_Paypal/js/in-context/product-express-checkout":<?= /* @noEscape */ $widgetConfig ?>}'></div>
@@ -19,20 +19,14 @@ var config = {
'jquery/hover-intent': ['jquery'],
'mage/adminhtml/backup': ['prototype'],
'mage/captcha': ['prototype'],
'mage/common': ['jquery'],
'mage/new-gallery': ['jquery'],
'mage/webapi': ['jquery'],
'jquery/ui': ['jquery'],
'MutationObserver': ['es6-collections'],
'moment': {
'exports': 'moment'
},
'matchMedia': {
'exports': 'mediaCheck'
},
'jquery/jquery-storageapi': {
'deps': ['jquery/jquery.cookie']
}
'magnifier/magnifier': ['jquery']
},
'paths': {
'jquery/validate': 'jquery/jquery.validate',
@@ -44,7 +44,7 @@ var config = {
'Magento_Theme/js/view/breadcrumbs': {
'Magento_Theme/js/view/add-home-breadcrumb': true
},
'jquery/jquery-ui': {
'jquery/ui-modules/dialog': {
'jquery/patches/jquery-ui': true
}
}
@@ -10,13 +10,12 @@
$group = $block->getGroupName();
$groupCss = $block->getGroupCss();
$groupBehavior = $block->getGroupBehaviour() ? $block->getGroupBehaviour() : '{"tabs":{"openedState":"active"}}';
?>
<?php if ($detailedInfoGroup = $block->getGroupChildNames($group, 'getChildHtml')) :?>
<div class="sections <?= $block->escapeHtmlAttr($groupCss) ?>">
<?php $layout = $block->getLayout(); ?>
<div class="section-items <?= $block->escapeHtmlAttr($groupCss) ?>-items"
data-mage-init='<?= $block->escapeHtmlAttr($groupBehavior) ?>'>
data-mage-init='{"tabs":{"openedState":"active"}}'>
<?php foreach ($detailedInfoGroup as $name) :?>
<?php
$html = $layout->renderElement($name);

0 comments on commit db43c11

Please sign in to comment.
You can’t perform that action at this time.