-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[Up port] Fixed the issue #19347. #19393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
tiagosampaio
wants to merge
2
commits into
magento:2.3-develop
from
tiagosampaio:2.3-develop-ISSUE-19347
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,8 @@ | |
|
|
||
| namespace Magento\Checkout\Block\Cart; | ||
|
|
||
| use Magento\Framework\View\Element\BlockInterface; | ||
| use Magento\Checkout\Block\Checkout\LayoutProcessorInterface; | ||
| use Magento\Framework\View\Element\BlockInterface; | ||
|
|
||
| /** | ||
| * Totals cart block. | ||
|
|
@@ -41,13 +41,19 @@ class Totals extends \Magento\Checkout\Block\Cart\AbstractCart | |
| */ | ||
| protected $layoutProcessors; | ||
|
|
||
| /** | ||
| * @var \Magento\Framework\Serialize\SerializerInterface | ||
| */ | ||
| private $serializer; | ||
|
|
||
| /** | ||
| * @param \Magento\Framework\View\Element\Template\Context $context | ||
| * @param \Magento\Customer\Model\Session $customerSession | ||
| * @param \Magento\Checkout\Model\Session $checkoutSession | ||
| * @param \Magento\Sales\Model\Config $salesConfig | ||
| * @param array $layoutProcessors | ||
| * @param array $data | ||
| * @param \Magento\Framework\Serialize\SerializerInterface $serializer | ||
| * @codeCoverageIgnore | ||
| */ | ||
| public function __construct( | ||
|
|
@@ -56,12 +62,15 @@ public function __construct( | |
| \Magento\Checkout\Model\Session $checkoutSession, | ||
| \Magento\Sales\Model\Config $salesConfig, | ||
| array $layoutProcessors = [], | ||
| array $data = [] | ||
| array $data = [], | ||
| \Magento\Framework\Serialize\SerializerInterface $serializer = null | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please inject this dependency via block argument in layout |
||
| ) { | ||
| $this->_salesConfig = $salesConfig; | ||
| parent::__construct($context, $customerSession, $checkoutSession, $data); | ||
| $this->_isScopePrivate = true; | ||
| $this->layoutProcessors = $layoutProcessors; | ||
| $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() | ||
| ->get(\Magento\Framework\Serialize\SerializerInterface::class); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -75,7 +84,7 @@ public function getJsLayout() | |
| $this->jsLayout = $processor->process($this->jsLayout); | ||
| } | ||
|
|
||
| return json_encode($this->jsLayout, JSON_HEX_TAG); | ||
| return $this->serializer->serialize($this->jsLayout); | ||
tiagosampaio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?php | ||
tiagosampaio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\Checkout\Model\Cart; | ||
|
|
||
| /** | ||
| * Provides the checkout configuration. | ||
| */ | ||
| class ConfigProvider implements \Magento\Framework\View\Element\Block\ArgumentInterface | ||
| { | ||
| /** | ||
| * @var \Magento\Checkout\Model\CompositeConfigProvider | ||
| */ | ||
| private $configProvider; | ||
|
|
||
| /** | ||
| * @var \Magento\Framework\Serialize\SerializerInterface | ||
| */ | ||
| private $serializer; | ||
|
|
||
| /** | ||
| * @var array | ||
| */ | ||
| private $providedConfig = null; | ||
|
|
||
| /** | ||
| * Config constructor. | ||
| * | ||
| * @param \Magento\Checkout\Model\CompositeConfigProvider $configProvider | ||
| * @param \Magento\Framework\Serialize\SerializerInterface $serializer | ||
| */ | ||
| public function __construct( | ||
| \Magento\Checkout\Model\CompositeConfigProvider $configProvider, | ||
| \Magento\Framework\Serialize\SerializerInterface $serializer | ||
| ) { | ||
| $this->configProvider = $configProvider; | ||
| $this->serializer = $serializer; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve checkout configuration | ||
| * | ||
| * @return array | ||
| */ | ||
| public function getCheckoutConfig() | ||
| { | ||
| if (null === $this->providedConfig) { | ||
| $this->providedConfig = $this->configProvider->getConfig(); | ||
| } | ||
|
|
||
| return $this->providedConfig; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve checkout serialized configuration | ||
| * | ||
| * @return bool|string | ||
| */ | ||
| public function getSerializedCheckoutConfig() | ||
| { | ||
| return $this->serializer->serialize($this->getCheckoutConfig()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
app/code/Magento/Checkout/Test/Unit/Model/Cart/ConfigProviderTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| namespace Magento\Checkout\Test\Unit\Model\Cart; | ||
|
|
||
| /** | ||
| * Test for Magento\Checkout\Model\Cart\ConfigProvider class. | ||
| */ | ||
| class ConfigProviderTest extends \PHPUnit\Framework\TestCase | ||
| { | ||
| /** | ||
| * @var \Magento\Checkout\Model\Cart\ConfigProvider | ||
| */ | ||
| private $model; | ||
|
|
||
| /** | ||
| * @var \PHPUnit_Framework_MockObject_MockObject | ||
| */ | ||
| private $cartConfigProvider; | ||
|
|
||
| /** | ||
| * @var \PHPUnit_Framework_MockObject_MockObject | ||
| */ | ||
| private $compositeConfigProvider; | ||
|
|
||
| /** | ||
| * @var \PHPUnit_Framework_MockObject_MockObject | ||
| */ | ||
| private $serializer; | ||
|
|
||
| protected function setUp() | ||
| { | ||
| $this->cartConfigProvider = $this->createMock(\Magento\Checkout\Model\Cart\ConfigProvider::class); | ||
| $this->compositeConfigProvider = $this->createMock(\Magento\Checkout\Model\CompositeConfigProvider::class); | ||
| $this->serializer = $this->createMock(\Magento\Framework\Serialize\SerializerInterface::class); | ||
|
|
||
| $this->model = new \Magento\Checkout\Model\Cart\ConfigProvider( | ||
| $this->compositeConfigProvider, | ||
| $this->serializer | ||
| ); | ||
| } | ||
|
|
||
| public function testGetCheckoutConfig() | ||
| { | ||
| $config = ['param' => 'value']; | ||
| $this->compositeConfigProvider | ||
| ->expects($this->once()) | ||
| ->method('getConfig') | ||
| ->willReturn($config); | ||
|
|
||
| $this->assertEquals($config, $this->model->getCheckoutConfig()); | ||
| } | ||
|
|
||
| public function testGetSerializedCheckoutConfig() | ||
| { | ||
| $config = '{"param":"value"}'; | ||
|
|
||
| $this->serializer | ||
| ->expects($this->once()) | ||
| ->method('serialize') | ||
| ->willReturn($config); | ||
|
|
||
| $this->assertEquals($config, $this->model->getSerializedCheckoutConfig()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,6 +133,7 @@ | |
| <container name="checkout.cart.totals.container" as="totals" label="Shopping Cart Totals"> | ||
| <block class="Magento\Checkout\Block\Cart\Totals" name="checkout.cart.totals" template="Magento_Checkout::cart/totals.phtml"> | ||
| <arguments> | ||
| <argument name="cart_config" xsi:type="object">Magento\Checkout\Model\Cart\ConfigProvider</argument> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please apply the same approach for other blocks' dependencies as well |
||
| <argument name="jsLayout" xsi:type="array"> | ||
| <item name="components" xsi:type="array"> | ||
| <item name="block-totals" xsi:type="array"> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|
|
||
| define([ | ||
| 'mage/url', | ||
| 'Magento_Ui/js/block-loader' | ||
| ], function (url, blockLoader) { | ||
| 'use strict'; | ||
|
|
||
| return function (config) { | ||
| window.checkoutConfig = config.checkoutConfig; | ||
| window.customerData = window.checkoutConfig.customerData; | ||
| window.isCustomerLoggedIn = window.checkoutConfig.isCustomerLoggedIn; | ||
|
|
||
| blockLoader(config.loaderFile); | ||
| url.setBaseUrl(config.baseUrl); | ||
| }; | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please inject this class via block argument in layout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sivaschenko
Based on the discussion in #23733 I think it's not backwards compatible to add block arguments via layout xml?
If custom modules try to instantiate the same block class in some custom xml file, then after upgrading Magento the module might crash as it's missing some arguments which are then undefined but still being used by the phtml file.
Can you double check this?